Skip to content

Commit

Permalink
Add implementation feature to protocol id
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane committed Jan 15, 2024
1 parent 3732b3f commit 4925058
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/packet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,25 @@ pub const MESSAGE_NONCE_LENGTH: usize = 12;
/// The Id nonce length (in bytes).
pub const ID_NONCE_LENGTH: usize = 16;

pub struct Nat;

impl ProtocolIdentity<3> for Nat {
const PROTOCOL_ID_BYTES: [u8; 6] = *b"discv5";
const PROTOCOL_VERSION_BYTES: [u8; 2] = 0x0001_u16.to_be_bytes();
const IMPLEMENTATION_FEATURES: [u8; 3] = *b"nat";
}
pub struct DefaultProtocolId {}

impl ProtocolIdentity for DefaultProtocolId {
const PROTOCOL_ID_BYTES: [u8; 6] = *b"discv5";
const PROTOCOL_VERSION_BYTES: [u8; 2] = 0x0001_u16.to_be_bytes();
const IMPLEMENTATION_FEATURES: [u8; 0] = *b"";
}

pub trait ProtocolIdentity {
pub trait ProtocolIdentity<const N: usize = 0>: Sync + Send {
const PROTOCOL_ID_BYTES: [u8; 6];
const PROTOCOL_VERSION_BYTES: [u8; 2];
const IMPLEMENTATION_FEATURES: [u8; N];
}

pub(crate) const MAX_PACKET_SIZE: usize = 1280;
Expand Down

0 comments on commit 4925058

Please sign in to comment.