Commit Graph

452 Commits

Author SHA1 Message Date
Ștefan Talpalaru 7f8090b166
SecioConn.readMessage(): fix the exception types 2020-04-02 19:07:14 +02:00
Dmitriy Ryajov 5285f0d091
Fix/misc (#116)
* only check for payload size

* only subscribe if connection succeeded

* fix failing test

* check that the strem is active before openning

* msg type should not be > than 0x7

* fix tests

* check max against enum val
2020-03-29 08:28:48 -06:00
Dmitriy Ryajov a35ecc6227 reverting connection changes 2020-03-28 09:29:43 -06:00
Dmitriy Ryajov 3effb95f10 close underlying bufferstream in lpchannel 2020-03-28 09:29:43 -06:00
Giovanni Petrantoni 56392913f9
Allow to specify a read size in readLp (#117)
* Allow to specify a read size in readLp

Also fix secio fragments + test

* Revert readLp changes, use just `read` in test
2020-03-26 15:06:47 +09:00
Giovanni Petrantoni 33ceefb209 Remove nim random usage from noise 2020-03-26 15:04:46 +09:00
Giovanni Petrantoni b132eae939 Add secio oversized payload fragmentation
Cannot be used because Connection Read size hard limit tho
2020-03-25 16:53:35 +09:00
Giovanni Petrantoni 1550bea1cc Support arbitrary stream write sizes in noise 2020-03-25 16:10:11 +09:00
Dmitriy Ryajov 4199508f17 readMplexVarint should return uint64 2020-03-24 15:41:40 -06:00
Dmitriy Ryajov 2de98751ae fix: use exact types for mplex id 2020-03-24 15:41:40 -06:00
cheatfate 1f5d994700
Fix compilation errors introduced by latest chronos. 2020-03-24 09:48:05 +02:00
Giovanni Petrantoni 3d10513b3e Properly await the handshake end in secure handler 2020-03-24 15:34:02 +09:00
Giovanni Petrantoni 0a3e4a764b
Less verbose traces (#112)
* Make traces less verbose with shortHexDump utility

* Rename shortHexDump into shortLog

* Improve shortLog, add shortLog for crypto keys

* Add proper shortLog implementations in messages
2020-03-23 15:03:36 +09:00
Giovanni Petrantoni b1a34f478e Avoid 2 async consecutive writes in noise HS 2020-03-18 20:40:51 +09:00
Giovanni Petrantoni c02fca25f8
Noise (#90)
* Start ChaCha20Poly1305 integration (BearSSL)

* Add Curve25519 (BearSSL) required operations for noise

* Fix curve mulgen iterate/derive

* Fix misleading header

* Add chachapoly proper test

* Curve25519 integration tests (failing, something is wrong)

* Add few converters, finish c25519 integration tests

* Remove implicit converters

* removed internal globals

* Start noise implementation

* Fix public() using proper bear mulgen

* Noise protocol WIP

* Noise progress

* Add a quick nim version of HKDF

* Converted hkdf to iterator, useful for noise

* Noise protocol implementation progress

* Noise progress

* XX handshake almost there

* noise progress

* Noise, testing handshake with test vectors

* Noise handshake progress, still wrong somewhere!

* Noise handshake success!

* Full verified noise XX handshake completed

* Fix and rewrite test to be similar to switch one

* Start with connection upgrade

* Switch chachapoly to CT implementations

* Improve HKDF implementation

* Use a type insted of tuple for HandshakeResult

* Remove unnecessary Let

* More cosmetic fixes

* Properly check randomBytes result

* Fix chachapoly signature

* Noise full circle (altho dispatcher is nil cursed)

* Allow nil aads in chachapoly routines

* Noise implementation up to running full test

* Use bearssl HKDF as well

* Directly use bearssl rng for curve25519 keys

* Add a (disabled/no CI) noise interop test server

* WIP on fixing interop issues

* More fixes in noise implementation for interop

* bump chronos requirement (nimble)

* Add a chachapoly test for very small size payloads

* Noise, more tracing

* Add 2 properly working noise tests

* Fix payload packing, following the spec properly (and not go version but
rather rust)

* Sanity, replace discard with asyncCheck

* Small fixes and optimization

* Use stew endian2 rather then system endian module

* Update nimble deps (chronos)

* Minor cosmetic/code sanity fixes

* Noise, handle Nonce max

* Noise tests, make sure to close secured conns

* More polish, improve code readability too

* More polish and testing again which test fails

* Further polishing

* Restore noise tests

* Remove useless Future[void]

* Remove useless CipherState initializer

* add a proper read wait future in second noise test

* Remove noise generic secure implementation for now

* Few fixes to run eth2 sim

* Add more debug info in noise traces

* Merge size + payload write in sendEncryptedMessage

* Revert secure interface, add outgoing property directly in newNoise

* remove sendEncrypted and receiveEncrypted

* Use openarray in chachapoly and curve25519 helpers
2020-03-17 13:30:01 +01:00
Dmitriy Ryajov 761b221b75 don't trace the payload 2020-03-12 08:01:43 -06:00
Dmitriy Ryajov 5c234f704d added 1 byte jitter test 2020-03-12 08:01:43 -06:00
Dmitriy Ryajov 406b79887d add jitter tolerance to mplex 2020-03-12 08:01:43 -06:00
Dmitriy Ryajov 82af623641 use correct shift 2020-03-11 09:58:24 -06:00
Dmitriy Ryajov 07695b2260 use `readExactly` not `read` to read all bytes 2020-03-11 09:58:24 -06:00
Jacek Sieka 52cb7ced04
prefer endians2 (#98) 2020-03-10 21:40:52 +01:00
Dmitriy Ryajov df29ac760e remove missing include 2020-03-09 13:26:38 -06:00
Dmitriy Ryajov fbe54e5c5a move SecureConn to secure.nim 2020-03-09 13:26:38 -06:00
Dmitriy Ryajov 19095a0f85 move `secure` to base as well 2020-03-09 13:26:38 -06:00
Eugene Kabanov d1c6591b8a Fix and refactoring of some procedures which are able to return nil as result (#97)
* Fix do not return nil as result.

* Fix mplex test to properly raise.
2020-03-09 13:26:38 -06:00
Dmitriy Ryajov c3e791db0d remove unused imports 2020-03-09 13:26:38 -06:00
Dmitriy Ryajov f1a297f0f3 add initiator flag to handshake 2020-03-09 13:26:38 -06:00
Dmitriy Ryajov d1d133319e change handleConn to be a proc 2020-03-09 13:26:38 -06:00
Dmitriy Ryajov 9aa9e97602 feat: move connection handling logic to base class 2020-03-09 13:26:38 -06:00
Dmitriy Ryajov 871d8d7478 remove white space 2020-03-09 13:26:38 -06:00
Eugene Kabanov 5701d937c8
Signed variable integers fixes. (#96)
* Fix signed varints.
Add tests for signed varints.
Remove some casts to allow usage at compile time.

* Fix vsizeof() on 32bit platforms.

* Add `hint` and `zint` types for proper signed integer encoding.

* Fix varint related bugs.

* Update requirements.

* Fix interop tests because of fixed readLine.

* Add putVarint, getVarint and tests.
2020-03-06 20:19:43 +01:00
Eugene Kabanov 381630f185
Fix and refactoring of some procedures which are able to return nil as result (#97)
* Fix do not return nil as result.

* Fix mplex test to properly raise.
2020-03-04 21:45:14 +02:00
Dmitriy Ryajov ffc3b04222 read should await for data on an empty buff 2020-03-01 04:06:42 -06:00
Eugene Kabanov 91d2f52f4e
Add some utility procedures to MultiAddress. (#94)
* Add some utility procedures to MultiAddress.

* Do not use result and add more operations to be more effective for compiler.
2020-02-27 19:26:42 +02:00
Dmitriy Ryajov 85d4baca95 await connection 2020-02-25 17:52:08 -06:00
Dmitriy Ryajov 946b9580c0 don't use nil result 2020-02-25 17:52:08 -06:00
Dmitriy Ryajov 52c270dcf9 warn on failed pubsub subscribe 2020-02-25 17:52:08 -06:00
Dmitriy Ryajov eb49d4b218 no empty proto dials and add connect method 2020-02-25 17:52:08 -06:00
Dmitriy Ryajov 9efc08cb2f fix: #83 2020-02-24 08:58:02 -06:00
Dmitriy Ryajov 6a7f9f058c address review comments 2020-02-21 09:21:06 -06:00
Dmitriy Ryajov fbcef69891 implicitelly dial pubsub if enabled 2020-02-21 09:21:06 -06:00
Giovanni Petrantoni cb156f3260 Fix public() using proper bear mulgen 2020-02-18 09:35:14 -06:00
Giovanni Petrantoni 93a480e6f3 removed internal globals 2020-02-18 09:35:14 -06:00
Giovanni Petrantoni e0e371994c Remove implicit converters 2020-02-18 09:35:14 -06:00
Giovanni Petrantoni f039853a19 Add few converters, finish c25519 integration tests 2020-02-18 09:35:14 -06:00
Giovanni Petrantoni 99a169b65d Curve25519 integration tests (failing, something is wrong) 2020-02-18 09:35:14 -06:00
Giovanni Petrantoni 2103aa59f3 Add chachapoly proper test 2020-02-18 09:35:14 -06:00
Giovanni Petrantoni 6ba274de27 Fix misleading header 2020-02-18 09:35:14 -06:00
Giovanni Petrantoni f47fb628f0 Fix curve mulgen iterate/derive 2020-02-18 09:35:14 -06:00
Giovanni Petrantoni 8dec368878 Add Curve25519 (BearSSL) required operations for noise 2020-02-18 09:35:14 -06:00
Giovanni Petrantoni 71998ffc67 Start ChaCha20Poly1305 integration (BearSSL) 2020-02-18 09:35:14 -06:00
Dmitriy Ryajov 1a987a9c5b fix: delete mplex channel 2020-02-16 13:51:03 -06:00
Dmitriy Ryajov 65ed2c7cee make code more robust 2020-02-16 11:31:35 -06:00
Dmitriy Ryajov 9023bf786d remove sleeps 2020-02-16 11:31:35 -06:00
Dmitriy Ryajov acdaeb8f5d working out synchronization issues 2020-02-16 11:31:35 -06:00
Dmitriy Ryajov b1dd564c32 make sure we don't exit the handler prematurely 2020-02-16 11:31:35 -06:00
Dmitriy Ryajov f9ad113d11 don't send close message if remote closed 2020-02-16 11:31:35 -06:00
Dmitriy Ryajov f767614827 remove unnecesary async lock 2020-02-16 11:31:35 -06:00
Dmitriy Ryajov 934c858542 increase timeout to allow floodsub to finish 2020-02-16 11:31:35 -06:00
Dmitriy Ryajov 26a4510377 remove unnecesary nil check in peerinfo 2020-02-16 11:31:35 -06:00
Dmitriy Ryajov 0349165830 typo 2020-02-16 11:31:35 -06:00
Dmitriy Ryajov 7f8eb0272e cleanup and fix tests 2020-02-16 11:31:35 -06:00
Dmitriy Ryajov 6316b07e81 don't crash when stringifying nil peerinfo 2020-02-16 11:31:35 -06:00
Dmitriy Ryajov 4faf35c52c throw exception if handshake failed 2020-02-16 11:31:35 -06:00
Dmitriy Ryajov f4e9bc8bfb remove sleepAsync for synchronization 2020-02-16 11:31:35 -06:00
Dmitriy Ryajov 53e163abf2 check for size bounds when reading varints 2020-02-16 11:31:35 -06:00
Dmitriy Ryajov 94fc4e6fd2 don't use sleeps for synchronization 2020-02-16 11:31:35 -06:00
Giovanni Petrantoni 39dc9ad8a3 Revert "Implement timeout in mplex in order to read reliably close state"
This reverts commit 314cb6e6bffe122bcfbd155a4ef830849ace66ef.
2020-02-12 11:57:38 -05:00
Giovanni Petrantoni 11bd55308f Revert "Properly use already specified MaxReadWriteTime as timeout"
This reverts commit 8f5dd75e7f28da08de2bf393b93cd290b82ed78b.
2020-02-12 11:57:38 -05:00
Giovanni Petrantoni ea0d167285 Fix max size write mplex test 2020-02-12 11:57:38 -05:00
Giovanni Petrantoni cf5dd27e57 Properly use already specified MaxReadWriteTime as timeout 2020-02-12 11:57:38 -05:00
Giovanni Petrantoni 4034dfae19 Implement timeout in mplex in order to read reliably close state 2020-02-12 11:57:38 -05:00
Giovanni Petrantoni 136ac3f550 Use already existing error for channel push over size 2020-02-12 11:57:38 -05:00
Giovanni Petrantoni f9cbdc252f Improve connection.nim read error clarity when buffer overflow 2020-02-12 11:57:38 -05:00
Giovanni Petrantoni 120ba0d528 Add a safety check on message size limit when pushing new data in mplex 2020-02-12 11:57:38 -05:00
Giovanni Petrantoni 3531ebf772 Fix typo 2020-02-12 11:57:38 -05:00
cheatfate 5b6f4bf5fa
Export MultiAddress pattern procedures. 2020-02-12 12:04:12 +02:00
Eugene Kabanov 540e79a430
Add peer lifetime feature for PeerInfo. (#77)
* Add peer lifetime feature for PeerInfo.
Refactor peerinfo to use openarrays instead of sequences.
Fix tests and examples to use arrays instead of sequences.

* Add access to lifetime Future[T] itself.
2020-02-11 12:53:39 -05:00
Giovanni Petrantoni 23712ecf3b
Lazy channels (#78)
* Implemented lazy stream opening for mplex connections

* Properly fix newStream usage

* Make lazy channel open optional

* Add Lazy channel test

* Cleanup mplex test

* Move lazyness properly into LPChannel

* Connection writeLp back to proc
2020-02-11 12:30:36 -05:00
Dmitriy Ryajov 88a030d8fb fix: removing timeouts from conn 2020-02-05 20:38:43 +01:00
Dmitriy Ryajov 2232ca598e don't timeout in pubsub 2020-02-04 17:59:57 +01:00
Zahary Karadjov 1bd933cd5a
More precise tracing 2020-02-04 17:27:32 +01:00
Zahary Karadjov 7bd305471c
Make sure the library can compile with json logging in trace mode 2020-02-04 15:17:39 +01:00
Dmitriy Ryajov 691efaa8a1 dont use result 2020-01-30 09:30:08 -06:00
Dmitriy Ryajov 171d60fb52 fix: reraise exception in readLp 2020-01-30 09:30:08 -06:00
cheatfate 06886290dd
Add links to specifications to varint comments. 2020-01-29 11:14:25 +02:00
Eugene Kabanov d902127595 Fix LibP2P varint implementation to follow latest specification. (#65)
* Fix LibP2P varint implementation to decode only minimal valus.
2020-01-28 16:29:42 +01:00
Dmitriy Ryajov 007b0219f3 use ECDSA as defaults, faster in tests 2020-01-09 12:55:21 -06:00
Dmitriy Ryajov 667691f784 send messages in batches 2020-01-09 12:55:21 -06:00
Dmitriy Ryajov cd8961cfb9 close and cleanup connections 2020-01-09 12:55:21 -06:00
Dmitriy Ryajov c6561b8851 add timeouts to connection/secio 2020-01-09 12:55:21 -06:00
cheatfate 107e71203d Fix #61. 2020-01-09 17:38:10 +02:00
Dmitriy Ryajov 58cdefac21 don't expose private api 2019-12-24 10:35:35 -06:00
Dmitriy Ryajov 0fb1f1c5b8 strenghten pubsub interop testing 2019-12-24 10:35:35 -06:00
Dmitriy Ryajov 8714c66353 allow empty protocol string in dial 2019-12-24 10:35:35 -06:00
Dmitriy Ryajov 68cc57669e
Feat/pubsub validators (#58)
* feat: adding validator hooks to pubsub

* expose add/remove validators on switch

* do less unnecessary copyng
2019-12-16 23:24:03 -06:00
Dmitriy Ryajov b6b0cdea98
fix: inconsistent error handling (#56)
* fix: inconsistent error handling

* fixing a few more returns

* remov reduntant returns

* feat: dont sleep in readLoop
2019-12-13 09:25:07 -06:00
Yuriy Glukhov e0aae6d8ac Moved base32, 58 and 64 to stew 2019-12-13 16:00:39 +02:00
Dmitriy Ryajov 293a219dbe
Cleanup (#55)
* fix: don't allow replacing pubkey

* fix: several small improvements

* removing pubkey setter

* improove error handling

* remove the use of Option[T] if not needed

* don't use optional

* fix-ci: temporarily pin p2pd to a working tag

* fix example to comply with latest changes

* bumping p2pd again to a higher version
2019-12-10 14:50:35 -06:00
Zahary Karadjov 77e866d29a
Address review comments 2019-12-09 19:17:29 +02:00