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

Relegate some p2p messages #4725

Merged
merged 1 commit into from Feb 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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