Note multicasting
This is an initial implementation of note multicast, which sends posted notes to other notedecks on the same network. This came about after I nerd sniped myself thinking about p2p nostr on local networks[1] You can test this exclusively without joining any other relays by passing -r multicast on the command line. [1] https://damus.io/note1j50pseqwma38g3aqrsnhvld0m0ysdgppw6fjnvvcj0haeulgswgq80lpca Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -1,13 +1,22 @@
|
||||
use crate::{Error, Note};
|
||||
use nostrdb::Filter;
|
||||
use crate::Error;
|
||||
use nostrdb::{Filter, Note};
|
||||
use serde_json::json;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EventClientMessage<'a> {
|
||||
note: Note<'a>,
|
||||
}
|
||||
|
||||
impl EventClientMessage<'_> {
|
||||
pub fn to_json(&self) -> Result<String, Error> {
|
||||
Ok(format!("[\"EVENT\", {}]", self.note.json()?))
|
||||
}
|
||||
}
|
||||
|
||||
/// Messages sent by clients, received by relays
|
||||
#[derive(Debug)]
|
||||
pub enum ClientMessage {
|
||||
Event {
|
||||
note: Note,
|
||||
},
|
||||
pub enum ClientMessage<'a> {
|
||||
Event(EventClientMessage<'a>),
|
||||
Req {
|
||||
sub_id: String,
|
||||
filters: Vec<Filter>,
|
||||
@@ -18,9 +27,9 @@ pub enum ClientMessage {
|
||||
Raw(String),
|
||||
}
|
||||
|
||||
impl ClientMessage {
|
||||
pub fn event(note: Note) -> Self {
|
||||
ClientMessage::Event { note }
|
||||
impl<'a> ClientMessage<'a> {
|
||||
pub fn event(note: Note<'a>) -> Self {
|
||||
ClientMessage::Event(EventClientMessage { note })
|
||||
}
|
||||
|
||||
pub fn raw(raw: String) -> Self {
|
||||
@@ -37,7 +46,7 @@ impl ClientMessage {
|
||||
|
||||
pub fn to_json(&self) -> Result<String, Error> {
|
||||
Ok(match self {
|
||||
Self::Event { note } => json!(["EVENT", note]).to_string(),
|
||||
Self::Event(ecm) => ecm.to_json()?,
|
||||
Self::Raw(raw) => raw.clone(),
|
||||
Self::Req { sub_id, filters } => {
|
||||
if filters.is_empty() {
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
mod message;
|
||||
|
||||
pub use message::ClientMessage;
|
||||
pub use message::{ClientMessage, EventClientMessage};
|
||||
|
||||
Reference in New Issue
Block a user