Commit Graph

128 Commits

Author SHA1 Message Date
Csaba Kiraly a9d0d0d69b
fix cross-connect key exchange
Since key exchange can be started both ways simultaneously, and
these might not get finalised with UDP transport, we can't be
sure what encryption key will be used by the other side:
- the one derived in the key-exchange started by us,
- the one derived in the key-exchange started by the other node.
To alleviate this issue, we store two decryption keys in each session.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-12 11:57:05 +02:00
Csaba Kiraly 304f0c089d
keyexchangeInProgress: do not remove on handshake received
This is the wrong direction, not needed

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-12 11:35:49 +02:00
Csaba Kiraly 4cf0ac30d0
rename handshakeInProgress to keyexchangeInProgress
Handshake is also a name of a message, which makes previous
name less clear.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-12 11:33:17 +02:00
Csaba Kiraly 03c363e18d
fix addValue not enough nodes
addValue cycle should consider number of nodes found.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-12 11:23:24 +02:00
Csaba Kiraly ec266ea478
simulation: fix pending packet release order
For some reason pending packets were released in the wrong order
in simulation. A minimal delay between them fixes this.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:54:04 +02:00
Csaba Kiraly a92fdcd050
simulation: log simTime
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:54:04 +02:00
Csaba Kiraly b5c0ae3c27
simulation: increase MaxNodesPerMessage to 6
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:54:04 +02:00
Csaba Kiraly b0b741429f
simulation: allow replacing bootstrap node
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:54:04 +02:00
Csaba Kiraly 8dc1ee5ac3
simulation: bump bucketIpLimit to 100000 to avoid test issues
Nodes on single IP are limited in normal operation. This
would create issues for tests, so better turn off this
mechanism.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:53:00 +02:00
Csaba Kiraly fc2e2a031d
trace log packet on receive
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:53:00 +02:00
Csaba Kiraly 0f802e3b23
just a comment
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:53:00 +02:00
Csaba Kiraly 622164ccf8
more trace and debug messages
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:53:00 +02:00
Csaba Kiraly 84ffef9787
remove unused sendRequest call
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:53:00 +02:00
Csaba Kiraly ee8540d6fb
queue messages during handshake and send later
If a handshake was already in progress, messages were dropped.
Instead of this, it is better to queue these and send as soon
as the handshake is finished and thus the encryption key is known.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:52:59 +02:00
Csaba Kiraly a8670ebbe8
encodeMessagePacket: expose haskey
encodeMessagePacket checks for session and behaves differently
based on that. Exposing this difference in behavior.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:52:59 +02:00
Csaba Kiraly 5af9a06258
introduce ProtocolBehavior property
Start implementing non-honest strategies.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:52:59 +02:00
Csaba Kiraly 5ae5295f26
secure transport: allow more sessions
Sessions were limited to 256 for some reason.
For large scale operation it makes sense to allow more
open sessions (symmetric key sessions).

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:52:59 +02:00
Csaba Kiraly 60f079e8b6
trace log: do not log binary encoding
Even at trace level this feels too much.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:52:59 +02:00
Csaba Kiraly 0d20e371b1
use 127.0.0.1 for these tests
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:52:59 +02:00
Csaba Kiraly 589a878985
remove lookupWorkerFast duplicate code
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:52:58 +02:00
Csaba Kiraly a540568e77
introduce FindNodeFastResultLimit
We do not need that many responses with FindNodeFast, since the
reposes can be ordered by distance

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:52:58 +02:00
Csaba Kiraly 742d0ea0ce
reduce default response timeout
We really don't need this to be 4 seconds.
Later we should tune it better based on measurements
or estimates,

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:52:58 +02:00
Csaba Kiraly e5512754f8
fix returning too many nodes when FindNodeResultLimit!=BUCKET_SIZE
Code assumed these two values to be the same, resulting in
reception errors.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:46:32 +02:00
Csaba Kiraly 106ae65e32
add debug on Handshake timeour
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:46:32 +02:00
Csaba Kiraly a4cea57165
add logging helper for Protocol
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:46:32 +02:00
Csaba Kiraly 5f6e55271a
use ChronoSim version of nim-chronos
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:46:31 +02:00
Csaba Kiraly 0d9118404e
addValue: use fast lookup
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:45:57 +02:00
Csaba Kiraly 5bc4bbffdf
fix ValueReplication counter
Number of replicas was ValueReplication+1 before.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:45:31 +02:00
Csaba Kiraly d7de86060c
implement findValue
retrieve a value from the DHT

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:45:20 +02:00
Csaba Kiraly bca26eb059
add ValueGetFrom count for naive getValue
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:43:37 +02:00
Csaba Kiraly 7c7cd29df1
add ValueReplication cound for addValue
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:43:30 +02:00
Csaba Kiraly cef43612ea
logging: GetValue error should be debug
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-09-05 08:43:18 +02:00
Csaba Kiraly fc7d04e3bb
add DHT storage (addValue/getValue) functionality
this is a minimal implementation, with lots of
work still needed.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-07-11 10:52:03 +02:00
Csaba Kiraly 12af1e626f
update .nimble and .lock files to work
Make dht compile with new new (0.14+) nimble.

Compilation with Nimble <0.14 can't work, as
the many of the libraries on the dependency
tree are not version tagged. As we can't change
that, two paths remain:
1, use nimbus-build-system (i.e. git submodules)
2, use lock files introduced in nimble 0.14+
First was already working, this fixes second

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-07-11 10:51:33 +02:00
Csaba Kiraly 96e5526ffb
fixing bearssl version in lockfile and in nimble file
It seems lockfile was generated wrong or not updated,
broken in 76bff752a2

setting it to version used in nimbus build system based build

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-07-11 10:51:33 +02:00
Csaba Kiraly 13e48b8836
encoding: introducing type cipher=aes128
Introducing the cipher type to ease changing cipher.
No functional change

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-07-11 00:36:46 +02:00
Csaba Kiraly 5c62d100e4
dht: waitMessage: expose timeout as parameter, keeping default
defults to ResponseTimeout as before

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-07-11 00:36:46 +02:00
Csaba Kiraly 9f4cec415c
remove some debug output 2023-07-11 00:36:46 +02:00
Csaba Kiraly 52530b7569
fixup: move sendRequest forward
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-07-11 00:36:46 +02:00
Csaba Kiraly 94a7d01d7b
introduce waitResponse wrapper
initialize wait for response before sending request.
This is needed in cases where the response arrives before
moving to the next instruction, such as a directly connected
test.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-07-11 00:36:46 +02:00
Csaba Kiraly 9cd6af5afd
change revalidateLoop to use [RevalidateMax/2, RevalidateMax]
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-07-11 00:36:46 +02:00
Csaba Kiraly c1f39a89c9
improve tracing of message exchange
run e.g. as
```
nim c -r -d:debug -d:chronicles_enabled=on -d:chronicles_log_level=TRACE -d:chronicles_sinks=textlines[nocolors,stdout] tests/dht/test_providers.nim >err
```

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
2023-07-11 00:36:45 +02:00
Csaba Kiraly f8523ae629
log routing table size periodically 2023-07-11 00:36:45 +02:00
Dmitriy Ryajov 4375b92298
use datastore `has` (#56) 2022-12-02 16:47:16 -06:00
Dmitriy Ryajov e4e7a3e11f
track nim-libp2p's unstable branch and nim-bearssl's master branch (#51)
* track nim-libp2p's unstable branch and nim-bearssl's master branch

refactor accordingly: mainly switching from `import bearssl` to
`import bearssl/rand`, `BrHmacDrbgContext` to `HmacDrbgContext`, and related
changes

* fix ambiguous identifier

* nim 1.4 is deprecated

Co-authored-by: Michael Bradley, Jr <michaelsbradleyjr@gmail.com>
2022-11-02 10:21:05 -06:00
Dmitriy Ryajov d6d255b4b5
Cleanups (#55)
* limit query to batchSize

* allow initializing node from ip and port

* misc cleanups
2022-10-31 22:41:33 -06:00
Dmitriy Ryajov 08928e57d8
Remove local providers (#53)
* refactor to use batch deletes

* add ability to remove local providers
2022-10-03 15:14:47 -06:00
Dmitriy Ryajov 4b9fa0356e
Adding maintenance routines to cleanup expired and orphaned records (#52)
* add maintenance routines and split out cache

* start provider manager

* export provider manager

* add maintenance tests

* start is now async
2022-10-01 10:05:03 -06:00
Dmitriy Ryajov 69ae7c2012
Persist providers (#49)
* initial providers manager implementation

* misc license update

* spelling

* rename provider tests

* add provider tests

* reexport provider manager

* only update provider record if it changed

* small bug in getProvByKey

* pass providers to both constructors

* fix records retrieval

* disable cache during tests

* avoid redefining data

* adding back tests with cache

* use `.errorOption`

* proper err msg unpacking
2022-09-29 17:49:55 -06:00
Dmitriy Ryajov bbcfb9f17b
Merge pull request #50 from status-im/revert-47-nim-libp2p-unstable
Revert "track nim-libp2p's unstable branch and nim-bearssl's master branch"
2022-09-23 18:18:48 -04:00