mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
p2p/protocols: add ClonePeer
This commit is contained in:
parent
a05e6d2d2f
commit
0697704f5f
2 changed files with 15 additions and 1 deletions
|
|
@ -222,6 +222,15 @@ func NewPeer(p *p2p.Peer, rw p2p.MsgReadWriter, spec *Spec) *Peer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClonePeer constructs a peer object with an arbitrary Spec, based on an existing Peer
|
||||||
|
func ClonePeer(p *Peer, spec *Spec) *Peer {
|
||||||
|
return &Peer{
|
||||||
|
Peer: p.Peer,
|
||||||
|
rw: p.rw,
|
||||||
|
spec: spec,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Run starts the forever loop that handles incoming messages
|
// Run starts the forever loop that handles incoming messages
|
||||||
// called within the p2p.Protocol#Run function
|
// called within the p2p.Protocol#Run function
|
||||||
// the handler argument is a function which is called for each message received
|
// the handler argument is a function which is called for each message received
|
||||||
|
|
|
||||||
|
|
@ -904,7 +904,12 @@ func sendMsg(p *Pss, sp *network.Peer, msg *PssMsg) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
err := sp.Send(context.TODO(), msg)
|
// get a Peer value, which supports the `pss` protocol
|
||||||
|
// `sp.BzzPeer.Peer` is a protocols.Peer, which is linked to the `hive` protocol, and
|
||||||
|
// doesn't support `pss` protocol messages.
|
||||||
|
pp := protocols.ClonePeer(sp.BzzPeer.Peer, pssSpec)
|
||||||
|
|
||||||
|
err := pp.Send(context.TODO(), msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
metrics.GetOrRegisterCounter("pss.pp.send.error", nil).Inc(1)
|
metrics.GetOrRegisterCounter("pss.pp.send.error", nil).Inc(1)
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue