Commit Graph

23 Commits

Author SHA1 Message Date
151420df58 fix(net): encode ping pong as snappy (#555) 2022-12-21 15:24:41 +02:00
aab385c84a feat(eth-wire): RLP encode then compress (#535) 2022-12-20 14:33:47 +02:00
5758c297b3 fix(eth-wire): fix disconnect reason rlp decoding (#502)
* add trace in DisconnectReason Decodable impl

* add trace for decoding p2p hello

* add traces to p2p and eth stream

* refactor P2PMessage decoding

 * improve disconnect tracing

* s/Hello/first

* add geth disconnect test

* add disconnectreason test cases

* add known failing disconnect messages

* add trace when disconnect reason decoding fails

* cargo fmt

* add more examples

 * adding more as they appear in traces
 * will add the rest since they can be exhaustively enumerated

* add every other possible encoding

* fix disconnect decoding

 * the four possible formats for a disconnect message (rlp list (y/n) x
   snappy (y/n)):
   * encoded as a single rlp byte
     * with snappy
     * without snappy
   * encoded as a rlp list
     * with snappy
     * without snappy
 * fix the type for decoding in the test_decode_known_reasons test

* sort reasons by length in test

* remove printlns

* use one call to advance

* simplify decode impl to strip last byte

 * todo: comment explaining the different formats being parsed?

* explicitly remove geth as a peer

* style: traces

* add another disconnect code from geth

* fix: add check for DisconnectRequested

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
2022-12-19 11:19:08 -05:00
dc85695d0d fix(net): set disconnect status (#520) 2022-12-19 16:22:55 +01:00
4da574df84 feat: add prometheus support (#474) 2022-12-16 20:21:26 +01:00
1e38ffa5ad feat(eth-wire): fuzzing wire encoding roundtrip (#350)
* move hello to separate file

* cargo fmt

* wip: actual fuzz test

 * should probably also take advantage of test-fuzz to generate
   benchmarks like impl_fuzzer_with_input

* impl generic roundtrip method

* generate test with macro

* change testname to fuzzname

* add reth-eth-wire to fuzz in ci

* add other message types to fuzz

* remove unused_crate_dependencies

 * was causing test issues, may want to revisit whether or not we can
   include this warning and still use test_fuzz

* more afl debugging ci

* use more explicit imports in fuzz_rlp

* impl Default for types and fuzz ping/pong

 * Default is necessary for test-fuzz to auto generate a corpus for each
   type we are fuzz testing

* enable AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES

 * not sure if we should do this in the workflow instead:
   echo core >/proc/sys/kernel/core_pattern

   we may miss crashes if we keep this enabled?

* remove reth-interfaces from fuzzing

* add secp256k1 to reth-db dev deps
2022-12-13 19:10:52 +02:00
6c91322251 feat(eth-wire): derive serde traits for eth-wire types (#348)
* wip: start adding serde to stuff

* add serde traits to NewBlockHashes

* derive serde traits for the rest of the types

* derive serde traits for p2p subprotocol messages

* cargo fmt
2022-12-06 18:05:22 -08:00
b40546b999 refactor(net): misc P2Pstream refactor (#336)
* refactor(net): misc P2Pstream refactor

* update note
2022-12-06 18:02:04 -08:00
a4472ca1c6 chore(clippy): make clippy happy (#334) 2022-12-06 18:02:04 -08:00
2b6ef0afcf fix(eth-wire): encode p2p message id as valid rlp (#324) 2022-12-06 18:02:04 -08:00
debc87177c fix(eth-wire): handle 0x80 for DisconnectReason and P2PMessageID (#313)
* fix disconnect reason encoding

* move disconnect to own file

* add encoding test for 0x80 in list

 * rlp([0u8]) is a good test case to have because it is the RLP encoding
   of a DisconnectRequested p2p message

* fix disconnect encoding and decoding

 * directly decode the disconnect id to handle the 0x80 case of
   DisconnectRequested
 * the previous manual snappy encoding / decoding was incorrect - a
   snappy encoded disconnect message is 4 bytes, not 3 bytes. The tests
   and implementation are changed to reflect this.

* fix p2p message decoding

 * had a similar issue to disconnect reason decoding where it would not
   handle a 0x80 message id

* make invalid rlp header case more explicit

* cargo fmt
2022-12-02 04:21:00 -08:00
04105ec82b test: add mainnet connection test (#306) 2022-12-01 17:59:52 +01:00
6da140ce1b chore(eth-wire): remove TODO about capability Ord (#263)
* chore(eth-wire): remove TODO about capability Ord

 * orderings should be consistent with geth, see updated comment

* move down string doc link
2022-11-25 22:17:57 -08:00
ebd27b6025 feat(net): add disconnect function (#223) 2022-11-18 16:26:49 +01:00
75a6d06301 refactor(net): separate Sink and Stream (#217) 2022-11-16 11:10:11 -08:00
f1e6639374 feat(net): authenticate sessions (#178)
* Switch stream type of ActiveSession to EthStream

 * Start `StatusBuilder` for initializing the `Status` message required
   for the handshake
 * Add `Hardfork` for `Status` default forkid
 * Add `MAINNET_GENESIS` constant

* finish `StatusBuilder`

* initialize eth streams in session

 * add status, hello, and fork filter to session manager
 * fix status builder example
 * add status and hello to network config
   * will probably remove

* removing status and hello from networkconfig

* move forkid to primitives

* change imports for forkid

* add hardfork to primitives

* remove hardfork and forkid from eth-wire

* fix remaining eth-wire forkid references

* put mainnet genesis in constants, remove NodeId

* replace NodeId with PeerId

 * the only NodeId remaining is inherited from enr
 * PeerId still needs to be documented
 * also run cargo fmt

* replace loop with iter().any()

* ignore missing docs for hardforks

* use correct PeerId for Discv4::bind example test

* document PeerId as secp256k1 public key

* cargo fmt

* temporarily allow too_many_arguments

 * the authenticate and start_pending_incoming_session methods have many
   arguments, we can reconsider the lint or fix the methods at a later
   point
2022-11-14 12:03:05 -05:00
d4aabe4751 fix(eth-wire): fix usage of sink API in P2PStream (#184)
* fix(eth-wire): fix usage of sink API in P2PStream

* add error checks for sink buffer inserts
2022-11-09 19:06:27 -05:00
5721262740 refactor(net): unify capability types (#168)
* refactor(net): unify capability types

* refactor(net): unify capability types
2022-11-07 18:04:17 +01:00
ca2b5ef7c7 style(p2p): simplify pinger (#165)
* style(p2p): simplify pinger

* update docs
2022-11-04 15:01:50 +01:00
5cb2c6e615 style(p2p): get rid of expects (#164)
* style(p2p): get rid of expects

* test: add test
2022-11-04 14:51:13 +01:00
9b74d7d39d feat(eth-wire): use UnauthedEthStream to create EthStream (#162)
* Create UnauthedEthStream

* remove authed flag from EthStream

* encode and decode in status handshake

 * update test to assert the proper status is communicated

* cargo fmt

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
2022-11-04 08:36:40 +01:00
43a0a2b160 feat(eth-wire): return Hello on handshake (#161)
* feat(eth-wire): return Hello on handshake

* update P2PStream docs based on new auth design

* cargo fmt

* make clippy happy
2022-11-04 08:14:41 +01:00
3c72a12aff feat(eth-wire): Implement p2p stream (#114)
* wip: p2pstream

* add comment for handshake timeout

* temp allow some lint violations

* ignore unused_variables

* start of ping task

 * TODO: make it compile
 * TODO: test ping/pong/disconnect state machine
 * TODO: send subprotocol messages to stream
 * TODO: encode non-hello p2p messages as snappy encoding without using
   an encoder
 * TODO: create test comparing encoder to hand-written snappy encoding
   for ping, pong, disconnect messages

* implement message handling in stream poll method

 * restricts S to be Stream+Sink for P2PStream to implement Stream
 * start of a poll-based refactor

* impl Stream and Sink for P2PStream

 * add tests
 * TODO: make stream/sink types compatible
 * TODO: handshake message ids
 * TODO: inner poll fn
 * TODO: pinger interval
 * TODO: ethstream test
 * TODO: passthrough test

* create pingers and test

* impl working timeout interval pinger

 * it should be much easier to poll for pings and detect timeouts now

* use pinger in p2p stream

 * change item produced by stream so it's compatible with EthStream
   * add note on pros/cons
 * shorten message sends in stream

* improve errors and remove redundant methods

* fix handshake

* debugging printlns

* fix encoding and decoding

 * switch to snappy formatting for non-hello p2p messages

* cargo fmt

* perform handshake in ethstream over p2pstream test

 * remove check for `Hello` messages outside of the handshake because
   `P2PStream`s should assume messages sent in the sink are subprotocol
   messages, not `p2p` messages.

* impl From<EthVersion> for CapabilityMessage

* remove printlns

* add total_message method to EthVersion

* decode Hello in handshake

 * disallow protocol versions other than v5

* Integrate snappy and implement message size limits

* document constants, move stream definition

* fix missing hello message id

* implement shared capabilities

 * todo: test shared capabilities
 * todo: determine how / when / why to support multiple capabilities
 * removes obsolete authed and offset fields

* add sink api TODOs

* remove les

 * should add protocols when necessary rather than name unsupported
   protocols

* fix snappy compression length

 * add test for p2pstream over a passthrough codec which tests that
   peers agree on a single shared capability

* fix some clippy lints
2022-11-03 00:01:54 -07:00