swarm/storage/mru: Fixes/comments as per review

cmd/swarm: remove rogue fmt

swarm/storage/mru: Add version / header for future use-
This commit is contained in:
Javier Peletier 2018-09-28 10:19:04 +02:00
parent 2d212ed246
commit 07c2aa7047
4 changed files with 31 additions and 36 deletions

BIN
cmd/swarm/swarm Executable file

Binary file not shown.

View file

@ -112,9 +112,12 @@ func (h *Handler) Validate(chunkAddr storage.Address, data []byte) bool {
// GetContent retrieves the data payload of the last synced update of the Mutable Resource // GetContent retrieves the data payload of the last synced update of the Mutable Resource
func (h *Handler) GetContent(view *View) (storage.Address, []byte, error) { func (h *Handler) GetContent(view *View) (storage.Address, []byte, error) {
if view == nil {
return nil, nil, NewError(ErrInvalidValue, "view is nil")
}
rsrc := h.get(view) rsrc := h.get(view)
if rsrc == nil { if rsrc == nil {
return nil, nil, NewError(ErrNotFound, " does not exist") return nil, nil, NewError(ErrNotFound, "resource does not exist")
} }
return rsrc.lastKey, rsrc.data, nil return rsrc.lastKey, rsrc.data, nil
} }
@ -279,10 +282,6 @@ func (h *Handler) Update(ctx context.Context, r *Request) (updateAddr storage.Ad
// Retrieves the resource cache value for the given nameHash // Retrieves the resource cache value for the given nameHash
func (h *Handler) get(view *View) *cacheEntry { func (h *Handler) get(view *View) *cacheEntry {
if view == nil {
log.Warn("Handler.get with invalid View")
return nil
}
mapKey := view.mapKey() mapKey := view.mapKey()
h.resourceLock.RLock() h.resourceLock.RLock()
defer h.resourceLock.RUnlock() defer h.resourceLock.RUnlock()
@ -292,10 +291,6 @@ func (h *Handler) get(view *View) *cacheEntry {
// Sets the resource cache value for the given View // Sets the resource cache value for the given View
func (h *Handler) set(view *View, rsrc *cacheEntry) { func (h *Handler) set(view *View, rsrc *cacheEntry) {
if view == nil {
log.Warn("Handler.set with invalid View")
return
}
mapKey := view.mapKey() mapKey := view.mapKey()
h.resourceLock.Lock() h.resourceLock.Lock()
defer h.resourceLock.Unlock() defer h.resourceLock.Unlock()

View file

@ -74,7 +74,7 @@ func Hint(last uint64) Epoch {
// but limited to not return a level that is smaller than the last-1 // but limited to not return a level that is smaller than the last-1
func GetNextLevel(last Epoch, now uint64) uint8 { func GetNextLevel(last Epoch, now uint64) uint8 {
// First XOR the last epoch base time with the current clock. // First XOR the last epoch base time with the current clock.
// This will set all the common most significant bits will to zero. // This will set all the common most significant bits to zero.
mix := (last.Base() ^ now) mix := (last.Base() ^ now)
// Then, make sure we stop the below loop before one level below the current, by setting // Then, make sure we stop the below loop before one level below the current, by setting
@ -149,7 +149,8 @@ func FluzCapacitorAlgorithm(now uint64, hint Epoch, read ReadFunc) (value interf
return value, nil return value, nil
} }
hint = epoch hint = epoch
} else { continue
}
if epoch.Base() == hint.Base() { if epoch.Base() == hint.Base() {
if lastFound != nil { if lastFound != nil {
return lastFound, nil return lastFound, nil
@ -177,4 +178,3 @@ func FluzCapacitorAlgorithm(now uint64, hint Epoch, read ReadFunc) (value interf
t = base - 1 t = base - 1
} }
} }
}

View file

@ -183,7 +183,7 @@ func TestEncodingDecodingUpdateRequests(t *testing.T) {
} }
// mess with the lookup key to make sure Verify fails: // mess with the lookup key to make sure Verify fails:
recoveredRequest.Time = 77999 recoveredRequest.Time = 77999 // this will alter the lookup key
if err = recoveredRequest.Verify(); err == nil { if err = recoveredRequest.Verify(); err == nil {
t.Fatalf("Expected Verify to fail since the lookup key has been altered") t.Fatalf("Expected Verify to fail since the lookup key has been altered")
} }
@ -212,7 +212,7 @@ func TestUpdateChunkSerializationErrorChecking(t *testing.T) {
r.data = []byte("Al bien hacer jamás le falta premio") // put some arbitrary length data r.data = []byte("Al bien hacer jamás le falta premio") // put some arbitrary length data
_, err = r.toChunk() _, err = r.toChunk()
if err == nil { if err == nil {
t.Fatal("expected request.toChunk to fail when there is no signature", err) t.Fatal("expected request.toChunk to fail when there is no signature")
} }
charlie := newCharlieSigner() charlie := newCharlieSigner()
@ -309,6 +309,6 @@ func TestReverse(t *testing.T) {
t.Fatalf("Expected epoch to be '%s', was '%s'", epoch.String(), checkUpdate.Epoch.String()) t.Fatalf("Expected epoch to be '%s', was '%s'", epoch.String(), checkUpdate.Epoch.String())
} }
if !bytes.Equal(data, checkUpdate.data) { if !bytes.Equal(data, checkUpdate.data) {
t.Fatalf("Expectedn data '%x', was '%x'", data, checkUpdate.data) t.Fatalf("Expected data '%x', was '%x'", data, checkUpdate.data)
} }
} }