set my ip if I happen to discover it for a best effort increase in discoverability

This commit is contained in:
StephenButtolph 2020-05-24 02:25:58 -04:00
parent 36ca80cf89
commit dfa9843722
2 changed files with 11 additions and 3 deletions

View File

@ -699,8 +699,12 @@ func (n *network) upgrade(p *peer, upgrader Upgrader) error {
// mark the IP as one of mine.
if id.Equals(n.id) {
if !p.ip.IsZero() {
// TODO: if n.ip is less useful than p.ip (either it is private, or
// it is zero), should we set it to this IP?
// if n.ip is less useful than p.ip 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()
delete(n.disconnectedIPs, str)
n.myIPs[str] = struct{}{}

View File

@ -257,6 +257,7 @@ func (p *peer) GetVersion() {
// assumes the stateLock is not held
func (p *peer) Version() {
p.net.stateLock.Lock()
msg, err := p.net.b.Version(
p.net.networkID,
p.net.nodeID,
@ -264,6 +265,7 @@ func (p *peer) Version() {
p.net.ip,
p.net.version.String(),
)
p.net.stateLock.Unlock()
p.net.log.AssertNoError(err)
p.Send(msg)
}
@ -431,14 +433,16 @@ func (p *peer) getPeerList(_ Msg) { p.SendPeerList() }
func (p *peer) peerList(msg Msg) {
ips := msg.Get(Peers).([]utils.IPDesc)
p.net.stateLock.Lock()
for _, ip := range ips {
if !ip.Equal(p.net.ip) &&
!ip.IsZero() &&
(p.net.allowPrivateIPs || !ip.IsPrivate()) {
// TODO: only try to connect once
p.net.Track(ip)
p.net.track(ip)
}
}
p.net.stateLock.Unlock()
}
// assumes the stateLock is not held