revert changes to geth_node.go

This commit is contained in:
frank 2023-02-24 00:07:18 +08:00
parent e8c1421997
commit e80e6d5b02
1 changed files with 1 additions and 37 deletions

View File

@ -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,