11// TODO: Replace with builtin autorelay behaviour from libp2p. See https://github.com/libp2p/rust-libp2p/pull/6156
2- use std:: {
3- collections:: { HashMap , HashSet , VecDeque } ,
4- num:: NonZeroU8 ,
5- task:: { Context , Poll , Waker } ,
6- time:: Duration ,
7- } ;
8-
92use crate :: behaviour:: autorelay:: handler:: Out ;
103use crate :: multiaddr_ext:: MultiaddrExt ;
114use crate :: prelude:: swarm:: derive_prelude:: { ListenerId , PortUse } ;
@@ -22,6 +15,13 @@ use crate::prelude::swarm::{
2215use crate :: prelude:: transport:: Endpoint ;
2316use crate :: prelude:: { PeerId , Protocol } ;
2417use either:: Either ;
18+ use std:: collections:: BTreeMap ;
19+ use std:: {
20+ collections:: { HashMap , HashSet , VecDeque } ,
21+ num:: NonZeroU8 ,
22+ task:: { Context , Poll , Waker } ,
23+ time:: Duration ,
24+ } ;
2525use web_time:: { Instant , SystemTime } ;
2626
2727mod handler;
@@ -220,10 +220,10 @@ impl Behaviour {
220220 /// This will dial and establish a connection to the peer if it doesn't already have a direct
221221 /// connection.
222222 /// Note that peers that are through a relay cannot be used as a static peer
223- pub fn add_static_relay ( & mut self , peer_id : PeerId , address : Multiaddr ) {
223+ pub fn add_static_relay ( & mut self , peer_id : PeerId , address : Multiaddr ) -> bool {
224224 if address. is_relayed ( ) {
225225 tracing:: warn!( %peer_id, %address, "static relay address is relayed. ignoring." ) ;
226- return ;
226+ return false ;
227227 }
228228
229229 let entry = self . static_relays . entry ( peer_id) . or_default ( ) ;
@@ -245,6 +245,8 @@ impl Behaviour {
245245 if let Some ( waker) = self . waker . take ( ) {
246246 waker. wake ( ) ;
247247 }
248+
249+ true
248250 }
249251
250252 /// Remove peer as a static relay.
@@ -410,7 +412,7 @@ impl Behaviour {
410412 }
411413
412414 /// Removes all existing reservations.
413- fn remove_all_reservations ( & mut self ) {
415+ pub fn remove_all_reservations ( & mut self ) {
414416 let relay_listeners = self
415417 . reservations
416418 . iter ( )
0 commit comments