Merge pull request #11262 from filecoin-project/steb/fix-dial-spam
fix: networking: avoid dialing when trying to handshake peers
This commit is contained in:
commit
e06604d342
@ -11,8 +11,8 @@ import (
|
|||||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||||
"github.com/libp2p/go-libp2p/core/event"
|
"github.com/libp2p/go-libp2p/core/event"
|
||||||
"github.com/libp2p/go-libp2p/core/host"
|
"github.com/libp2p/go-libp2p/core/host"
|
||||||
|
"github.com/libp2p/go-libp2p/core/network"
|
||||||
"github.com/libp2p/go-libp2p/core/peer"
|
"github.com/libp2p/go-libp2p/core/peer"
|
||||||
"github.com/libp2p/go-libp2p/core/protocol"
|
|
||||||
"github.com/libp2p/go-libp2p/p2p/host/eventbus"
|
"github.com/libp2p/go-libp2p/p2p/host/eventbus"
|
||||||
"go.uber.org/fx"
|
"go.uber.org/fx"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
@ -66,18 +66,22 @@ func RunHello(mctx helpers.MetricsCtx, lc fx.Lifecycle, h host.Host, svc *hello.
|
|||||||
ctx := helpers.LifecycleCtx(mctx, lc)
|
ctx := helpers.LifecycleCtx(mctx, lc)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
// We want to get information on connected peers, we don't want to trigger new connections.
|
||||||
|
ctx := network.WithNoDial(ctx, "filecoin hello")
|
||||||
for evt := range sub.Out() {
|
for evt := range sub.Out() {
|
||||||
pic := evt.(event.EvtPeerIdentificationCompleted)
|
pic := evt.(event.EvtPeerIdentificationCompleted)
|
||||||
|
// We just finished identifying the peer, that means we should know what
|
||||||
|
// protocols it speaks. Check if it speeks the Filecoin hello protocol
|
||||||
|
// before continuing.
|
||||||
|
if p, _ := h.Peerstore().FirstSupportedProtocol(pic.Peer, hello.ProtocolID); p != hello.ProtocolID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
if err := svc.SayHello(ctx, pic.Peer); err != nil {
|
if err := svc.SayHello(ctx, pic.Peer); err != nil {
|
||||||
protos, _ := h.Peerstore().GetProtocols(pic.Peer)
|
protos, _ := h.Peerstore().GetProtocols(pic.Peer)
|
||||||
agent, _ := h.Peerstore().Get(pic.Peer, "AgentVersion")
|
agent, _ := h.Peerstore().Get(pic.Peer, "AgentVersion")
|
||||||
if protosContains(protos, hello.ProtocolID) {
|
|
||||||
log.Warnw("failed to say hello", "error", err, "peer", pic.Peer, "supported", protos, "agent", agent)
|
log.Warnw("failed to say hello", "error", err, "peer", pic.Peer, "supported", protos, "agent", agent)
|
||||||
} else {
|
|
||||||
log.Debugw("failed to say hello", "error", err, "peer", pic.Peer, "supported", protos, "agent", agent)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
@ -85,15 +89,6 @@ func RunHello(mctx helpers.MetricsCtx, lc fx.Lifecycle, h host.Host, svc *hello.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func protosContains(protos []protocol.ID, search protocol.ID) bool {
|
|
||||||
for _, p := range protos {
|
|
||||||
if p == search {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func RunPeerMgr(mctx helpers.MetricsCtx, lc fx.Lifecycle, pmgr *peermgr.PeerMgr) {
|
func RunPeerMgr(mctx helpers.MetricsCtx, lc fx.Lifecycle, pmgr *peermgr.PeerMgr) {
|
||||||
go pmgr.Run(helpers.LifecycleCtx(mctx, lc))
|
go pmgr.Run(helpers.LifecycleCtx(mctx, lc))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user