mirror of
https://github.com/scsibug/nostr-rs-relay.git
synced 2024-11-14 15:09:07 -05:00
Don't bother breaking stream apart into read/write handles.
This commit is contained in:
parent
60319999a6
commit
2238743c59
18
src/main.rs
18
src/main.rs
|
@ -72,21 +72,19 @@ async fn nostr_server(stream: TcpStream) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles valid clients who have upgraded to WebSockets
|
// Handles valid clients who have upgraded to WebSockets
|
||||||
async fn process_client(stream: WebSocketStream<TcpStream>) {
|
async fn process_client(mut stream: WebSocketStream<TcpStream>) {
|
||||||
// get a protocol helper;
|
// get a protocol helper;
|
||||||
let mut proto = Proto::new();
|
let mut proto = Proto::new();
|
||||||
// futures::stream::Stream?
|
|
||||||
let (mut write, mut read) = stream.split();
|
|
||||||
// TODO: select on a timeout to kill non-responsive clients
|
// TODO: select on a timeout to kill non-responsive clients
|
||||||
|
|
||||||
while let Some(mes_res) = read.next().await {
|
while let Some(mes_res) = stream.next().await {
|
||||||
// as long as connection is not closed...
|
// as long as connection is not closed...
|
||||||
match mes_res {
|
match mes_res {
|
||||||
Ok(Message::Text(cmd)) => {
|
Ok(Message::Text(cmd)) => {
|
||||||
info!("Message received");
|
info!("Message received");
|
||||||
let length = cmd.len();
|
let length = cmd.len();
|
||||||
debug!("Message: {}", cmd);
|
debug!("Message: {}", cmd);
|
||||||
write
|
stream
|
||||||
.send(Message::Text(format!(
|
.send(Message::Text(format!(
|
||||||
"got your message of length {}",
|
"got your message of length {}",
|
||||||
length
|
length
|
||||||
|
@ -97,7 +95,7 @@ async fn process_client(stream: WebSocketStream<TcpStream>) {
|
||||||
let proto_error = proto.process_message(cmd);
|
let proto_error = proto.process_message(cmd);
|
||||||
match proto_error {
|
match proto_error {
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
write
|
stream
|
||||||
.send(Message::Text(
|
.send(Message::Text(
|
||||||
"[\"NOTICE\", \"Failed to process message.\"]".to_owned(),
|
"[\"NOTICE\", \"Failed to process message.\"]".to_owned(),
|
||||||
))
|
))
|
||||||
|
@ -111,7 +109,7 @@ async fn process_client(stream: WebSocketStream<TcpStream>) {
|
||||||
}
|
}
|
||||||
Ok(Message::Binary(_)) => {
|
Ok(Message::Binary(_)) => {
|
||||||
info!("Ignoring Binary message");
|
info!("Ignoring Binary message");
|
||||||
write
|
stream
|
||||||
.send(Message::Text(
|
.send(Message::Text(
|
||||||
"[\"NOTICE\", \"BINARY_INVALID: Binary messages are not supported.\"]"
|
"[\"NOTICE\", \"BINARY_INVALID: Binary messages are not supported.\"]"
|
||||||
.to_owned(),
|
.to_owned(),
|
||||||
|
@ -131,10 +129,8 @@ async fn process_client(stream: WebSocketStream<TcpStream>) {
|
||||||
"Message size too large, disconnecting this client. ({} > {})",
|
"Message size too large, disconnecting this client. ({} > {})",
|
||||||
size, max_size
|
size, max_size
|
||||||
);
|
);
|
||||||
write.send(Message::Text("[\"NOTICE\", \"MAX_EVENT_SIZE_EXCEEDED: Exceeded maximum event size for this relay. Closing Connection.\"]".to_owned())).await.expect("send notice failed");
|
stream.send(Message::Text("[\"NOTICE\", \"MAX_EVENT_SIZE_EXCEEDED: Exceeded maximum event size for this relay. Closing Connection.\"]".to_owned())).await.expect("send notice failed");
|
||||||
write
|
stream
|
||||||
.reunite(read)
|
|
||||||
.expect("reunite failed")
|
|
||||||
.close(Some(CloseFrame {
|
.close(Some(CloseFrame {
|
||||||
code: CloseCode::Size,
|
code: CloseCode::Size,
|
||||||
reason: "Exceeded max message size".into(),
|
reason: "Exceeded max message size".into(),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user