From 96e374efe59393c8799255c7035f11ab97ee6bbc Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Mon, 5 Mar 2018 10:43:09 +0100 Subject: [PATCH] p2p/sim: use ipv4 --- p2p/simulations/adapters/exec.go | 28 +++++++++++++------ .../simulations/discovery/discovery_test.go | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/p2p/simulations/adapters/exec.go b/p2p/simulations/adapters/exec.go index 64a4704d48..185123206c 100644 --- a/p2p/simulations/adapters/exec.go +++ b/p2p/simulations/adapters/exec.go @@ -340,17 +340,27 @@ type execNodeConfig struct { // ExternalIP gets an external IP address so that Enode URL is usable func ExternalIP() net.IP { - addrs, err := net.InterfaceAddrs() + //addrs, err := net.InterfaceAddrs() + //if err != nil { + //log.Crit("error getting IP address", "err", err) + //} + //for _, addr := range addrs { + //if ip, ok := addr.(*net.IPNet); ok && !ip.IP.IsLoopback() { + //return ip.IP + //} + //} + //log.Crit("unable to determine explicit IP address") + //return net.IP{127, 0, 0, 1} + + conn, err := net.Dial("udp", "8.8.8.8:80") if err != nil { - log.Crit("error getting IP address", "err", err) + panic(err) } - for _, addr := range addrs { - if ip, ok := addr.(*net.IPNet); ok && !ip.IP.IsLoopback() { - return ip.IP - } - } - log.Crit("unable to determine explicit IP address") - return net.IP{127, 0, 0, 1} + defer conn.Close() + + localAddr := conn.LocalAddr().(*net.UDPAddr) + + return localAddr.IP } // execP2PNode starts a devp2p node when the current binary is executed with diff --git a/swarm/network/simulations/discovery/discovery_test.go b/swarm/network/simulations/discovery/discovery_test.go index 2782aa84a5..4372788d47 100644 --- a/swarm/network/simulations/discovery/discovery_test.go +++ b/swarm/network/simulations/discovery/discovery_test.go @@ -233,7 +233,7 @@ func discoverySimulation(nodes, conns int, adapter adapters.NodeAdapter) (*simul // 64 nodes ~ 1min // 128 nodes ~ - timeout := 60 * time.Second + timeout := 300 * time.Second ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() result := simulations.NewSimulation(net).Run(ctx, &simulations.Step{