Skip to content

Commit

Permalink
fix(network): close connection when unbale to get supported protocols (
Browse files Browse the repository at this point in the history
  • Loading branch information
themantre authored Oct 24, 2023
1 parent 9498ba9 commit 70bd1eb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
7 changes: 0 additions & 7 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,6 @@ func (n *network) Start() error {
n.gossip.Start()
n.stream.Start()

if n.config.EnableRelay {
for _, relayAddr := range n.config.RelayAddrs {
addrInfo, _ := MakeAddressInfo(relayAddr)
ConnectAsync(n.ctx, n.host, *addrInfo, n.logger)
}
}

n.logger.Info("network started", "addr", n.host.Addrs())
return nil
}
Expand Down
7 changes: 5 additions & 2 deletions network/notifee.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

type NotifeeService struct {
host lp2phost.Host
eventChannel chan<- Event
logger *logger.SubLogger
protocolID protocol.ID
Expand All @@ -20,6 +21,7 @@ func newNotifeeService(host lp2phost.Host, eventChannel chan<- Event,
logger *logger.SubLogger, protocolID protocol.ID,
) *NotifeeService {
notifee := &NotifeeService{
host: host,
eventChannel: eventChannel,
logger: logger,
protocolID: protocolID,
Expand All @@ -36,7 +38,7 @@ func (n *NotifeeService) Connected(lp2pn lp2pnetwork.Network, conn lp2pnetwork.C
for i := 0; i < 10; i++ {
// TODO: better way?
// Wait to complete libp2p identify
time.Sleep(500 * time.Millisecond)
time.Sleep(1 * time.Second)

protocols, _ := lp2pn.Peerstore().SupportsProtocols(peerID, n.protocolID)
if len(protocols) > 0 {
Expand All @@ -45,7 +47,8 @@ func (n *NotifeeService) Connected(lp2pn lp2pnetwork.Network, conn lp2pnetwork.C
}
}

n.logger.Info("this node doesn't support stream protocol", "pid", peerID)
n.logger.Info("unable to get supported protocols", "pid", peerID)
_ = n.host.Network().ClosePeer(peerID)
}()
}

Expand Down
2 changes: 1 addition & 1 deletion network/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *streamService) Stop() {
func (s *streamService) handleStream(stream lp2pnetwork.Stream) {
from := stream.Conn().RemotePeer()

s.logger.Debug("receiving stream", "from", from)
s.logger.Trace("receiving stream", "from", from)
event := &StreamMessage{
Source: from,
Reader: stream,
Expand Down

0 comments on commit 70bd1eb

Please sign in to comment.