]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Make IPBlockList accessible from Client
authorMatt Joiner <anacrolix@gmail.com>
Wed, 25 Feb 2015 00:25:22 +0000 (11:25 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 25 Feb 2015 00:25:22 +0000 (11:25 +1100)
client.go
iplist/iplist.go

index a111b54b1487d1b120614f2400ed28c3644409e0..55bb9aca03c234280fae11929cf558ee80bb0d01 100644 (file)
--- a/client.go
+++ b/client.go
@@ -124,8 +124,12 @@ type Client struct {
        handshaking int
 
        torrents map[InfoHash]*torrent
+}
 
-       dataWaits map[*torrent][]dataWait
+func (me *Client) IPBlockList() *iplist.IPList {
+       me.mu.Lock()
+       defer me.mu.Unlock()
+       return me.ipBlockList
 }
 
 func (me *Client) SetIPBlockList(list *iplist.IPList) {
index ed8ac06e8db807a3c839a4eadb0983c0673bd030..756c0263d5d62fe8fe1d0aeb7672814f3441c199 100644 (file)
@@ -28,8 +28,18 @@ func New(initSorted []Range) *IPList {
        }
 }
 
+func (me *IPList) NumRanges() int {
+       if me == nil {
+               return 0
+       }
+       return len(me.ranges)
+}
+
 // Return the range the given IP is in. Returns nil if no range is found.
 func (me *IPList) Lookup(ip net.IP) (r *Range) {
+       if me == nil {
+               return nil
+       }
        // Find the index of the first range for which the following range exceeds
        // it.
        i := sort.Search(len(me.ranges), func(i int) bool {