9 "github.com/anacrolix/dht"
10 "golang.org/x/time/rate"
12 "github.com/anacrolix/torrent/iplist"
13 "github.com/anacrolix/torrent/storage"
16 var DefaultHTTPClient = &http.Client{
17 Timeout: time.Second * 15,
18 Transport: &http.Transport{
20 Timeout: 15 * time.Second,
22 TLSHandshakeTimeout: 15 * time.Second,
23 TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
27 // Override Client defaults.
29 // Store torrent file data in this directory unless TorrentDataOpener is
31 DataDir string `long:"data-dir" description:"directory to store downloaded torrent data"`
32 // The address to listen for new uTP and TCP bittorrent protocol
33 // connections. DHT shares a UDP socket with uTP unless configured
35 ListenAddr string `long:"listen-addr" value-name:"HOST:PORT"`
36 // Don't announce to trackers. This only leaves DHT to discover peers.
37 DisableTrackers bool `long:"disable-trackers"`
38 DisablePEX bool `long:"disable-pex"`
39 // Don't create a DHT.
40 NoDHT bool `long:"disable-dht"`
41 // Overrides the default DHT configuration.
42 DHTConfig dht.ServerConfig
44 // Never send chunks to peers.
45 NoUpload bool `long:"no-upload"`
46 // Disable uploading even when it isn't fair.
47 DisableAggressiveUpload bool `long:"disable-aggressive-upload"`
48 // Upload even after there's nothing in it for us. By default uploading is
49 // not altruistic, we'll upload slightly more than we download from each
51 Seed bool `long:"seed"`
52 // Events are data bytes sent in pieces. The burst must be large enough to
53 // fit a whole chunk, which is usually 16 KiB.
54 UploadRateLimiter *rate.Limiter
55 // The events are bytes read from connections. The burst must be bigger
56 // than the largest Read performed on a Conn minus one. This is likely to
57 // be the larger of the main read loop buffer (~4096), and the requested
58 // chunk size (~16KiB).
59 DownloadRateLimiter *rate.Limiter
61 // User-provided Client peer ID. If not present, one is generated automatically.
63 // For the bittorrent protocol.
65 // For the bittorrent protocol.
66 DisableTCP bool `long:"disable-tcp"`
67 // Called to instantiate storage for each added torrent. Builtin backends
68 // are in the storage package. If not set, the "file" implementation is
70 DefaultStorage storage.ClientImpl
74 IPBlocklist iplist.Ranger
75 DisableIPv6 bool `long:"disable-ipv6"`
76 // Perform logging and any other behaviour that will help debug.
77 Debug bool `help:"enable debugging"`
79 // HTTP client used to query the tracker endpoint. Default is DefaultHTTPClient
81 // Updated occasionally to when there's been some changes to client
82 // behaviour in case other clients are assuming anything of us. See also
84 ExtendedHandshakeClientVersion string // default "go.torrent dev 20150624"
85 // Peer ID client identifier prefix. We'll update this occasionally to
86 // reflect changes to client behaviour that other clients may depend on.
87 // Also see `extendedHandshakeClientVersion`.
88 Bep20 string // default "-GT0001-"
90 NominalDialTimeout time.Duration // default time.Second * 30
91 MinDialTimeout time.Duration // default 5 * time.Second
92 EstablishedConnsPerTorrent int // default 80
93 HalfOpenConnsPerTorrent int // default 80
94 TorrentPeersHighWater int // default 200
95 TorrentPeersLowWater int // default 50
97 // Limit how long handshake can take. This is to reduce the lingering
98 // impact of a few bad apples. 4s loses 1% of successful handshakes that
99 // are obtained with 60s timeout, and 5% of unsuccessful handshakes.
100 HandshakesTimeout time.Duration // default 20 * time.Second
103 func (cfg *Config) setDefaults() {
105 cfg.HTTP = DefaultHTTPClient
107 if cfg.ExtendedHandshakeClientVersion == "" {
108 cfg.ExtendedHandshakeClientVersion = "go.torrent dev 20150624"
111 cfg.Bep20 = "-GT0001-"
113 if cfg.NominalDialTimeout == 0 {
114 cfg.NominalDialTimeout = 30 * time.Second
116 if cfg.MinDialTimeout == 0 {
117 cfg.MinDialTimeout = 5 * time.Second
119 if cfg.EstablishedConnsPerTorrent == 0 {
120 cfg.EstablishedConnsPerTorrent = 80
122 if cfg.HalfOpenConnsPerTorrent == 0 {
123 cfg.HalfOpenConnsPerTorrent = 80
125 if cfg.TorrentPeersHighWater == 0 {
126 cfg.TorrentPeersHighWater = 200
128 if cfg.TorrentPeersLowWater == 0 {
129 cfg.TorrentPeersLowWater = 50
131 if cfg.HandshakesTimeout == 0 {
132 cfg.HandshakesTimeout = 20 * time.Second
136 type EncryptionPolicy struct {
137 DisableEncryption bool
138 ForceEncryption bool // Don't allow unobfuscated connections.
139 PreferNoEncryption bool