mirror of
https://github.com/LBRYFoundation/tracker.git
synced 2025-08-23 17:47:29 +00:00
clients in whitelist
This commit is contained in:
parent
7c304b8c00
commit
79a6c79067
2 changed files with 29 additions and 25 deletions
|
@ -26,6 +26,11 @@ func (d *Duration) UnmarshalJSON(b []byte) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Client struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
PeerID string `json:"peer_id"`
|
||||||
|
}
|
||||||
|
|
||||||
type Storage struct {
|
type Storage struct {
|
||||||
Driver string `json:"driver"`
|
Driver string `json:"driver"`
|
||||||
Protocol string `json:"protocol"`
|
Protocol string `json:"protocol"`
|
||||||
|
@ -47,7 +52,7 @@ type Config struct {
|
||||||
MinAnnounce Duration `json:"min_announce"`
|
MinAnnounce Duration `json:"min_announce"`
|
||||||
ReadTimeout Duration `json:"read_timeout"`
|
ReadTimeout Duration `json:"read_timeout"`
|
||||||
|
|
||||||
Whitelist []string `json:"whitelist"`
|
Whitelist []Client `json:"whitelist"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(path string) (*Config, error) {
|
func New(path string) (*Config, error) {
|
||||||
|
@ -66,18 +71,13 @@ func New(path string) (*Config, error) {
|
||||||
return conf, nil
|
return conf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) Whitelisted(peerId string) bool {
|
func (c *Config) Whitelisted(peerId string) (matched bool) {
|
||||||
var (
|
for _, client := range c.Whitelist {
|
||||||
widLen int
|
length := len(client.PeerID)
|
||||||
matched bool
|
if length <= len(peerId) {
|
||||||
)
|
|
||||||
|
|
||||||
for _, whitelistedId := range c.Whitelist {
|
|
||||||
widLen = len(whitelistedId)
|
|
||||||
if widLen <= len(peerId) {
|
|
||||||
matched = true
|
matched = true
|
||||||
for i := 0; i < widLen; i++ {
|
for i := 0; i < length; i++ {
|
||||||
if peerId[i] != whitelistedId[i] {
|
if peerId[i] != client.PeerID[i] {
|
||||||
matched = false
|
matched = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,24 @@
|
||||||
{
|
{
|
||||||
|
|
||||||
"addr": ":34000",
|
"addr": ":34000",
|
||||||
"storage": {
|
"storage": {
|
||||||
"driver": "redis",
|
"driver": "redis",
|
||||||
"addr": "127.0.0.1:6379",
|
"addr": "127.0.0.1:6379",
|
||||||
"user": "root",
|
"user": "root",
|
||||||
"pass": "",
|
"pass": ""
|
||||||
},
|
},
|
||||||
|
|
||||||
"private": true,
|
"private": true,
|
||||||
"freeleech": false,
|
"freeleech": false,
|
||||||
|
|
||||||
"announce": "30m",
|
"announce": "30m",
|
||||||
"min_announce": "15m",
|
"min_announce": "15m",
|
||||||
"read_timeout": "20s",
|
"read_timeout": "20s",
|
||||||
|
|
||||||
"whitelist": [],
|
"whitelist": [
|
||||||
|
{ "name": "Azureus 2.5.x", "peer_id": "-AZ25" },
|
||||||
|
{ "name": "Azureus 3.0.x", "peer_id": "-AZ30" },
|
||||||
|
{ "name": "btgdaemon 0.9", "peer_id": "-BG09" }
|
||||||
|
]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue