mirror of
https://github.com/LBRYFoundation/tracker.git
synced 2025-08-23 17:47:29 +00:00
add whitelist flag
This commit is contained in:
parent
941de3d12e
commit
64d08ca16b
4 changed files with 78 additions and 9 deletions
15
chihaya.go
15
chihaya.go
|
@ -23,15 +23,17 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
maxProcs int
|
maxProcs int
|
||||||
profile string
|
profile string
|
||||||
configPath string
|
configPath string
|
||||||
|
whitelistPath string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.IntVar(&maxProcs, "maxprocs", runtime.NumCPU(), "maximum parallel threads")
|
flag.IntVar(&maxProcs, "maxprocs", runtime.NumCPU(), "maximum parallel threads")
|
||||||
flag.StringVar(&profile, "profile", "", "if non-empty, path to write profiling data")
|
flag.StringVar(&profile, "profile", "", "if non-empty, path to write profiling data")
|
||||||
flag.StringVar(&configPath, "config", "", "path to the configuration file")
|
flag.StringVar(&configPath, "config", "", "path to the configuration file")
|
||||||
|
flag.StringVar(&whitelistPath, "whitelist", "", "path to a client whitelist")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Boot starts Chihaya. By exporting this function, anyone can import their own
|
// Boot starts Chihaya. By exporting this function, anyone can import their own
|
||||||
|
@ -78,6 +80,13 @@ func Boot() {
|
||||||
glog.Fatal("New: ", err)
|
glog.Fatal("New: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if whitelistPath != "" {
|
||||||
|
err = tkr.LoadApprovedClients(whitelistPath)
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatal("Failed to load whitelist: ", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
http.Serve(cfg, tkr)
|
http.Serve(cfg, tkr)
|
||||||
glog.Info("Gracefully shut down")
|
glog.Info("Gracefully shut down")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
{
|
{
|
||||||
"network": "tcp",
|
|
||||||
"addr": ":6881",
|
"addr": ":6881",
|
||||||
|
|
||||||
"tracker": {
|
"tracker": {
|
||||||
|
@ -11,14 +10,25 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
"private_tracker": false,
|
"private_tracker": false,
|
||||||
"freeleech": false,
|
"freelech": false,
|
||||||
"whitelist": false,
|
"whitelist": true,
|
||||||
"purge_inactive_torrents": true,
|
"purge_inactive_torrents": true,
|
||||||
"allow_ip_spoofing": true,
|
|
||||||
"dual_stacked_peers": true,
|
|
||||||
|
|
||||||
"announce": "30m",
|
"announce": "30m",
|
||||||
"min_announce": "15m",
|
"min_announce": "15m",
|
||||||
"request_timeout": "10s",
|
"request_timeout": "10s",
|
||||||
"default_num_want": 50
|
"default_num_want": 50,
|
||||||
|
|
||||||
|
"allow_ip_spoofing": true,
|
||||||
|
"dual_stacked_peers": true,
|
||||||
|
"real_ip_header": "",
|
||||||
|
"preferred_subnet": false,
|
||||||
|
"preferred_ipv4_subnet": 0,
|
||||||
|
"preferred_ipv6_subnet": 0,
|
||||||
|
|
||||||
|
"stats_buffer_size": 0,
|
||||||
|
"include_mem_stats": true,
|
||||||
|
"verbose_mem_stats": true,
|
||||||
|
"mem_stats_interval": "30s"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
14
example_whitelist.json
Normal file
14
example_whitelist.json
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
[
|
||||||
|
"UT340-",
|
||||||
|
"AZ2500",
|
||||||
|
"exbc0J",
|
||||||
|
"FUTB0L",
|
||||||
|
"XBT054",
|
||||||
|
"OP1011",
|
||||||
|
"ML2.7.",
|
||||||
|
"BOWA0C",
|
||||||
|
"Q1-0-0",
|
||||||
|
"Q1-10-",
|
||||||
|
"346---",
|
||||||
|
"QVOD00"
|
||||||
|
]
|
|
@ -7,6 +7,8 @@
|
||||||
package tracker
|
package tracker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
@ -66,6 +68,40 @@ func (tkr *Tracker) Close() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadApprovedClients takes a path to a JSON file containing a list of clients
|
||||||
|
// and inserts them into the tracker's data store.
|
||||||
|
func (tkr *Tracker) LoadApprovedClients(path string) error {
|
||||||
|
if path == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := os.Open(os.ExpandEnv(path))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
var clients []string
|
||||||
|
err = json.NewDecoder(f).Decode(&clients)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
conn, err := tkr.Pool.Get()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, client := range clients {
|
||||||
|
err = conn.PutClient(client)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Writer serializes a tracker's responses, and is implemented for each
|
// Writer serializes a tracker's responses, and is implemented for each
|
||||||
// response transport used by the tracker.
|
// response transport used by the tracker.
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Reference in a new issue