use std::{
borrow::Cow,
collections::{HashMap, HashSet, VecDeque, hash_map::Entry},
fmt,
num::NonZero,
str::{self, FromStr},
sync::Arc,
task,
time::{Duration, Instant},
};
use libp2p::{
Multiaddr, PeerId, StreamProtocol,
kad::{self, StoreInserts, store::RecordStore},
swarm::{
ConnectionDenied, ConnectionId, DialError, DialFailure, FromSwarm, NetworkBehaviour,
NewExternalAddrOfPeer, THandler, THandlerInEvent, THandlerOutEvent, ToSwarm,
behaviour::ConnectionEstablished,
},
};
use tokio::sync::{mpsc, oneshot};
use crate::{
actor::{ActorId, ActorIdFromBytesError},
error::RegistryError,
};
fn proto_name() -> StreamProtocol {
use std::sync::LazyLock;
static NAME: LazyLock<StreamProtocol> = LazyLock::new(|| {
StreamProtocol::try_from_owned(super::session::applied_protocol("/piying/registry/1.0.0"))
.expect("registry protocol id must start with '/'")
});
NAME.clone()
}
type RegisterResult = Result<(), RegistryError>;
pub(super) type LookupResult = Result<ActorRegistration<'static>, RegistryError>;
type LookupLocalResult = Result<Option<ActorRegistration<'static>>, RegistryError>;
pub(super) type RegisterReply = oneshot::Sender<RegisterResult>;
pub(super) type LookupReply = mpsc::UnboundedSender<LookupResult>;
pub(super) type LookupLocalReply = oneshot::Sender<LookupLocalResult>;
pub(super) type UnregisterReply = oneshot::Sender<()>;
include!("registry/events.rs");
include!("registry/behaviour.rs");
include!("registry/network_behaviour.rs");
include!("registry/types.rs");