2016-02-05 11:45:36 +00:00
|
|
|
// 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
|
2016-02-05 11:45:36 +00:00
|
|
|
|
|
|
|
import (
|
2023-05-08 14:03:59 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/direct"
|
|
|
|
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/p2p"
|
|
|
|
"github.com/ledgerwatch/erigon/p2p/nat"
|
2022-05-30 10:08:49 +00:00
|
|
|
"github.com/ledgerwatch/erigon/rpc/rpccfg"
|
2016-02-05 11:45:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2022-08-02 06:15:01 +00:00
|
|
|
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
|
2023-05-08 14:03:59 +00:00
|
|
|
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
|
2016-02-05 11:45:36 +00:00
|
|
|
)
|
|
|
|
|
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"},
|
2022-05-30 10:08:49 +00:00
|
|
|
HTTPTimeouts: rpccfg.DefaultHTTPTimeouts,
|
2021-06-19 10:38:45 +00:00
|
|
|
WSPort: DefaultWSPort,
|
|
|
|
WSModules: []string{"net", "web3"},
|
2017-04-12 14:27:23 +00:00
|
|
|
P2P: p2p.Config{
|
2022-04-28 02:21:52 +00:00
|
|
|
ListenAddr: ":30303",
|
2023-05-15 19:31:35 +00:00
|
|
|
ProtocolVersion: []uint{direct.ETH68, direct.ETH67}, // No need to specify direct.ETH66, because 1 sentry is used for both 66 and 67
|
2022-04-28 02:21:52 +00:00
|
|
|
MaxPeers: 100,
|
2022-04-28 22:21:22 +00:00
|
|
|
MaxPendingPeers: 1000,
|
2022-04-28 02:21:52 +00:00
|
|
|
NAT: nat.Any(),
|
2017-04-12 14:27:23 +00:00
|
|
|
},
|
|
|
|
}
|