Skip to content

Commit

Permalink
fix: reduce nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
metacertain committed Jul 2, 2021
1 parent a2a0fb5 commit efa8966
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions pkg/pushsync/pushsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,26 +299,27 @@ func (ps *PushSync) pushToClosest(ctx context.Context, ch swarm.Chunk, retryAllo
return nil, ErrWarmup
}

if ps.topologyDriver.IsWithinDepth(ch.Address()) {
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.
_ = ps.topologyDriver.EachNeighbor(func(peer swarm.Address, po uint8) (bool, bool, error) {
// skip forwarding peer
if peer.Equal(origin) {
return false, false, nil
}

if count == nPeersToPushsync {
return true, false, nil
}
count++
go ps.pushToNeighbour(peer, ch, retryAllowed)
return false, false, nil
})
return nil, err
if !ps.topologyDriver.IsWithinDepth(ch.Address()) {
return nil, ErrNoPush
}
return nil, fmt.Errorf("closest peer: none available")

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.
_ = ps.topologyDriver.EachNeighbor(func(peer swarm.Address, po uint8) (bool, bool, error) {
// skip forwarding peer
if peer.Equal(origin) {
return false, false, nil
}

if count == nPeersToPushsync {
return true, false, nil
}
count++
go ps.pushToNeighbour(peer, ch, retryAllowed)
return false, false, nil
})
return nil, err
}
return nil, fmt.Errorf("closest peer: %w", err)
}
Expand Down

0 comments on commit efa8966

Please sign in to comment.