mirror of
https://github.com/mikedilger/chorus.git
synced 2026-05-03 06:51:42 +00:00
Start parsing nostr command
This commit is contained in:
parent
a6a0da07f4
commit
7aabebf657
38
src/nostr.rs
38
src/nostr.rs
@ -1,5 +1,6 @@
|
|||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::reply::NostrReply;
|
use crate::reply::NostrReply;
|
||||||
|
use crate::types::parse::json_parse::*;
|
||||||
use crate::WebSocketService;
|
use crate::WebSocketService;
|
||||||
use futures::SinkExt;
|
use futures::SinkExt;
|
||||||
use hyper_tungstenite::tungstenite::Message;
|
use hyper_tungstenite::tungstenite::Message;
|
||||||
@ -13,9 +14,42 @@ impl WebSocketService {
|
|||||||
self.buffer.resize(newlen, 0);
|
self.buffer.resize(newlen, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
log::warn!("Received unhandled text message: {}", msg);
|
let input = msg.as_bytes();
|
||||||
let reply = NostrReply::Notice("NIP-01 is not yet fully supported".to_owned());
|
let mut inpos = 0;
|
||||||
|
eat_whitespace(input, &mut inpos);
|
||||||
|
verify_char(input, b'[', &mut inpos)?;
|
||||||
|
eat_whitespace(input, &mut inpos);
|
||||||
|
verify_char(input, b'"', &mut inpos)?;
|
||||||
|
if &input[inpos..inpos + 4] == b"REQ\"" {
|
||||||
|
self.req(msg, inpos + 4).await?;
|
||||||
|
} else if &input[inpos..inpos + 6] == b"EVENT\"" {
|
||||||
|
self.event(msg, inpos + 6).await?;
|
||||||
|
} else if &input[inpos..inpos + 6] == b"CLOSE\"" {
|
||||||
|
self.close(msg, inpos + 6).await?;
|
||||||
|
} else if &input[inpos..inpos + 5] == b"AUTH\"" {
|
||||||
|
self.auth(msg, inpos + 5).await?;
|
||||||
|
} else {
|
||||||
|
log::warn!("{}: Received unhandled text message: {}", self.peer, msg);
|
||||||
|
let reply = NostrReply::Notice("Command unrecognized".to_owned());
|
||||||
self.websocket.send(Message::text(reply.as_json())).await?;
|
self.websocket.send(Message::text(reply.as_json())).await?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn req(&mut self, _msg: String, mut _inpos: usize) -> Result<(), Error> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn event(&mut self, _msg: String, mut _inpos: usize) -> Result<(), Error> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn close(&mut self, _msg: String, mut _inpos: usize) -> Result<(), Error> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn auth(&mut self, _msg: String, __inpos: usize) -> Result<(), Error> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user