mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-02-24 06:23:15 +00:00
Merge pull request #100 from libp2p/fix/issue-98
fix data race in gossipsub piggybacking
This commit is contained in:
commit
35c945373f
10
comm.go
10
comm.go
@ -122,3 +122,13 @@ func rpcWithControl(msgs []*pb.Message,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func copyRPC(rpc *RPC) *RPC {
|
||||
res := new(RPC)
|
||||
*res = *rpc
|
||||
if rpc.Control != nil {
|
||||
res.Control = new(pb.ControlMessage)
|
||||
*res.Control = *rpc.Control
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
@ -308,9 +308,14 @@ func (gs *GossipSubRouter) sendPrune(p peer.ID, topic string) {
|
||||
}
|
||||
|
||||
func (gs *GossipSubRouter) sendRPC(p peer.ID, out *RPC) {
|
||||
// do we own the RPC?
|
||||
own := false
|
||||
|
||||
// piggyback cotrol message retries
|
||||
ctl, ok := gs.control[p]
|
||||
if ok {
|
||||
out = copyRPC(out)
|
||||
own = true
|
||||
gs.piggybackControl(p, out, ctl)
|
||||
delete(gs.control, p)
|
||||
}
|
||||
@ -318,6 +323,10 @@ func (gs *GossipSubRouter) sendRPC(p peer.ID, out *RPC) {
|
||||
// piggyback gossip
|
||||
ihave, ok := gs.gossip[p]
|
||||
if ok {
|
||||
if !own {
|
||||
out = copyRPC(out)
|
||||
own = true
|
||||
}
|
||||
gs.piggybackGossip(p, out, ihave)
|
||||
delete(gs.gossip, p)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user