move out of go-routine (#3883)

This commit is contained in:
Nishant Das 2019-10-30 13:32:53 +08:00 committed by GitHub
parent 2b444ea954
commit 2785a6d5ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,18 +15,19 @@ import (
func (s *Service) AddConnectionHandler(reqFunc func(ctx context.Context, id peer.ID) error) {
s.host.Network().Notify(&network.NotifyBundle{
ConnectedF: func(net network.Network, conn network.Conn) {
// Must be handled in a goroutine as this callback cannot be blocking.
go func() {
if peerstatus.IsBadPeer(conn.RemotePeer()) {
// Add Peer to gossipsub blacklist
s.pubsub.BlacklistPeer(conn.RemotePeer())
log.WithField("peerID", conn.RemotePeer().Pretty()).Debug("Disconnecting with bad peer")
if err := s.Disconnect(conn.RemotePeer()); err != nil {
log.WithError(err).Errorf("Unable to close peer %s", conn.RemotePeer())
return
}
if peerstatus.IsBadPeer(conn.RemotePeer()) {
// Add Peer to gossipsub blacklist
s.pubsub.BlacklistPeer(conn.RemotePeer())
log.WithField("peerID", conn.RemotePeer().Pretty()).Trace("Disconnecting with bad peer")
if err := s.Disconnect(conn.RemotePeer()); err != nil {
log.WithError(err).Errorf("Unable to close peer %s", conn.RemotePeer())
return
}
return
}
// Must be handled in a goroutine as this callback cannot be blocking.
go func() {
ctx := context.Background()
log := log.WithField("peer", conn.RemotePeer())
if conn.Stat().Direction == network.DirInbound {