mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-12 06:33:46 +03:00
Format Rust code using rustfmt
This commit is contained in:
parent
b318e57d5e
commit
878be1b51e
@ -715,8 +715,7 @@ async fn recv_connection_via_router(
|
||||
let Ok(ws_url) = make_ws_url(our_ip, ip, port) else {
|
||||
return Err(anyhow!("failed to parse websocket url"));
|
||||
};
|
||||
let Ok(Ok((websocket, _response))) = time::timeout(TIMEOUT, connect_async(ws_url)).await
|
||||
else {
|
||||
let Ok(Ok((websocket, _response))) = time::timeout(TIMEOUT, connect_async(ws_url)).await else {
|
||||
return Err(anyhow!("failed to connect to target"));
|
||||
};
|
||||
let (mut write_stream, mut read_stream) = websocket.split();
|
||||
@ -798,7 +797,8 @@ async fn init_connection(
|
||||
let Ok(ws_url) = make_ws_url(our_ip, ip, port) else {
|
||||
return Err(anyhow!("failed to parse websocket url"));
|
||||
};
|
||||
let Ok(Ok((websocket, _response))) = time::timeout(TIMEOUT, connect_async(ws_url)).await
|
||||
let Ok(Ok((websocket, _response))) =
|
||||
time::timeout(TIMEOUT, connect_async(ws_url)).await
|
||||
else {
|
||||
return Err(anyhow!("failed to connect to target"));
|
||||
};
|
||||
@ -811,7 +811,8 @@ async fn init_connection(
|
||||
let Ok(ws_url) = make_ws_url(our_ip, ip, port) else {
|
||||
return Err(anyhow!("failed to parse websocket url"));
|
||||
};
|
||||
let Ok(Ok((websocket, _response))) = time::timeout(TIMEOUT, connect_async(ws_url)).await
|
||||
let Ok(Ok((websocket, _response))) =
|
||||
time::timeout(TIMEOUT, connect_async(ws_url)).await
|
||||
else {
|
||||
return Err(anyhow!("failed to connect to target"));
|
||||
};
|
||||
@ -930,20 +931,24 @@ async fn handle_local_message(
|
||||
// respond by attempting to init a matching passthrough.
|
||||
// TODO can discriminate more here..
|
||||
if our.allowed_routers.contains(&km.source.node) {
|
||||
let Ok((peer_id, peer_conn)) = time::timeout(TIMEOUT,
|
||||
recv_connection_via_router(
|
||||
our,
|
||||
our_ip,
|
||||
&from,
|
||||
pki,
|
||||
keypair,
|
||||
&peers
|
||||
.get(&km.source.node)
|
||||
.ok_or(anyhow!("unknown router"))?
|
||||
.identity,
|
||||
)).await? else {
|
||||
return Err(anyhow!("someone tried to connect to us but it timed out"))
|
||||
};
|
||||
let Ok((peer_id, peer_conn)) = time::timeout(
|
||||
TIMEOUT,
|
||||
recv_connection_via_router(
|
||||
our,
|
||||
our_ip,
|
||||
&from,
|
||||
pki,
|
||||
keypair,
|
||||
&peers
|
||||
.get(&km.source.node)
|
||||
.ok_or(anyhow!("unknown router"))?
|
||||
.identity,
|
||||
),
|
||||
)
|
||||
.await?
|
||||
else {
|
||||
return Err(anyhow!("someone tried to connect to us but it timed out"));
|
||||
};
|
||||
let (peer_tx, peer_rx) = unbounded_channel::<KernelMessage>();
|
||||
let peer = Arc::new(Peer {
|
||||
identity: peer_id,
|
||||
|
@ -46,16 +46,24 @@ pub async fn create_passthrough(
|
||||
let Some((ref ip, ref port)) = to_id.ws_routing else {
|
||||
// create passthrough to indirect node that we do routing for
|
||||
//
|
||||
let target_peer = peers.get(&to_name).ok_or(anyhow!("can't route to that indirect node"))?;
|
||||
let target_peer = peers
|
||||
.get(&to_name)
|
||||
.ok_or(anyhow!("can't route to that indirect node"))?;
|
||||
if !target_peer.routing_for {
|
||||
return Err(anyhow!("we don't route for that indirect node"))
|
||||
return Err(anyhow!("we don't route for that indirect node"));
|
||||
}
|
||||
// send their net:sys:uqbar process a message, notifying it to create a *matching*
|
||||
// passthrough request, which we can pair with this pending one.
|
||||
target_peer.sender.send(KernelMessage {
|
||||
id: rand::random(),
|
||||
source: Address { node: our.name.clone(), process: ProcessId::from_str("net:sys:uqbar").unwrap() },
|
||||
target: Address { node: to_name.clone(), process: ProcessId::from_str("net:sys:uqbar").unwrap() },
|
||||
source: Address {
|
||||
node: our.name.clone(),
|
||||
process: ProcessId::from_str("net:sys:uqbar").unwrap(),
|
||||
},
|
||||
target: Address {
|
||||
node: to_name.clone(),
|
||||
process: ProcessId::from_str("net:sys:uqbar").unwrap(),
|
||||
},
|
||||
rsvp: None,
|
||||
message: Message::Request(Request {
|
||||
inherit: false,
|
||||
@ -73,7 +81,7 @@ pub async fn create_passthrough(
|
||||
target: to_name,
|
||||
write_stream: write_stream_1,
|
||||
read_stream: read_stream_1,
|
||||
})
|
||||
}),
|
||||
));
|
||||
};
|
||||
// create passthrough to direct node
|
||||
@ -117,7 +125,7 @@ pub fn validate_routing_request(
|
||||
&routing_request.signature,
|
||||
)?;
|
||||
if routing_request.target == routing_request.source {
|
||||
return Err(anyhow!("can't route to self"))
|
||||
return Err(anyhow!("can't route to self"));
|
||||
}
|
||||
Ok((their_id.clone(), routing_request.target))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user