pub struct PeerDb { /* private fields */ }Expand description
A database that stores a map of peers by PeerId and multiple indices.
Assumes that all indexed fields are unique per-node, with a few notable exceptions:
- Hostname may be duplicated, though the fqdn (including the tailnet component) may not be.
- Accepted routes may overlap.
Implementations§
Source§impl PeerDb
impl PeerDb
Sourcepub fn upsert(&mut self, new: &Node) -> PeerId
pub fn upsert(&mut self, new: &Node) -> PeerId
Upsert a node into the peer db.
The StableNodeId is used as the primary key to identify the node.
Sourcepub fn remove(&mut self, field: &dyn IndexedField) -> Option<(PeerId, Node)>
pub fn remove(&mut self, field: &dyn IndexedField) -> Option<(PeerId, Node)>
Remove a peer by a given indexed field.
Sourcepub fn get(&self, field: &dyn IndexedField) -> Option<(PeerId, &Node)>
pub fn get(&self, field: &dyn IndexedField) -> Option<(PeerId, &Node)>
Get the node with the given field.
Sourcepub fn get_route(&self, route: IpNet) -> impl Iterator<Item = (PeerId, &Node)>
pub fn get_route(&self, route: IpNet) -> impl Iterator<Item = (PeerId, &Node)>
Get the nodes with the closest matching route.
Sourcepub fn has(&self, field: &dyn IndexedField) -> Option<PeerId>
pub fn has(&self, field: &dyn IndexedField) -> Option<PeerId>
Check whether there is a peer with the given field in the db.
Sourcepub fn peer_by_known_disco_key(
&self,
key: &DiscoPublicKey,
) -> Option<(PeerId, &Node, DiscoKeyMatch)>
pub fn peer_by_known_disco_key( &self, key: &DiscoPublicKey, ) -> Option<(PeerId, &Node, DiscoKeyMatch)>
Resolve an inbound disco frame’s sender key to the peer that owns it, accepting either
of that peer’s two known disco keys — Go endpoint.checkAndUpdateDiscoKey.
The active key is tried first, so a key that is one peer’s active key and another peer’s
stale inactive one resolves to the peer that is actually using it. A key belonging to
neither slot of any peer returns None and must be refused by the caller: that refusal is
what stops an unknown disco key from opening a path or being attributed to a peer.
Two peers can transiently claim the same key under netmap churn (see
disco_key_reassigned_across_peers_no_panic); like every other index here the answer is the
last writer’s, never a panic.
Sourcepub fn set_inactive_disco_key(
&mut self,
id: PeerId,
key: Option<DiscoPublicKey>,
)
pub fn set_inactive_disco_key( &mut self, id: PeerId, key: Option<DiscoPublicKey>, )
Register (or clear) the peer’s known-but-inactive disco key, so ingress under it still resolves to the peer.
A control Node carries a single disco key, so the second slot of Go’s endpointDisco
cannot come in through upsert; the peer tracker — which owns that state —
writes it here immediately after each upsert. Passing None retracts the entry, which is
what a peer that has only ever had one key needs.
Trait Implementations§
Auto Trait Implementations§
impl Forget for PeerDb
impl Freeze for PeerDbwhere
*const u8 is !null: Freeze,
PhantomData<(PeerId, Node)>: Freeze,
PhantomData<(NodePublicKey, PeerId)>: Freeze,
PhantomData<(DiscoPublicKey, PeerId)>: Freeze,
PhantomData<(PeerId, DiscoPublicKey)>: Freeze,
PhantomData<(StableId, PeerId)>: Freeze,
PhantomData<(i64, PeerId)>: Freeze,
PhantomData<(String, PeerId)>: Freeze,
PhantomData<PeerId>: Freeze,
PhantomData<Child<Box<Node<PeerId>>, PeerId>>: Freeze,
PhantomData<SmallVec<[PeerId; 2]>>: Freeze,
PhantomData<Child<Box<Node<SmallVec<[PeerId; 2]>>>, SmallVec<[PeerId; 2]>>>: Freeze,
impl Move for PeerDb
impl RefUnwindSafe for PeerDbwhere
NonZero<i32>: RefUnwindSafe,
Utc: RefUnwindSafe,
NonZero<u32>: RefUnwindSafe,
Box<Node<PeerId>>: RefUnwindSafe,
PeerId: RefUnwindSafe,
Box<Node<SmallVec<[PeerId; 2]>>>: RefUnwindSafe,
impl Send for PeerDbwhere
RawTable<(PeerId, Node)>: Send,
RawTable<(NodePublicKey, PeerId)>: Send,
RawTable<(DiscoPublicKey, PeerId)>: Send,
RawTable<(PeerId, DiscoPublicKey)>: Send,
RawTable<(StableId, PeerId)>: Send,
RawTable<(i64, PeerId)>: Send,
RawTable<(String, PeerId)>: Send,
RawVecInner: Send,
Box<Node<PeerId>>: Send,
SmallVec<[PeerId; 2]>: Send,
Box<Node<SmallVec<[PeerId; 2]>>>: Send,
impl Sync for PeerDbwhere
RawTable<(PeerId, Node)>: Sync,
RawTable<(NodePublicKey, PeerId)>: Sync,
RawTable<(DiscoPublicKey, PeerId)>: Sync,
RawTable<(PeerId, DiscoPublicKey)>: Sync,
RawTable<(StableId, PeerId)>: Sync,
RawTable<(i64, PeerId)>: Sync,
RawTable<(String, PeerId)>: Sync,
RawVecInner: Sync,
Box<Node<PeerId>>: Sync,
SmallVecData<[PeerId; 2]>: Sync,
PeerId: Sync,
Box<Node<SmallVec<[PeerId; 2]>>>: Sync,
impl Unpin for PeerDbwhere
*const u8 is !null: Unpin,
NonZero<i32>: Unpin,
Utc: Unpin,
NonZero<u32>: Unpin,
*const LeafNode<String, Vec<String>> is !null: Unpin,
Box<(String, Vec<String>)>: Unpin,
*const LeafNode<String, Vec<IpAddr>> is !null: Unpin,
Box<(String, Vec<IpAddr>)>: Unpin,
Box<Node<PeerId>>: Unpin,
*const PeerId is !null: Unpin,
PeerId: Unpin,
Box<Node<SmallVec<[PeerId; 2]>>>: Unpin,
impl UnsafeUnpin for PeerDbwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<(PeerId, Node)>: UnsafeUnpin,
PhantomData<(NodePublicKey, PeerId)>: UnsafeUnpin,
PhantomData<(DiscoPublicKey, PeerId)>: UnsafeUnpin,
PhantomData<(PeerId, DiscoPublicKey)>: UnsafeUnpin,
PhantomData<(StableId, PeerId)>: UnsafeUnpin,
PhantomData<(i64, PeerId)>: UnsafeUnpin,
PhantomData<(String, PeerId)>: UnsafeUnpin,
PhantomData<PeerId>: UnsafeUnpin,
PhantomData<Child<Box<Node<PeerId>>, PeerId>>: UnsafeUnpin,
PhantomData<SmallVec<[PeerId; 2]>>: UnsafeUnpin,
PhantomData<Child<Box<Node<SmallVec<[PeerId; 2]>>>, SmallVec<[PeerId; 2]>>>: UnsafeUnpin,
impl UnwindSafe for PeerDbwhere
HashMap<PeerId, Node>: UnwindSafe,
HashMap<NodePublicKey, PeerId>: UnwindSafe,
HashMap<DiscoPublicKey, PeerId>: UnwindSafe,
HashMap<PeerId, DiscoPublicKey>: UnwindSafe,
HashMap<StableId, PeerId>: UnwindSafe,
HashMap<i64, PeerId>: UnwindSafe,
HashMap<String, PeerId>: UnwindSafe,
RawVecInner: UnwindSafe,
Box<Node<PeerId>>: UnwindSafe,
NonNull<PeerId>: UnwindSafe,
PeerId: UnwindSafe,
Box<Node<SmallVec<[PeerId; 2]>>>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<A, T> DynMessage<A> for T
impl<A, T> DynMessage<A> for T
Source§fn handle_dyn<'a>(
self: Box<T>,
state: &'a mut A,
actor_ref: ActorRef<A>,
tx: Option<Sender<Result<Box<dyn Any + Send>, SendError<Box<dyn Any + Send>, Box<dyn Any + Send>>>>>,
stop: &'a mut bool,
) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn ReplyError>>> + Send + 'a>>
fn handle_dyn<'a>( self: Box<T>, state: &'a mut A, actor_ref: ActorRef<A>, tx: Option<Sender<Result<Box<dyn Any + Send>, SendError<Box<dyn Any + Send>, Box<dyn Any + Send>>>>>, stop: &'a mut bool, ) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn ReplyError>>> + Send + 'a>>
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more