github.com/neatlab/neatio@v1.7.3-0.20220425043230-d903e92fcc75/network/node/defaults.go (about)

     1  package node
     2  
     3  import (
     4  	"os"
     5  	"os/user"
     6  	"path/filepath"
     7  	"runtime"
     8  
     9  	"github.com/neatlab/neatio/network/p2p"
    10  	"github.com/neatlab/neatio/network/p2p/nat"
    11  	"github.com/neatlab/neatio/network/rpc"
    12  )
    13  
    14  const (
    15  	DefaultHTTPHost = "localhost"
    16  	DefaultHTTPPort = 9915
    17  	DefaultWSHost   = "localhost"
    18  	DefaultWSPort   = 9916
    19  )
    20  
    21  var DefaultConfig = Config{
    22  	GeneralDataDir:   DefaultDataDir(),
    23  	DataDir:          DefaultDataDir(),
    24  	HTTPPort:         DefaultHTTPPort,
    25  	HTTPModules:      []string{"net", "web3"},
    26  	HTTPVirtualHosts: []string{"localhost"},
    27  	HTTPTimeouts:     rpc.DefaultHTTPTimeouts,
    28  	WSPort:           DefaultWSPort,
    29  	WSModules:        []string{"net", "web3"},
    30  	P2P: p2p.Config{
    31  		ListenAddr: ":9910",
    32  		MaxPeers:   200,
    33  		NAT:        nat.Any(),
    34  	},
    35  }
    36  
    37  func DefaultDataDir() string {
    38  
    39  	home := homeDir()
    40  	if home != "" {
    41  
    42  		if runtime.GOOS == "windows" {
    43  			return filepath.Join(home, "AppData", "Roaming", "neatio")
    44  		} else {
    45  			return filepath.Join(home, ".neatio")
    46  		}
    47  	}
    48  
    49  	return ""
    50  }
    51  
    52  func homeDir() string {
    53  	if home := os.Getenv("HOME"); home != "" {
    54  		return home
    55  	}
    56  	if usr, err := user.Current(); err == nil {
    57  		return usr.HomeDir
    58  	}
    59  	return ""
    60  }