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 (
|
||||
maxProcs int
|
||||
profile string
|
||||
configPath string
|
||||
maxProcs int
|
||||
profile string
|
||||
configPath string
|
||||
whitelistPath string
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.IntVar(&maxProcs, "maxprocs", runtime.NumCPU(), "maximum parallel threads")
|
||||
flag.StringVar(&profile, "profile", "", "if non-empty, path to write profiling data")
|
||||
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
|
||||
|
@ -78,6 +80,13 @@ func Boot() {
|
|||
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)
|
||||
glog.Info("Gracefully shut down")
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
{
|
||||
"network": "tcp",
|
||||
"addr": ":6881",
|
||||
|
||||
"tracker": {
|
||||
|
@ -11,14 +10,25 @@
|
|||
},
|
||||
|
||||
"private_tracker": false,
|
||||
"freeleech": false,
|
||||
"whitelist": false,
|
||||
"freelech": false,
|
||||
"whitelist": true,
|
||||
"purge_inactive_torrents": true,
|
||||
"allow_ip_spoofing": true,
|
||||
"dual_stacked_peers": true,
|
||||
|
||||
"announce": "30m",
|
||||
"min_announce": "15m",
|
||||
"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
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
@ -66,6 +68,40 @@ func (tkr *Tracker) Close() (err error) {
|
|||
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
|
||||
// response transport used by the tracker.
|
||||
//
|
||||
|
|
Loading…
Add table
Reference in a new issue