From 4ca47eb3581072a13c68c77f9731a1541f7f1c08 Mon Sep 17 00:00:00 2001
From: Matt Joiner <anacrolix@gmail.com>
Date: Tue, 21 Sep 2021 13:04:51 +1000
Subject: [PATCH] Add ClientConfig.AlwaysWantConns

---
 client.go | 3 +++
 config.go | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/client.go b/client.go
index e7683016..ae40f458 100644
--- a/client.go
+++ b/client.go
@@ -451,6 +451,9 @@ func (cl *Client) ipIsBlocked(ip net.IP) bool {
 }
 
 func (cl *Client) wantConns() bool {
+	if cl.config.AlwaysWantConns {
+		return true
+	}
 	for _, t := range cl.torrents {
 		if t.wantConns() {
 			return true
diff --git a/config.go b/config.go
index 1895f3c3..0e3cd2c2 100644
--- a/config.go
+++ b/config.go
@@ -139,6 +139,9 @@ type ClientConfig struct {
 	DropMutuallyCompletePeers bool
 	// Whether to accept peer connections at all.
 	AcceptPeerConnections bool
+	// Whether a Client should want conns without delegating to any attached Torrents. This is
+	// useful when torrents might be added dynmically in callbacks for example.
+	AlwaysWantConns bool
 
 	// OnQuery hook func
 	DHTOnQuery func(query *krpc.Msg, source net.Addr) (propagate bool)
-- 
2.51.0