Skip to main content

Module session

Module session 

Source
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.
PeerEvent
Something the model should hear about.
Session
The session state both roles share.
StatusDefaults
Status values configured at startup, used for whatever the model leaves out.
StatusSpec
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.
EstablishError
Why a session never got past Hello.
Inbound
What the reader task hands over.
PeerEventKind
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 eth version.
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.

Type Aliases§

BoxRead
BoxWrite
SharedWriter