use as_bytes everywhere

This commit is contained in:
Septias
2024-01-29 16:12:02 +01:00
parent f5a7a22239
commit eca8ed3d56
2 changed files with 7 additions and 4 deletions

View File

@@ -67,7 +67,10 @@ impl Context {
};
// restore old peers from db, if any
let peers = self.get_peers_for_topic(&topic.to_string()).await?;
let peers = self.get_peers_for_topic(topic).await?;
if peers.len() == 0 {
warn!(self, "joining gossip with zero peers: {peers:?}");
}
// TODO: add timeout as the returned future might be pending forever
let connect_future = gossip.join(topic, peers).await?;
@@ -81,11 +84,11 @@ impl Context {
/// Get list of [NodeId]s for one topic.
/// This is used to rejoin a gossip group when reopening the xdc.
/// Only [NodeId] is needed because the magic endpoint caches region and derp server for [NodeId]s.
pub async fn get_peers_for_topic(&self, topic: &str) -> Result<Vec<NodeId>> {
pub async fn get_peers_for_topic(&self, topic: TopicId) -> Result<Vec<NodeId>> {
self.sql
.query_map(
"SELECT public_key FROM iroh_gossip_peers WHERE topic = ?",
(topic,),
(topic.as_bytes(),),
|row| {
let data = row.get::<_, Vec<u8>>(0)?;
Ok(data)

View File

@@ -460,8 +460,8 @@ pub(crate) async fn receive_imf_inner(
.add_node_addr(node_addr.clone())
.context("Failed to add node address")?;
let node_id = node_addr.node_id;
for topic in topics {
let node_id = node_addr.node_id;
context
.add_peer_for_topic(instance_id, topic, node_id)
.await?;