mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
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:
parent
2d212ed246
commit
07c2aa7047
4 changed files with 31 additions and 36 deletions
BIN
cmd/swarm/swarm
Executable file
BIN
cmd/swarm/swarm
Executable file
Binary file not shown.
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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,7 +149,8 @@ func FluzCapacitorAlgorithm(now uint64, hint Epoch, read ReadFunc) (value interf
|
|||
return value, nil
|
||||
}
|
||||
hint = epoch
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
if epoch.Base() == hint.Base() {
|
||||
if lastFound != nil {
|
||||
return lastFound, nil
|
||||
|
|
@ -177,4 +178,3 @@ func FluzCapacitorAlgorithm(now uint64, hint Epoch, read ReadFunc) (value interf
|
|||
t = base - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue