Parcourir la source

Working on a personal relayer crate

Cesar Rodas il y a 3 mois
Parent
commit
6430281f57
3 fichiers modifiés avec 26 ajouts et 9 suppressions
  1. 12 0
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 13 8
      src/main.rs

+ 12 - 0
Cargo.lock

@@ -938,6 +938,18 @@ dependencies = [
 ]
 
 [[package]]
+name = "nostr-rs-personal-relayer"
+version = "0.1.0"
+dependencies = [
+ "nostr-rs-client",
+ "nostr-rs-relayer",
+ "nostr-rs-storage-base",
+ "nostr-rs-types",
+ "thiserror",
+ "url",
+]
+
+[[package]]
 name = "nostr-rs-relayer"
 version = "0.1.0"
 dependencies = [

+ 1 - 1
Cargo.toml

@@ -9,7 +9,7 @@ members = [
     "crates/client",
     "crates/relayer",
     "crates/storage/base",
-    "crates/storage/rocksdb", "crates/dump", "crates/storage/memory",
+    "crates/storage/rocksdb", "crates/dump", "crates/storage/memory", "crates/personal-relayer",
 ]
 
 [dependencies]

+ 13 - 8
src/main.rs

@@ -1,13 +1,10 @@
 use futures::Future;
 use nostr_rs_client::Pool;
+use nostr_rs_relayer::Relayer;
 use nostr_rs_rocksdb::RocksDb;
-use nostr_rs_types::{relayer, types::Filter, Request, Response};
-use std::{collections::HashMap, env, fs, pin::Pin, sync::Arc};
-use tokio::{
-    net::TcpListener,
-    sync::mpsc,
-    time::{sleep, Duration},
-};
+use nostr_rs_types::{types::Filter, Request, Response};
+use std::{env, fs, pin::Pin, sync::Arc};
+use tokio::{net::TcpListener, sync::mpsc};
 use url::Url;
 
 mod config;
@@ -86,6 +83,15 @@ async fn main() {
     ];
 
     let _ = client_pool.subscribe(initial_subscription.into()).await;
+
+    let relayer = Relayer::new(Some(db), Some(client_pool)).expect("relayer");
+
+    let addr = "127.0.0.1:3000";
+    let listener: TcpListener = TcpListener::bind(&addr).await.unwrap();
+
+    let _ = relayer.main(listener).expect("valid main").await;
+
+    /*
     loop {
         tokio::select! {
             Some((event, url)) = client_pool.recv() => {
@@ -94,7 +100,6 @@ async fn main() {
         }
     }
 
-    /*
     let db = RocksDb::new("./relayer-db").expect("db");
     let (relayer, mut server_receiver) = nostr_rs_relayer::Relayer::new(Some(db));
     let mut clients = nostr_rs_client::Pool::new()