Add ClientConfig.AcceptPeerConnections
This commit is contained in:
parent
af1ca91e04
commit
a01b451857
|
@ -248,9 +248,11 @@ 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)
|
||||
if cl.config.AcceptPeerConnections {
|
||||
go cl.acceptConnections(s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
go cl.forwardPort()
|
||||
if !cfg.NoDHT {
|
||||
|
@ -322,12 +324,14 @@ func (cl *Client) Listeners() []Listener {
|
|||
// yourself.
|
||||
func (cl *Client) AddListener(l Listener) {
|
||||
cl.listeners = append(cl.listeners, 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)
|
||||
|
|
|
@ -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)
|
||||
|
@ -184,6 +186,7 @@ func NewDefaultClientConfig() *ClientConfig {
|
|||
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