mirror of
https://github.com/scsibug/nostr-rs-relay.git
synced 2024-11-14 23:19:07 -05:00
Work on request filter deserialization
This commit is contained in:
parent
ba19c978a5
commit
bd7d083107
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -359,6 +359,7 @@ dependencies = [
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-tungstenite",
|
"tokio-tungstenite",
|
||||||
"tungstenite",
|
"tungstenite",
|
||||||
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -923,6 +924,15 @@ version = "0.7.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
|
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "uuid"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "version_check"
|
name = "version_check"
|
||||||
version = "0.9.3"
|
version = "0.9.3"
|
||||||
|
|
|
@ -13,6 +13,7 @@ futures-util = "0.3.17"
|
||||||
tokio-tungstenite = "0.16.0"
|
tokio-tungstenite = "0.16.0"
|
||||||
tungstenite = "0.16.0"
|
tungstenite = "0.16.0"
|
||||||
thiserror = "1.0.30"
|
thiserror = "1.0.30"
|
||||||
|
uuid = { version = "0.8", features = ["v4"] }
|
||||||
|
|
||||||
|
|
||||||
bitcoin_hashes = { version = "0.10.0", features = ["serde"] }
|
bitcoin_hashes = { version = "0.10.0", features = ["serde"] }
|
||||||
|
|
|
@ -2,6 +2,7 @@ use std::{env, io::Error};
|
||||||
|
|
||||||
use futures_util::{SinkExt, StreamExt};
|
use futures_util::{SinkExt, StreamExt};
|
||||||
use log::{debug, info, warn};
|
use log::{debug, info, warn};
|
||||||
|
use nostr_rs_relay::proto::Proto;
|
||||||
use tokio::net::{TcpListener, TcpStream};
|
use tokio::net::{TcpListener, TcpStream};
|
||||||
use tokio::runtime::Builder;
|
use tokio::runtime::Builder;
|
||||||
use tokio_tungstenite::WebSocketStream;
|
use tokio_tungstenite::WebSocketStream;
|
||||||
|
@ -67,9 +68,9 @@ 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(stream: WebSocketStream<TcpStream>) {
|
||||||
|
// get a protocol helper;
|
||||||
|
let proto = Proto::new();
|
||||||
let (mut write, mut read) = stream.split();
|
let (mut write, mut read) = stream.split();
|
||||||
// TODO: error on binary messages
|
|
||||||
// TODO: error on text messages > MAX_EVENT_SIZE
|
|
||||||
// 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) = read.next().await {
|
||||||
|
@ -86,6 +87,7 @@ async fn process_client(stream: WebSocketStream<TcpStream>) {
|
||||||
)))
|
)))
|
||||||
.await
|
.await
|
||||||
.expect("send failed");
|
.expect("send failed");
|
||||||
|
proto.process_message(cmd);
|
||||||
// Handle this request. Everything else below is basically error handling.
|
// Handle this request. Everything else below is basically error handling.
|
||||||
}
|
}
|
||||||
Ok(Message::Binary(_)) => {
|
Ok(Message::Binary(_)) => {
|
||||||
|
|
|
@ -1 +1,43 @@
|
||||||
|
use crate::error::{Error, Result};
|
||||||
|
use serde::{Deserialize, Deserializer, Serialize};
|
||||||
|
//use serde_json::json;
|
||||||
|
//use serde_json::Result;
|
||||||
|
|
||||||
|
|
||||||
|
// Container for a request filter
|
||||||
|
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
|
||||||
|
pub struct ReqCmd {
|
||||||
|
|
||||||
|
#[serde(deserialize_with = "u32_from_string")]
|
||||||
|
id: u32,
|
||||||
|
#[serde(deserialize_with = "u32_from_string")]
|
||||||
|
pubkey: u32,
|
||||||
|
created_at: u64,
|
||||||
|
kind: u8,
|
||||||
|
#[serde(deserialize_with = "tag_from_string")]
|
||||||
|
tags: Vec<Vec<String>>,
|
||||||
|
content: String,
|
||||||
|
#[serde(deserialize_with = "u64_from_string")]
|
||||||
|
sig: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
|
||||||
|
pub struct Subscription {
|
||||||
|
id: String,
|
||||||
|
Vec<ReqFilter>
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
|
||||||
|
pub struct ReqFilter {
|
||||||
|
id: Option<String>,
|
||||||
|
author: Option<String>,
|
||||||
|
kind: Option<u8>,
|
||||||
|
#[serde(rename = "e#")]
|
||||||
|
event: Option<String>,
|
||||||
|
#[serde(rename = "p#")]
|
||||||
|
pubkey: Option<String>,
|
||||||
|
since: Option<u64>,
|
||||||
|
authors: Option<Vec<String>>,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Request {}
|
pub struct Request {}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user