mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
Implement ETH P2P (#81)
* refactor: move things to types
* feat(ethwire): bring in message type from ethp2p
30c11138d5/src/message.rs
* feat(ethwire): add eth-stream with Stream/Sink impls
* feat(ethwire): make Sink error an EthStreamError
* feat(ecies): expose util module
* add more deps
* feat: add broadcast newblockhashes
* fix: rlp serialize with message-id first
* chore: cleanup doc
* wip: test eth connection
* bump cargo lock
* feat: add rlp codec and get stream tests working
* fix: convert RlpCodec to PassthroughCodec
we were rlp encoding twice
* Revert "fix: convert RlpCodec to PassthroughCodec"
This reverts commit 6e6e0a58112c14d7ffba62dc83f9747ddc280641.
This does not handle framing, which would fail decoding if a partial
write happened to the socket.
* add tracing
* refactor: add handshake error
* feat(ethwire): add status handshake
* test(ethwire): handshake works
* refactor: expose EthStream::new
* chore: clippy lints
* fix: get rid of rlp codec
we can instead use LengthLimitedCodec from Tokio IO, which we re-export
as PassthroughCodec
* fix(eth): add handshake + msg error checks
1. 10MB message lengths
2. Same Genesis, Version, Chain on Status Handshake
* chore: ignore result_large_err
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
committed by
GitHub
parent
5dfe5ac29b
commit
8009d997c0
@ -10,6 +10,7 @@ fn zeroless_view(v: &impl AsRef<[u8]>) -> &[u8] {
|
||||
}
|
||||
|
||||
impl Header {
|
||||
/// Encodes the header into the `out` buffer.
|
||||
pub fn encode(&self, out: &mut dyn BufMut) {
|
||||
if self.payload_length < 56 {
|
||||
let code = if self.list { EMPTY_LIST_CODE } else { EMPTY_STRING_CODE };
|
||||
@ -22,6 +23,13 @@ impl Header {
|
||||
out.put_slice(len_be);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the length of the encoded header
|
||||
pub fn length(&self) -> usize {
|
||||
let mut out = BytesMut::new();
|
||||
self.encode(&mut out);
|
||||
out.len()
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn length_of_length(payload_length: usize) -> usize {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#[derive(Clone, Default, PartialEq)]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||
pub struct Header {
|
||||
pub list: bool,
|
||||
pub payload_length: usize,
|
||||
|
||||
Reference in New Issue
Block a user