Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
warnings + relay connected_peers fn
Browse files Browse the repository at this point in the history
  • Loading branch information
chunningham committed Apr 5, 2023
1 parent 9dd9983 commit fbe2547
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/p2p/behaviour/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ where
autonat: AutoNat,
}

async fn poll_swarm<KS>(mut swarm: Swarm<Behaviour<KS>>) -> Result<(), ()>
async fn poll_swarm<KS>(_swarm: Swarm<Behaviour<KS>>) -> Result<(), ()>
where
KS: RecordStore + Send + 'static,
{
Expand Down
10 changes: 10 additions & 0 deletions src/p2p/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ enum Message {
GetAddresses(oneshot::Sender<Vec<Multiaddr>>),
ListenOn(Vec<Multiaddr>, oneshot::Sender<Result<(), Error>>),
Dial(Multiaddr, oneshot::Sender<Result<(), Error>>),
GetConnectedPeers(oneshot::Sender<Vec<PeerId>>),
}

impl RelayNode {
Expand Down Expand Up @@ -82,6 +83,12 @@ impl RelayNode {
self.sender.send(Message::Dial(addr, s)).await?;
r.await?
}

pub async fn connected_peers(&mut self) -> Result<Vec<PeerId>, Error> {
let (s, r) = oneshot::channel();
self.sender.send(Message::GetConnectedPeers(s)).await?;
Ok(r.await?)
}
}

#[derive(Debug)]
Expand Down Expand Up @@ -235,6 +242,9 @@ async fn poll_swarm(
swarm.dial(addr)?;
s.send(Ok(())).map_err(|_| SwarmError::SendError)?
}
Message::GetConnectedPeers(s) => s
.send(swarm.connected_peers().map(|p| p.to_owned()).collect())
.map_err(|_| SwarmError::SendError)?,
},
Either::Right((Some(_), _)) => {
// process swarm event
Expand Down

0 comments on commit fbe2547

Please sign in to comment.