@@ -150,9 +150,9 @@ impl Relayer {
break;
}
- // Throttle down to not spam the server with reconnections
- sleep(Duration::from_millis(500)).await;
+ // Throttle down to not spam the server with reconnections
+ sleep(Duration::from_millis(500)).await;
log::warn!("{}: Disconnected", url);
@@ -64,8 +64,9 @@ impl Connection {
});
- pub async fn send(&self, _response: Response) -> Result<(), Error> {
- Ok(())
+ #[inline]
+ pub fn send(&self, response: Response) -> Result<(), Error> {
+ Ok(self.sender.try_send(response)?)
pub fn create_connection(&self, id: String) -> Result<(u128, u128, Sender<Response>), Error> {
@@ -1,3 +1,5 @@
+use nostr_rs_types::Response;
+
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("The identifier {0} is already in use")]
@@ -14,4 +16,7 @@ pub enum Error {
#[error("Unknown connection: {0}")]
UnknownConnection(u128),
+ #[error("TrySendError: {0}")]
+ TrySendError(#[from] tokio::sync::mpsc::error::TrySendError<Response>),
@@ -41,17 +41,12 @@ async fn main() {
let db = RocksDb::new("./db").expect("db");
loop {
- println!("going into loop");
if let Some((msg, _relayed_by)) = clients.recv().await.expect("valid connection") {
match msg {
Response::Event(x) => {
let event = x.event;
- if db.store(&event).expect("valid") {
- println!("\tStored");
- } else {
- println!("\tSkip");
- }
+ let _ = db.store(&event).expect("valid");
_ => {}