@ -607,6 +607,38 @@ bool MyMesh::onPeerPathRecv(mesh::Packet *packet, int sender_idx, const uint8_t
return false ;
}
# define CTL_TYPE_NODE_DISCOVER_REQ 0x80
# define CTL_TYPE_NODE_DISCOVER_RESP 0x90
void MyMesh : : onControlDataRecv ( mesh : : Packet * packet ) {
uint8_t type = packet - > payload [ 0 ] & 0xF0 ; // just test upper 4 bits
if ( type = = CTL_TYPE_NODE_DISCOVER_REQ & & packet - > payload_len > = 6 ) {
// TODO: apply rate limiting to these!
int i = 1 ;
uint8_t filter = packet - > payload [ i + + ] ;
uint32_t tag ;
memcpy ( & tag , & packet - > payload [ i ] , 4 ) ; i + = 4 ;
uint32_t since ;
if ( packet - > payload_len > = i + 4 ) { // optional since field
memcpy ( & since , & packet - > payload [ i ] , 4 ) ; i + = 4 ;
} else {
since = 0 ;
}
if ( ( filter & ( 1 < < ADV_TYPE_REPEATER ) ) ! = 0 & & _prefs . discovery_mod_timestamp > = since ) {
uint8_t data [ 6 + PUB_KEY_SIZE ] ;
data [ 0 ] = CTL_TYPE_NODE_DISCOVER_RESP | ADV_TYPE_REPEATER ; // low 4-bits for node type
data [ 1 ] = packet - > _snr ; // let sender know the inbound SNR ( x 4)
memcpy ( & data [ 2 ] , & tag , 4 ) ; // include tag from request, for client to match to
memcpy ( & data [ 6 ] , self_id . pub_key , PUB_KEY_SIZE ) ;
auto resp = createControlData ( data , sizeof ( data ) ) ;
if ( resp ) {
sendZeroHop ( resp , getRetransmitDelay ( resp ) ) ; // apply random delay, as multiple nodes can respond to this
}
}
}
}
MyMesh : : MyMesh ( mesh : : MainBoard & board , mesh : : Radio & radio , mesh : : MillisecondClock & ms , mesh : : RNG & rng ,
mesh : : RTCClock & rtc , mesh : : MeshTables & tables )
: mesh : : Mesh ( radio , ms , rng , rtc , * new StaticPoolPacketManager ( 32 ) , tables ) ,