Skip to content

Commit

Permalink
Relegate some p2p messages (prysmaticlabs#4725)
Browse files Browse the repository at this point in the history
* Relegate some p2p messages
  • Loading branch information
mcdee authored and cryptomental committed Feb 24, 2020
1 parent 93a8e5e commit 14c704e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions beacon-chain/p2p/handshake.go
Expand Up @@ -23,19 +23,19 @@ func (s *Service) AddConnectionHandler(reqFunc func(ctx context.Context, id peer
// Handle the various pre-existing conditions that will result in us not handshaking.
peerConnectionState, err := s.peers.ConnectionState(conn.RemotePeer())
if err == nil && (peerConnectionState == peers.PeerConnected || peerConnectionState == peers.PeerConnecting) {
log.WithField("currentState", peerConnectionState).WithField("reason", "already active").Debug("Ignoring connection request")
log.WithField("currentState", peerConnectionState).WithField("reason", "already active").Trace("Ignoring connection request")
return
}
s.peers.Add(conn.RemotePeer(), conn.RemoteMultiaddr(), conn.Stat().Direction)
if len(s.peers.Active()) >= int(s.cfg.MaxPeers) {
log.WithField("reason", "at peer limit").Debug("Ignoring connection request")
log.WithField("reason", "at peer limit").Trace("Ignoring connection request")
if err := s.Disconnect(conn.RemotePeer()); err != nil {
log.WithError(err).Error("Unable to disconnect from peer")
}
return
}
if s.peers.IsBad(conn.RemotePeer()) {
log.WithField("reason", "bad peer").Debug("Ignoring connection request")
log.WithField("reason", "bad peer").Trace("Ignoring connection request")
if err := s.Disconnect(conn.RemotePeer()); err != nil {
log.WithError(err).Error("Unable to disconnect from peer")
}
Expand All @@ -46,11 +46,11 @@ func (s *Service) AddConnectionHandler(reqFunc func(ctx context.Context, id peer
go func() {
// Go through the handshake process.
multiAddr := fmt.Sprintf("%s/p2p/%s", conn.RemoteMultiaddr().String(), conn.RemotePeer().String())
log.WithFields(logrus.Fields{
log := log.WithFields(logrus.Fields{
"direction": conn.Stat().Direction,
"multiAddr": multiAddr,
"activePeers": len(s.peers.Active()),
}).Debug("Peer handshaking")
})
s.peers.SetConnectionState(conn.RemotePeer(), peers.PeerConnecting)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
Expand All @@ -73,7 +73,7 @@ func (s *Service) AddConnectionHandler(reqFunc func(ctx context.Context, id peer
}
s.host.ConnManager().Protect(conn.RemotePeer(), "protocol")
s.peers.SetConnectionState(conn.RemotePeer(), peers.PeerConnected)
log.WithField("active", len(s.peers.Active())).Info("Peer connected")
log.Info("Peer connected")
}()
},
})
Expand Down

0 comments on commit 14c704e

Please sign in to comment.