Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Jul 11, 2018
1 parent 6181e0a commit f453955
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
15 changes: 9 additions & 6 deletions modules/renter/siafile/metadata.go
Expand Up @@ -13,12 +13,15 @@ import (
type (
// Metadata is the metadata of a SiaFile and is JSON encoded.
Metadata struct {
staticVersion [16]byte // version of the sia file format used
staticFileSize int64 // total size of the file
staticMasterKey crypto.TwofishKey // masterkey used to encrypt pieces
staticPieceSize uint64 // size of a single piece of the file
localPath string // file to the local copy of the file used for repairing
siaPath string // the path of the file on the Sia network
staticVersion [16]byte // version of the sia file format used
staticFileSize int64 // total size of the file
staticPieceSize uint64 // size of a single piece of the file
localPath string // file to the local copy of the file used for repairing
siaPath string // the path of the file on the Sia network

// fields for encryption
staticMasterKey crypto.TwofishKey // masterkey used to encrypt pieces
staticSharingKey crypto.TwofishKey // key used to encrypt shared pieces

// The following fields are the usual unix timestamps of files.
modTime time.Time // time of last content modification
Expand Down
5 changes: 3 additions & 2 deletions modules/renter/siafile/siafile.go
Expand Up @@ -69,7 +69,6 @@ type (

// Piece represents a single piece of a chunk on disk
Piece struct {
KeyNonce [4]byte // nonce used for encrypting the piece
HostPubKey types.SiaPublicKey // public key of the host
MerkleRoot crypto.Hash // merkle root of the piece
}
Expand Down Expand Up @@ -270,7 +269,9 @@ func (sf *SiaFile) Redundancy(offlineMap map[string]bool, goodForRenewMap map[st
// a better user experience. If the renter operates correctly, redundancy
// should never go above numPieces / minPieces and redundancyNoRenew should
// never go below 1.
if minRedundancy < 1 {
if minRedundancy < 1 && minRedundancyNoRenew >= 1 {
return 1
} else if minRedunancy < 1 {
return minRedundancyNoRenew
}
return minRedundancy
Expand Down
2 changes: 1 addition & 1 deletion modules/renter/upload.go
Expand Up @@ -28,7 +28,7 @@ var (
errUploadDirectory = errors.New("cannot upload directory")
)

// newFile is a helper to more easily create a new Siafile for testing.
// newFile is a helper to more easily create a new Siafile.
func newFile(name string, rsc modules.ErasureCoder, pieceSize, fileSize uint64, mode os.FileMode, source string) *siafile.SiaFile {
numChunks := 1
chunkSize := pieceSize * uint64(rsc.MinPieces())
Expand Down
17 changes: 10 additions & 7 deletions modules/renter/uploadheap.go
Expand Up @@ -173,9 +173,9 @@ func (r *Renter) buildUnfinishedChunks(f *siafile.SiaFile, hosts map[string]stru
pks[string(pk.Key)] = pk
}

// Iterate through the pieces of the file and mark which hosts are already
// in use for the chunk. As you delete hosts from the 'unusedHosts' map,
// also increment the 'piecesCompleted' value.
// Iterate through the pieces of all chunks of the file and mark which
// hosts are already in use for a particular chunk. As you delete hosts
// from the 'unusedHosts' map, also increment the 'piecesCompleted' value.
for chunkIndex := uint64(0); chunkIndex < f.NumChunks(); chunkIndex++ {
pieces, err := f.Pieces(chunkIndex)
if err != nil {
Expand Down Expand Up @@ -208,10 +208,13 @@ func (r *Renter) buildUnfinishedChunks(f *siafile.SiaFile, hosts map[string]stru
newUnfinishedChunks[chunkIndex].piecesCompleted++
delete(newUnfinishedChunks[chunkIndex].unusedHosts, pk.String())
} else if exists {
// This host has a piece, but it is the same piece another host
// has. We should still remove the host from the unusedHosts
// since one host having multiple pieces of a chunk might lead
// to unexpected issues.
// This host has a piece, but it is the same piece another
// host has. We should still remove the host from the
// unusedHosts since one host having multiple pieces of a
// chunk might lead to unexpected issues. e.g. if a host
// has multiple pieces and another host with redundant
// pieces goes offline, we end up with false redundancy
// reporting.
delete(newUnfinishedChunks[chunkIndex].unusedHosts, pk.String())
}
}
Expand Down

0 comments on commit f453955

Please sign in to comment.