Improvements to P2P blocklist scanning errors
This commit is contained in:
parent
e4dec03a32
commit
1c5bd1855a
|
@ -380,12 +380,14 @@ func (cl *Client) setEnvBlocklist() (err error) {
|
||||||
var ranges []iplist.Range
|
var ranges []iplist.Range
|
||||||
uniqStrs := make(map[string]string)
|
uniqStrs := make(map[string]string)
|
||||||
scanner := bufio.NewScanner(f)
|
scanner := bufio.NewScanner(f)
|
||||||
|
lineNum := 1
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
r, ok, lineErr := iplist.ParseBlocklistP2PLine(scanner.Bytes())
|
r, ok, lineErr := iplist.ParseBlocklistP2PLine(scanner.Bytes())
|
||||||
if lineErr != nil {
|
if lineErr != nil {
|
||||||
err = fmt.Errorf("error reading torrent blocklist line: %s", lineErr)
|
err = fmt.Errorf("error reading torrent blocklist line %d: %s", lineNum, lineErr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
lineNum++
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package iplist
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -67,7 +68,16 @@ func ParseBlocklistP2PLine(l []byte) (r Range, ok bool, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
colon := bytes.IndexByte(l, ':')
|
colon := bytes.IndexByte(l, ':')
|
||||||
hyphen := bytes.IndexByte(l[colon+1:], '-') + colon + 1
|
if colon == -1 {
|
||||||
|
err = errors.New("missing colon")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
hyphen := bytes.IndexByte(l[colon+1:], '-')
|
||||||
|
if hyphen == -1 {
|
||||||
|
err = errors.New("missing hyphen")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
hyphen += colon + 1
|
||||||
r.Description = string(l[:colon])
|
r.Description = string(l[:colon])
|
||||||
r.First = net.ParseIP(string(l[colon+1 : hyphen]))
|
r.First = net.ParseIP(string(l[colon+1 : hyphen]))
|
||||||
r.Last = net.ParseIP(string(l[hyphen+1:]))
|
r.Last = net.ParseIP(string(l[hyphen+1:]))
|
||||||
|
|
Loading…
Reference in New Issue