Skip to content

Commit

Permalink
fix: review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aloknerurkar committed Sep 8, 2021
1 parent 46b655c commit 443f020
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/debugapi/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (s *Service) peerConnectHandler(w http.ResponseWriter, r *http.Request) {
}

if err := s.topologyDriver.Connected(r.Context(), p2p.Peer{Address: bzzAddr.Overlay}, true); err != nil {
_ = s.p2p.Disconnect(bzzAddr.Overlay, "failed to process connection notification")
_ = s.p2p.Disconnect(bzzAddr.Overlay, "failed to notify topology")
s.logger.Debugf("debug api: peer connect handler %s: %v", addr, err)
s.logger.Errorf("unable to connect to peer %s", addr)
jsonhttp.InternalServerError(w, err)
Expand Down
16 changes: 8 additions & 8 deletions pkg/p2p/libp2p/libp2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,15 @@ func (s *Service) handleIncoming(stream network.Stream) {
if err = handshakeStream.FullClose(); err != nil {
s.logger.Debugf("stream handler: could not close stream %s: %v", overlay, err)
s.logger.Errorf("stream handler: unable to handshake with peer %v", overlay)
_ = s.Disconnect(overlay, "unable to handshake")
_ = s.Disconnect(overlay, "unable to close handshake stream")
}
return
}

if err = handshakeStream.FullClose(); err != nil {
s.logger.Debugf("stream handler: could not close stream %s: %v", overlay, err)
s.logger.Errorf("stream handler: unable to handshake with peer %v", overlay)
_ = s.Disconnect(overlay, "unable to handshake")
_ = s.Disconnect(overlay, "could not fully close stream on handshake")
return
}

Expand Down Expand Up @@ -513,7 +513,7 @@ func (s *Service) AddProtocol(p p2p.ProtocolSpec) (err error) {
logger.Debugf("blocklist: could not blocklist peer %s: %v", peerID, err)
logger.Errorf("unable to blocklist peer %v", peerID)
}
logger.Tracef("handler(%s): blocklisted %s reason %s", p.Name, overlay.String(), bpe.Error())
logger.Tracef("handler(%s): blocklisted %s", p.Name, overlay.String())
}
// count unexpected requests
if errors.Is(err, p2p.ErrUnexpected) {
Expand Down Expand Up @@ -556,10 +556,10 @@ func (s *Service) NATManager() basichost.NATManager {
}

func (s *Service) Blocklist(overlay swarm.Address, duration time.Duration, reason string) error {
s.logger.Tracef("libp2p blocklist: peer %s for %v reason %s", overlay.String(), duration, reason)
s.logger.Tracef("libp2p blocklist: peer %s for %v reason: %s", overlay.String(), duration, reason)
if err := s.blocklist.Add(overlay, duration); err != nil {
s.metrics.BlocklistedPeerErrCount.Inc()
_ = s.Disconnect(overlay, "blocklisting peer")
_ = s.Disconnect(overlay, "failed blocklisting peer")
return fmt.Errorf("blocklist peer %s: %v", overlay, err)
}
s.metrics.BlocklistedPeerCount.Inc()
Expand Down Expand Up @@ -652,15 +652,15 @@ func (s *Service) Connect(ctx context.Context, addr ma.Multiaddr) (address *bzz.

if exists := s.peers.addIfNotExists(stream.Conn(), overlay, i.FullNode); exists {
if err := handshakeStream.FullClose(); err != nil {
_ = s.Disconnect(overlay, "failed closing handshake")
_ = s.Disconnect(overlay, "failed closing handshake stream after connect")
return nil, fmt.Errorf("peer exists, full close: %w", err)
}

return i.BzzAddress, nil
}

if err := handshakeStream.FullClose(); err != nil {
_ = s.Disconnect(overlay, "failed closing handshake")
_ = s.Disconnect(overlay, "could not fully close handshake stream after connect")
return nil, fmt.Errorf("connect full close %w", err)
}

Expand Down Expand Up @@ -702,7 +702,7 @@ func (s *Service) Connect(ctx context.Context, addr ma.Multiaddr) (address *bzz.
func (s *Service) Disconnect(overlay swarm.Address, reason string) error {
s.metrics.DisconnectCount.Inc()

s.logger.Debugf("libp2p disconnect: disconnecting peer %s reason %s", overlay, reason)
s.logger.Debugf("libp2p disconnect: disconnecting peer %s reason: %s", overlay, reason)

// found is checked at the bottom of the function
found, full, peerID := s.peers.remove(overlay)
Expand Down

0 comments on commit 443f020

Please sign in to comment.