defaults.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. package node
  17. import (
  18. "os"
  19. "os/user"
  20. "path/filepath"
  21. "runtime"
  22. "github.com/ethereum/go-ethereum/p2p"
  23. "github.com/ethereum/go-ethereum/p2p/nat"
  24. "github.com/ethereum/go-ethereum/rpc"
  25. )
  26. const (
  27. DefaultHTTPHost = "localhost" // Default host interface for the HTTP RPC server
  28. DefaultHTTPPort = 8545 // Default TCP port for the HTTP RPC server
  29. DefaultWSHost = "localhost" // Default host interface for the websocket RPC server
  30. DefaultWSPort = 8546 // Default TCP port for the websocket RPC server
  31. )
  32. // DefaultConfig contains reasonable default settings.
  33. var DefaultConfig = Config{
  34. DataDir: DefaultDataDir(),
  35. HTTPPort: DefaultHTTPPort,
  36. HTTPModules: []string{"net", "web3"},
  37. HTTPVirtualHosts: []string{"localhost"},
  38. HTTPTimeouts: rpc.DefaultHTTPTimeouts,
  39. WSPort: DefaultWSPort,
  40. WSModules: []string{"net", "web3"},
  41. P2P: p2p.Config{
  42. ListenAddr: ":30303",
  43. MaxPeers: 25,
  44. NAT: nat.Any(),
  45. },
  46. }
  47. // DefaultDataDir is the default data directory to use for the databases and other
  48. // persistence requirements.
  49. func DefaultDataDir() string {
  50. // Try to place the data folder in the user's home dir
  51. home := homeDir()
  52. if home != "" {
  53. if runtime.GOOS == "darwin" {
  54. return filepath.Join(home, "Library", "Ethereum")
  55. } else if runtime.GOOS == "windows" {
  56. return filepath.Join(home, "AppData", "Roaming", "Ethereum")
  57. } else {
  58. return filepath.Join(home, ".ethereum")
  59. }
  60. }
  61. // As we cannot guess a stable location, return empty and handle later
  62. return ""
  63. }
  64. func homeDir() string {
  65. if home := os.Getenv("HOME"); home != "" {
  66. return home
  67. }
  68. if usr, err := user.Current(); err == nil {
  69. return usr.HomeDir
  70. }
  71. return ""
  72. }