Fix usages of eachListener() and make inlineable (#599)
This commit is contained in:
parent
52e8c82999
commit
134eea8418
31
client.go
31
client.go
|
@ -110,10 +110,11 @@ func (cl *Client) PeerID() PeerID {
|
||||||
// numbers are the same, due to support for custom listeners. Returns zero if no port number is
|
// numbers are the same, due to support for custom listeners. Returns zero if no port number is
|
||||||
// found.
|
// found.
|
||||||
func (cl *Client) LocalPort() (port int) {
|
func (cl *Client) LocalPort() (port int) {
|
||||||
cl.eachListener(func(l Listener) bool {
|
for i := 0; i < len(cl.listeners); i += 1 {
|
||||||
port = addrPortOrZero(l.Addr())
|
if port = addrPortOrZero(cl.listeners[i].Addr()); port != 0 {
|
||||||
return port == 0
|
return
|
||||||
})
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1436,13 +1437,15 @@ func (cl *Client) eachListener(f func(Listener) bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cl *Client) findListener(f func(Listener) bool) (ret Listener) {
|
func (cl *Client) findListener(f func(Listener) bool) (ret Listener) {
|
||||||
cl.eachListener(func(l Listener) bool {
|
for i := 0; i < len(cl.listeners); i += 1 {
|
||||||
ret = l
|
if ret = cl.listeners[i]; f(ret) {
|
||||||
return !f(l)
|
return
|
||||||
})
|
}
|
||||||
return
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (cl *Client) publicIp(peer net.IP) net.IP {
|
func (cl *Client) publicIp(peer net.IP) net.IP {
|
||||||
// TODO: Use BEP 10 to determine how peers are seeing us.
|
// TODO: Use BEP 10 to determine how peers are seeing us.
|
||||||
if peer.To4() != nil {
|
if peer.To4() != nil {
|
||||||
|
@ -1478,11 +1481,11 @@ func (cl *Client) publicAddr(peer net.IP) IpPort {
|
||||||
// ListenAddrs addresses currently being listened to.
|
// ListenAddrs addresses currently being listened to.
|
||||||
func (cl *Client) ListenAddrs() (ret []net.Addr) {
|
func (cl *Client) ListenAddrs() (ret []net.Addr) {
|
||||||
cl.lock()
|
cl.lock()
|
||||||
defer cl.unlock()
|
ret = make([]net.Addr, len(cl.listeners))
|
||||||
cl.eachListener(func(l Listener) bool {
|
for i := 0; i < len(cl.listeners); i += 1 {
|
||||||
ret = append(ret, l.Addr())
|
ret[i] = cl.listeners[i].Addr()
|
||||||
return true
|
}
|
||||||
})
|
cl.unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue