diff --git a/cmd/swarm/swarm b/cmd/swarm/swarm new file mode 100755 index 0000000000..26952e479d Binary files /dev/null and b/cmd/swarm/swarm differ diff --git a/swarm/storage/mru/handler.go b/swarm/storage/mru/handler.go index b615e1b077..3e76547953 100644 --- a/swarm/storage/mru/handler.go +++ b/swarm/storage/mru/handler.go @@ -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 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) 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 } @@ -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 func (h *Handler) get(view *View) *cacheEntry { - if view == nil { - log.Warn("Handler.get with invalid View") - return nil - } mapKey := view.mapKey() h.resourceLock.RLock() defer h.resourceLock.RUnlock() @@ -292,10 +291,6 @@ func (h *Handler) get(view *View) *cacheEntry { // Sets the resource cache value for the given View func (h *Handler) set(view *View, rsrc *cacheEntry) { - if view == nil { - log.Warn("Handler.set with invalid View") - return - } mapKey := view.mapKey() h.resourceLock.Lock() defer h.resourceLock.Unlock() diff --git a/swarm/storage/mru/lookup/lookup.go b/swarm/storage/mru/lookup/lookup.go index 7d0b4af18e..c98248d70b 100644 --- a/swarm/storage/mru/lookup/lookup.go +++ b/swarm/storage/mru/lookup/lookup.go @@ -74,7 +74,7 @@ func Hint(last uint64) Epoch { // but limited to not return a level that is smaller than the last-1 func GetNextLevel(last Epoch, now uint64) uint8 { // 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) // Then, make sure we stop the below loop before one level below the current, by setting @@ -149,32 +149,32 @@ func FluzCapacitorAlgorithm(now uint64, hint Epoch, read ReadFunc) (value interf return value, nil } hint = epoch - } else { - if epoch.Base() == hint.Base() { - if lastFound != nil { - return lastFound, nil - } - // we have reached the hint itself - if hint == worstHint { - return nil, nil - } - // check it out - value, err = read(hint, now) - if err != nil { - return nil, err - } - if value != nil { - return value, nil - } - // bad hint. - epoch = hint - hint = worstHint + continue + } + if epoch.Base() == hint.Base() { + if lastFound != nil { + return lastFound, nil } - base := epoch.Base() - if base == 0 { + // we have reached the hint itself + if hint == worstHint { return nil, nil } - t = base - 1 + // check it out + value, err = read(hint, now) + if err != nil { + return nil, err + } + if value != nil { + return value, nil + } + // bad hint. + epoch = hint + hint = worstHint } + base := epoch.Base() + if base == 0 { + return nil, nil + } + t = base - 1 } } diff --git a/swarm/storage/mru/request_test.go b/swarm/storage/mru/request_test.go index 87eef99a0f..c32d5ec136 100644 --- a/swarm/storage/mru/request_test.go +++ b/swarm/storage/mru/request_test.go @@ -183,7 +183,7 @@ func TestEncodingDecodingUpdateRequests(t *testing.T) { } // 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 { 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 _, err = r.toChunk() 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() @@ -309,6 +309,6 @@ func TestReverse(t *testing.T) { t.Fatalf("Expected epoch to be '%s', was '%s'", epoch.String(), checkUpdate.Epoch.String()) } 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) } }