Record slice 1 in the design; consume a host that is no TeamSpeak one
- docs/session-seam.md: the status line, and section 13 with how the code differs from the design, a follow-up for the protocol repository (P12), and what ran against the baseline. - docs/architecture.md and the crate docs describe the engine on the Session. - A departed client's talk state is dropped before the new snapshot replaces the table it is looked up in. - The backend of a host that names none is its product and version. - A unit test drives the engine over the protocol repository's FakeSession through the registry: connect, presence, a move, chat in the channel, disconnect. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c473ab216e
commit
1b7abdf4c7
7 files changed
+244
-20
No files matched your search
@@ -4,7 +4,8 @@
|
||||
//! Each server the user works with is a session with up to three sources:
|
||||
//!
|
||||
//! - **voice**: a normal client connection (visible, can talk), made by a
|
||||
//! [`link::ServerLink`] ([`TsLink`] for TeamSpeak servers; see [`link`])
|
||||
//! [`link::ServerLink`] (the engine's `SessionLink` over a `voelin_proto::link::Session`,
|
||||
//! [`TsLink`] inside it for TeamSpeak servers; see [`link`])
|
||||
//! - **gateway**: a `tsgw` gateway (invisible presence, relayed chat)
|
||||
//! - **query**: the user's own ServerQuery credentials (same, without a gateway)
|
||||
//!
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
//!
|
||||
//! # Implementations
|
||||
//!
|
||||
//! The engine's own implementation is [`SessionLink`]: it connects through
|
||||
//! The engine's own implementation is `SessionLink`: it connects through
|
||||
//! [`Backends`], the registry of connectors by address scheme, and talks to
|
||||
//! the `voelin_proto::link::Session` it gets (`session_link.rs`, with
|
||||
//! `project.rs` and `media.rs`). Nothing of a backend shows above it:
|
||||
|
||||
@@ -361,8 +361,15 @@ impl Conn {
|
||||
let _ = self.events.send(event);
|
||||
}
|
||||
|
||||
/// What the host says it is: its backend, else the product and version of
|
||||
/// the host itself.
|
||||
fn backend(&self) -> v1::BackendInfo {
|
||||
self.welcome.host.as_ref().and_then(|h| h.backend.clone()).unwrap_or_default()
|
||||
let Some(host) = self.welcome.host.as_ref() else { return Default::default() };
|
||||
host.backend.clone().unwrap_or_else(|| v1::BackendInfo {
|
||||
product: host.product.clone(),
|
||||
version: host.version.clone(),
|
||||
flavor: String::new(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Warn about `what` the first time only.
|
||||
|
||||
@@ -1317,3 +1317,119 @@ async fn a_connect_that_the_link_fails_is_an_error_with_its_reason() {
|
||||
async fn next_body(pushes: &mut mpsc::Receiver<v1::Push>) -> v1::push::Body {
|
||||
within("a push", pushes.recv()).await.body.expect("a push with a body")
|
||||
}
|
||||
|
||||
/// A session that is no TeamSpeak one: the engine consumes it as it does
|
||||
/// the TeamSpeak side's, through the registry (the fake host of the protocol
|
||||
/// repository stands for a Voelin host).
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn the_engine_consumes_any_session_a_connector_makes() {
|
||||
use v1::entity::Kind;
|
||||
use voelin_proto::test_util::FakeConnector;
|
||||
|
||||
let connector = FakeConnector::new();
|
||||
let host = connector.host();
|
||||
let put = |kind: Kind| host.put(v1::Entity { kind: Some(kind) }).unwrap();
|
||||
put(Kind::Server(v1::Server {
|
||||
id: 1,
|
||||
name: "Fake Host".into(),
|
||||
uid: "fake-host".into(),
|
||||
default_channel_id: 10,
|
||||
..Default::default()
|
||||
}));
|
||||
let channel = |id, name: &str, position| v1::Channel {
|
||||
id,
|
||||
server_id: 1,
|
||||
kind: v1::ChannelKind::Voice as i32,
|
||||
name: name.into(),
|
||||
position,
|
||||
..Default::default()
|
||||
};
|
||||
put(Kind::Channel(channel(10, "Lobby", 0)));
|
||||
put(Kind::Channel(channel(11, "Games", 1024)));
|
||||
put(Kind::User(v1::User {
|
||||
id: 2,
|
||||
uid: vec![2; 32].into(),
|
||||
uid_kind: v1::IdKind::Voelin as i32,
|
||||
name: "alice".into(),
|
||||
..Default::default()
|
||||
}));
|
||||
put(Kind::Voice(v1::VoiceState {
|
||||
server_id: 1,
|
||||
participant_id: 50,
|
||||
user_id: 2,
|
||||
channel_id: 11,
|
||||
slot: 90,
|
||||
nick: "alice".into(),
|
||||
..Default::default()
|
||||
}));
|
||||
|
||||
let mut backends = Backends::empty();
|
||||
backends.register(Arc::new(connector.clone()));
|
||||
let link = SessionLink::new(backends);
|
||||
let ctx = LocalCtx::standalone().link;
|
||||
let (cmd_tx, cmd_rx) = mpsc::unbounded_channel();
|
||||
let (event_tx, mut events) = mpsc::unbounded_channel();
|
||||
link.spawn(ConnectOptions::new("fake://host", "tester"), ctx, cmd_rx, event_tx);
|
||||
|
||||
async fn event<T>(
|
||||
events: &mut mpsc::UnboundedReceiver<LinkEvent>,
|
||||
mut f: impl FnMut(LinkEvent) -> Option<T>,
|
||||
) -> T {
|
||||
within("an event", async {
|
||||
loop {
|
||||
if let Some(t) = f(events.recv().await?) {
|
||||
return Some(t);
|
||||
}
|
||||
}
|
||||
})
|
||||
.await
|
||||
}
|
||||
let (name, backend, own_client, server_uid) = event(&mut events, |e| match e {
|
||||
LinkEvent::Connected { name, backend, own_client, server_uid, .. } => {
|
||||
Some((name, backend, own_client, server_uid))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
assert_eq!((name.as_str(), server_uid.as_str()), ("Fake Host", "fake-host"));
|
||||
assert_eq!(backend.product, "voelin-fake");
|
||||
// The host seated us: its participant id is the client id of the older model.
|
||||
assert_ne!(own_client, 0);
|
||||
let presence = event(&mut events, |e| match e {
|
||||
LinkEvent::Presence(p) => Some(*p),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
assert_eq!(presence.server.name, "Fake Host");
|
||||
assert_eq!(presence.channels.len(), 2);
|
||||
assert_eq!(presence.channels[&11].order, 10, "the order follows the positions");
|
||||
let alice = &presence.clients[&50];
|
||||
assert_eq!((alice.nickname.as_str(), alice.channel), ("alice", 11));
|
||||
assert!(alice.uid.as_deref().is_some_and(|uid| uid.len() == 52), "a Voelin uid is base32");
|
||||
|
||||
// A move is a JoinVoice; the host's voice state tells where we are.
|
||||
cmd_tx.send(LinkCmd::Move(11, None)).unwrap();
|
||||
event(&mut events, |e| match e {
|
||||
LinkEvent::OwnChannel(11) => Some(()),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
// Chat in the channel we are in: the host's copy comes back as ours.
|
||||
cmd_tx.send(LinkCmd::SendChat(ChatTarget::Channel(11), "hello host".into())).unwrap();
|
||||
let chat = event(&mut events, |e| match e {
|
||||
LinkEvent::Chat(chat) => Some(chat),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
assert_eq!((chat.text.as_str(), chat.target), ("hello host", ChatTarget::Channel(11)));
|
||||
|
||||
// The session closes with us.
|
||||
cmd_tx.send(LinkCmd::Disconnect).unwrap();
|
||||
let reason = event(&mut events, |e| match e {
|
||||
LinkEvent::Disconnected(reason) => Some(reason),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
assert_eq!(reason, None);
|
||||
assert_eq!(connector.connects().len(), 1);
|
||||
}
|
||||
@@ -609,6 +609,10 @@ impl Driver {
|
||||
let own = Some(self.cfg.own_client);
|
||||
let Built { server, live, own_user, by_uid } =
|
||||
entities::build(&presence, self.cfg.ts6, own);
|
||||
// Clients that left take their talk state with them.
|
||||
for id in self.by_client.keys().filter(|id| !presence.clients.contains_key(id)) {
|
||||
self.downlink.forget(*id);
|
||||
}
|
||||
self.by_client = presence
|
||||
.clients
|
||||
.values()
|
||||
@@ -627,16 +631,6 @@ impl Driver {
|
||||
if own_user.is_some() {
|
||||
self.own_user = own_user;
|
||||
}
|
||||
// Clients that left take their talk state with them.
|
||||
let gone: Vec<u16> = self
|
||||
.by_client
|
||||
.keys()
|
||||
.copied()
|
||||
.filter(|id| !presence.clients.contains_key(id))
|
||||
.collect();
|
||||
for id in gone {
|
||||
self.downlink.forget(id);
|
||||
}
|
||||
|
||||
let (put, del) = entities::diff(&self.server, &server);
|
||||
self.server = server;
|
||||
|
||||
Reference in new issue
Block a user