github.com/intfoundation/intchain@v0.0.0-20220727031208-4316ad31ca73/node/defaults.go (about)

     1  // Copyright 2016 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package node
    18  
    19  import (
    20  	"os"
    21  	"os/user"
    22  	"path/filepath"
    23  	"runtime"
    24  
    25  	"github.com/intfoundation/intchain/p2p"
    26  	"github.com/intfoundation/intchain/p2p/nat"
    27  	"github.com/intfoundation/intchain/rpc"
    28  )
    29  
    30  const (
    31  	DefaultHTTPHost = "localhost" // Default host interface for the HTTP RPC server
    32  	DefaultHTTPPort = 8555        // Default TCP port for the HTTP RPC server
    33  	DefaultWSHost   = "localhost" // Default host interface for the websocket RPC server
    34  	DefaultWSPort   = 8556        // Default TCP port for the websocket RPC server
    35  )
    36  
    37  // DefaultConfig contains reasonable default settings.
    38  var DefaultConfig = Config{
    39  	GeneralDataDir:   DefaultDataDir(),
    40  	DataDir:          DefaultDataDir(),
    41  	HTTPPort:         DefaultHTTPPort,
    42  	HTTPModules:      []string{"net", "web3"},
    43  	HTTPVirtualHosts: []string{"localhost"},
    44  	HTTPTimeouts:     rpc.DefaultHTTPTimeouts,
    45  	WSPort:           DefaultWSPort,
    46  	WSModules:        []string{"net", "web3"},
    47  	P2P: p2p.Config{
    48  		ListenAddr: ":8550",
    49  		MaxPeers:   200,
    50  		NAT:        nat.Any(),
    51  	},
    52  }
    53  
    54  // DefaultDataDir is the default data directory to use for the databases and other
    55  // persistence requirements.
    56  func DefaultDataDir() string {
    57  	// Try to place the data folder in the user's home dir
    58  	home := homeDir()
    59  	if home != "" {
    60  		//if runtime.GOOS == "darwin" {
    61  		//	return filepath.Join(home, "Library", "intchain")
    62  		//} else
    63  		if runtime.GOOS == "windows" {
    64  			return filepath.Join(home, "AppData", "Roaming", "intchain")
    65  		} else {
    66  			return filepath.Join(home, ".intchain")
    67  		}
    68  	}
    69  	// As we cannot guess a stable location, return empty and handle later
    70  	return ""
    71  }
    72  
    73  func homeDir() string {
    74  	if home := os.Getenv("HOME"); home != "" {
    75  		return home
    76  	}
    77  	if usr, err := user.Current(); err == nil {
    78  		return usr.HomeDir
    79  	}
    80  	return ""
    81  }