github.com/SmartMeshFoundation/Spectrum@v0.0.0-20220621030607-452a266fee1e/node/defaults.go (about) 1 // Copyright 2016 The Spectrum Authors 2 // This file is part of the Spectrum library. 3 // 4 // The Spectrum 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 Spectrum 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 Spectrum 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/SmartMeshFoundation/Spectrum/p2p" 26 "github.com/SmartMeshFoundation/Spectrum/p2p/nat" 27 ) 28 29 const ( 30 DefaultHTTPHost = "localhost" // Default host interface for the HTTP RPC server 31 DefaultHTTPPort = 18545 // Default TCP port for the HTTP RPC server 32 DefaultWSHost = "localhost" // Default host interface for the websocket RPC server 33 DefaultWSPort = 18546 // Default TCP port for the websocket RPC server 34 ) 35 36 // DefaultConfig contains reasonable default settings. 37 var DefaultConfig = Config{ 38 DataDir: DefaultDataDir(), 39 HTTPPort: DefaultHTTPPort, 40 HTTPModules: []string{"net", "web3"}, 41 WSPort: DefaultWSPort, 42 WSModules: []string{"net", "web3"}, 43 P2P: p2p.Config{ 44 ListenAddr: ":60303", 45 DiscoveryV5Addr: ":44945", 46 MaxPeers: 25, 47 NAT: nat.Any(), 48 }, 49 } 50 51 func DefaultDataDir() string { 52 // Try to place the data folder in the user's home dir 53 home := homeDir() 54 if home != "" { 55 if runtime.GOOS == "darwin" { 56 return filepath.Join(home, "Library", "Spectrum") 57 } else if runtime.GOOS == "windows" { 58 return filepath.Join(home, "AppData", "Roaming", "Spectrum") 59 } else { 60 return filepath.Join(home, ".spectrum") 61 } 62 } 63 // As we cannot guess a stable location, return empty and handle later 64 return "" 65 } 66 67 //add by liangc : for testnet build ipc path 68 func TestDataDir() string { 69 home := homeDir() 70 if home != "" { 71 testnet := "testnet" 72 if runtime.GOOS == "darwin" { 73 return filepath.Join(home, "Library", "Spectrum", testnet) 74 } else if runtime.GOOS == "windows" { 75 return filepath.Join(home, "AppData", "Roaming", "Spectrum", testnet) 76 } else { 77 return filepath.Join(home, ".spectrum", testnet) 78 } 79 } 80 return "" 81 } 82 83 //add by liangc : for testnet build ipc path 84 func DevDataDir() string { 85 home := homeDir() 86 if home != "" { 87 devnet := "devnet" 88 if runtime.GOOS == "darwin" { 89 return filepath.Join(home, "Library", "Spectrum", devnet) 90 } else if runtime.GOOS == "windows" { 91 return filepath.Join(home, "AppData", "Roaming", "Spectrum", devnet) 92 } else { 93 return filepath.Join(home, ".spectrum", devnet) 94 } 95 } 96 return "" 97 } 98 99 func homeDir() string { 100 if home := os.Getenv("HOME"); home != "" { 101 return home 102 } 103 if usr, err := user.Current(); err == nil { 104 return usr.HomeDir 105 } 106 return "" 107 }