Start on a new BridgeRelay type.
This is the one we'll actually use to connect to bridges. It has a `Bridge` line, and an optional `BridgeDesc`. Maybe this will turn into a `BridgeRelay<'a>` by analogy to `Relay` some time; I'm not sure.
This commit is contained in:
parent
013b9bff1b
commit
d9e3d38bd6
|
@ -12,6 +12,8 @@
|
|||
|
||||
mod config;
|
||||
mod descs;
|
||||
mod relay;
|
||||
|
||||
pub use config::Bridge;
|
||||
pub use descs::{BridgeDescEvent, BridgeDescList, BridgeDescProvider};
|
||||
pub use descs::{BridgeDesc, BridgeDescEvent, BridgeDescList, BridgeDescProvider};
|
||||
pub use relay::BridgeRelay;
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
//! Implementation code to make a bridge something that we can connect to and use to relay traffic.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use tor_linkspec::{HasRelayIds, RelayIdRef, RelayIdType};
|
||||
|
||||
use super::{Bridge, BridgeDesc};
|
||||
|
||||
/// The information about a Bridge that is necessary to connect to it and relay traffic.
|
||||
#[derive(Clone, Debug)]
|
||||
|
||||
pub struct BridgeRelay {
|
||||
/// The local configurations for the bridge.
|
||||
///
|
||||
/// This is _always_ necessary, since it without it we can't know whether
|
||||
/// any pluggable transports are needed.
|
||||
bridge_line: Arc<Bridge>,
|
||||
|
||||
/// A descriptor for the bridge.
|
||||
///
|
||||
/// If present, it MUST have every RelayId that the `bridge_line` does.
|
||||
desc: Option<BridgeDesc>,
|
||||
}
|
||||
|
||||
impl BridgeRelay {
|
||||
/// Return true if this BridgeRelay has a known descriptor and can be used for relays.
|
||||
pub fn has_descriptor(&self) -> bool {
|
||||
self.desc.is_some()
|
||||
}
|
||||
}
|
||||
|
||||
impl HasRelayIds for BridgeRelay {
|
||||
fn identity(&self, key_type: RelayIdType) -> Option<RelayIdRef<'_>> {
|
||||
self.bridge_line
|
||||
.identity(key_type)
|
||||
.or_else(|| self.desc.as_ref().and_then(|d| d.identity(key_type)))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue