Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(network): close connection when unbale to get supported protocols #781

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
)

type NotifeeService struct {
host lp2phost.Host
eventChannel chan<- Event
logger *logger.SubLogger
protocolID protocol.ID
Expand All @@ -20,6 +21,7 @@
logger *logger.SubLogger, protocolID protocol.ID,
) *NotifeeService {
notifee := &NotifeeService{
host: host,
eventChannel: eventChannel,
logger: logger,
protocolID: protocolID,
Expand All @@ -36,7 +38,7 @@
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 @@
}
}

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)

Check warning on line 51 in network/notifee.go

View check run for this annotation

Codecov / codecov/patch

network/notifee.go#L50-L51

Added lines #L50 - L51 were not covered by tests
}()
}

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
Loading