diff --git a/Cargo.lock b/Cargo.lock index 72b86be..3110c0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -144,6 +144,31 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chorus" version = "1.0.6" +dependencies = [ + "chorus-lib", + "dashmap", + "env_logger", + "futures", + "heed", + "hyper", + "hyper-tungstenite", + "lazy_static", + "log", + "mmap-append", + "ron", + "rustls-pemfile", + "secp256k1", + "serde", + "tempfile", + "textnonce", + "tokio", + "tokio-rustls", + "url", +] + +[[package]] +name = "chorus-lib" +version = "1.0.6" dependencies = [ "dashmap", "env_logger", diff --git a/Cargo.toml b/Cargo.toml index cc35005..f700f67 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,30 +1,6 @@ -[package] -name = "chorus" -version = "1.0.6" -description = "A personal relay for nostr" -authors = ["Mike Dilger "] -license = "MIT" -repository = "https://github.com/mikedilger/chorus" -edition = "2021" - -[dependencies] -dashmap = "5.5" -env_logger = "0.10" -futures = "0.3" -heed = { git = "https://github.com/meilisearch/heed", rev = "64fd6fec293c0dee94855b8267557ce03e7ce5d8" } -hyper = { version = "0.14", features = [ "http1", "server", "runtime", "stream" ] } -hyper-tungstenite = "0.11" -lazy_static = "1.4" -log = "0.4" -mmap-append = { git = "https://github.com/mikedilger/mmap-append", rev = "0d20e193e7f13a442865a4a40a5da9a120e87411" } -ron = "0.8" -rustls-pemfile = "1.0" -secp256k1 = { version = "0.28", features = [ "hashes", "global-context", "rand-std" ] } -serde = { version = "1.0", features = ["derive"] } -textnonce = "1" -tokio = { version = "1", features = [ "full" ] } -tokio-rustls = "0.24" -url = "2.5" - -[dev-dependencies] -tempfile = "3" \ No newline at end of file +[workspace] +members = [ + "chorus-lib", + "chorus-bin", +] +resolver = "2" diff --git a/chorus-bin/Cargo.toml b/chorus-bin/Cargo.toml new file mode 100644 index 0000000..fde599a --- /dev/null +++ b/chorus-bin/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "chorus" +version = "1.0.6" +description = "A personal relay for nostr" +authors = ["Mike Dilger "] +license = "MIT" +repository = "https://github.com/mikedilger/chorus" +edition = "2021" + +[dependencies] +chorus-lib = { path = "../chorus-lib" } +dashmap = "5.5" +env_logger = "0.10" +futures = "0.3" +heed = { git = "https://github.com/meilisearch/heed", rev = "64fd6fec293c0dee94855b8267557ce03e7ce5d8" } +hyper = { version = "0.14", features = [ "http1", "server", "runtime", "stream" ] } +hyper-tungstenite = "0.11" +lazy_static = "1.4" +log = "0.4" +mmap-append = { git = "https://github.com/mikedilger/mmap-append", rev = "0d20e193e7f13a442865a4a40a5da9a120e87411" } +ron = "0.8" +rustls-pemfile = "1.0" +secp256k1 = { version = "0.28", features = [ "hashes", "global-context", "rand-std" ] } +serde = { version = "1.0", features = ["derive"] } +textnonce = "1" +tokio = { version = "1", features = [ "full" ] } +tokio-rustls = "0.24" +url = "2.5" + +[dev-dependencies] +tempfile = "3" \ No newline at end of file diff --git a/src/globals.rs b/chorus-bin/src/globals.rs similarity index 95% rename from src/globals.rs rename to chorus-bin/src/globals.rs index 9927167..e2f7fda 100644 --- a/src/globals.rs +++ b/chorus-bin/src/globals.rs @@ -1,6 +1,6 @@ -use crate::config::Config; -use crate::ip::{Ban, IpData}; -use crate::store::Store; +use chorus_lib::config::Config; +use chorus_lib::ip::{Ban, IpData}; +use chorus_lib::store::Store; use dashmap::DashMap; use hyper::server::conn::Http; use lazy_static::lazy_static; diff --git a/src/main.rs b/chorus-bin/src/main.rs similarity index 98% rename from src/main.rs rename to chorus-bin/src/main.rs index 3767fbc..52e1c7f 100644 --- a/src/main.rs +++ b/chorus-bin/src/main.rs @@ -1,24 +1,16 @@ -include!("macros.rs"); - -pub mod config; -pub mod error; pub mod globals; -pub mod ip; pub mod nostr; -pub mod reply; -pub mod store; pub mod tls; -pub mod types; pub mod web; -use crate::config::{Config, FriendlyConfig}; -use crate::error::{ChorusError, Error}; use crate::globals::{Globals, GLOBALS}; -use crate::ip::Ban; -use crate::reply::NostrReply; -use crate::store::Store; use crate::tls::MaybeTlsStream; -use crate::types::{OwnedFilter, Pubkey, Time}; +use chorus_lib::config::{Config, FriendlyConfig}; +use chorus_lib::error::{ChorusError, Error}; +use chorus_lib::ip::Ban; +use chorus_lib::reply::NostrReply; +use chorus_lib::store::Store; +use chorus_lib::types::{OwnedFilter, Pubkey, Time}; use futures::{sink::SinkExt, stream::StreamExt}; use hyper::service::Service; use hyper::upgrade::Upgraded; diff --git a/src/nostr.rs b/chorus-bin/src/nostr.rs similarity index 98% rename from src/nostr.rs rename to chorus-bin/src/nostr.rs index 4f23dfb..eca3699 100644 --- a/src/nostr.rs +++ b/chorus-bin/src/nostr.rs @@ -1,10 +1,10 @@ -use crate::error::{ChorusError, Error}; use crate::globals::GLOBALS; -use crate::reply::{NostrReply, NostrReplyPrefix}; -use crate::types::parse::json_escape::json_unescape; -use crate::types::parse::json_parse::*; -use crate::types::{Event, Filter, Kind, OwnedFilter, Pubkey, Time}; use crate::WebSocketService; +use chorus_lib::error::{ChorusError, Error}; +use chorus_lib::reply::{NostrReply, NostrReplyPrefix}; +use chorus_lib::types::parse::json_escape::json_unescape; +use chorus_lib::types::parse::json_parse::*; +use chorus_lib::types::{Event, Filter, Kind, OwnedFilter, Pubkey, Time}; use futures::SinkExt; use hyper_tungstenite::tungstenite::Message; use url::Url; diff --git a/src/tls.rs b/chorus-bin/src/tls.rs similarity index 97% rename from src/tls.rs rename to chorus-bin/src/tls.rs index 1e6ca52..15d3d7c 100644 --- a/src/tls.rs +++ b/chorus-bin/src/tls.rs @@ -1,5 +1,5 @@ -use crate::config::Config; -use crate::error::{ChorusError, Error}; +use chorus_lib::config::Config; +use chorus_lib::error::{ChorusError, Error}; use rustls::{Certificate, PrivateKey}; use std::fs::File; use std::io::BufReader; diff --git a/src/web.rs b/chorus-bin/src/web.rs similarity index 98% rename from src/web.rs rename to chorus-bin/src/web.rs index d0e74ab..40c0559 100644 --- a/src/web.rs +++ b/chorus-bin/src/web.rs @@ -1,6 +1,6 @@ -use crate::config::Config; -use crate::error::Error; use crate::globals::GLOBALS; +use chorus_lib::config::Config; +use chorus_lib::error::Error; use hyper::{Body, Request, Response, StatusCode}; use std::net::SocketAddr; diff --git a/chorus-lib/Cargo.toml b/chorus-lib/Cargo.toml new file mode 100644 index 0000000..38f2793 --- /dev/null +++ b/chorus-lib/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "chorus-lib" +version = "1.0.6" +description = "A personal relay for nostr" +authors = ["Mike Dilger "] +license = "MIT" +repository = "https://github.com/mikedilger/chorus" +edition = "2021" + +[dependencies] +dashmap = "5.5" +env_logger = "0.10" +futures = "0.3" +heed = { git = "https://github.com/meilisearch/heed", rev = "64fd6fec293c0dee94855b8267557ce03e7ce5d8" } +hyper = { version = "0.14", features = [ "http1", "server", "runtime", "stream" ] } +hyper-tungstenite = "0.11" +lazy_static = "1.4" +log = "0.4" +mmap-append = { git = "https://github.com/mikedilger/mmap-append", rev = "0d20e193e7f13a442865a4a40a5da9a120e87411" } +ron = "0.8" +rustls-pemfile = "1.0" +secp256k1 = { version = "0.28", features = [ "hashes", "global-context", "rand-std" ] } +serde = { version = "1.0", features = ["derive"] } +textnonce = "1" +tokio = { version = "1", features = [ "full" ] } +tokio-rustls = "0.24" +url = "2.5" + +[dev-dependencies] +tempfile = "3" \ No newline at end of file diff --git a/src/config.rs b/chorus-lib/src/config.rs similarity index 100% rename from src/config.rs rename to chorus-lib/src/config.rs diff --git a/src/error.rs b/chorus-lib/src/error.rs similarity index 100% rename from src/error.rs rename to chorus-lib/src/error.rs diff --git a/src/ip.rs b/chorus-lib/src/ip.rs similarity index 100% rename from src/ip.rs rename to chorus-lib/src/ip.rs diff --git a/chorus-lib/src/lib.rs b/chorus-lib/src/lib.rs new file mode 100644 index 0000000..ffd9f0c --- /dev/null +++ b/chorus-lib/src/lib.rs @@ -0,0 +1,8 @@ +include!("macros.rs"); + +pub mod config; +pub mod error; +pub mod ip; +pub mod reply; +pub mod store; +pub mod types; diff --git a/src/macros.rs b/chorus-lib/src/macros.rs similarity index 100% rename from src/macros.rs rename to chorus-lib/src/macros.rs diff --git a/src/reply.rs b/chorus-lib/src/reply.rs similarity index 100% rename from src/reply.rs rename to chorus-lib/src/reply.rs diff --git a/src/store/event_store.rs b/chorus-lib/src/store/event_store.rs similarity index 100% rename from src/store/event_store.rs rename to chorus-lib/src/store/event_store.rs diff --git a/src/store/migrations.rs b/chorus-lib/src/store/migrations.rs similarity index 100% rename from src/store/migrations.rs rename to chorus-lib/src/store/migrations.rs diff --git a/src/store/mod.rs b/chorus-lib/src/store/mod.rs similarity index 100% rename from src/store/mod.rs rename to chorus-lib/src/store/mod.rs diff --git a/src/types/event/json_event.rs b/chorus-lib/src/types/event/json_event.rs similarity index 100% rename from src/types/event/json_event.rs rename to chorus-lib/src/types/event/json_event.rs diff --git a/src/types/event/mod.rs b/chorus-lib/src/types/event/mod.rs similarity index 100% rename from src/types/event/mod.rs rename to chorus-lib/src/types/event/mod.rs diff --git a/src/types/filter/json_filter.rs b/chorus-lib/src/types/filter/json_filter.rs similarity index 100% rename from src/types/filter/json_filter.rs rename to chorus-lib/src/types/filter/json_filter.rs diff --git a/src/types/filter/mod.rs b/chorus-lib/src/types/filter/mod.rs similarity index 100% rename from src/types/filter/mod.rs rename to chorus-lib/src/types/filter/mod.rs diff --git a/src/types/id.rs b/chorus-lib/src/types/id.rs similarity index 100% rename from src/types/id.rs rename to chorus-lib/src/types/id.rs diff --git a/src/types/kind.rs b/chorus-lib/src/types/kind.rs similarity index 100% rename from src/types/kind.rs rename to chorus-lib/src/types/kind.rs diff --git a/src/types/mod.rs b/chorus-lib/src/types/mod.rs similarity index 100% rename from src/types/mod.rs rename to chorus-lib/src/types/mod.rs diff --git a/src/types/parse/json_escape.rs b/chorus-lib/src/types/parse/json_escape.rs similarity index 100% rename from src/types/parse/json_escape.rs rename to chorus-lib/src/types/parse/json_escape.rs diff --git a/src/types/parse/json_parse.rs b/chorus-lib/src/types/parse/json_parse.rs similarity index 100% rename from src/types/parse/json_parse.rs rename to chorus-lib/src/types/parse/json_parse.rs diff --git a/src/types/parse/mod.rs b/chorus-lib/src/types/parse/mod.rs similarity index 100% rename from src/types/parse/mod.rs rename to chorus-lib/src/types/parse/mod.rs diff --git a/src/types/parse/utf8.rs b/chorus-lib/src/types/parse/utf8.rs similarity index 100% rename from src/types/parse/utf8.rs rename to chorus-lib/src/types/parse/utf8.rs diff --git a/src/types/pubkey.rs b/chorus-lib/src/types/pubkey.rs similarity index 98% rename from src/types/pubkey.rs rename to chorus-lib/src/types/pubkey.rs index 5ae727e..8afd2a3 100644 --- a/src/types/pubkey.rs +++ b/chorus-lib/src/types/pubkey.rs @@ -1,4 +1,4 @@ -use crate::Error; +use crate::error::Error; use serde::{Deserialize, Serialize}; use std::fmt; diff --git a/src/types/sig.rs b/chorus-lib/src/types/sig.rs similarity index 98% rename from src/types/sig.rs rename to chorus-lib/src/types/sig.rs index a0c569c..87a0f48 100644 --- a/src/types/sig.rs +++ b/chorus-lib/src/types/sig.rs @@ -1,4 +1,4 @@ -use crate::Error; +use crate::error::Error; use std::fmt; #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/src/types/tags.rs b/chorus-lib/src/types/tags.rs similarity index 100% rename from src/types/tags.rs rename to chorus-lib/src/types/tags.rs diff --git a/src/types/time.rs b/chorus-lib/src/types/time.rs similarity index 100% rename from src/types/time.rs rename to chorus-lib/src/types/time.rs