erigon-pulse/node/nodecfg/defaults.go

55 lines
2.3 KiB
Go
Raw Normal View History

// Copyright 2016 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
2022-05-26 05:27:44 +00:00
package nodecfg
import (
"github.com/ledgerwatch/erigon-lib/direct"
"github.com/ledgerwatch/erigon/p2p"
"github.com/ledgerwatch/erigon/p2p/nat"
"github.com/ledgerwatch/erigon/rpc/rpccfg"
)
const (
DefaultHTTPHost = "localhost" // Default host interface for the HTTP RPC server
DefaultHTTPPort = 8545 // Default TCP port for the HTTP RPC server
DefaultAuthRpcPort = 8551 // Default TCP port for the Engine API HTTP RPC server
DefaultWSHost = "localhost" // Default host interface for the websocket RPC server
DefaultWSPort = 8546 // Default TCP port for the websocket RPC server
DefaultGRPCHost = "localhost" // Default host interface for the GRPC server
DefaultGRPCPort = 8547 // Default TCP port for the GRPC server
DefaultTCPHost = "localhost" // default host interface for TCP RPC server
allow rpcdaemon to bind to tcp (#6184) this pr adds CLI flag to allow the rpcdaemon to bind to a TCP port. this is very useful if one wants to maintain a remote connection with the rpcdaemon without using websocket. This is useful because a lot of issues come with the websocket protocol (compression, max size, etc). TCP socket gets around these things (it is just raw json over tcp stream) the rpc package already supports this, it was just a matter of adding the bind. try `echo '{"jsonrpc":"2.0","method":"eth_blockNumber","id":"1","params":[""]}' | nc localhost 8548` as a basic test to test. Subscriptions are also working (idk how to send keepalives with netcat) the default rpc.(*Client).Dial method does not support TCP. I have not included that in this PR. The code for such is as follow ``` // DialTCP create a new TCP client that connects to the given endpoint. // // The context is used for the initial connection establishment. It does not // affect subsequent interactions with the client. func DialTCP(ctx context.Context, endpoint string) (*Client, error) { parsed, err := url.Parse(endpoint) if err != nil { return nil, err } ans := make(chan *Client) errc := make(chan error) go func() { client, err := newClient(ctx, func(ctx context.Context) (ServerCodec, error) { conn, err := net.Dial("tcp", parsed.Host) if err != nil { return nil, err } return NewCodec(conn), nil }) if err != nil { errc <- err return } ans <- client }() select { case err := <-errc: return nil, err case a := <-ans: return a, nil case <-ctx.Done(): return nil, ctx.Err() } } // DialContext creates a new RPC client, just like Dial. // // The context is used to cancel or time out the initial connection establishment. It does // not affect subsequent interactions with the client. func DialContext(ctx context.Context, rawurl string) (*Client, error) { u, err := url.Parse(rawurl) if err != nil { return nil, err } switch u.Scheme { case "http", "https": return DialHTTP(rawurl) case "ws", "wss": return DialWebsocket(ctx, rawurl, "") case "tcp": return DialTCP(ctx, rawurl) case "stdio": return DialStdIO(ctx) case "": return DialIPC(ctx, rawurl) default: return nil, fmt.Errorf("no known transport for URL scheme %q", u.Scheme) } } ``` let me know if you would like me to add this to the PR as well. the TCP connection can then be established with `rpc.Dial("tcp://host:port")`
2022-12-03 07:22:47 +00:00
DefaultTCPPort = 8548 // default TCP port for TCP RPC server
)
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
2017-04-12 14:27:23 +00:00
// DefaultConfig contains reasonable default settings.
var DefaultConfig = Config{
2021-06-19 10:38:45 +00:00
HTTPPort: DefaultHTTPPort,
HTTPModules: []string{"net", "web3"},
HTTPVirtualHosts: []string{"localhost"},
HTTPTimeouts: rpccfg.DefaultHTTPTimeouts,
2021-06-19 10:38:45 +00:00
WSPort: DefaultWSPort,
WSModules: []string{"net", "web3"},
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
2017-04-12 14:27:23 +00:00
P2P: p2p.Config{
ListenAddr: ":30303",
ProtocolVersion: []uint{direct.ETH68, direct.ETH67}, // No need to specify direct.ETH66, because 1 sentry is used for both 66 and 67
MaxPeers: 100,
MaxPendingPeers: 1000,
NAT: nat.Any(),
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
2017-04-12 14:27:23 +00:00
},
}