mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 01:52:26 +08:00
address comments from CR
This commit is contained in:
@ -349,7 +349,8 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg
|
|||||||
keys = append(keys, block.Key())
|
keys = append(keys, block.Key())
|
||||||
}
|
}
|
||||||
|
|
||||||
return bs.cancelBlocks(ctx, keys)
|
bs.cancelBlocks(ctx, keys)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connected/Disconnected warns bitswap about peer connections
|
// Connected/Disconnected warns bitswap about peer connections
|
||||||
@ -369,9 +370,9 @@ func (bs *Bitswap) PeerDisconnected(p peer.ID) {
|
|||||||
bs.engine.PeerDisconnected(p)
|
bs.engine.PeerDisconnected(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bs *Bitswap) cancelBlocks(ctx context.Context, bkeys []u.Key) error {
|
func (bs *Bitswap) cancelBlocks(ctx context.Context, bkeys []u.Key) {
|
||||||
if len(bkeys) < 1 {
|
if len(bkeys) < 1 {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
message := bsmsg.New()
|
message := bsmsg.New()
|
||||||
message.SetFull(false)
|
message.SetFull(false)
|
||||||
@ -379,14 +380,21 @@ func (bs *Bitswap) cancelBlocks(ctx context.Context, bkeys []u.Key) error {
|
|||||||
log.Debug("cancel block: %s", k)
|
log.Debug("cancel block: %s", k)
|
||||||
message.Cancel(k)
|
message.Cancel(k)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
for _, p := range bs.engine.Peers() {
|
for _, p := range bs.engine.Peers() {
|
||||||
err := bs.send(ctx, p, message)
|
wg.Add(1)
|
||||||
if err != nil {
|
go func(p peer.ID) {
|
||||||
log.Debugf("Error sending message: %s", err)
|
defer wg.Done()
|
||||||
return err
|
err := bs.send(ctx, p, message)
|
||||||
}
|
if err != nil {
|
||||||
|
log.Warningf("Error sending message: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}(p)
|
||||||
}
|
}
|
||||||
return nil
|
wg.Wait()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bs *Bitswap) wantNewBlocks(ctx context.Context, bkeys []u.Key) {
|
func (bs *Bitswap) wantNewBlocks(ctx context.Context, bkeys []u.Key) {
|
||||||
|
Reference in New Issue
Block a user