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:
@@ -19,7 +19,7 @@ use crate::{
|
||||
|
||||
use notedeck::{Accounts, AppContext, DataPath, DataPathType, FilterState, ImageCache, UnknownIds};
|
||||
|
||||
use enostr::{ClientMessage, Keypair, Pubkey, RelayEvent, RelayMessage, RelayPool};
|
||||
use enostr::{ClientMessage, Keypair, PoolRelay, Pubkey, RelayEvent, RelayMessage, RelayPool};
|
||||
use uuid::Uuid;
|
||||
|
||||
use egui_extras::{Size, StripBuilder};
|
||||
@@ -124,7 +124,9 @@ fn try_process_event(
|
||||
RelayEvent::Closed => warn!("{} connection closed", &ev.relay),
|
||||
RelayEvent::Error(e) => error!("{}: {}", &ev.relay, e),
|
||||
RelayEvent::Other(msg) => trace!("other event {:?}", &msg),
|
||||
RelayEvent::Message(msg) => process_message(damus, app_ctx, &ev.relay, &msg),
|
||||
RelayEvent::Message(msg) => {
|
||||
process_message(damus, app_ctx, &ev.relay, &msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,16 +214,6 @@ fn update_damus(damus: &mut Damus, app_ctx: &mut AppContext<'_>, ctx: &egui::Con
|
||||
}
|
||||
}
|
||||
|
||||
fn process_event(ndb: &Ndb, _subid: &str, event: &str) {
|
||||
#[cfg(feature = "profiling")]
|
||||
puffin::profile_function!();
|
||||
|
||||
//info!("processing event {}", event);
|
||||
if let Err(_err) = ndb.process_event(event) {
|
||||
error!("error processing event {}", event);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_eose(
|
||||
damus: &mut Damus,
|
||||
ctx: &mut AppContext<'_>,
|
||||
@@ -314,7 +306,29 @@ fn handle_eose(
|
||||
|
||||
fn process_message(damus: &mut Damus, ctx: &mut AppContext<'_>, relay: &str, msg: &RelayMessage) {
|
||||
match msg {
|
||||
RelayMessage::Event(subid, ev) => process_event(ctx.ndb, subid, ev),
|
||||
RelayMessage::Event(_subid, ev) => {
|
||||
let relay = if let Some(relay) = ctx.pool.relays.iter().find(|r| r.url() == relay) {
|
||||
relay
|
||||
} else {
|
||||
error!("couldn't find relay {} for note processing!?", relay);
|
||||
return;
|
||||
};
|
||||
|
||||
match relay {
|
||||
PoolRelay::Websocket(_) => {
|
||||
//info!("processing event {}", event);
|
||||
if let Err(err) = ctx.ndb.process_event(ev) {
|
||||
error!("error processing event {ev}: {err}");
|
||||
}
|
||||
}
|
||||
PoolRelay::Multicast(_) => {
|
||||
// multicast events are client events
|
||||
if let Err(err) = ctx.ndb.process_client_event(ev) {
|
||||
error!("error processing multicast event {ev}: {err}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
RelayMessage::Notice(msg) => warn!("Notice from {}: {}", relay, msg),
|
||||
RelayMessage::OK(cr) => info!("OK {:?}", cr),
|
||||
RelayMessage::Eose(sid) => {
|
||||
|
||||
Reference in New Issue
Block a user