mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
move 'connecting to the network' into interface/
This commit is contained in:
parent
05ff2a51e1
commit
b93e48b562
1 changed files with 41 additions and 41 deletions
|
|
@ -1,42 +1,43 @@
|
||||||
---
|
---
|
||||||
title: Connecting to the network
|
title: Connecting To The Network
|
||||||
---
|
---
|
||||||
|
|
||||||
## How Peers Are Found
|
## How Peers Are Found
|
||||||
|
|
||||||
Geth continuously attempts to connect to other nodes on the network
|
Geth continuously attempts to connect to other nodes on the network until it has peers. If
|
||||||
until it has peers. If you have UPnP enabled on your router or run
|
you have UPnP enabled on your router or run ethereum on an Internet-facing server, it will
|
||||||
ethereum on an Internet-facing server, it will also accept connections
|
also accept connections from other nodes.
|
||||||
from other nodes.
|
|
||||||
|
|
||||||
Geth finds peers through something called the discovery protocol. In
|
Geth finds peers through something called the discovery protocol. In the discovery
|
||||||
the discovery protocol, nodes are gossipping with each other to find
|
protocol, nodes are gossipping with each other to find out about other nodes on the
|
||||||
out about other nodes on the network. In order to get going initially,
|
network. In order to get going initially, geth uses a set of bootstrap nodes whose
|
||||||
geth uses a set of bootstrap nodes whose endpoints are recorded in the
|
endpoints are recorded in the source code.
|
||||||
source code.
|
|
||||||
|
|
||||||
To change the bootnodes on startup, use the `--bootnodes` option and
|
To change the bootnodes on startup, use the `--bootnodes` option and separate the nodes by
|
||||||
separate the nodes by commas. For example:
|
commas. For example:
|
||||||
|
|
||||||
geth --bootnodes enode://pubkey1@ip1:port1,enode://pubkey2@ip2:port2,enode://pubkey3@ip3:port3
|
geth --bootnodes enode://pubkey1@ip1:port1,enode://pubkey2@ip2:port2,enode://pubkey3@ip3:port3
|
||||||
|
|
||||||
## Common Problems With Connectivity
|
## Common Problems With Connectivity
|
||||||
|
|
||||||
Sometimes you just can't get connected. The most common reasons are
|
Sometimes you just can't get connected. The most common reasons are as follows:
|
||||||
as follows:
|
|
||||||
|
|
||||||
- Your local time might be incorrect. An accurate clock is required
|
- Your local time might be incorrect. An accurate clock is required to participate in the
|
||||||
to participate in the Ethereum network. Check your OS for how to resync
|
Ethereum network. Check your OS for how to resync your clock (example sudo ntpdate -s
|
||||||
your clock (example sudo ntpdate -s time.nist.gov) because even 12
|
time.nist.gov) because even 12 seconds too fast can lead to 0 peers.
|
||||||
seconds too fast can lead to 0 peers.
|
- Some firewall configurations can prevent UDP traffic from flowing. You can use the
|
||||||
- Some firewall configurations can prevent UDP traffic from flowing.
|
static nodes feature or `admin.addPeer()` on the console to configure connections by
|
||||||
You can use the static nodes feature or `admin.addPeer()` on the console
|
hand.
|
||||||
to configure connections by hand.
|
|
||||||
|
|
||||||
To start geth without the discovery protocol, you can use the `--nodiscover` parameter. You only want this is you are running a test node or an experimental test network with fixed nodes.
|
To start geth without the discovery protocol, you can use the `--nodiscover` parameter.
|
||||||
|
You only want this is you are running a test node or an experimental test network with
|
||||||
|
fixed nodes.
|
||||||
|
|
||||||
## Checking Connectivity
|
## Checking Connectivity
|
||||||
|
|
||||||
To check how many peers the client is connected to in the interactive console, the `net` module has two attributes give you info about the number of peers and whether you are a listening node.
|
To check how many peers the client is connected to in the interactive console, the `net`
|
||||||
|
module has two attributes give you info about the number of peers and whether you are a
|
||||||
|
listening node.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
> net.listening
|
> net.listening
|
||||||
|
|
@ -45,7 +46,9 @@ true
|
||||||
4
|
4
|
||||||
```
|
```
|
||||||
|
|
||||||
To get more information about the connected peers, such as IP address and port number, supported protocols, use the `peers()` function of the `admin` object. `admin.peers()` returns the list of currently connected peers.
|
To get more information about the connected peers, such as IP address and port number,
|
||||||
|
supported protocols, use the `peers()` function of the `admin` object. `admin.peers()`
|
||||||
|
returns the list of currently connected peers.
|
||||||
|
|
||||||
```
|
```
|
||||||
> admin.peers
|
> admin.peers
|
||||||
|
|
@ -78,6 +81,7 @@ To get more information about the connected peers, such as IP address and port n
|
||||||
```
|
```
|
||||||
|
|
||||||
To check the ports used by geth and also find your enode URI run:
|
To check the ports used by geth and also find your enode URI run:
|
||||||
|
|
||||||
```
|
```
|
||||||
> admin.nodeInfo
|
> admin.nodeInfo
|
||||||
{
|
{
|
||||||
|
|
@ -92,21 +96,18 @@ To check the ports used by geth and also find your enode URI run:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Custom Networks
|
## Custom Networks
|
||||||
|
|
||||||
Sometimes you might not need to connect to the live public network,
|
Sometimes you might not need to connect to the live public network, you can instead choose
|
||||||
you can instead choose to create your own private testnet. This is
|
to create your own private testnet. This is very useful if you don't need to test external
|
||||||
very useful if you don't need to test external contracts and want just
|
contracts and want just to test the technology, because you won't have to compete with
|
||||||
to test the technology, because you won't have to compete with other
|
other miners and will easily generate a lot of test ether to play around (replace 12345
|
||||||
miners and will easily generate a lot of test ether to play around
|
with any non-negative number):
|
||||||
(replace 12345 with any non-negative number):
|
|
||||||
|
|
||||||
geth -—networkid="12345" console
|
geth -—networkid="12345" console
|
||||||
|
|
||||||
It is also possible to run geth with a custom genesis block from a JSON file
|
It is also possible to run geth with a custom genesis block from a JSON file by supplying
|
||||||
by supplying the `--genesis` flag. The genesis JSON file should have the following
|
the `--genesis` flag. The genesis JSON file should have the following format:
|
||||||
format:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
{
|
{
|
||||||
|
|
@ -132,10 +133,10 @@ format:
|
||||||
|
|
||||||
## Static nodes
|
## Static nodes
|
||||||
|
|
||||||
Geth also supports a feature called static nodes if you have certain
|
Geth also supports a feature called static nodes if you have certain peers you always want
|
||||||
peers you always want to connect to. Static nodes are re-connected
|
to connect to. Static nodes are re-connected on disconnects. You can configure permanent
|
||||||
on disconnects. You can configure permanent static nodes by putting something like
|
static nodes by putting something like the following into
|
||||||
the following into `<datadir>/geth/static-nodes.json`:
|
`<datadir>/geth/static-nodes.json`:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
[
|
[
|
||||||
|
|
@ -144,10 +145,9 @@ the following into `<datadir>/geth/static-nodes.json`:
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also add static nodes at runtime via the js console using [`admin.addPeer()`](../interface/management-apis#admin_addpeer):
|
You can also add static nodes at runtime via the js console using
|
||||||
|
[`admin.addPeer()`](../interface/management-apis#admin_addpeer):
|
||||||
|
|
||||||
```js
|
```js
|
||||||
admin.addPeer("enode://f4642fa65af50cfdea8fa7414a5def7bb7991478b768e296f5e4a54e8b995de102e0ceae2e826f293c481b5325f89be6d207b003382e18a8ecba66fbaf6416c0@33.4.2.1:30303")
|
admin.addPeer("enode://f4642fa65af50cfdea8fa7414a5def7bb7991478b768e296f5e4a54e8b995de102e0ceae2e826f293c481b5325f89be6d207b003382e18a8ecba66fbaf6416c0@33.4.2.1:30303")
|
||||||
```
|
```
|
||||||
|
|
||||||
Caveat: Currently the console is lacking support for removing a peer, increasing peercount or adding a non-static peer but not to keep try reconnecting.
|
|
||||||
Loading…
Reference in a new issue