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 73f4f73 commit be60360
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/handler/request_call.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use crate::node_info::{NodeAddress, NodeContact};
pub use crate::node_info::{NodeContact};
use crate::{
packet::Packet,
rpc::{Request, RequestBody},
Expand Down
2 changes: 1 addition & 1 deletion src/kbucket/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
pub use super::{
bucket::{
AppliedPending, ConnectionState, InsertResult, Node, NodeStatus, MAX_NODES_PER_BUCKET,
AppliedPending, ConnectionState, InsertResult, Node, NodeStatus,
},
key::*,
ConnectionDirection,
Expand Down
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 be60360

Please sign in to comment.