mirror of
https://github.com/jmcorgan/fips.git
synced 2026-08-10 16:43:12 +00:00
Discovery protocol: LookupRequest/LookupResponse handlers
Implement the coordinate discovery protocol with flood-based lookup and reverse-path response routing. Wire format: LookupRequest (0x30) encode/decode with TTL, visited bloom filter, origin coords. LookupResponse (0x31) encode/decode with target coords and Schnorr proof signature. Handler logic: request dedup by request_id, visited filter loop prevention, TTL enforcement, lazy purge of expired entries (10s). Response routing: originator caches route in route_cache, transit nodes reverse-path forward via recent_requests. Node state: RecentRequest struct, route_cache (RouteCache), and recent_requests map for dedup + reverse-path forwarding. 13 handler tests (9 unit + 4 integration) plus 4 protocol tests. 392 tests pass, clean build.
This commit is contained in:
@@ -76,7 +76,7 @@ impl fmt::Display for SessionMessageType {
|
||||
///
|
||||
/// Session-layer messages serialize coordinates as NodeAddr arrays (16 bytes each),
|
||||
/// without the sequence/timestamp metadata used by the tree gossip protocol.
|
||||
fn encode_coords(coords: &TreeCoordinate, buf: &mut Vec<u8>) {
|
||||
pub(crate) fn encode_coords(coords: &TreeCoordinate, buf: &mut Vec<u8>) {
|
||||
let addrs: Vec<&NodeAddr> = coords.node_addrs().collect();
|
||||
let count = addrs.len() as u16;
|
||||
buf.extend_from_slice(&count.to_le_bytes());
|
||||
@@ -88,7 +88,7 @@ fn encode_coords(coords: &TreeCoordinate, buf: &mut Vec<u8>) {
|
||||
/// Decode a TreeCoordinate from address-only wire format.
|
||||
///
|
||||
/// Returns the decoded coordinate and the number of bytes consumed.
|
||||
fn decode_coords(data: &[u8]) -> Result<(TreeCoordinate, usize), ProtocolError> {
|
||||
pub(crate) fn decode_coords(data: &[u8]) -> Result<(TreeCoordinate, usize), ProtocolError> {
|
||||
if data.len() < 2 {
|
||||
return Err(ProtocolError::MessageTooShort {
|
||||
expected: 2,
|
||||
|
||||
Reference in New Issue
Block a user