Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listen to all Network Interfaces for discovery #7434

Merged
merged 42 commits into from
Oct 8, 2020
Merged
Changes from 17 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
be235d5
listen to all ifaces for discovery
nisdas Oct 5, 2020
7bdab2e
Merge branch 'master' into listenToAllIfaces
nisdas Oct 5, 2020
57e6218
fix test
nisdas Oct 5, 2020
32e4e68
Merge branch 'listenToAllIfaces' of https://github.com/prysmaticlabs/…
nisdas Oct 5, 2020
b7a0cf5
fix tests
nisdas Oct 5, 2020
a5d6fff
fix all tests
nisdas Oct 5, 2020
00626c8
Merge branch 'master' into listenToAllIfaces
farazdagi Oct 5, 2020
10a1a5b
Merge refs/heads/master into listenToAllIfaces
prylabs-bulldozer[bot] Oct 5, 2020
e3c0f08
Merge refs/heads/master into listenToAllIfaces
prylabs-bulldozer[bot] Oct 6, 2020
9b0eb10
Merge refs/heads/master into listenToAllIfaces
prylabs-bulldozer[bot] Oct 6, 2020
03f70e3
Merge refs/heads/master into listenToAllIfaces
prylabs-bulldozer[bot] Oct 6, 2020
e7823fe
Revert "fix all tests"
nisdas Oct 6, 2020
ad492ef
Revert "fix tests"
nisdas Oct 6, 2020
cffce26
Revert "fix test"
nisdas Oct 6, 2020
336714c
fix and use loopback
nisdas Oct 6, 2020
fba2e03
Merge branch 'listenToAllIfaces' of https://github.com/prysmaticlabs/…
nisdas Oct 6, 2020
51b0df3
do properly
nisdas Oct 6, 2020
a29b449
Merge refs/heads/master into listenToAllIfaces
prylabs-bulldozer[bot] Oct 6, 2020
4fd9ad5
fix
nisdas Oct 6, 2020
e2696f5
Merge branch 'listenToAllIfaces' of https://github.com/prysmaticlabs/…
nisdas Oct 6, 2020
5c86814
Merge refs/heads/master into listenToAllIfaces
prylabs-bulldozer[bot] Oct 6, 2020
9afc223
Merge refs/heads/master into listenToAllIfaces
prylabs-bulldozer[bot] Oct 6, 2020
7b266db
Merge refs/heads/master into listenToAllIfaces
prylabs-bulldozer[bot] Oct 6, 2020
c644c4b
Merge refs/heads/master into listenToAllIfaces
prylabs-bulldozer[bot] Oct 7, 2020
e2fdd9e
listen to all ifaces
nisdas Oct 7, 2020
abbf2b6
Merge branch 'listenToAllIfaces' of https://github.com/prysmaticlabs/…
nisdas Oct 7, 2020
142a550
fix bootnode
nisdas Oct 7, 2020
0123570
Merge refs/heads/master into listenToAllIfaces
prylabs-bulldozer[bot] Oct 7, 2020
cdadc16
Merge refs/heads/master into listenToAllIfaces
prylabs-bulldozer[bot] Oct 7, 2020
f5f46d1
make it trace
nisdas Oct 7, 2020
b1336ca
Merge branch 'listenToAllIfaces' of https://github.com/prysmaticlabs/…
nisdas Oct 7, 2020
7c2ee91
make it loopback
nisdas Oct 8, 2020
7f1a5a5
Merge branch 'master' into listenToAllIfaces
nisdas Oct 8, 2020
9108fad
Merge branch 'master' of https://github.com/prysmaticlabs/geth-shardi…
nisdas Oct 8, 2020
039e02a
swap out
nisdas Oct 8, 2020
ef4cb7b
change back
nisdas Oct 8, 2020
6809169
Merge branch 'listenToAllIfaces' of https://github.com/prysmaticlabs/…
nisdas Oct 8, 2020
90a8fb1
Merge branch 'master' of https://github.com/prysmaticlabs/geth-shardi…
nisdas Oct 8, 2020
8b23f5a
fix e2e
nisdas Oct 8, 2020
7e9fccb
fix
nisdas Oct 8, 2020
6742a84
Merge branch 'master' into listenToAllIfaces
nisdas Oct 8, 2020
110d145
Update beacon-chain/p2p/discovery.go
nisdas Oct 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 16 additions & 36 deletions beacon-chain/p2p/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"crypto/ecdsa"
"net"
"strconv"
"time"

"github.com/ethereum/go-ethereum/p2p/discover"
Expand Down Expand Up @@ -98,16 +97,17 @@ func (s *Service) createListener(
ipAddr net.IP,
privKey *ecdsa.PrivateKey,
) (*discover.UDPv5, error) {
// assume ip is either ipv4 or ipv6
// Listen to all network interfaces
// for both ip protocols.
networkVersion := ""
nisdas marked this conversation as resolved.
Show resolved Hide resolved
if ipAddr.To4() != nil {
networkVersion = "udp4"
ipAddr = net.IPv4zero
} else {
networkVersion = "udp6"
ipAddr = net.IPv6zero
}
// Check for the real local address which may
// be different in the presence of virtual networks.
ipAddr = s.localAddress(networkVersion, ipAddr)

// If local ip is specified then use that instead.
if s.cfg.LocalIP != "" {
ipAddr = net.ParseIP(s.cfg.LocalIP)
Expand Down Expand Up @@ -185,6 +185,17 @@ func (s *Service) createLocalNode(
return nil, errors.Wrap(err, "could not open node's peer database")
}
localNode := enode.NewLocalNode(db, privKey)
// In the event we have a zero ip passed in, we
// instead persist the loopback ip in the
// localnode entry.
switch {
case ipAddr.Equal(net.IPv4zero):
ipAddr = net.ParseIP("127.0.0.1")
case ipAddr.Equal(net.IPv6zero):
ipAddr = net.IPv6loopback
default:
// do nothing
}
ipEntry := enr.IP(ipAddr)
udpEntry := enr.UDP(udpPort)
tcpEntry := enr.TCP(tcpPort)
Expand Down Expand Up @@ -275,37 +286,6 @@ func (s *Service) isPeerAtLimit() bool {
return activePeers >= maxPeers || numOfConns >= maxPeers
}

// retrieve real local address of the node. In the event
// that is not possible we return the provided ip.
func (s *Service) localAddress(network string, addr net.IP) net.IP {
if len(s.cfg.BootstrapNodeAddr) == 0 {
return addr
}
// Dial the first bootnode to determine our 'real' local address.
bootNode, err := enode.Parse(enode.ValidSchemes, s.cfg.BootstrapNodeAddr[0])
if err != nil {
log.Error("Could not parse bootnode address")
return addr
}
conn, err := net.DialTimeout(network, net.JoinHostPort(bootNode.IP().String(), strconv.Itoa(bootNode.UDP())), dialTimeout)
if err != nil {
log.Error("Could not dial remote peer")
return addr
}
defer func() {
if err := conn.Close(); err != nil {
log.Error(err)
}
}()
// Determine the real address from which the initial connection was made.
realAddr, _, err := net.SplitHostPort(conn.LocalAddr().String())
if err != nil {
log.Error("Could not dial remote peer")
return addr
}
return net.ParseIP(realAddr)
}

func parseBootStrapAddrs(addrs []string) (discv5Nodes []string) {
discv5Nodes, _ = parseGenericAddrs(addrs)
if len(discv5Nodes) == 0 {
Expand Down