Compare commits

...

7 Commits
0.1.4 ... 0.1.6

Author SHA1 Message Date
Greg Heartsfield
2e2e01203b build: bump version to 0.1.6 2021-12-23 21:44:12 -06:00
Greg Heartsfield
100f890284 feat: add until for request filters
This implements an additional filter criteria for selecting events
prior to some timestamp.

See https://github.com/fiatjaf/nostr/issues/39x
2021-12-23 21:38:32 -06:00
Greg Heartsfield
0e288fe678 feat: send messages in order of oldest to newest 2021-12-23 21:36:46 -06:00
Greg Heartsfield
bfc804e18c feat: debug protocol messages 2021-12-23 21:30:04 -06:00
Greg Heartsfield
8a8ee5c425 build: bump version to 0.1.5 2021-12-19 16:45:17 -06:00
Greg Heartsfield
55bb6bd440 feat: add resource limits for websocket messages 2021-12-19 16:26:32 -06:00
Greg Heartsfield
7933abaa48 fix: allow unknown fields, like author 2021-12-19 16:18:03 -06:00
7 changed files with 23 additions and 5 deletions

2
Cargo.lock generated
View File

@@ -435,7 +435,7 @@ dependencies = [
[[package]]
name = "nostr-rs-relay"
version = "0.1.4"
version = "0.1.6"
dependencies = [
"bitcoin_hashes",
"env_logger",

View File

@@ -1,6 +1,6 @@
[package]
name = "nostr-rs-relay"
version = "0.1.4"
version = "0.1.6"
edition = "2021"
[dependencies]

View File

@@ -53,7 +53,7 @@ impl ClientConn {
v.push(id);
}
}
return v;
v
}
/// Add a new subscription for this connection.

View File

@@ -229,6 +229,12 @@ fn query_from_sub(sub: &Subscription) -> String {
let created_clause = format!("created_at > {}", f.since.unwrap());
filter_components.push(created_clause);
}
// Query for timestamp
if f.until.is_some() {
let until_clause = format!("created_at < {}", f.until.unwrap());
filter_components.push(until_clause);
}
// combine all clauses, and add to filter_clauses
if !filter_components.is_empty() {
let mut fc = "( ".to_owned();
@@ -246,6 +252,8 @@ fn query_from_sub(sub: &Subscription) -> String {
query.push_str(" WHERE ");
query.push_str(&filter_clauses.join(" OR "));
}
// add order clause
query.push_str(" ORDER BY created_at ASC");
debug!("query string: {}", query);
query
}

View File

@@ -18,6 +18,7 @@ use tokio::sync::broadcast;
use tokio::sync::broadcast::{Receiver, Sender};
use tokio::sync::mpsc;
use tokio::sync::oneshot;
use tungstenite::protocol::WebSocketConfig;
/// Start running a Nostr relay server.
fn main() -> Result<(), Error> {
@@ -93,8 +94,15 @@ async fn nostr_server(
) {
// get a broadcast channel for clients to communicate on
let mut bcast_rx = broadcast.subscribe();
// websocket configuration / limits
let config = WebSocketConfig {
max_send_queue: None,
max_message_size: Some(2 << 19), // 512K
max_frame_size: Some(2 << 19), // 512k
accept_unmasked_frames: false, // follow the spec
};
// upgrade the TCP connection to WebSocket
let conn = tokio_tungstenite::accept_async(stream).await;
let conn = tokio_tungstenite::accept_async_with_config(stream, Some(config)).await;
let ws_stream = conn.expect("websocket handshake error");
// wrap websocket into a stream & sink of Nostr protocol messages
let mut nostr_stream = protostream::wrap_ws_in_nostr(ws_stream);

View File

@@ -53,6 +53,7 @@ impl Stream for NostrStream {
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
/// Convert Message to NostrMessage
fn convert(msg: String) -> Result<NostrMessage> {
debug!("raw msg: {}", msg);
let parsed_res: Result<NostrMessage> = serde_json::from_str(&msg).map_err(|e| e.into());
match parsed_res {
Ok(m) => Ok(m),

View File

@@ -16,7 +16,6 @@ pub struct Subscription {
/// element can be present if it should be used in filtering, or
/// absent ([`None`]) if it should be ignored.
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
#[serde(deny_unknown_fields)]
pub struct ReqFilter {
/// Event hash
pub id: Option<String>,
@@ -30,6 +29,8 @@ pub struct ReqFilter {
pub pubkey: Option<String>,
/// Events published after this time
pub since: Option<u64>,
/// Events published before this time
pub until: Option<u64>,
/// List of author public keys
pub authors: Option<Vec<String>>,
}