From f453955e226c574991dd43ad6226c56d2b69e0db Mon Sep 17 00:00:00 2001 From: Christopher Schinnerl Date: Wed, 11 Jul 2018 10:07:25 -0400 Subject: [PATCH] review comments --- modules/renter/siafile/metadata.go | 15 +++++++++------ modules/renter/siafile/siafile.go | 5 +++-- modules/renter/upload.go | 2 +- modules/renter/uploadheap.go | 17 ++++++++++------- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/modules/renter/siafile/metadata.go b/modules/renter/siafile/metadata.go index 4d2c6137f5..6ccab5c0ab 100644 --- a/modules/renter/siafile/metadata.go +++ b/modules/renter/siafile/metadata.go @@ -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 diff --git a/modules/renter/siafile/siafile.go b/modules/renter/siafile/siafile.go index 41b5184719..169d226c19 100644 --- a/modules/renter/siafile/siafile.go +++ b/modules/renter/siafile/siafile.go @@ -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 } @@ -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 diff --git a/modules/renter/upload.go b/modules/renter/upload.go index 6bf3d51985..6690a635ea 100644 --- a/modules/renter/upload.go +++ b/modules/renter/upload.go @@ -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()) diff --git a/modules/renter/uploadheap.go b/modules/renter/uploadheap.go index 1d8915bf2f..c1b0d0d06f 100644 --- a/modules/renter/uploadheap.go +++ b/modules/renter/uploadheap.go @@ -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 { @@ -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()) } }