Add ClientConfig.AcceptPeerConnections
This commit is contained in:
parent
af1ca91e04
commit
a01b451857
10
client.go
10
client.go
|
@ -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)
|
||||
|
|
11
config.go
11
config.go
|
@ -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 }
|
||||
|
|
Loading…
Reference in New Issue