Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
review feedback
Browse files Browse the repository at this point in the history
iansuvak committed Aug 31, 2023
1 parent 4d94d5a commit 55a0f95
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions network/p2pNetwork.go
Original file line number Diff line number Diff line change
@@ -163,7 +163,6 @@ func (n *P2PNetwork) Stop() {

// innerStop context for shutting down peers
func (n *P2PNetwork) innerStop() {
n.log.Warn("Entering innerStop()")
closeGroup := sync.WaitGroup{}
n.wsPeersLock.Lock()
closeGroup.Add(len(n.wsPeers))
@@ -235,23 +234,22 @@ func (n *P2PNetwork) Relay(ctx context.Context, tag protocol.Tag, data []byte, w

// Disconnect from a peer, probably due to protocol errors.
func (n *P2PNetwork) Disconnect(badnode Peer) {
switch node := badnode.(type) {
case peer.ID:
n.wsPeersLock.Lock()
defer n.wsPeersLock.Unlock()
if wsPeer, ok := n.wsPeers[node]; ok {
wsPeer.CloseAndWait(time.Now().Add(peerDisconnectionAckDuration))
delete(n.wsPeers, node)
} else {
n.log.Warnf("Could not find wsPeer reference for peer %s", node)
}
err := n.service.ClosePeer(node)
if err != nil {
n.log.Warnf("Error disconnecting from peer %s: %v", node, err)
}

default:
node, ok := badnode.(peer.ID)
if !ok {

Check warning on line 238 in network/p2pNetwork.go

Codecov / codecov/patch

network/p2pNetwork.go#L237-L238

Added lines #L237 - L238 were not covered by tests
n.log.Warnf("Unknown peer type %T", badnode)
return

Check warning on line 240 in network/p2pNetwork.go

Codecov / codecov/patch

network/p2pNetwork.go#L240

Added line #L240 was not covered by tests
}
n.wsPeersLock.Lock()
defer n.wsPeersLock.Unlock()
if wsPeer, ok := n.wsPeers[node]; ok {
wsPeer.CloseAndWait(time.Now().Add(peerDisconnectionAckDuration))
delete(n.wsPeers, node)
} else {
n.log.Warnf("Could not find wsPeer reference for peer %s", node)

Check warning on line 248 in network/p2pNetwork.go

Codecov / codecov/patch

network/p2pNetwork.go#L242-L248

Added lines #L242 - L248 were not covered by tests
}
err := n.service.ClosePeer(node)
if err != nil {
n.log.Warnf("Error disconnecting from peer %s: %v", node, err)

Check warning on line 252 in network/p2pNetwork.go

Codecov / codecov/patch

network/p2pNetwork.go#L250-L252

Added lines #L250 - L252 were not covered by tests
}
}

0 comments on commit 55a0f95

Please sign in to comment.