mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
les: allow multiple free clients from loopback ip
This commit is contained in:
parent
99711a2edf
commit
ba1a974ca4
1 changed files with 19 additions and 4 deletions
|
|
@ -93,10 +93,25 @@ func (f *freeClientPool) stop() {
|
||||||
f.lock.Unlock()
|
f.lock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// freeClientId returns a string identifier for the peer. Multiple peers with the
|
||||||
|
// same identifier can not be in the free client pool simultaneously.
|
||||||
|
func freeClientId(p *peer) string {
|
||||||
|
if addr, ok := p.RemoteAddr().(*net.TCPAddr); ok {
|
||||||
|
if addr.IP.IsLoopback() {
|
||||||
|
// using peer id instead of loopback ip address allows multiple free
|
||||||
|
// connections from local machine to own server
|
||||||
|
return p.id
|
||||||
|
} else {
|
||||||
|
return addr.IP.String()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
// registerPeer implements clientPool
|
// registerPeer implements clientPool
|
||||||
func (f *freeClientPool) registerPeer(p *peer) {
|
func (f *freeClientPool) registerPeer(p *peer) {
|
||||||
if addr, ok := p.RemoteAddr().(*net.TCPAddr); ok {
|
if freeId := freeClientId(p); freeId != "" {
|
||||||
if !f.connect(addr.IP.String(), p.id) {
|
if !f.connect(freeId, p.id) {
|
||||||
f.removePeer(p.id)
|
f.removePeer(p.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -163,8 +178,8 @@ func (f *freeClientPool) connect(address, id string) bool {
|
||||||
|
|
||||||
// unregisterPeer implements clientPool
|
// unregisterPeer implements clientPool
|
||||||
func (f *freeClientPool) unregisterPeer(p *peer) {
|
func (f *freeClientPool) unregisterPeer(p *peer) {
|
||||||
if addr, ok := p.RemoteAddr().(*net.TCPAddr); ok {
|
if freeId := freeClientId(p); freeId != "" {
|
||||||
f.disconnect(addr.IP.String())
|
f.disconnect(freeId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue