Promote ipPort to its own file

This commit is contained in:
Matt Joiner 2018-11-04 16:56:02 +11:00
parent 4f5387cbbd
commit f1f54ce949
2 changed files with 21 additions and 5 deletions

View File

@ -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))

21
ipport.go Normal file
View File

@ -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))}
}