mirror of
https://github.com/scsibug/nostr-rs-relay.git
synced 2024-11-22 09:09:07 -05:00
refactor: remove unnecessary Option wrapping
This commit is contained in:
parent
99e117f620
commit
e66fa4ac42
22
src/main.rs
22
src/main.rs
|
@ -418,15 +418,15 @@ async fn nostr_server(
|
||||||
let nostr_msg = match ws_next {
|
let nostr_msg = match ws_next {
|
||||||
Some(Ok(Message::Text(m))) => {
|
Some(Ok(Message::Text(m))) => {
|
||||||
let msg_parse = convert_to_msg(m);
|
let msg_parse = convert_to_msg(m);
|
||||||
Some(msg_parse)
|
msg_parse
|
||||||
},
|
},
|
||||||
Some(Ok(Message::Binary(_))) => {
|
Some(Ok(Message::Binary(_))) => {
|
||||||
ws_stream.send(Message::Text(format!("[\"NOTICE\",\"{}\"]", "binary messages are not accepted"))).await.ok();
|
ws_stream.send(Message::Text(format!("[\"NOTICE\",\"{}\"]", "binary messages are not accepted"))).await.ok();
|
||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
None | Some(Ok(Message::Close(_))) | Some(Err(WsError::AlreadyClosed)) | Some(Err(WsError::ConnectionClosed)) => {
|
None | Some(Ok(Message::Close(_))) | Some(Err(WsError::AlreadyClosed)) | Some(Err(WsError::ConnectionClosed)) => {
|
||||||
info!("Closing connection");
|
debug!("normal websocket close from client: {:?}",cid);
|
||||||
None
|
break;
|
||||||
},
|
},
|
||||||
x => {
|
x => {
|
||||||
info!("message was: {:?} (ignoring)", x);
|
info!("message was: {:?} (ignoring)", x);
|
||||||
|
@ -436,7 +436,7 @@ async fn nostr_server(
|
||||||
|
|
||||||
// convert ws_next into proto_next
|
// convert ws_next into proto_next
|
||||||
match nostr_msg {
|
match nostr_msg {
|
||||||
Some(Ok(NostrMessage::EventMsg(ec))) => {
|
Ok(NostrMessage::EventMsg(ec)) => {
|
||||||
// An EventCmd needs to be validated to be converted into an Event
|
// An EventCmd needs to be validated to be converted into an Event
|
||||||
// handle each type of message
|
// handle each type of message
|
||||||
let parsed : Result<Event> = Result::<Event>::from(ec);
|
let parsed : Result<Event> = Result::<Event>::from(ec);
|
||||||
|
@ -460,7 +460,7 @@ async fn nostr_server(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some(Ok(NostrMessage::SubMsg(s))) => {
|
Ok(NostrMessage::SubMsg(s)) => {
|
||||||
debug!("client {} requesting a subscription", cid);
|
debug!("client {} requesting a subscription", cid);
|
||||||
// subscription handling consists of:
|
// subscription handling consists of:
|
||||||
// * registering the subscription so future events can be matched
|
// * registering the subscription so future events can be matched
|
||||||
|
@ -485,7 +485,7 @@ async fn nostr_server(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some(Ok(NostrMessage::CloseMsg(cc))) => {
|
Ok(NostrMessage::CloseMsg(cc)) => {
|
||||||
// closing a request simply removes the subscription.
|
// closing a request simply removes the subscription.
|
||||||
let parsed : Result<Close> = Result::<Close>::from(cc);
|
let parsed : Result<Close> = Result::<Close>::from(cc);
|
||||||
match parsed {
|
match parsed {
|
||||||
|
@ -506,19 +506,15 @@ async fn nostr_server(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => {
|
Err(Error::ConnError) => {
|
||||||
debug!("normal websocket close from client: {:?}",cid);
|
|
||||||
break;
|
|
||||||
},
|
|
||||||
Some(Err(Error::ConnError)) => {
|
|
||||||
debug!("got connection close/error, disconnecting client: {:?}",cid);
|
debug!("got connection close/error, disconnecting client: {:?}",cid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Some(Err(Error::EventMaxLengthError(s))) => {
|
Err(Error::EventMaxLengthError(s)) => {
|
||||||
info!("client {:?} sent event larger ({} bytes) than max size", cid, s);
|
info!("client {:?} sent event larger ({} bytes) than max size", cid, s);
|
||||||
ws_stream.send(Message::Text(format!("[\"NOTICE\",\"{}\"]", "event exceeded max size"))).await.ok();
|
ws_stream.send(Message::Text(format!("[\"NOTICE\",\"{}\"]", "event exceeded max size"))).await.ok();
|
||||||
},
|
},
|
||||||
Some(Err(e)) => {
|
Err(e) => {
|
||||||
info!("got non-fatal error from client: {:?}, error: {:?}", cid, e);
|
info!("got non-fatal error from client: {:?}, error: {:?}", cid, e);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user