8 // Extracts the port as an integer from an address string.
9 func addrPortOrZero(addr net.Addr) int {
10 switch raw := addr.(type) {
16 _, port, err := net.SplitHostPort(addr.String())
20 i64, err := strconv.ParseUint(port, 0, 16)
28 func addrIpOrNil(addr net.Addr) net.IP {
32 switch raw := addr.(type) {
38 host, _, err := net.SplitHostPort(addr.String())
42 return net.ParseIP(host)
46 type ipPortAddr struct {
51 func (ipPortAddr) Network() string {
55 func (me ipPortAddr) String() string {
56 return net.JoinHostPort(me.IP.String(), strconv.FormatInt(int64(me.Port), 10))
59 func tryIpPortFromNetAddr(addr PeerRemoteAddr) (ipPortAddr, bool) {
61 host, port, err := net.SplitHostPort(addr.String())
65 portI64, err := strconv.ParseInt(port, 10, 0)
69 return ipPortAddr{net.ParseIP(host), int(portI64)}, ok