Skip to content

Commit

Permalink
mutinyd: deliver announcements directed to local peer #34
Browse files Browse the repository at this point in the history
  • Loading branch information
caolan committed Jul 29, 2024
1 parent 51ece1a commit 11425ba
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion mutinyd/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,24 @@ impl Server {
}).await;
},
RequestBody::Announce {peer, app_uuid, data} => {
self.send_announce(&peer, app_uuid, data)?;
// If the announce is directed at local peer just write directly to database
if peer.eq(&self.peer_id.to_base58()) {
// Can't store u64 timestamp directly in sqlite, would have to store as blob
let received: i64 = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs().try_into()?;
let tx = self.store.transaction()?;
let peer_id = tx.get_or_put_peer(&peer)?;
let app = tx.get_or_put_app(peer_id, &app_uuid)?;
tx.set_app_announcement(app, received, &data)?;
tx.commit()?;
self.announce_subscribers_send(ResponseBody::AppAnnouncement {
peer,
app_uuid,
data,
}).await;
} else {
// Else if announce is directed at another peer, send libp2p request
self.send_announce(&peer, app_uuid, data)?;
}
let _ = request.response.send(ResponseBody::Success).await;
},
RequestBody::MessageSend {peer, app_uuid, from_app_uuid, message} => {
Expand Down

0 comments on commit 11425ba

Please sign in to comment.