Commit Graph

261 Commits

Author SHA1 Message Date
KonradStaniec 9c8e9d9f64
Handle selective acks (#456)
* Handle selective acks
2022-01-04 09:52:38 +01:00
Kim De Mey 8b7d41f596
Don't use exceptions for enr get call (#453)
The ENR code used to be solely exception based, and these
exceptions where a left-over of that. They are useless as later
calls use Result anyhow.

Additionally, they cause quite the performance loss because they
are used in the "common path" for the toTypedRecord call, e.g.
when reading the fields of ip6, tcp6 and udp6.
2021-12-21 15:09:32 +01:00
Kim De Mey 2c236f6495
Style fixes according to --styleCheck:usages (#452)
Currently only setting `--styleCheck:hint` as there are some
dependency fixes required and the compiler seems to trip over the
findnode MessageKind, findnode Message field and the findNode
proc. Also over protocol.Protocol usage.
2021-12-20 13:14:50 +01:00
KonradStaniec 0cfe7df817
Handle packets with selective acks (#451)
* Handle packets with selective acks
2021-12-15 13:35:17 +01:00
Etan Kissling 5655bd035c
Merge pull request #450 from etan-status/reject-whoareyou-len
reject WHOAREYOU packets with non-empty message
2021-12-14 16:22:25 +01:00
Ștefan Talpalaru 2088d7568d
CI: test with multiple Nim version (#429)
* CI: test with multiple Nim version

* clean up the testing tree a little

* replace "unittest" with "unittest2"
2021-12-11 19:12:55 +01:00
Etan Kissling 45387ad4d2
reject WHOAREYOU packets with non-empty message
This changes the `discv5` parser to reject malformed WHOAREYOU packets
that have a non-0 message length. The extra data used to be ignored.
The `message` part of WHOAREYOU packets is always empty.
See https://github.com/ethereum/devp2p/blob/master/discv5/discv5-wire.md
2021-12-11 15:55:14 +01:00
Etan Kissling 3ce2d9a58e
remove outdated and incorrect SSZ code
This removes the outdated copy of the SSZ code. It became incorrect
over time (e.g., empty SSZ list elements), and is no longer in use by
GitHub projects: https://github.com/search?q=extension%3Anim+eth%2Fssz

The canonical SSZ implementation resides at `nim-ssz-serialization`.
Compared to `nim-eth`, these changes were made meanwhile:
- `bitseqs` was extended with JSON serialization support,
  and with the new functions `isZero` and `countOnes`.
- `bytes_reader` was renamed to `codec`, extended with a few additional
  SSZ type conversions as well as support for `SingleMemberUnion`.
- The simplified merkle tree implementation in `merkle_tree.nim`
  was removed. It was not used by other projects.
- `merkleization` was extended with support for `HashArray`, `HashList`
  and `SingleMemberUnion`. The `isValidProof` functionality has been
  moved to `nimbus-eth2` and replaced with the EF defined function
  `is_valid_merkle_branch`. The test was also moved to `nimbus-eth2`.
  There are no other GitHub projects using `isValidProof`:
  https://github.com/search?q=extension%3Anim+isValidProof
  Furthermore, a definition for `GeneralizedIndex` was added.
- `ssz_serialization` was moved one directory up, and improved with
  bug fixes and `HashArray`, `HashList` and `SingleMemberUnion` support.
- `types` was extended with JSON serialization and new type support for
  `Uint128`, `Uint256`, `HashArray`, `HashList` and `SingleMemberUnion`.
  There is also a new `getBit` function for `BitList`.
2021-12-10 15:51:22 +01:00
Kim De Mey 41d2d3c991
Utp top level raises & some clean-up (#445)
* Add few missing top level raises Defect in uTP

- Add top level {.push raises: [Defect].}
- remove some local raises, including some unneeded
CatchableErrors.
- Don't export messageHandler (avoiding annoying naming collisions)
- export utp_router as those connection callbacks are in the API

* Add some missing copyright clauses

* Some ident and max line length cleanup

* Rename utp_discv5_protocol.nim to be more consistent
2021-12-10 11:12:24 +01:00
KonradStaniec 09959d2a3f
Update timestamp and ackNr on packet resend (#444)
* Update timestamp and ackNr on packet resend
2021-12-10 10:18:00 +01:00
KonradStaniec b4066a5688
Ledbat congestion control (#443)
* Return delay to remote peer

* Initial ledbat window calculation

* Add tests for window grow and decay

* Add delay histograms

* Add calculation of clock drift
2021-12-09 10:52:21 +01:00
KonradStaniec e7bc10ab00
Add config for max snd buffer size (#440)
* Add config for max snd buffer size
2021-12-02 16:51:44 +01:00
KonradStaniec 3c8915cae1
Track send buffer and properly handle back pressoure when window is to small to process data (#437)
* Add separate datastructure to keep track of window

* Asynchronously block write until until new space in snd buffer

* Introduce write loop

* Properly handle write cancellation

* Proper handling of sending fin packet

* Reset remote window after configured amount of time
2021-12-02 15:46:18 +01:00
KonradStaniec 139c6fa2a8
Track current bytes in flight (#434) 2021-11-24 17:49:13 +01:00
KonradStaniec ce296ff76e
Make initial state of socket configurable (#428)
* Make initial state of socket configurable
2021-11-19 11:36:46 +01:00
KonradStaniec d5e5ec9f90
Add possibility to connect with requested conneciton id (#425)
* Improve error handling when initiating connection

* Add api to connect with requested id

* Add callback to allow only specific incoming peers
2021-11-18 10:05:56 +01:00
Kim De Mey 22757db83b
Fix logDistance for BE arch and remove toBytes for NodeId (#427)
toBytes for NodeId wasn't selected by compiler byt if it does
get selected, it will fail on the test cases due to the
countdown that is done in logDistance.
Set to toBytesBE properly now and do countup, that should make
it correct also for BE architecture.

Removed toBytes to avoid confusion and avoid this one being
selected ever. The only place toBytes for NodeId was used is in
sessions.nim makeKey func and there also the stint one
(thus native endianness) was selected in Nim 1.2.x.
Native endianness is fine there as it is only an internal
representation.
2021-11-17 22:55:19 +01:00
KonradStaniec 73d9bf4c80
Add ackNr validation (#424) 2021-11-15 11:32:00 +01:00
KonradStaniec 8139aae346
Advertise correct rcv buffer size (#423)
* Advertise correct rcv buffer size
2021-11-12 10:58:49 +01:00
KonradStaniec b671f6c901
Handling of fin packet (#421)
* Handling of connection finalization by sending and receiving FIN packets
2021-11-09 15:29:59 +01:00
Kim De Mey df802248d8
Remove test_merkleization as it is moved to nim-ssz-serialization (#422) 2021-11-09 09:00:46 +01:00
KonradStaniec 7a113ffa48
Add handling of reset packet (#420)
* Add handling of reset packet
2021-11-05 09:41:41 +01:00
KonradStaniec d4cc42241d
Add handling of out of order packets (#418)
* Add handling of out of order packets
2021-11-04 07:38:46 +01:00
KonradStaniec 34bac6e703
Utp code cleanup (#417)
* Refactor tests and move socket to separate file

* Move sockets handling to separate class

* Abstract over underlying transport

* Fix bug with receiving duplicated SYN packet

* Fix race condition in connect
2021-10-28 11:41:43 +02:00
KonradStaniec fd4f78d1c0
Add timeout loop (#416)
* Modify outbuffer

Each element of outbuffer keeps encoded packet ,number
of transmissions of givern packet and information if
given packet needs to be re-send.

* Add initial handling of timeouts

* Add tests for syn re-sends
2021-10-25 09:58:13 +02:00
Kim De Mey 9a1bb5e125
Make ENR $ call print the IP address prettier (#409) 2021-10-19 14:13:09 +02:00
KonradStaniec 88795c6477
Add sending and receiving data procedures (#407)
* Add sending and receiving data procedures
2021-10-19 13:36:57 +02:00
Kim De Mey f101c83626
Enr rlp lists (#408)
* Don't fail ENR decoding when value is an RLP list

* Store RLP raw list in the ENR field pair instead

* Add ENR kList FieldKind so lists can be treated differently

Treated differently now when printing out the ENR, mentioning
that it is a raw RLP list
2021-10-19 09:26:14 +02:00
KonradStaniec 6fbf129ba9
Add initial handling of acks (#406)
* Add initial handling of acks

Add implemetaion of circular buffer based on reference implementation
Add way to test number of packet in flight
Add acking of initial syn packet
2021-10-15 13:38:51 +02:00
KonradStaniec 7ae287ad1b
Add rudimentary connect function (#405)
* Add rudimentary connect function
2021-10-11 14:16:06 +02:00
Kim De Mey 5125a438db
Make the custom distances call somewhat more accessible (#404)
And make the naming more consistent
2021-10-07 16:03:12 +02:00
Kim De Mey 1babe38226
Allow for tcp/udp ports to always be configured (#402)
* Allow for tcp/udp ports to always be configured

- Allow for an ENR to be build with tcp and udp ports also when
no IP address is provided
- In the address set-up always provide best efforttcp and udp ports
also when configuration of external ip (and/or ports) fails.
2021-09-29 18:50:23 +02:00
KonradStaniec 9f2f101070
Add initial skeleton of utp protocol (#397)
* Add initial impl of utp over udp

* Add more comments

* Add licenses and push declarations

* Add tests to nimble task

* Pr comments

Use better random generator
Raise assert error in case of buffer io exception
2021-09-13 14:54:06 +02:00
KonradStaniec a95b205cf7
Modify nodes verification (#398)
* Modify nodes verification

* Move nodes verification to separate module

By moving verification to separate module it can be re-used
in different contexts not only in discoveryv5.
2021-09-13 14:20:26 +02:00
KonradStaniec e219547d64
Fix lookupDistances function and make it public (#399) 2021-09-10 17:26:22 +02:00
Kim De Mey df6020832b
Build fuzzing tests in CI and fix current fuzzing tests (#396)
* Build fuzzing tests in CI and fix current fuzzing tests

* Build fuzzing tests separately (fix Windows CI)
2021-09-07 16:00:01 +02:00
Kim De Mey bea1f1c6a1
Clean-up routing table object constructions (#395) 2021-09-07 11:56:16 +02:00
KonradStaniec c078f85e48
Expose id and address of talkreq sender (#393) 2021-09-07 10:49:18 +02:00
KonradStaniec bfadcfbfaf
Make Routing table distance function configurable (#392) 2021-09-02 14:00:36 +02:00
KonradStaniec aa3fbbd95d
Add proof verification to public api (#390) 2021-08-12 16:15:02 +02:00
KonradStaniec 50c0c5f123
Add helpers to generate merkle proofs (#381) 2021-08-09 12:17:21 +02:00
Kim De Mey 9bc4fa366a
Let talkreq directly return the seq[byte] for easier API (#384) 2021-07-30 16:04:14 +02:00
KonradStaniec e3fba48f0f
add merkle proof verification (#379)
* add merkle proof verification

* remove redundant buffer

* simplify verification function
2021-07-23 13:40:47 +02:00
KonradStaniec 20ad6504b7
Add merkleization tests (#378)
* Add merkleization tests

* Fix typo in build file

* add test prefix
2021-07-21 09:24:07 +02:00
Kim De Mey eb0908e33f
Push raises Defect to rlpx and accompanying changes (#373) 2021-07-14 10:35:35 +02:00
Kim De Mey 79911ed5d8
Log distance to uint16 and add public neighbours calls (#371)
* Use uint16 instead of uint32 for discv5 log distance

* Make neighboursAtDistances and neighbours calls available
2021-07-13 10:05:46 +02:00
Kim De Mey 41127eaee8
Remove portal wire code which was moved to nimbus-eth1 repo (#370) 2021-07-09 22:14:31 +02:00
jangko a10d301085
implement EIP-1559 Transaction and BlockHeader 2021-06-27 20:12:47 +07:00
kdeme e2e30247bf
Add implementation of Portal wire protocol 2021-06-09 14:57:30 +02:00
Jacek Sieka 3514ee6484
sqlite: quick exec with result (#361) 2021-05-27 11:31:34 +02:00