/
client.go
37 lines (34 loc) · 832 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package confluence
import (
"log"
"github.com/anacrolix/missinggo/v2/filecache"
"github.com/anacrolix/torrent"
"github.com/anacrolix/torrent/iplist"
"github.com/anacrolix/torrent/storage"
)
func NewDefaultTorrentClient() (ret *torrent.Client, err error) {
blocklist, err := iplist.MMapPackedFile("packed-blocklist")
if err != nil {
log.Print(err)
}
defer func() {
if err != nil {
blocklist.Close()
} else {
go func() {
<-ret.Closed()
blocklist.Close()
}()
}
}()
fileCache, err := filecache.NewCache("filecache")
if err != nil {
return
}
fileCache.SetCapacity(10 << 30)
storageProvider := fileCache.AsResourceProvider()
cfg := torrent.NewDefaultClientConfig()
cfg.IPBlocklist = blocklist
cfg.DefaultStorage = storage.NewResourcePieces(storageProvider)
return torrent.NewClient(cfg)
}