Register num_hops
This commit is contained in:
@@ -108,16 +108,26 @@ pub enum IpPacketRequestData {
|
||||
pub struct StaticConnectRequest {
|
||||
pub request_id: u64,
|
||||
pub ip: IpAddr,
|
||||
// The nym-address the response should be sent back to
|
||||
pub reply_to: Recipient,
|
||||
// The number of mix node hops that responses should take, in addition to the entry and exit
|
||||
// node. Zero means only client -> entry -> exit -> client.
|
||||
pub reply_to_hops: Option<u8>,
|
||||
// The average delay at each mix node, in milliseconds. Currently this is not supported by the
|
||||
// ip packet router.
|
||||
pub reply_to_avg_mix_delays: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct DynamicConnectRequest {
|
||||
pub request_id: u64,
|
||||
// The nym-address the response should be sent back to
|
||||
pub reply_to: Recipient,
|
||||
// The number of mix node hops that responses should take, in addition to the entry and exit
|
||||
// node. Zero means only client -> entry -> exit -> client.
|
||||
pub reply_to_hops: Option<u8>,
|
||||
// The average delay at each mix node, in milliseconds. Currently this is not supported by the
|
||||
// ip packet router.
|
||||
pub reply_to_avg_mix_delays: Option<f64>,
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ pub(crate) struct MixnetListener {
|
||||
|
||||
pub(crate) struct ConnectedClient {
|
||||
pub(crate) nym_address: Recipient,
|
||||
pub(crate) mix_hops: Option<u8>,
|
||||
pub(crate) last_activity: std::time::Instant,
|
||||
}
|
||||
|
||||
@@ -51,7 +52,8 @@ impl MixnetListener {
|
||||
let request_id = connect_request.request_id;
|
||||
let requested_ip = connect_request.ip;
|
||||
let reply_to = connect_request.reply_to;
|
||||
// TODO: ignoring reply_to_hops and reply_to_avg_mix_delays for now
|
||||
let reply_to_hops = connect_request.reply_to_hops;
|
||||
// TODO: ignoring reply_to_avg_mix_delays for now
|
||||
|
||||
// Check that the IP is available in the set of connected clients
|
||||
let is_ip_taken = self.connected_clients.contains_key(&requested_ip);
|
||||
@@ -81,14 +83,16 @@ impl MixnetListener {
|
||||
requested_ip,
|
||||
ConnectedClient {
|
||||
nym_address: reply_to,
|
||||
mix_hops: reply_to_hops,
|
||||
last_activity: std::time::Instant::now(),
|
||||
},
|
||||
);
|
||||
self.connected_client_tx
|
||||
.send(ConnectedClientEvent::Connect(
|
||||
requested_ip,
|
||||
Box::new(reply_to),
|
||||
))
|
||||
.send(ConnectedClientEvent::Connect(ConnectEvent {
|
||||
ip: requested_ip,
|
||||
nym_address: reply_to,
|
||||
mix_hops: reply_to_hops,
|
||||
}))
|
||||
.unwrap();
|
||||
Ok(Some(IpPacketResponse::new_static_connect_success(
|
||||
request_id, reply_to,
|
||||
@@ -124,7 +128,8 @@ impl MixnetListener {
|
||||
|
||||
let request_id = connect_request.request_id;
|
||||
let reply_to = connect_request.reply_to;
|
||||
// TODO: ignoring reply_to_hops and reply_to_avg_mix_delays for now
|
||||
let reply_to_hops = connect_request.reply_to_hops;
|
||||
// TODO: ignoring reply_to_avg_mix_delays for now
|
||||
|
||||
// Check if it's the same client connecting again, then we just reuse the same IP
|
||||
// TODO: this is problematic. Until we sign connect requests this means you can spam people
|
||||
@@ -165,11 +170,16 @@ impl MixnetListener {
|
||||
new_ip,
|
||||
ConnectedClient {
|
||||
nym_address: reply_to,
|
||||
mix_hops: reply_to_hops,
|
||||
last_activity: std::time::Instant::now(),
|
||||
},
|
||||
);
|
||||
self.connected_client_tx
|
||||
.send(ConnectedClientEvent::Connect(new_ip, Box::new(reply_to)))
|
||||
.send(ConnectedClientEvent::Connect(ConnectEvent {
|
||||
ip: new_ip,
|
||||
nym_address: reply_to,
|
||||
mix_hops: reply_to_hops,
|
||||
}))
|
||||
.unwrap();
|
||||
Ok(Some(IpPacketResponse::new_dynamic_connect_success(
|
||||
request_id, reply_to, new_ip,
|
||||
@@ -285,7 +295,7 @@ impl MixnetListener {
|
||||
for ip in inactive_clients {
|
||||
log::info!("Disconnect inactive client: {ip}");
|
||||
self.connected_clients.remove(&ip);
|
||||
self.connected_client_tx.send(ConnectedClientEvent::Disconnect(ip)).unwrap();
|
||||
self.connected_client_tx.send(ConnectedClientEvent::Disconnect(DisconnectEvent(ip))).unwrap();
|
||||
}
|
||||
},
|
||||
msg = self.mixnet_client.next() => {
|
||||
@@ -330,6 +340,14 @@ impl MixnetListener {
|
||||
}
|
||||
|
||||
pub(crate) enum ConnectedClientEvent {
|
||||
Disconnect(IpAddr),
|
||||
Connect(IpAddr, Box<Recipient>),
|
||||
Disconnect(DisconnectEvent),
|
||||
Connect(ConnectEvent),
|
||||
}
|
||||
|
||||
pub(crate) struct DisconnectEvent(pub(crate) IpAddr);
|
||||
|
||||
pub(crate) struct ConnectEvent {
|
||||
pub(crate) ip: IpAddr,
|
||||
pub(crate) nym_address: Recipient,
|
||||
pub(crate) mix_hops: Option<u8>,
|
||||
}
|
||||
|
||||
@@ -31,14 +31,15 @@ impl TunListener {
|
||||
log::trace!("TunListener: received shutdown");
|
||||
},
|
||||
event = self.connected_client_rx.recv() => match event {
|
||||
Some(mixnet_listener::ConnectedClientEvent::Connect(ip, nym_addr)) => {
|
||||
Some(mixnet_listener::ConnectedClientEvent::Connect(mixnet_listener::ConnectEvent { ip, nym_address, mix_hops })) => {
|
||||
log::trace!("Connect client: {ip}");
|
||||
self.connected_clients.insert(ip, mixnet_listener::ConnectedClient {
|
||||
nym_address: *nym_addr,
|
||||
nym_address,
|
||||
mix_hops,
|
||||
last_activity: std::time::Instant::now(),
|
||||
});
|
||||
},
|
||||
Some(mixnet_listener::ConnectedClientEvent::Disconnect(ip)) => {
|
||||
Some(mixnet_listener::ConnectedClientEvent::Disconnect(mixnet_listener::DisconnectEvent(ip))) => {
|
||||
log::trace!("Disconnect client: {ip}");
|
||||
self.connected_clients.remove(&ip);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user