Add ClientConfig.AcceptPeerConnections

This commit is contained in:
Matt Joiner 2021-06-18 14:59:20 +10:00
parent af1ca91e04
commit a01b451857
2 changed files with 14 additions and 7 deletions

View File

@ -248,7 +248,9 @@ func NewClient(cfg *ClientConfig) (cl *Client, err error) {
if peerNetworkEnabled(parseNetworkString(s.Addr().Network()), cl.config) {
cl.dialers = append(cl.dialers, s)
cl.listeners = append(cl.listeners, s)
go cl.acceptConnections(s)
if cl.config.AcceptPeerConnections {
go cl.acceptConnections(s)
}
}
}
@ -322,12 +324,14 @@ func (cl *Client) Listeners() []Listener {
// yourself.
func (cl *Client) AddListener(l Listener) {
cl.listeners = append(cl.listeners, l)
go cl.acceptConnections(l)
if cl.config.AcceptPeerConnections {
go cl.acceptConnections(l)
}
}
func (cl *Client) firewallCallback(net.Addr) bool {
cl.rLock()
block := !cl.wantConns()
block := !cl.wantConns() || !cl.config.AcceptPeerConnections
cl.rUnlock()
if block {
torrent.Add("connections firewalled", 1)

View File

@ -133,6 +133,8 @@ type ClientConfig struct {
// bit of a special case, since a peer could also be useless if they're just not interested, or
// we don't intend to obtain all of a torrent's data.
DropMutuallyCompletePeers bool
// Whether to accept peer connections at all.
AcceptPeerConnections bool
// OnQuery hook func
DHTOnQuery func(query *krpc.Msg, source net.Addr) (propagate bool)
@ -180,10 +182,11 @@ func NewDefaultClientConfig() *ClientConfig {
Preferred: true,
RequirePreferred: false,
},
CryptoSelector: mse.DefaultCryptoSelector,
CryptoProvides: mse.AllSupportedCrypto,
ListenPort: 42069,
Extensions: defaultPeerExtensionBytes(),
CryptoSelector: mse.DefaultCryptoSelector,
CryptoProvides: mse.AllSupportedCrypto,
ListenPort: 42069,
Extensions: defaultPeerExtensionBytes(),
AcceptPeerConnections: true,
}
//cc.ConnTracker.SetNoMaxEntries()
//cc.ConnTracker.Timeout = func(conntrack.Entry) time.Duration { return 0 }