Skip to content

Commit 198e2b7

Browse files
authored
Merge 4cd62a6 into c8c24d1
2 parents c8c24d1 + 4cd62a6 commit 198e2b7

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

examples/limit.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,19 @@ fn limit_by_node_id(allowed_nodes: HashSet<NodeId>) -> EventSender {
8888
n0_future::task::spawn(async move {
8989
while let Some(msg) = rx.recv().await {
9090
if let ProviderMessage::ClientConnected(msg) = msg {
91-
let node_id = msg.node_id;
92-
let res = if allowed_nodes.contains(&node_id) {
93-
println!("Client connected: {node_id}");
94-
Ok(())
95-
} else {
96-
println!("Client rejected: {node_id}");
97-
Err(AbortReason::Permission)
91+
let res = match msg.node_id {
92+
Some(node_id) if allowed_nodes.contains(&node_id) => {
93+
println!("Client connected: {node_id}");
94+
Ok(())
95+
}
96+
Some(node_id) => {
97+
println!("Client rejected: {node_id}");
98+
Err(AbortReason::Permission)
99+
}
100+
None => {
101+
println!("Client rejected: no node id");
102+
Err(AbortReason::Permission)
103+
}
98104
};
99105
msg.tx.send(res).await.ok();
100106
}
@@ -202,7 +208,7 @@ fn limit_max_connections(max_connections: usize) -> EventSender {
202208
let connection_id = msg.connection_id;
203209
let node_id = msg.node_id;
204210
let res = if let Ok(n) = requests.inc() {
205-
println!("Accepting connection {n}, node_id {node_id}, connection_id {connection_id}");
211+
println!("Accepting connection {n}, node_id {node_id:?}, connection_id {connection_id}");
206212
Ok(())
207213
} else {
208214
Err(AbortReason::RateLimited)

src/provider.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use n0_future::StreamExt;
1616
use quinn::{ClosedStream, ConnectionError, ReadToEndError};
1717
use serde::{de::DeserializeOwned, Deserialize, Serialize};
1818
use tokio::select;
19-
use tracing::{debug, debug_span, warn, Instrument};
19+
use tracing::{debug, debug_span, Instrument};
2020

2121
use crate::{
2222
api::{
@@ -319,14 +319,10 @@ pub async fn handle_connection(
319319
let connection_id = connection.stable_id() as u64;
320320
let span = debug_span!("connection", connection_id);
321321
async move {
322-
let Ok(node_id) = connection.remote_node_id() else {
323-
warn!("failed to get node id");
324-
return;
325-
};
326322
if let Err(cause) = progress
327323
.client_connected(|| ClientConnected {
328324
connection_id,
329-
node_id,
325+
node_id: connection.remote_node_id().ok(),
330326
})
331327
.await
332328
{

src/provider/events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ mod proto {
578578
#[derive(Debug, Serialize, Deserialize)]
579579
pub struct ClientConnected {
580580
pub connection_id: u64,
581-
pub node_id: NodeId,
581+
pub node_id: Option<NodeId>,
582582
}
583583

584584
#[derive(Debug, Serialize, Deserialize)]

src/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,10 @@ fn event_handler(
348348
while let Some(event) = events_rx.recv().await {
349349
match event {
350350
ProviderMessage::ClientConnected(msg) => {
351-
let res = if allowed_nodes.contains(&msg.inner.node_id) {
352-
Ok(())
353-
} else {
354-
Err(AbortReason::Permission)
351+
let res = match msg.node_id {
352+
Some(node_id) if allowed_nodes.contains(&node_id) => Ok(()),
353+
Some(_) => Err(AbortReason::Permission),
354+
None => Err(AbortReason::Permission),
355355
};
356356
msg.tx.send(res).await.ok();
357357
}

0 commit comments

Comments
 (0)