mirror of
https://github.com/scsibug/nostr-rs-relay.git
synced 2024-12-23 00:45:52 -05:00
chore: rustfmt
This commit is contained in:
parent
4d983dd1e0
commit
1b9f364e15
|
@ -20,9 +20,9 @@ use rusqlite::params;
|
||||||
use rusqlite::types::ToSql;
|
use rusqlite::types::ToSql;
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use rusqlite::OpenFlags;
|
use rusqlite::OpenFlags;
|
||||||
|
use std::fmt::Write as _;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::fmt::Write as _;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use tokio::task;
|
use tokio::task;
|
||||||
|
@ -342,7 +342,7 @@ pub fn write_event(conn: &mut PooledConnection, e: &Event) -> Result<usize> {
|
||||||
// if this event is a deletion, hide the referenced events from the same author.
|
// if this event is a deletion, hide the referenced events from the same author.
|
||||||
if e.kind == 5 {
|
if e.kind == 5 {
|
||||||
let event_candidates = e.tag_values_by_name("e");
|
let event_candidates = e.tag_values_by_name("e");
|
||||||
// first parameter will be author
|
// first parameter will be author
|
||||||
let mut params: Vec<Box<dyn ToSql>> = vec![Box::new(hex::decode(&e.pubkey)?)];
|
let mut params: Vec<Box<dyn ToSql>> = vec![Box::new(hex::decode(&e.pubkey)?)];
|
||||||
event_candidates
|
event_candidates
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -516,7 +516,7 @@ fn query_from_filter(f: &ReqFilter) -> (String, Vec<Box<dyn ToSql>>) {
|
||||||
// Apply per-filter limit to this subquery.
|
// Apply per-filter limit to this subquery.
|
||||||
// The use of a LIMIT implies a DESC order, to capture only the most recent events.
|
// The use of a LIMIT implies a DESC order, to capture only the most recent events.
|
||||||
if let Some(lim) = f.limit {
|
if let Some(lim) = f.limit {
|
||||||
let _ = write!(query, " ORDER BY e.created_at DESC LIMIT {}", lim);
|
let _ = write!(query, " ORDER BY e.created_at DESC LIMIT {}", lim);
|
||||||
} else {
|
} else {
|
||||||
query.push_str(" ORDER BY e.created_at ASC")
|
query.push_str(" ORDER BY e.created_at ASC")
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ impl Event {
|
||||||
let tagnamechar = tagnamechar_opt.unwrap();
|
let tagnamechar = tagnamechar_opt.unwrap();
|
||||||
let tagval = t.get(1).unwrap();
|
let tagval = t.get(1).unwrap();
|
||||||
// ensure a vector exists for this tag
|
// ensure a vector exists for this tag
|
||||||
idx.entry(tagnamechar).or_insert_with(HashSet::new);
|
idx.entry(tagnamechar).or_insert_with(HashSet::new);
|
||||||
// get the tag vec and insert entry
|
// get the tag vec and insert entry
|
||||||
let tidx = idx.get_mut(&tagnamechar).expect("could not get tag vector");
|
let tidx = idx.get_mut(&tagnamechar).expect("could not get tag vector");
|
||||||
tidx.insert(tagval.clone());
|
tidx.insert(tagval.clone());
|
||||||
|
|
45
src/main.rs
45
src/main.rs
|
@ -229,21 +229,21 @@ fn main() -> Result<(), Error> {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// start tokio
|
// start tokio
|
||||||
rt.block_on(async {
|
rt.block_on(async {
|
||||||
let broadcast_buffer_limit;
|
let broadcast_buffer_limit;
|
||||||
let persist_buffer_limit;
|
let persist_buffer_limit;
|
||||||
let verified_users_active;
|
let verified_users_active;
|
||||||
let db_min_conn;
|
let db_min_conn;
|
||||||
let db_max_conn;
|
let db_max_conn;
|
||||||
// hack to prove we drop the mutexguard prior to any await points
|
// hack to prove we drop the mutexguard prior to any await points
|
||||||
// (https://github.com/rust-lang/rust-clippy/issues/6446)
|
// (https://github.com/rust-lang/rust-clippy/issues/6446)
|
||||||
{
|
{
|
||||||
let settings = config::SETTINGS.read().unwrap();
|
let settings = config::SETTINGS.read().unwrap();
|
||||||
broadcast_buffer_limit = settings.limits.broadcast_buffer;
|
broadcast_buffer_limit = settings.limits.broadcast_buffer;
|
||||||
persist_buffer_limit = settings.limits.event_persist_buffer;
|
persist_buffer_limit = settings.limits.event_persist_buffer;
|
||||||
verified_users_active = settings.verified_users.is_active();
|
verified_users_active = settings.verified_users.is_active();
|
||||||
db_min_conn = settings.database.min_conn;
|
db_min_conn = settings.database.min_conn;
|
||||||
db_max_conn = settings.database.max_conn;
|
db_max_conn = settings.database.max_conn;
|
||||||
}
|
}
|
||||||
info!("listening on: {}", socket_addr);
|
info!("listening on: {}", socket_addr);
|
||||||
// all client-submitted valid events are broadcast to every
|
// all client-submitted valid events are broadcast to every
|
||||||
// other client on this channel. This should be large enough
|
// other client on this channel. This should be large enough
|
||||||
|
@ -252,8 +252,7 @@ fn main() -> Result<(), Error> {
|
||||||
let (bcast_tx, _) = broadcast::channel::<Event>(broadcast_buffer_limit);
|
let (bcast_tx, _) = broadcast::channel::<Event>(broadcast_buffer_limit);
|
||||||
// validated events that need to be persisted are sent to the
|
// validated events that need to be persisted are sent to the
|
||||||
// database on via this channel.
|
// database on via this channel.
|
||||||
let (event_tx, event_rx) =
|
let (event_tx, event_rx) = mpsc::channel::<SubmittedEvent>(persist_buffer_limit);
|
||||||
mpsc::channel::<SubmittedEvent>(persist_buffer_limit);
|
|
||||||
// establish a channel for letting all threads now about a
|
// establish a channel for letting all threads now about a
|
||||||
// requested server shutdown.
|
// requested server shutdown.
|
||||||
let (invoke_shutdown, shutdown_listen) = broadcast::channel::<()>(1);
|
let (invoke_shutdown, shutdown_listen) = broadcast::channel::<()>(1);
|
||||||
|
@ -301,7 +300,7 @@ fn main() -> Result<(), Error> {
|
||||||
rusqlite::OpenFlags::SQLITE_OPEN_READ_ONLY
|
rusqlite::OpenFlags::SQLITE_OPEN_READ_ONLY
|
||||||
| rusqlite::OpenFlags::SQLITE_OPEN_SHARED_CACHE,
|
| rusqlite::OpenFlags::SQLITE_OPEN_SHARED_CACHE,
|
||||||
db_min_conn,
|
db_min_conn,
|
||||||
db_max_conn,
|
db_max_conn,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
// A `Service` is needed for every connection, so this
|
// A `Service` is needed for every connection, so this
|
||||||
|
@ -482,9 +481,9 @@ async fn nostr_server(
|
||||||
Some(Ok(Message::Text(m))) => {
|
Some(Ok(Message::Text(m))) => {
|
||||||
convert_to_msg(m)
|
convert_to_msg(m)
|
||||||
},
|
},
|
||||||
Some(Ok(Message::Binary(_))) => {
|
Some(Ok(Message::Binary(_))) => {
|
||||||
ws_stream.send(
|
ws_stream.send(
|
||||||
make_notice_message("binary messages are not accepted")).await.ok();
|
make_notice_message("binary messages are not accepted")).await.ok();
|
||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Some(Ok(Message::Ping(_))) | Some(Ok(Message::Pong(_))) => {
|
Some(Ok(Message::Ping(_))) | Some(Ok(Message::Pong(_))) => {
|
||||||
|
@ -492,12 +491,12 @@ async fn nostr_server(
|
||||||
// send responses automatically.
|
// send responses automatically.
|
||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
Some(Err(WsError::Capacity(MessageTooLong{size, max_size}))) => {
|
Some(Err(WsError::Capacity(MessageTooLong{size, max_size}))) => {
|
||||||
ws_stream.send(
|
ws_stream.send(
|
||||||
make_notice_message(
|
make_notice_message(
|
||||||
&format!("message too large ({} > {})",size, max_size))).await.ok();
|
&format!("message too large ({} > {})",size, max_size))).await.ok();
|
||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
None |
|
None |
|
||||||
Some(Ok(Message::Close(_))) |
|
Some(Ok(Message::Close(_))) |
|
||||||
Some(Err(WsError::AlreadyClosed)) |
|
Some(Err(WsError::AlreadyClosed)) |
|
||||||
|
|
Loading…
Reference in New Issue
Block a user