Expand description
One devp2p session after the TCP connection, shared by the server and the client.
establish runs the RLPx handshake and the Hello exchange (bounded by
HANDSHAKE_TIMEOUT); read_loop is the reader task, which answers Ping itself so a
model call in progress never makes the peer time the session out; Session holds what the
two sides have said — both Statuses, the requests each side still owes an answer — decodes
every eth message into a PeerEvent for the model, and carries out the model’s
Commands, refusing any that would put something on the wire the session cannot vouch for:
headers that do not answer the request they claim to, transactions nobody asked for, a reply
to a request that is already answered.
Structs§
- End
- Why a session ended, and how to tag it.
- Established
- A session past Hello.
- Peer
Event - Something the model should hear about.
- Session
- The session state both roles share.
- Status
Defaults - Status values configured at startup, used for whatever the model leaves out.
- Status
Spec - A Status as the model specifies it: explicit fields, optionally mirroring the peer’s.
- Writer
- The write side: the frame codec and the socket half, behind one lock so frames never interleave.
Enums§
- Applied
- The outcome of one command.
- Command
- One validated action.
- Establish
Error - Why a session never got past Hello.
- Inbound
- What the reader task hands over.
- Peer
Event Kind - Role
- Who dials.
Constants§
- DISCONNECT
- HANDSHAKE_
TIMEOUT - The RLPx handshake and the Hello exchange together.
- IDLE_
TIMEOUT - How long a session may go without a frame. Peers ping every 15 seconds.
- MAX_
ANSWER_ ITEMS - The most headers, bodies or transactions one answer may carry (go-ethereum serves at most 1024 headers).
- MAX_
MESSAGE_ BYTES - The largest message accepted after decompression, and the server’s
max_inbound_bytes. go-ethereum’s own cap is 10 MiB; nothing a model answers or asks for comes near either. - MAX_
OUTSTANDING - Requests NetGet may have outstanding at once.
- MAX_
OWED - Peer requests NetGet may owe an answer to at once; past this, the session is closed.
- MAX_
PEER_ HASHES - The most hashes a peer may ask about or announce in one message.
- MAX_
REQUEST_ HASHES - The most hashes NetGet asks about in one request.
- MAX_
REQUEST_ HEADERS - The most headers NetGet asks for in one request.
- PING_
INTERVAL - How often this side pings.
- REQUEST_
BODIES - REQUEST_
HEADERS - REQUEST_
POOLED - REQUEST_
TIMEOUT - How long a request NetGet sent may stay unanswered.
- SEND_
BODIES - SEND_
HEADERS - SEND_
POOLED - SEND_
STATUS - WRITE_
TIMEOUT - How long one frame may take to write.
Functions§
- build_
status - Resolve a Status: each field from the action, else the peer’s (with
mirror_peer), else the startup configuration, else a refusal naming the field. The fork hash, when nobody gave one, is computed from the genesis hash and the passed forks. - close
- compatible
- Whether two Statuses describe the same chain, and if not, why not.
- disconnect
- Send Disconnect and close our side. Best effort: the peer may already be gone.
- establish
- The RLPx handshake, then Hello both ways. Our Hello goes out first and unconditionally — it
is NetGet’s identity, not a decision — and the peer’s must name the key it authenticated
with and share an
ethversion. - parse_
command - Validate one action. Everything a peer would see is checked here, so an action the executor accepts is one the session can carry out.
- read_
loop - The reader task: read frames until the session ends, answering Ping with Pong itself.
- send
- Send one message; returns the bytes written.
- validate_
answer - Refuse headers that do not answer
req: more than asked for, the wrong numbers, a first header whose hash is not the one asked for, or (for a contiguous request) a header that does not name the previous one as its parent.