X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=bep40.go;h=9a643553d730e2a6b408ea37a7eb6ec4af558c4b;hb=ac086bb3bd3b8e31c117362551eb0fe295a0f78d;hp=5930247f15d6116299f0051baed218115de3b589;hpb=fad06c7ddfc1328f275a79cb3285af41a82a037b;p=btrtrc.git diff --git a/bep40.go b/bep40.go index 5930247f..9a643553 100644 --- a/bep40.go +++ b/bep40.go @@ -13,11 +13,6 @@ var table = crc32.MakeTable(crc32.Castagnoli) type peerPriority = uint32 -type ipPort struct { - IP net.IP - Port uint16 -} - func sameSubnet(ones, bits int, a, b net.IP) bool { mask := net.CIDRMask(ones, bits) return a.Mask(mask).Equal(b.Mask(mask)) @@ -53,7 +48,7 @@ func ipv6Mask(a, b net.IP) net.IPMask { panic(fmt.Sprintf("%s %s", a, b)) } -func bep40PriorityBytes(a, b ipPort) ([]byte, error) { +func bep40PriorityBytes(a, b IpPort) ([]byte, error) { if a.IP.Equal(b.IP) { var ret [4]byte binary.BigEndian.PutUint16(ret[0:2], a.Port) @@ -71,10 +66,10 @@ func bep40PriorityBytes(a, b ipPort) ([]byte, error) { return nil, errors.New("incomparable IPs") } -func bep40Priority(a, b ipPort) (peerPriority, error) { +func bep40Priority(a, b IpPort) (peerPriority, error) { bs, err := bep40PriorityBytes(a, b) if err != nil { - return 0, nil + return 0, err } i := len(bs) / 2 _a, _b := bs[:i], bs[i:] @@ -84,7 +79,7 @@ func bep40Priority(a, b ipPort) (peerPriority, error) { return crc32.Checksum(bs, table), nil } -func bep40PriorityIgnoreError(a, b ipPort) peerPriority { +func bep40PriorityIgnoreError(a, b IpPort) peerPriority { prio, _ := bep40Priority(a, b) return prio }