github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/node/defaults.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 19:16:40</date> 10 //</624450102219509760> 11 12 13 package node 14 15 import ( 16 "os" 17 "os/user" 18 "path/filepath" 19 "runtime" 20 21 "github.com/ethereum/go-ethereum/p2p" 22 "github.com/ethereum/go-ethereum/p2p/nat" 23 "github.com/ethereum/go-ethereum/rpc" 24 ) 25 26 const ( 27 DefaultHTTPHost = "localhost" //HTTP RPC服务器的默认主机接口 28 DefaultHTTPPort = 8545 //HTTP RPC服务器的默认TCP端口 29 DefaultWSHost = "localhost" //WebSocket RPC服务器的默认主机接口 30 DefaultWSPort = 8546 //WebSocket RPC服务器的默认TCP端口 31 ) 32 33 //默认配置包含合理的默认设置。 34 var DefaultConfig = Config{ 35 DataDir: DefaultDataDir(), 36 HTTPPort: DefaultHTTPPort, 37 HTTPModules: []string{"net", "web3"}, 38 HTTPVirtualHosts: []string{"localhost"}, 39 HTTPTimeouts: rpc.DefaultHTTPTimeouts, 40 WSPort: DefaultWSPort, 41 WSModules: []string{"net", "web3"}, 42 P2P: p2p.Config{ 43 ListenAddr: ":30303", 44 MaxPeers: 25, 45 NAT: nat.Any(), 46 }, 47 } 48 49 //defaultdatadir是用于数据库和其他数据库的默认数据目录 50 //持久性要求。 51 func DefaultDataDir() string { 52 //尝试将数据文件夹放在用户的home目录中 53 home := homeDir() 54 if home != "" { 55 if runtime.GOOS == "darwin" { 56 return filepath.Join(home, "Library", "Ethereum") 57 } else if runtime.GOOS == "windows" { 58 return filepath.Join(home, "AppData", "Roaming", "Ethereum") 59 } else { 60 return filepath.Join(home, ".ethereum") 61 } 62 } 63 //因为我们无法猜测一个稳定的位置,所以返回空的,稍后再处理 64 return "" 65 } 66 67 func homeDir() string { 68 if home := os.Getenv("HOME"); home != "" { 69 return home 70 } 71 if usr, err := user.Current(); err == nil { 72 return usr.HomeDir 73 } 74 return "" 75 } 76