mirror of https://github.com/poanetwork/gecko.git
set my ip if I happen to discover it for a best effort increase in discoverability
This commit is contained in:
parent
36ca80cf89
commit
dfa9843722
|
@ -699,8 +699,12 @@ func (n *network) upgrade(p *peer, upgrader Upgrader) error {
|
||||||
// mark the IP as one of mine.
|
// mark the IP as one of mine.
|
||||||
if id.Equals(n.id) {
|
if id.Equals(n.id) {
|
||||||
if !p.ip.IsZero() {
|
if !p.ip.IsZero() {
|
||||||
// TODO: if n.ip is less useful than p.ip (either it is private, or
|
// if n.ip is less useful than p.ip set it to this IP
|
||||||
// it is zero), should we set it to this IP?
|
if n.ip.IsZero() {
|
||||||
|
n.log.Info("setting my ip to %s because I was able to connect to myself through this channel",
|
||||||
|
p.ip)
|
||||||
|
n.ip = p.ip
|
||||||
|
}
|
||||||
str := p.ip.String()
|
str := p.ip.String()
|
||||||
delete(n.disconnectedIPs, str)
|
delete(n.disconnectedIPs, str)
|
||||||
n.myIPs[str] = struct{}{}
|
n.myIPs[str] = struct{}{}
|
||||||
|
|
|
@ -257,6 +257,7 @@ func (p *peer) GetVersion() {
|
||||||
|
|
||||||
// assumes the stateLock is not held
|
// assumes the stateLock is not held
|
||||||
func (p *peer) Version() {
|
func (p *peer) Version() {
|
||||||
|
p.net.stateLock.Lock()
|
||||||
msg, err := p.net.b.Version(
|
msg, err := p.net.b.Version(
|
||||||
p.net.networkID,
|
p.net.networkID,
|
||||||
p.net.nodeID,
|
p.net.nodeID,
|
||||||
|
@ -264,6 +265,7 @@ func (p *peer) Version() {
|
||||||
p.net.ip,
|
p.net.ip,
|
||||||
p.net.version.String(),
|
p.net.version.String(),
|
||||||
)
|
)
|
||||||
|
p.net.stateLock.Unlock()
|
||||||
p.net.log.AssertNoError(err)
|
p.net.log.AssertNoError(err)
|
||||||
p.Send(msg)
|
p.Send(msg)
|
||||||
}
|
}
|
||||||
|
@ -431,14 +433,16 @@ func (p *peer) getPeerList(_ Msg) { p.SendPeerList() }
|
||||||
func (p *peer) peerList(msg Msg) {
|
func (p *peer) peerList(msg Msg) {
|
||||||
ips := msg.Get(Peers).([]utils.IPDesc)
|
ips := msg.Get(Peers).([]utils.IPDesc)
|
||||||
|
|
||||||
|
p.net.stateLock.Lock()
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
if !ip.Equal(p.net.ip) &&
|
if !ip.Equal(p.net.ip) &&
|
||||||
!ip.IsZero() &&
|
!ip.IsZero() &&
|
||||||
(p.net.allowPrivateIPs || !ip.IsPrivate()) {
|
(p.net.allowPrivateIPs || !ip.IsPrivate()) {
|
||||||
// TODO: only try to connect once
|
// TODO: only try to connect once
|
||||||
p.net.Track(ip)
|
p.net.track(ip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
p.net.stateLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// assumes the stateLock is not held
|
// assumes the stateLock is not held
|
||||||
|
|
Loading…
Reference in New Issue