improvement: log source IP for persisted events

This commit is contained in:
Greg Heartsfield 2023-02-06 17:15:27 -06:00
parent bd07a11f50
commit 2e42b1b86e
2 changed files with 5 additions and 3 deletions

View File

@ -26,6 +26,7 @@ pub type PooledConnection = r2d2::PooledConnection<r2d2_sqlite::SqliteConnection
pub struct SubmittedEvent { pub struct SubmittedEvent {
pub event: Event, pub event: Event,
pub notice_tx: tokio::sync::mpsc::Sender<Notice>, pub notice_tx: tokio::sync::mpsc::Sender<Notice>,
pub source_ip: String,
} }
/// Database file /// Database file
@ -227,11 +228,12 @@ pub async fn db_writer(
notice_tx.try_send(Notice::duplicate(event.id)).ok(); notice_tx.try_send(Notice::duplicate(event.id)).ok();
} else { } else {
info!( info!(
"persisted event: {:?} (kind: {}) from: {:?} in: {:?}", "persisted event: {:?} (kind: {}) from: {:?} in: {:?} (IP: {:?})",
event.get_event_id_prefix(), event.get_event_id_prefix(),
event.kind, event.kind,
event.get_author_prefix(), event.get_author_prefix(),
start.elapsed() start.elapsed(),
subm_event.source_ip,
); );
event_write = true; event_write = true;
// send this out to all clients // send this out to all clients

View File

@ -736,7 +736,7 @@ async fn nostr_server(
// check if the event is too far in the future. // check if the event is too far in the future.
if e.is_valid_timestamp(settings.options.reject_future_seconds) { if e.is_valid_timestamp(settings.options.reject_future_seconds) {
// Write this to the database. // Write this to the database.
let submit_event = SubmittedEvent { event: e.clone(), notice_tx: notice_tx.clone() }; let submit_event = SubmittedEvent { event: e.clone(), notice_tx: notice_tx.clone(), source_ip: conn.ip().to_string()};
event_tx.send(submit_event).await.ok(); event_tx.send(submit_event).await.ok();
client_published_event_count += 1; client_published_event_count += 1;
} else { } else {