// Check for panics.
cl.LocalPort()
- for _, _s := range sockets {
- s := _s // Go is fucking retarded.
+ for _, s := range sockets {
cl.onClose = append(cl.onClose, func() { go s.Close() })
if peerNetworkEnabled(parseNetworkString(s.Addr().Network()), cl.config) {
- cl.dialers = append(cl.dialers, s)
+ if cl.config.DialForPeerConns {
+ cl.dialers = append(cl.dialers, s)
+ }
cl.listeners = append(cl.listeners, s)
if cl.config.AcceptPeerConnections {
go cl.acceptConnections(s)
cl.webseedRequestTimer = time.AfterFunc(webseedRequestUpdateTimerInterval, cl.updateWebseedRequestsTimerFunc)
+ err = cl.checkConfig()
return
}
panicif.Zero(key)
return cl.numWebSeedRequests[key] < defaultRequestsPerWebseedHost
}
+
+// Check for bad arrangements. This is a candidate for an error state check method.
+func (cl *Client) checkConfig() error {
+ if cl.config.DownloadRateLimiter.Limit() == 0 {
+ if len(cl.dialers) != 0 {
+ return errors.New("download rate limit is zero, but dialers are set")
+ }
+ if len(cl.listeners) != 0 && cl.config.AcceptPeerConnections {
+ return errors.New("download rate limit is zero, but listening for peer connections")
+ }
+ }
+ return nil
+}
// 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
+ // Use dialers to obtain connections to regular peers.
+ DialForPeerConns bool
// Whether to accept peer connections at all.
AcceptPeerConnections bool
// Whether a Client should want conns without delegating to any attached Torrents. This is
CryptoProvides: mse.AllSupportedCrypto,
ListenPort: 42069,
Extensions: defaultPeerExtensionBytes(),
+ DialForPeerConns: true,
AcceptPeerConnections: true,
MaxUnverifiedBytes: 64 << 20,
DialRateLimiter: rate.NewLimiter(10, 10),
// Ensure the data is present when the torrent is added, and not obtained
// over the network as the test runs.
cfg.DownloadRateLimiter = rate.NewLimiter(0, 0)
+ cfg.DialForPeerConns = false
cl, err := NewClient(cfg)
require.NoError(t, err)
defer cl.Close()