Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

[devp2p discovery] assemble packet refactor#11566

Closed
niklasad1 wants to merge 10 commits into
masterfrom
na-devp2p-assemble-packet-refactor
Closed

[devp2p discovery] assemble packet refactor#11566
niklasad1 wants to merge 10 commits into
masterfrom
na-devp2p-assemble-packet-refactor

Conversation

@niklasad1
Copy link
Copy Markdown
Collaborator

@niklasad1 niklasad1 commented Mar 12, 2020

Introduced to achieve more type-safety than u8.
Part of this the verify `packet_kind` before doing more expensive operations such as
`hashing`, `signing`, `ecc recover` and similar
Comment thread util/network-devp2p/src/discovery.rs Outdated

let payload_with_packet_id = &packet[HASH_LEN + SIGNATURE_LEN..];
let packet_kind = payload_with_packet_id[0];
let packet_kind: PacketKind = packet_kind.try_into().map_err(|e| {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do this check earlier to avoid hashing, ecc recover when we get invalid/unsupported packet kinds

Comment thread util/network-devp2p/src/discovery.rs Outdated
/// Helper to disassemble node discovery packets
///
/// The packet format is: `hash || signature || packet_type || payload`, where the maximum packet length is 1280 bytes
fn disassemble_packet(packet: &[u8]) -> Result<(NodeId, &[u8], PacketKind, H256), Error> {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently, when we read a discovery UDP datagrams they are capped here

@niklasad1 niklasad1 closed this Apr 7, 2020
@ordian ordian deleted the na-devp2p-assemble-packet-refactor branch April 23, 2020 20:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant