X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=bep40.go;h=9a643553d730e2a6b408ea37a7eb6ec4af558c4b;hb=20b437730ddd9862348871516aa2f4ca5433d959;hp=fa696bdac57233917e868cc40e2664ebb00b09ac;hpb=f149d0b82a49bae510a9ddc5f722ba92e5eb2a49;p=btrtrc.git diff --git a/bep40.go b/bep40.go index fa696bda..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,7 +66,7 @@ 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, err @@ -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 }