diff options
author | Felix Lange <fjl@users.noreply.github.com> | 2017-04-12 22:27:23 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-04-12 22:27:23 +0800 |
commit | 30d706c35e16305e2e3ec0eb6a6bdd6aba50d9d2 (patch) | |
tree | 3ec076154049f1fa71b19fd9b7762085059ff15b /p2p | |
parent | b57680b0b21036460c689aab1e82d89297738d50 (diff) | |
download | dexon-30d706c35e16305e2e3ec0eb6a6bdd6aba50d9d2.tar dexon-30d706c35e16305e2e3ec0eb6a6bdd6aba50d9d2.tar.gz dexon-30d706c35e16305e2e3ec0eb6a6bdd6aba50d9d2.tar.bz2 dexon-30d706c35e16305e2e3ec0eb6a6bdd6aba50d9d2.tar.lz dexon-30d706c35e16305e2e3ec0eb6a6bdd6aba50d9d2.tar.xz dexon-30d706c35e16305e2e3ec0eb6a6bdd6aba50d9d2.tar.zst dexon-30d706c35e16305e2e3ec0eb6a6bdd6aba50d9d2.zip |
cmd/geth: add --config file flag (#13875)
* p2p/discover, p2p/discv5: add marshaling methods to Node
* p2p/netutil: make Netlist decodable from TOML
* common/math: encode nil HexOrDecimal256 as 0x0
* cmd/geth: add --config file flag
* cmd/geth: add missing license header
* eth: prettify Config again, fix tests
* eth: use gasprice.Config instead of duplicating its fields
* eth/gasprice: hide nil default from dumpconfig output
* cmd/geth: hide genesis block in dumpconfig output
* node: make tests compile
* console: fix tests
* cmd/geth: make TOML keys look exactly like Go struct fields
* p2p: use discovery by default
This makes the zero Config slightly more useful. It also fixes package
node tests because Node detects reuse of the datadir through the
NodeDatabase.
* cmd/geth: make ethstats URL settable through config file
* cmd/faucet: fix configuration
* cmd/geth: dedup attach tests
* eth: add comment for DefaultConfig
* eth: pass downloader.SyncMode in Config
This removes the FastSync, LightSync flags in favour of a more
general SyncMode flag.
* cmd/utils: remove jitvm flags
* cmd/utils: make mutually exclusive flag error prettier
It now reads:
Fatal: flags --dev, --testnet can't be used at the same time
* p2p: fix typo
* node: add DefaultConfig, use it for geth
* mobile: add missing NoDiscovery option
* cmd/utils: drop MakeNode
This exposed a couple of places that needed to be updated to use
node.DefaultConfig.
* node: fix typo
* eth: make fast sync the default mode
* cmd/utils: remove IPCApiFlag (unused)
* node: remove default IPC path
Set it in the frontends instead.
* cmd/geth: add --syncmode
* cmd/utils: make --ipcdisable and --ipcpath mutually exclusive
* cmd/utils: don't enable WS, HTTP when setting addr
* cmd/utils: fix --identity
Diffstat (limited to 'p2p')
-rw-r--r-- | p2p/discover/node.go | 14 | ||||
-rw-r--r-- | p2p/discv5/node.go | 14 | ||||
-rw-r--r-- | p2p/netutil/net.go | 25 | ||||
-rw-r--r-- | p2p/server.go | 34 |
4 files changed, 70 insertions, 17 deletions
diff --git a/p2p/discover/node.go b/p2p/discover/node.go index 6a7ab814e..d9cbd9448 100644 --- a/p2p/discover/node.go +++ b/p2p/discover/node.go @@ -207,6 +207,20 @@ func MustParseNode(rawurl string) *Node { return n } +// MarshalText implements encoding.TextMarshaler. +func (n *Node) MarshalText() ([]byte, error) { + return []byte(n.String()), nil +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (n *Node) UnmarshalText(text []byte) error { + dec, err := ParseNode(string(text)) + if err == nil { + *n = *dec + } + return err +} + // NodeID is a unique identifier for each node. // The node identifier is a marshaled elliptic curve public key. type NodeID [NodeIDBits / 8]byte diff --git a/p2p/discv5/node.go b/p2p/discv5/node.go index c99b4da14..2db7a508f 100644 --- a/p2p/discv5/node.go +++ b/p2p/discv5/node.go @@ -215,6 +215,20 @@ func MustParseNode(rawurl string) *Node { return n } +// MarshalText implements encoding.TextMarshaler. +func (n *Node) MarshalText() ([]byte, error) { + return []byte(n.String()), nil +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (n *Node) UnmarshalText(text []byte) error { + dec, err := ParseNode(string(text)) + if err == nil { + *n = *dec + } + return err +} + // type nodeQueue []*Node // // // pushNew adds n to the end if it is not present. diff --git a/p2p/netutil/net.go b/p2p/netutil/net.go index 3c3715788..f6005afd2 100644 --- a/p2p/netutil/net.go +++ b/p2p/netutil/net.go @@ -84,6 +84,31 @@ func ParseNetlist(s string) (*Netlist, error) { return &l, nil } +// MarshalTOML implements toml.MarshalerRec. +func (l Netlist) MarshalTOML() interface{} { + list := make([]string, 0, len(l)) + for _, net := range l { + list = append(list, net.String()) + } + return list +} + +// UnmarshalTOML implements toml.UnmarshalerRec. +func (l *Netlist) UnmarshalTOML(fn func(interface{}) error) error { + var masks []string + if err := fn(&masks); err != nil { + return err + } + for _, mask := range masks { + _, n, err := net.ParseCIDR(mask) + if err != nil { + return err + } + *l = append(*l, *n) + } + return nil +} + // Add parses a CIDR mask and appends it to the list. It panics for invalid masks and is // intended to be used for setting up static lists. func (l *Netlist) Add(cidr string) { diff --git a/p2p/server.go b/p2p/server.go index b2b8c9762..d7909d53a 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -58,7 +58,7 @@ var errServerStopped = errors.New("server stopped") // Config holds Server options. type Config struct { // This field must be set to a valid secp256k1 private key. - PrivateKey *ecdsa.PrivateKey + PrivateKey *ecdsa.PrivateKey `toml:"-"` // MaxPeers is the maximum number of peers that can be // connected. It must be greater than zero. @@ -67,22 +67,22 @@ type Config struct { // MaxPendingPeers is the maximum number of peers that can be pending in the // handshake phase, counted separately for inbound and outbound connections. // Zero defaults to preset values. - MaxPendingPeers int + MaxPendingPeers int `toml:",omitempty"` - // Discovery specifies whether the peer discovery mechanism should be started - // or not. Disabling is usually useful for protocol debugging (manual topology). - Discovery bool + // NoDiscovery can be used to disable the peer discovery mechanism. + // Disabling is useful for protocol debugging (manual topology). + NoDiscovery bool // DiscoveryV5 specifies whether the the new topic-discovery based V5 discovery // protocol should be started or not. - DiscoveryV5 bool + DiscoveryV5 bool `toml:",omitempty"` // Listener address for the V5 discovery protocol UDP traffic. - DiscoveryV5Addr string + DiscoveryV5Addr string `toml:",omitempty"` // Name sets the node name of this server. // Use common.MakeName to create a name that follows existing conventions. - Name string + Name string `toml:"-"` // BootstrapNodes are used to establish connectivity // with the rest of the network. @@ -91,7 +91,7 @@ type Config struct { // BootstrapNodesV5 are used to establish connectivity // with the rest of the network using the V5 discovery // protocol. - BootstrapNodesV5 []*discv5.Node + BootstrapNodesV5 []*discv5.Node `toml:",omitempty"` // Static nodes are used as pre-configured connections which are always // maintained and re-connected on disconnects. @@ -104,16 +104,16 @@ type Config struct { // Connectivity can be restricted to certain IP networks. // If this option is set to a non-nil value, only hosts which match one of the // IP networks contained in the list are considered. - NetRestrict *netutil.Netlist + NetRestrict *netutil.Netlist `toml:",omitempty"` // NodeDatabase is the path to the database containing the previously seen // live nodes in the network. - NodeDatabase string + NodeDatabase string `toml:",omitempty"` // Protocols should contain the protocols supported // by the server. Matching protocols are launched for // each peer. - Protocols []Protocol + Protocols []Protocol `toml:"-"` // If ListenAddr is set to a non-nil address, the server // will listen for incoming connections. @@ -126,14 +126,14 @@ type Config struct { // If set to a non-nil value, the given NAT port mapper // is used to make the listening port available to the // Internet. - NAT nat.Interface + NAT nat.Interface `toml:",omitempty"` // If Dialer is set to a non-nil value, the given Dialer // is used to dial outbound peer connections. - Dialer *net.Dialer + Dialer *net.Dialer `toml:"-"` // If NoDial is true, the server will not dial any peers. - NoDial bool + NoDial bool `toml:",omitempty"` } // Server manages all peer connections. @@ -370,7 +370,7 @@ func (srv *Server) Start() (err error) { srv.peerOpDone = make(chan struct{}) // node table - if srv.Discovery { + if !srv.NoDiscovery { ntab, err := discover.ListenUDP(srv.PrivateKey, srv.ListenAddr, srv.NAT, srv.NodeDatabase, srv.NetRestrict) if err != nil { return err @@ -393,7 +393,7 @@ func (srv *Server) Start() (err error) { } dynPeers := (srv.MaxPeers + 1) / 2 - if !srv.Discovery { + if srv.NoDiscovery { dynPeers = 0 } dialer := newDialState(srv.StaticNodes, srv.BootstrapNodes, srv.ntab, dynPeers, srv.NetRestrict) |