Skip to content

Commit

Permalink
fix: only in neighborhood replication
Browse files Browse the repository at this point in the history
  • Loading branch information
metacertain authored and istae committed Jul 6, 2021
1 parent 67a4212 commit 04fed0e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 4 additions & 0 deletions pkg/pushsync/pushsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ func (ps *PushSync) pushToClosest(ctx context.Context, ch swarm.Chunk, retryAllo
return nil, ErrWarmup
}

if !ps.topologyDriver.IsWithinDepth(ch.Address()) {
return nil, ErrNoPush
}

count := 0
// Push the chunk to some peers in the neighborhood in parallel for replication.
// Any errors here should NOT impact the rest of the handler.
Expand Down
6 changes: 1 addition & 5 deletions pkg/pushsync/pushsync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,9 @@ func TestReplicateBeforeReceipt(t *testing.T) {
defer storerEmpty.Close()
emptyRecorder := streamtest.New(streamtest.WithProtocols(psEmpty.Protocol()), streamtest.WithBaseAddr(secondPeer))

wFunc := func(addr swarm.Address) bool {
return true
}

// node that is connected to closestPeer
// will receieve chunk from closestPeer
psSecond, storerSecond, _, secondAccounting := createPushSyncNode(t, secondPeer, defaultPrices, emptyRecorder, nil, defaultSigner, mock.WithPeers(emptyPeer), mock.WithIsWithinFunc(wFunc))
psSecond, storerSecond, _, secondAccounting := createPushSyncNode(t, secondPeer, defaultPrices, emptyRecorder, nil, defaultSigner, mock.WithPeers(emptyPeer))
defer storerSecond.Close()
secondRecorder := streamtest.New(streamtest.WithProtocols(psSecond.Protocol()), streamtest.WithBaseAddr(closestPeer))

Expand Down
2 changes: 1 addition & 1 deletion pkg/topology/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (m *mock) IsWithinDepth(addr swarm.Address) bool {
if m.isWithinFunc != nil {
return m.isWithinFunc(addr)
}
return false
return true
}

func (m *mock) EachNeighbor(f topology.EachPeerFunc) error {
Expand Down

0 comments on commit 04fed0e

Please sign in to comment.