Make the engine's link vocabulary private and the options neutral
VoiceOptions is a struct of its own, no longer an alias of the TeamSpeak link's options: identity is an IdentityBlob and client_version a spec for ts::versions::resolve, which rides the address as the link parameter client_version and which the TeamSpeak connector resolves (a spec it refuses fails the connect in words). SessionLink builds the connect parameters (link/connect.rs: the bookmark's link, the hello, the credential of the identity's kind, now also a Voelin key's signer) and session.rs holds it directly: the ServerLink trait between them was redundant. The trait lives on in the TeamSpeak module (ts/ts_link.rs, with the TeamSpeak-typed ConnectOptions) for TsLink and the in-memory link of the tests. ServerLink, TsLink, LinkCtx, LinkCmd, LinkEvent and Remote are crate-private, Engine::start_with_link is gone, and the three tests that needed the inner link (tests/link_fake.rs) are unit tests of link/ now. The rg over the crate for tsclientlib, tsproto and voelin_query, outside ts/ and the three files that use them privately (gateway.rs, query.rs, stream.rs), is empty. The UI and voelinctl get compile fixes: the identity blob and the spec string. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
be84874a09
commit
1edc52ce74
17 files changed
+549
-370
No files matched your search
@@ -26,5 +26,5 @@ pub(crate) mod ts_session;
|
||||
pub mod versions;
|
||||
mod voice;
|
||||
|
||||
pub use ts_link::TsLink;
|
||||
pub(crate) use ts_link::{ConnectOptions, ServerLink, TsLink};
|
||||
pub use ts_session::TsConnector;
|
||||
@@ -1,6 +1,11 @@
|
||||
//! [`TsLink`]: the TeamSpeak implementation of [`ServerLink`].
|
||||
//! The inner link of the TeamSpeak side: [`ServerLink`], the trait that
|
||||
//! [`TsLink`] implements, and the [`ConnectOptions`] it connects with.
|
||||
//!
|
||||
//! It connects as a normal TeamSpeak 3 or 6 client with `tsclientlib` and
|
||||
//! The engine does not know this vocabulary: it talks to a
|
||||
//! `voelin_proto::link::Session`. The `ts_session` module makes a `Session`
|
||||
//! of a [`ServerLink`] (`LinkSession`), and the engine's tests give it a link
|
||||
//! of their own, an in-memory one. [`TsLink`] connects as a normal TeamSpeak 3
|
||||
//! or 6 client with `tsclientlib` and
|
||||
//! runs the connection ([`super::voice`]) with everything that rides on it:
|
||||
//! chat, voice, files, pokes, offline messages and, on TeamSpeak 6, the
|
||||
//! stream task. Which product the server is (and what it can do) is decided
|
||||
@@ -15,9 +20,73 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use tokio::sync::{mpsc, watch};
|
||||
use voelin_stream::PeerConfig;
|
||||
|
||||
use super::voice;
|
||||
use crate::link::{ConnectOptions, LinkCmd, LinkCtx, LinkEvent, ServerLink};
|
||||
use crate::link::{LinkCmd, LinkCtx, LinkEvent};
|
||||
|
||||
/// Starts the connection of a link: the contract of `crate::link` for the
|
||||
/// vocabulary ([`LinkCmd`] in, [`LinkEvent`] out) holds for what a link does
|
||||
/// with them, and the module documentation of `link/session_link.rs` states
|
||||
/// it.
|
||||
///
|
||||
/// One link serves every session of an engine; [`spawn`](Self::spawn) starts
|
||||
/// one connection.
|
||||
pub(crate) trait ServerLink: Send + Sync + 'static {
|
||||
/// Connect to the server `options` names and run the connection on its
|
||||
/// own task: take commands from `cmds`, report through `events`, and end
|
||||
/// the connection with [`LinkEvent::Disconnected`]. Does not block.
|
||||
fn spawn(
|
||||
&self,
|
||||
options: ConnectOptions,
|
||||
ctx: LinkCtx,
|
||||
cmds: mpsc::UnboundedReceiver<LinkCmd>,
|
||||
events: mpsc::UnboundedSender<LinkEvent>,
|
||||
);
|
||||
}
|
||||
|
||||
/// What a TeamSpeak connection needs to know: the server, who to be, where
|
||||
/// to join. The reverse of what the engine's `ConnectParams` carry
|
||||
/// (`ts_session::inner_options`).
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct ConnectOptions {
|
||||
pub address: String,
|
||||
pub nickname: String,
|
||||
/// The identity to connect with; none generates one.
|
||||
pub identity: Option<tsclientlib::Identity>,
|
||||
/// Signed compatibility version; `None` selects the native platform's tuple.
|
||||
pub client_version: Option<tsclientlib::Version>,
|
||||
pub server_password: Option<String>,
|
||||
/// Channel path to join, e.g. `Lobby/Sub`, or `/<id>`.
|
||||
pub channel: Option<String>,
|
||||
/// The password of `channel`.
|
||||
pub channel_password: Option<String>,
|
||||
/// A privilege key to use when connecting.
|
||||
pub token: Option<String>,
|
||||
/// Open the audio devices (capture and playback).
|
||||
pub audio: bool,
|
||||
/// Network settings for stream peer connections.
|
||||
pub stream_peer: PeerConfig,
|
||||
}
|
||||
|
||||
impl ConnectOptions {
|
||||
/// Options for `address` and `nickname`, the rest as a test leaves it.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn new(address: impl Into<String>, nickname: impl Into<String>) -> Self {
|
||||
Self {
|
||||
address: address.into(),
|
||||
nickname: nickname.into(),
|
||||
identity: None,
|
||||
client_version: None,
|
||||
server_password: None,
|
||||
channel: None,
|
||||
channel_password: None,
|
||||
token: None,
|
||||
audio: false,
|
||||
stream_peer: PeerConfig::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The main myTeamSpeak account of an application, as its connections show
|
||||
/// it to the servers: the proof of the myTS ID, and what servers are shown
|
||||
@@ -97,9 +166,9 @@ impl Watches {
|
||||
}
|
||||
}
|
||||
|
||||
/// Connects to TeamSpeak 3 and 6 servers. The engine's default link.
|
||||
/// Connects to TeamSpeak 3 and 6 servers. The link of [`TsConnector`](super::TsConnector).
|
||||
#[derive(Clone, Default)]
|
||||
pub struct TsLink {
|
||||
pub(crate) struct TsLink {
|
||||
account: Arc<Account>,
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ use voelin_proto::v1::request::Op;
|
||||
use voelin_proto::v1::{self, entity::Kind};
|
||||
|
||||
use super::*;
|
||||
use crate::link::{Backends, VoiceOptions, connect_params};
|
||||
|
||||
fn live() -> bool {
|
||||
std::env::var("VOELIN_LIVE").is_ok_and(|v| v == "1")
|
||||
@@ -136,7 +137,7 @@ async fn raise_flood_limits(dev: &Dev) {
|
||||
/// connector, with its push channel and media sink.
|
||||
async fn session(
|
||||
dev: &Dev,
|
||||
options: &ConnectOptions,
|
||||
options: &VoiceOptions,
|
||||
) -> (Arc<dyn Session>, mpsc::Receiver<v1::Push>, MediaReceiver) {
|
||||
raise_flood_limits(dev).await;
|
||||
let (sink, media) = media_channel();
|
||||
@@ -169,10 +170,10 @@ fn scope(kind: v1::ScopeKind, id: u64) -> v1::Scope {
|
||||
|
||||
impl Client {
|
||||
async fn connect(dev: &Dev, nick: &str) -> Self {
|
||||
Self::connect_with(dev, ConnectOptions::new(dev.voice, nick)).await
|
||||
Self::connect_with(dev, VoiceOptions::new(dev.voice, nick)).await
|
||||
}
|
||||
|
||||
async fn connect_with(dev: &Dev, options: ConnectOptions) -> Self {
|
||||
async fn connect_with(dev: &Dev, options: VoiceOptions) -> Self {
|
||||
let (session, pushes, media) = session(dev, &options).await;
|
||||
let mut client = Self {
|
||||
session,
|
||||
@@ -414,7 +415,7 @@ const EXPECTED: [(&str, Expect); 17] = [
|
||||
/// of an unrelated fake host, which the cases that are run never touch.
|
||||
async fn fixture(dev: Dev) -> Fixture {
|
||||
let (session, pushes, media) =
|
||||
session(&dev, &ConnectOptions::new(dev.voice, dev.nick("conf"))).await;
|
||||
session(&dev, &VoiceOptions::new(dev.voice, dev.nick("conf"))).await;
|
||||
let unrelated = FakeConnector::new();
|
||||
let (params, _media) = voelin_proto::test_util::connect_params("fake://unrelated");
|
||||
unrelated.connect(params).await.expect("a fake session");
|
||||
@@ -547,7 +548,7 @@ async fn refused_moves(dev: Dev) {
|
||||
let check = {
|
||||
let token = token.clone();
|
||||
tokio::spawn(async move {
|
||||
let mut options = ConnectOptions::new(dev.voice, dev.nick("moves"));
|
||||
let mut options = VoiceOptions::new(dev.voice, dev.nick("moves"));
|
||||
options.token = Some(token);
|
||||
let client = Client::connect_with(&dev, options).await;
|
||||
let code = |result: Result<v1::VoiceState, SessionError>| match result {
|
||||
@@ -742,7 +743,7 @@ async fn group_token(admin: &voelin_query::QueryClient, name: &str) -> String {
|
||||
}
|
||||
|
||||
async fn channel_file_with_a_key(dev: Dev, token: String) {
|
||||
let mut options = ConnectOptions::new(dev.voice, dev.nick("files"));
|
||||
let mut options = VoiceOptions::new(dev.voice, dev.nick("files"));
|
||||
options.token = Some(token);
|
||||
let a = Client::connect_with(&dev, options).await;
|
||||
let channel = a.seat.channel_id;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! A TeamSpeak connection as a `voelin_proto::link::Session`
|
||||
//! (`docs/session-seam.md`, "the TeamSpeak side").
|
||||
//!
|
||||
//! [`LinkSession`] is a `Session` over any [`ServerLink`](crate::link::ServerLink):
|
||||
//! [`LinkSession`] is a `Session` over any [`ServerLink`]:
|
||||
//! it turns the link's `LinkCmd`s and `LinkEvent`s (the client's older,
|
||||
//! TeamSpeak-shaped vocabulary) into v1 entities, pushes and answers. With
|
||||
//! `TsLink` inside it is the in-process TeamSpeak `Session`; with a fake link
|
||||
@@ -11,10 +11,10 @@
|
||||
//!
|
||||
//! This module and the files it is made of are TeamSpeak's: they keep the
|
||||
//! TeamSpeak types (`tsclientlib`'s identity and client version) in
|
||||
//! [`connect_params`] and [`TsConnector`], and everything else is v1 and the
|
||||
//! client's own model. In the second half of the decoupling plan they move,
|
||||
//! with `TsLink`, to the TeamSpeak gateway (`voelin-gateway-ts` of
|
||||
//! VoelinGateWay).
|
||||
//! [`inner_options`], the reverse of what the engine's `connect_params` wrote,
|
||||
//! and everything else is v1 and the client's own model. In the second half
|
||||
//! of the decoupling plan they move, with `TsLink`, to the TeamSpeak gateway
|
||||
//! (`voelin-gateway-ts` of VoelinGateWay).
|
||||
|
||||
mod driver;
|
||||
pub(crate) mod entities;
|
||||
@@ -37,24 +37,21 @@ use tokio::sync::{broadcast, mpsc, oneshot, watch};
|
||||
use voelin_model::{Link, ServerDetails};
|
||||
use voelin_proto::link::{
|
||||
BoxFuture, CloseReason, ConnectParams, Connected, Connector, Credential, Download, Features,
|
||||
IssuerTrust, LinkStats, MAX_RTP, MediaClass, MediaError, MediaPacket, MediaSink, Placement,
|
||||
Sent, Session, SessionError, Upload, placement, voice_sub,
|
||||
LinkStats, MAX_RTP, MediaClass, MediaError, MediaPacket, Placement, Sent, Session,
|
||||
SessionError, Upload, placement, voice_sub,
|
||||
};
|
||||
use voelin_proto::v1::{self, response::Result as Answer};
|
||||
|
||||
use self::driver::{Cmd, Config, Driver, Parts, rejected};
|
||||
use super::{ConnectOptions, ServerLink, TsLink, versions};
|
||||
use crate::BackendInfo;
|
||||
use crate::link::{
|
||||
Backends, BoxDuplex, ConnectOptions, LinkCmd, LinkCtx, LinkEvent, LocalConnected,
|
||||
LocalConnector, LocalCtx, ServerLink, StreamPort,
|
||||
BoxDuplex, LinkCmd, LinkCtx, LinkEvent, LocalConnected, LocalConnector, LocalCtx, StreamPort,
|
||||
VERSION_PARAM,
|
||||
};
|
||||
use crate::ts::TsLink;
|
||||
|
||||
/// The `Credential::Foreign` kind of a stored TeamSpeak identity.
|
||||
const IDENTITY_KIND: &str = "teamspeak";
|
||||
/// The link parameter that carries the client version to impersonate: the
|
||||
/// JSON of `tsclientlib::Version`, in unpadded URL-safe base64.
|
||||
const VERSION_PARAM: &str = "client_version";
|
||||
const IDENTITY_KIND: &str = voelin_identity::KIND_TEAMSPEAK;
|
||||
/// How long the link may take to report its first snapshot after it said it
|
||||
/// is connected; the snapshot gives the `Welcome` its own user.
|
||||
const FIRST_SNAPSHOT: Duration = Duration::from_millis(250);
|
||||
@@ -70,122 +67,9 @@ fn now_ms() -> i64 {
|
||||
|
||||
// ---- what the engine hands a connector ------------------------------------
|
||||
|
||||
/// The connect parameters of a TeamSpeak connection, from the options the
|
||||
/// session was asked to connect with (`docs/session-seam.md` section 4.2).
|
||||
///
|
||||
/// The address is the `ts3server://` link of the bookmark (the channel and
|
||||
/// its password ride in it, and so does the client version to claim, until
|
||||
/// v1 has fields for them), the server password is `Hello.password` and the
|
||||
/// privilege key `Hello.invite_code`. The identity goes as
|
||||
/// `Credential::Foreign`; no account is used yet.
|
||||
///
|
||||
/// An address a link cannot carry is refused here ([`bookmark`]).
|
||||
pub(crate) fn connect_params(
|
||||
options: &ConnectOptions,
|
||||
media: Arc<dyn MediaSink>,
|
||||
backends: &Backends,
|
||||
) -> Result<ConnectParams, SessionError> {
|
||||
let credential = Credential::Foreign {
|
||||
kind: IDENTITY_KIND,
|
||||
blob: options
|
||||
.identity
|
||||
.as_ref()
|
||||
.and_then(|identity| serde_json::to_vec(identity).ok())
|
||||
.map(Bytes::from)
|
||||
.unwrap_or_default(),
|
||||
};
|
||||
let hello = v1::Hello {
|
||||
version: 1,
|
||||
client: Some(v1::ClientInfo {
|
||||
name: "Voelin".into(),
|
||||
version: voelin_platform::crash::app_version().to_owned(),
|
||||
platform: std::env::consts::OS.into(),
|
||||
kind: v1::ClientKind::User as i32,
|
||||
}),
|
||||
nickname: options.nickname.clone(),
|
||||
password: options.server_password.clone().unwrap_or_default(),
|
||||
invite_code: options.token.clone().unwrap_or_default(),
|
||||
..Default::default()
|
||||
};
|
||||
Ok(ConnectParams {
|
||||
address: address_link(options)?,
|
||||
credential,
|
||||
linked: Vec::new(),
|
||||
account: backends.account(),
|
||||
issuer_trust: IssuerTrust::Unknown,
|
||||
hello,
|
||||
host_pin: None,
|
||||
trust: backends.trust(),
|
||||
media,
|
||||
push_capacity: 1024,
|
||||
timeout: Duration::from_secs(35),
|
||||
})
|
||||
}
|
||||
|
||||
/// The `ts3server://` link of the options' address, with the channel to join
|
||||
/// and the client version to claim.
|
||||
fn address_link(options: &ConnectOptions) -> Result<String, SessionError> {
|
||||
let mut link = match Link::parse(&options.address) {
|
||||
Some(Link::Server(link)) => link,
|
||||
// Not a TeamSpeak link, or none: a bookmark's `host[:port]`.
|
||||
_ if !options.address.contains("://") => bookmark(&options.address)?,
|
||||
// Some other scheme: as given, for the connector of that scheme.
|
||||
_ => return Ok(options.address.clone()),
|
||||
};
|
||||
link.channel = options.channel.clone().filter(|c| !c.is_empty()).or(link.channel);
|
||||
link.channel_password =
|
||||
options.channel_password.clone().filter(|p| !p.is_empty()).or(link.channel_password);
|
||||
let mut url = link.to_url();
|
||||
if let Some(version) = options.client_version.as_ref().and_then(|v| serde_json::to_vec(v).ok())
|
||||
{
|
||||
url.push(if url.contains('?') { '&' } else { '?' });
|
||||
url.push_str(VERSION_PARAM);
|
||||
url.push('=');
|
||||
url.push_str(&URL_SAFE_NO_PAD.encode(version));
|
||||
}
|
||||
Ok(url)
|
||||
}
|
||||
|
||||
/// The link to a bookmark's `host[:port]`.
|
||||
///
|
||||
/// A link cannot say everything an address can: it drops a port that is no
|
||||
/// port (`ServerLink::new` takes `host:99999` for the host `host` and joins
|
||||
/// the default port), and it ends the host at a `?`, `#` or `/` and decodes a
|
||||
/// `%` (so that a `?` in the host would hide the channel behind the next
|
||||
/// one). The TeamSpeak library refuses such an address when it resolves it;
|
||||
/// so does this, in words, instead of connecting to something else.
|
||||
fn bookmark(address: &str) -> Result<voelin_model::ServerLink, SessionError> {
|
||||
let address = address.trim();
|
||||
// Without the query: a link keeps secrets in it.
|
||||
let shown = crate::link::without_query(address);
|
||||
let not_an_address = || SessionError::Protocol(format!("not a server address: {shown}"));
|
||||
if address.is_empty()
|
||||
|| address
|
||||
.chars()
|
||||
.any(|c| matches!(c, '?' | '#' | '/' | '%') || c.is_whitespace() || c.is_control())
|
||||
{
|
||||
return Err(not_an_address());
|
||||
}
|
||||
// The text after the port's colon: `[v6]:port`, or `host:port` with the one
|
||||
// colon (more colons are an IPv6 address without a port).
|
||||
let port = if let Some(rest) = address.strip_prefix('[') {
|
||||
let (_, after) = rest.split_once(']').ok_or_else(not_an_address)?;
|
||||
(!after.is_empty()).then(|| after.strip_prefix(':').unwrap_or(after))
|
||||
} else {
|
||||
address.rsplit_once(':').filter(|(host, _)| !host.contains(':')).map(|(_, port)| port)
|
||||
};
|
||||
if let Some(port) = port
|
||||
&& !port.parse::<u16>().is_ok_and(|port| port != 0)
|
||||
{
|
||||
return Err(SessionError::Protocol(format!(
|
||||
"the port in {shown} is not a number from 1 to 65535"
|
||||
)));
|
||||
}
|
||||
Ok(voelin_model::ServerLink::new(address))
|
||||
}
|
||||
|
||||
/// The options a TeamSpeak link is connected with: the reverse of
|
||||
/// [`connect_params`].
|
||||
/// `link::connect_params`. A client version spec that [`versions::resolve`]
|
||||
/// refuses fails the connect, in words.
|
||||
fn inner_options(params: &ConnectParams, ctx: &LocalCtx) -> Result<ConnectOptions, SessionError> {
|
||||
let link = match Link::parse(¶ms.address) {
|
||||
Some(Link::Server(link)) => link,
|
||||
@@ -208,14 +92,26 @@ fn inner_options(params: &ConnectParams, ctx: &LocalCtx) -> Result<ConnectOption
|
||||
));
|
||||
}
|
||||
};
|
||||
let client_version = params
|
||||
let spec = params
|
||||
.address
|
||||
.split_once('?')
|
||||
.and_then(|(_, query)| {
|
||||
query.split('&').find_map(|pair| pair.strip_prefix(&format!("{VERSION_PARAM}=")))
|
||||
})
|
||||
.and_then(|text| URL_SAFE_NO_PAD.decode(text).ok())
|
||||
.and_then(|json| serde_json::from_slice(&json).ok());
|
||||
.map(|text| {
|
||||
URL_SAFE_NO_PAD
|
||||
.decode(text)
|
||||
.ok()
|
||||
.and_then(|bytes| String::from_utf8(bytes).ok())
|
||||
.ok_or_else(|| SessionError::Protocol("the client version cannot be read".into()))
|
||||
})
|
||||
.transpose()?;
|
||||
let client_version = match spec {
|
||||
None => None,
|
||||
Some(spec) => versions::resolve(&spec).map_err(|e| {
|
||||
SessionError::Protocol(format!("invalid client compatibility version: {e}"))
|
||||
})?,
|
||||
};
|
||||
let nonempty = |text: &str| (!text.is_empty()).then(|| text.to_owned());
|
||||
Ok(ConnectOptions {
|
||||
address: link.address(),
|
||||
@@ -485,6 +381,7 @@ impl LinkConnector {
|
||||
}
|
||||
|
||||
/// A connector for addresses of every scheme.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn any(link: Arc<dyn ServerLink>) -> Self {
|
||||
Self { link, schemes: &[], any: true }
|
||||
}
|
||||
@@ -516,13 +413,14 @@ impl LocalConnector for LinkConnector {
|
||||
}
|
||||
|
||||
/// Connects to TeamSpeak 3 and 6 servers (`ts3server://` and `teamspeak://`)
|
||||
/// with `tsclientlib`: [`LinkSession`]s over [`TsLink`].
|
||||
/// with `tsclientlib`: a `LinkSession` over a `TsLink` for every connection.
|
||||
///
|
||||
/// Clones share one account: the main myTeamSpeak account that every
|
||||
/// connection of the connector presents ([`TsConnector::set_myts_identity`],
|
||||
/// [`TsConnector::set_myts_data`]), also those made before it was set.
|
||||
/// Register a connector in the engine's registry with
|
||||
/// [`Backends::register_teamspeak`] and keep a clone to set the account.
|
||||
/// [`Backends::register_teamspeak`](crate::Backends::register_teamspeak) and
|
||||
/// keep a clone to set the account.
|
||||
#[derive(Clone)]
|
||||
pub struct TsConnector {
|
||||
connector: LinkConnector,
|
||||
@@ -754,19 +652,21 @@ async fn connect_link(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::link::{Backends, VoiceOptions, connect_params};
|
||||
use voelin_proto::link::IssuerTrust;
|
||||
|
||||
fn params(options: &ConnectOptions) -> ConnectParams {
|
||||
fn params(options: &VoiceOptions) -> ConnectParams {
|
||||
let (media, _rx) = voelin_proto::test_util::media_channel();
|
||||
connect_params(options, media, &Backends::empty()).unwrap()
|
||||
}
|
||||
|
||||
fn back(options: &ConnectOptions) -> ConnectOptions {
|
||||
fn back(options: &VoiceOptions) -> ConnectOptions {
|
||||
inner_options(¶ms(options), &LocalCtx::standalone()).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_options_of_a_bookmark_come_back_as_they_went() {
|
||||
let mut options = ConnectOptions::new("ts.example.com:9988", "nick");
|
||||
let mut options = VoiceOptions::new("ts.example.com:9988", "nick");
|
||||
let same = back(&options);
|
||||
assert_eq!(
|
||||
(same.address.as_str(), same.nickname.as_str()),
|
||||
@@ -782,8 +682,10 @@ mod tests {
|
||||
options.channel = Some("Games/Raid Night".into());
|
||||
options.channel_password = Some("p w+%".into());
|
||||
options.token = Some("tokenvalue".into());
|
||||
options.identity = Some(tsclientlib::Identity::create());
|
||||
options.client_version = Some(crate::ts::versions::native_version().unwrap());
|
||||
let identity = tsclientlib::Identity::create();
|
||||
options.identity = Some(crate::ts::identity::to_blob(&identity));
|
||||
// A spec the user can give; the connector resolves it.
|
||||
options.client_version = Some("generic".into());
|
||||
options.audio = false;
|
||||
let sent = params(&options);
|
||||
assert_eq!(sent.hello.password, "s3cret pass&word");
|
||||
@@ -801,44 +703,44 @@ mod tests {
|
||||
assert_eq!(got.channel.as_deref(), Some("Games/Raid Night"));
|
||||
assert_eq!(got.channel_password, options.channel_password);
|
||||
assert_eq!(got.token.as_deref(), Some("tokenvalue"));
|
||||
assert_eq!(got.client_version, options.client_version);
|
||||
assert_eq!(got.client_version, versions::resolve("generic").unwrap());
|
||||
assert!(got.client_version.is_some());
|
||||
// The identity is the same key and counters.
|
||||
let (a, b) = (options.identity.as_ref().unwrap(), got.identity.as_ref().unwrap());
|
||||
assert_eq!(serde_json::to_value(a).unwrap(), serde_json::to_value(b).unwrap());
|
||||
let b = got.identity.as_ref().unwrap();
|
||||
assert_eq!(serde_json::to_value(&identity).unwrap(), serde_json::to_value(b).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_channel_by_id_and_an_address_that_is_a_link_are_kept() {
|
||||
let mut options = ConnectOptions::new("[::1]:9987", "nick");
|
||||
let mut options = VoiceOptions::new("[::1]:9987", "nick");
|
||||
options.channel = Some("/12".into());
|
||||
let got = back(&options);
|
||||
assert_eq!(got.address, "[::1]:9987");
|
||||
assert_eq!(got.channel.as_deref(), Some("/12"));
|
||||
|
||||
// A bookmark that is a link keeps its own parameters.
|
||||
let options =
|
||||
ConnectOptions::new("ts3server://ts.example.com?port=1&channel=Lobby", "nick");
|
||||
let options = VoiceOptions::new("ts3server://ts.example.com?port=1&channel=Lobby", "nick");
|
||||
let got = back(&options);
|
||||
assert_eq!(
|
||||
(got.address.as_str(), got.channel.as_deref()),
|
||||
("ts.example.com:1", Some("Lobby"))
|
||||
);
|
||||
// Another scheme is left as it is for the connector of that scheme.
|
||||
let options = ConnectOptions::new("voelin://host/i/code", "nick");
|
||||
let options = VoiceOptions::new("voelin://host/i/code", "nick");
|
||||
assert_eq!(params(&options).address, "voelin://host/i/code");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn what_is_no_teamspeak_identity_is_refused() {
|
||||
let mut sent = params(&ConnectOptions::new("ts.example.com", "nick"));
|
||||
let mut sent = params(&VoiceOptions::new("ts.example.com", "nick"));
|
||||
sent.credential = Credential::Voelin(Arc::new(voelin_proto::test_util::FakeSigner));
|
||||
let error = inner_options(&sent, &LocalCtx::standalone()).unwrap_err();
|
||||
assert!(matches!(error, SessionError::Protocol(_)));
|
||||
let mut sent = params(&ConnectOptions::new("ts.example.com", "nick"));
|
||||
let mut sent = params(&VoiceOptions::new("ts.example.com", "nick"));
|
||||
sent.credential =
|
||||
Credential::Account { kind: "teamspeak", integration_id: Bytes::from_static(b"id") };
|
||||
assert!(inner_options(&sent, &LocalCtx::standalone()).is_err());
|
||||
let mut sent = params(&ConnectOptions::new("ts.example.com", "nick"));
|
||||
let mut sent = params(&VoiceOptions::new("ts.example.com", "nick"));
|
||||
sent.credential =
|
||||
Credential::Foreign { kind: "teamspeak", blob: Bytes::from_static(b"not json") };
|
||||
assert!(inner_options(&sent, &LocalCtx::standalone()).is_err());
|
||||
@@ -854,7 +756,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn the_params_carry_what_the_session_needs_and_no_account_yet() {
|
||||
let sent = params(&ConnectOptions::new("ts.example.com", "nick"));
|
||||
let sent = params(&VoiceOptions::new("ts.example.com", "nick"));
|
||||
assert!(sent.account.is_none());
|
||||
assert_eq!(sent.issuer_trust, IssuerTrust::Unknown);
|
||||
assert!(sent.linked.is_empty() && sent.host_pin.is_none());
|
||||
@@ -867,7 +769,7 @@ mod tests {
|
||||
/// Why `connect_params` refused an address, if it did.
|
||||
fn refused(address: &str) -> Option<String> {
|
||||
let (media, _rx) = voelin_proto::test_util::media_channel();
|
||||
match connect_params(&ConnectOptions::new(address, "nick"), media, &Backends::empty()) {
|
||||
match connect_params(&VoiceOptions::new(address, "nick"), media, &Backends::empty()) {
|
||||
Ok(_) => None,
|
||||
Err(SessionError::Protocol(text)) => Some(text),
|
||||
Err(other) => panic!("{address}: {other}"),
|
||||
@@ -925,7 +827,7 @@ mod tests {
|
||||
("::1", "::1"),
|
||||
("2001:db8::1", "2001:db8::1"),
|
||||
] {
|
||||
let mut options = ConnectOptions::new(address, "nick");
|
||||
let mut options = VoiceOptions::new(address, "nick");
|
||||
options.channel = Some("Games/Raid".into());
|
||||
let got = back(&options);
|
||||
assert_eq!((got.address.as_str(), got.channel.as_deref()), (host, Some("Games/Raid")));
|
||||
@@ -936,7 +838,7 @@ mod tests {
|
||||
/// (13): an empty option is none, and an empty nickname stays empty.
|
||||
#[test]
|
||||
fn empty_options_come_back_as_none() {
|
||||
let mut options = ConnectOptions::new("ts.example.com", "");
|
||||
let mut options = VoiceOptions::new("ts.example.com", "");
|
||||
options.server_password = Some(String::new());
|
||||
options.channel = Some(String::new());
|
||||
options.channel_password = Some(String::new());
|
||||
|
||||
@@ -37,10 +37,10 @@ use voelin_model::{Capabilities, ChannelId, ChatMessage, ChatTarget, ServerFlavo
|
||||
use voelin_stream::{ClientState, Request, StreamNotification};
|
||||
|
||||
use super::book::presence_from_book;
|
||||
use super::ts_link::Watches;
|
||||
use super::ts_link::{ConnectOptions, Watches};
|
||||
use crate::cache::{self, IMAGE_NEGOTIATION, image_download_time};
|
||||
use crate::files::{self, FileEntry, Report, RequestId, Sink, TransferId, TransferState};
|
||||
use crate::link::{BoxDuplex, BoxRead, ConnectOptions, LinkCmd, LinkCtx, LinkEvent, Remote};
|
||||
use crate::link::{BoxDuplex, BoxRead, LinkCmd, LinkCtx, LinkEvent, Remote};
|
||||
use crate::offline::{OfflineMessage, OfflineMessageInfo};
|
||||
use crate::settings::FILES_PROGRESS_MS;
|
||||
use crate::stream::{StreamCmd, StreamHandle, StreamInput};
|
||||
|
||||
Reference in new issue
Block a user