-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Connection Gater to Manage Peer Connections (#6243)
* use gater * Merge branch 'master' into connGater * Update beacon-chain/p2p/testing/p2p.go * fmt * gaz
- Loading branch information
Showing
8 changed files
with
82 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package p2p | ||
|
||
import ( | ||
"github.com/libp2p/go-libp2p-core/control" | ||
"github.com/libp2p/go-libp2p-core/network" | ||
"github.com/libp2p/go-libp2p-core/peer" | ||
"github.com/multiformats/go-multiaddr" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// InterceptPeerDial tests whether we're permitted to Dial the specified peer. | ||
func (s *Service) InterceptPeerDial(p peer.ID) (allow bool) { | ||
return true | ||
} | ||
|
||
// InterceptAddrDial tests whether we're permitted to dial the specified | ||
// multiaddr for the given peer. | ||
func (s *Service) InterceptAddrDial(peer.ID, multiaddr.Multiaddr) (allow bool) { | ||
return true | ||
} | ||
|
||
// InterceptAccept tests whether an incipient inbound connection is allowed. | ||
func (s *Service) InterceptAccept(n network.ConnMultiaddrs) (allow bool) { | ||
if len(s.Peers().Active()) >= int(s.cfg.MaxPeers) { | ||
log.WithFields(logrus.Fields{"peer": n.RemoteMultiaddr(), | ||
"reason": "at peer limit"}).Trace("Not accepting inbound dial") | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
// InterceptSecured tests whether a given connection, now authenticated, | ||
// is allowed. | ||
func (s *Service) InterceptSecured(network.Direction, peer.ID, network.ConnMultiaddrs) (allow bool) { | ||
return true | ||
} | ||
|
||
// InterceptUpgraded tests whether a fully capable connection is allowed. | ||
func (s *Service) InterceptUpgraded(network.Conn) (allow bool, reason control.DisconnectReason) { | ||
return true, 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters