From: Matt Joiner Date: Sun, 4 Nov 2018 05:56:02 +0000 (+1100) Subject: Promote ipPort to its own file X-Git-Tag: v1.0.0~26 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=f1f54ce94955206929028487b93cd6ba634c92ef;p=btrtrc.git Promote ipPort to its own file --- diff --git a/bep40.go b/bep40.go index fa696bda..6c507d35 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)) diff --git a/ipport.go b/ipport.go new file mode 100644 index 00000000..38036cb4 --- /dev/null +++ b/ipport.go @@ -0,0 +1,21 @@ +package torrent + +import ( + "net" + "strconv" + + "github.com/anacrolix/missinggo" +) + +type ipPort struct { + IP net.IP + Port uint16 +} + +func (me ipPort) String() string { + return net.JoinHostPort(me.IP.String(), strconv.FormatUint(uint64(me.Port), 10)) +} + +func ipPortFromNetAddr(na net.Addr) ipPort { + return ipPort{missinggo.AddrIP(na), uint16(missinggo.AddrPort(na))} +}