From e80e6d5b029a192ba5093f19ec0a1f7d59338d67 Mon Sep 17 00:00:00 2001 From: frank Date: Fri, 24 Feb 2023 00:07:18 +0800 Subject: [PATCH] revert changes to geth_node.go --- node/geth_node.go | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/node/geth_node.go b/node/geth_node.go index e3f6f9276..701b3039f 100644 --- a/node/geth_node.go +++ b/node/geth_node.go @@ -3,7 +3,6 @@ package node import ( "errors" "fmt" - "net" "os" "path/filepath" @@ -65,36 +64,6 @@ func MakeNode(config *params.NodeConfig, accs *accounts.Manager, db *leveldb.DB) return stack, nil } -func getUsableTCPPort() (int, error) { - conn, err := net.ListenTCP("tcp", &net.TCPAddr{ - IP: net.IPv4zero, - Port: 0, - }) - if err != nil { - return 0, err - } - defer conn.Close() - return conn.Addr().(*net.TCPAddr).Port, nil -} - -func handleListenAddr(listenAddr string) (string, error) { - if listenAddr == "" { - return "", nil - } - ip, port, err := net.SplitHostPort(listenAddr) - if err != nil { - return "", err - } - if port == "0" { - randomPort, err := getUsableTCPPort() - if err != nil { - return "", err - } - listenAddr = net.JoinHostPort(ip, fmt.Sprintf("%d", randomPort)) - } - return listenAddr, nil -} - // newGethNodeConfig returns default stack configuration for mobile client node func newGethNodeConfig(config *params.NodeConfig) (*node.Config, error) { // NOTE: I haven't changed anything related to this parameters, but @@ -111,11 +80,6 @@ func newGethNodeConfig(config *params.NodeConfig) (*node.Config, error) { maxPendingPeers = config.MaxPendingPeers } - listenAddr, err := handleListenAddr(config.ListenAddr) - if err != nil { - return nil, err - } - nc := &node.Config{ DataDir: config.DataDir, KeyStoreDir: config.KeyStoreDir, @@ -125,7 +89,7 @@ func newGethNodeConfig(config *params.NodeConfig) (*node.Config, error) { Version: config.Version, P2P: p2p.Config{ NoDiscovery: true, // we always use only v5 server - ListenAddr: listenAddr, + ListenAddr: config.ListenAddr, NAT: nat.Any(), MaxPeers: maxPeers, MaxPendingPeers: maxPendingPeers,