Skip to content

Commit

Permalink
fix: not close connection for bootstrap nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
themantre committed Nov 3, 2023
1 parent d87b82a commit 34c2fb7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func newNetwork(networkName string, conf *Config, opts []lp2p.Option) (*network,
n.peerMgr = newPeerMgr(ctx, host, n.dht.kademlia, conf, n.logger)
n.stream = newStreamService(ctx, n.host, streamProtocolID, relayAddrs, n.eventChannel, n.logger)
n.gossip = newGossipService(ctx, n.host, n.eventChannel, conf, n.logger)
n.notifee = newNotifeeService(n.host, n.eventChannel, n.logger, streamProtocolID)
n.notifee = newNotifeeService(n.host, n.eventChannel, n.logger, streamProtocolID, conf.Bootstrapper)

n.host.Network().Notify(n.notifee)

Expand Down
10 changes: 7 additions & 3 deletions network/notifee.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ type NotifeeService struct {
eventChannel chan<- Event
logger *logger.SubLogger
protocolID protocol.ID
bootstrapper bool
}

func newNotifeeService(host lp2phost.Host, eventChannel chan<- Event,
log *logger.SubLogger, protocolID protocol.ID,
log *logger.SubLogger, protocolID protocol.ID, bootstrapper bool,
) *NotifeeService {
notifee := &NotifeeService{
host: host,
eventChannel: eventChannel,
logger: log,
protocolID: protocolID,
bootstrapper: bootstrapper,
}
host.Network().Notify(notifee)
return notifee
Expand All @@ -49,8 +51,10 @@ func (n *NotifeeService) Connected(lp2pn lp2pnetwork.Network, conn lp2pnetwork.C

n.logger.Info("unable to get supported protocols", "pid", peerID)

// Close this connection since we can't send a direct message to this peer.
_ = n.host.Network().ClosePeer(peerID)
if !n.bootstrapper {

Check warning on line 54 in network/notifee.go

View check run for this annotation

Codecov / codecov/patch

network/notifee.go#L54

Added line #L54 was not covered by tests
// Close this connection since we can't send a direct message to this peer.
_ = n.host.Network().ClosePeer(peerID)

Check warning on line 56 in network/notifee.go

View check run for this annotation

Codecov / codecov/patch

network/notifee.go#L56

Added line #L56 was not covered by tests
}
}()
}

Expand Down

0 comments on commit 34c2fb7

Please sign in to comment.