clients in whitelist

This commit is contained in:
Jimmy Zelinskie 2013-06-24 00:19:24 -04:00
parent 7c304b8c00
commit 79a6c79067
2 changed files with 29 additions and 25 deletions

View file

@ -26,6 +26,11 @@ func (d *Duration) UnmarshalJSON(b []byte) error {
return err
}
type Client struct {
Name string `json:"name"`
PeerID string `json:"peer_id"`
}
type Storage struct {
Driver string `json:"driver"`
Protocol string `json:"protocol"`
@ -47,7 +52,7 @@ type Config struct {
MinAnnounce Duration `json:"min_announce"`
ReadTimeout Duration `json:"read_timeout"`
Whitelist []string `json:"whitelist"`
Whitelist []Client `json:"whitelist"`
}
func New(path string) (*Config, error) {
@ -66,18 +71,13 @@ func New(path string) (*Config, error) {
return conf, nil
}
func (c *Config) Whitelisted(peerId string) bool {
var (
widLen int
matched bool
)
for _, whitelistedId := range c.Whitelist {
widLen = len(whitelistedId)
if widLen <= len(peerId) {
func (c *Config) Whitelisted(peerId string) (matched bool) {
for _, client := range c.Whitelist {
length := len(client.PeerID)
if length <= len(peerId) {
matched = true
for i := 0; i < widLen; i++ {
if peerId[i] != whitelistedId[i] {
for i := 0; i < length; i++ {
if peerId[i] != client.PeerID[i] {
matched = false
break
}

View file

@ -1,20 +1,24 @@
{
"addr": ":34000",
"storage": {
"driver": "redis",
"addr": "127.0.0.1:6379",
"user": "root",
"pass": "",
},
"addr": ":34000",
"storage": {
"driver": "redis",
"addr": "127.0.0.1:6379",
"user": "root",
"pass": ""
},
"private": true,
"freeleech": false,
"private": true,
"freeleech": false,
"announce": "30m",
"min_announce": "15m",
"read_timeout": "20s",
"announce": "30m",
"min_announce": "15m",
"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" }
]
}