diff --git a/crates/voelin-core/src/lib.rs b/crates/voelin-core/src/lib.rs index a9b6ee8..59343bb 100644 --- a/crates/voelin-core/src/lib.rs +++ b/crates/voelin-core/src/lib.rs @@ -47,14 +47,12 @@ //! volume) are engine-wide ([`contacts`]). mod audio; -mod book; pub mod cache; pub mod contacts; pub mod discover; pub mod files; pub mod gateway; pub mod history; -pub mod identity; pub mod link; #[cfg(feature = "media")] pub mod media; @@ -67,10 +65,7 @@ pub mod stream; mod stream_types; #[cfg(feature = "media")] pub mod studio; -mod ts_link; -mod ts_session; -pub mod versions; -mod voice; +pub mod ts; mod web; use std::collections::HashMap; @@ -102,7 +97,7 @@ pub use route::{ChatRoute, Dedup, route_chat}; use settings::{SettingChange, Settings, SharedSettings}; use stream::{EncodedFrame, LayerId, LayerSpec, StreamInfo, StreamSetup, ViewerInfo}; pub use stream::{StreamFrame, StreamSink, StreamState, WatchState}; -pub use ts_link::TsLink; +pub use ts::TsLink; /// Banners are downloaded and shown by the same rule. pub use web::is_svg; /// Pictures from the web go through the desktop's proxy (set at startup). @@ -812,7 +807,7 @@ impl Engine { link: Arc, ) -> Self { let mut backends = Backends::empty(); - backends.register_local(Arc::new(ts_session::LinkConnector::any(link))); + backends.register_local(Arc::new(ts::ts_session::LinkConnector::any(link))); Self::start_with_backends(settings, history, backends) } diff --git a/crates/voelin-core/src/link/backends.rs b/crates/voelin-core/src/link/backends.rs index 549add5..2a30874 100644 --- a/crates/voelin-core/src/link/backends.rs +++ b/crates/voelin-core/src/link/backends.rs @@ -146,7 +146,7 @@ impl Default for Backends { /// `teamspeak://`, and an address without a scheme). fn default() -> Self { let mut backends = Self::empty(); - backends.register_local(Arc::new(crate::ts_session::TsConnector::new())); + backends.register_local(Arc::new(crate::ts::ts_session::TsConnector::new())); backends } } diff --git a/crates/voelin-core/src/link/project.rs b/crates/voelin-core/src/link/project.rs index d152a6c..60d28f3 100644 --- a/crates/voelin-core/src/link/project.rs +++ b/crates/voelin-core/src/link/project.rs @@ -17,8 +17,8 @@ use voelin_proto::link::Features; use voelin_proto::v1::{self, ChannelKind, MessageFlag, RoleScope}; use super::media::TalkTracker; -use crate::ts_session::entities::user_uid; -use crate::ts_session::ids::{self, FOREIGN_SYSTEM}; +use crate::ts::ts_session::entities::user_uid; +use crate::ts::ts_session::ids::{self, FOREIGN_SYSTEM}; /// What the projection needs to know besides the replica. pub(crate) struct View<'a> { diff --git a/crates/voelin-core/src/link/session_link.rs b/crates/voelin-core/src/link/session_link.rs index 20069f4..79c2db6 100644 --- a/crates/voelin-core/src/link/session_link.rs +++ b/crates/voelin-core/src/link/session_link.rs @@ -207,7 +207,7 @@ async fn drive( ) -> Option { let (media_tx, media_rx) = mpsc::unbounded_channel(); let sink: Arc = Arc::new(MediaQueue(media_tx)); - let params = match crate::ts_session::connect_params(options, sink, backends) { + let params = match crate::ts::ts_session::connect_params(options, sink, backends) { Ok(params) => params, Err(e) => return connect_failure(&e), }; @@ -498,7 +498,7 @@ impl Conn { let backend = self.backend(); let own_uid = - self.replica.user(self.own_user()).and_then(crate::ts_session::entities::user_uid); + self.replica.user(self.own_user()).and_then(crate::ts::ts_session::entities::user_uid); let name = self .replica .server(self.server) @@ -906,7 +906,7 @@ impl Conn { .filter(|n| !n.is_empty()); self.send(LinkEvent::Poke { from: u16::try_from(signal.from_participant).unwrap_or_default(), - from_uid: user.and_then(crate::ts_session::entities::user_uid), + from_uid: user.and_then(crate::ts::ts_session::entities::user_uid), from_name: nick.or_else(|| user.map(|u| u.name.clone())).unwrap_or_default(), message: poke.message, }); @@ -1261,7 +1261,7 @@ impl Conn { /// user to make one with. fn direct_channel(&self, uid: &str) -> Direct { let user_of = |id: u64| { - self.replica.user(id).and_then(crate::ts_session::entities::user_uid).as_deref() + self.replica.user(id).and_then(crate::ts::ts_session::entities::user_uid).as_deref() == Some(uid) }; let own = self.own_user(); @@ -1752,7 +1752,7 @@ mod tests { ("Fake", "1.2"), ] { let info = BackendInfo { product: product.into(), version: version.into() }; - assert_eq!(backend_info(&crate::ts_session::backend_to_v1(&info)), info); + assert_eq!(backend_info(&crate::ts::ts_session::backend_to_v1(&info)), info); } } @@ -1795,8 +1795,8 @@ mod tests { { let caps = Capabilities { streams, file_transfer, offline_messages, ..Default::default() }; - let features = Features::new(crate::ts_session::features_of(&caps)); - let host = crate::ts_session::backend_to_v1(&BackendInfo::default()); + let features = Features::new(crate::ts::ts_session::features_of(&caps)); + let host = crate::ts::ts_session::backend_to_v1(&BackendInfo::default()); let back = capabilities(&features, &host, true); assert_eq!( (back.streams, back.file_transfer, back.offline_messages), diff --git a/crates/voelin-core/src/link/tests.rs b/crates/voelin-core/src/link/tests.rs index ab1bf27..dd6a17d 100644 --- a/crates/voelin-core/src/link/tests.rs +++ b/crates/voelin-core/src/link/tests.rs @@ -27,7 +27,7 @@ use crate::files::{DownloadTo, FileEntry, TransferState}; use crate::offline::OfflineMessage; use crate::offline::OfflineMessageInfo; use crate::stream::{OwnStreamEvent, StreamCmd, StreamKind}; -use crate::ts_session::LinkConnector; +use crate::ts::ts_session::LinkConnector; use crate::{BackendInfo, Event, JoinFailure}; const ME: u16 = 7; diff --git a/crates/voelin-core/src/settings.rs b/crates/voelin-core/src/settings.rs index f7390d4..c89a46c 100644 --- a/crates/voelin-core/src/settings.rs +++ b/crates/voelin-core/src/settings.rs @@ -1135,7 +1135,7 @@ pub static CACHE_FETCH_IMAGES: Key = Key::new( ); /// Import identities from the official TeamSpeak clients when the app -/// starts ([`crate::identity::import_new`]; their files are only read). +/// starts ([`crate::ts::identity::import_new`]; their files are only read). pub static IDENTITY_IMPORT: Key = Key::new( "identity.import_from_teamspeak", Kind::Bool, diff --git a/crates/voelin-core/src/book.rs b/crates/voelin-core/src/ts/book.rs similarity index 99% rename from crates/voelin-core/src/book.rs rename to crates/voelin-core/src/ts/book.rs index 00db757..8450843 100644 --- a/crates/voelin-core/src/book.rs +++ b/crates/voelin-core/src/ts/book.rs @@ -345,7 +345,7 @@ mod tests { use crate::link::media::TalkTracker; use crate::link::project::{View, presence as project}; - use crate::ts_session::entities::build; + use crate::ts::ts_session::entities::build; let built = build(presence, ts6, own); let mut replica = Replica::new(SCHEMA_GENERATION); diff --git a/crates/voelin-core/src/identity.rs b/crates/voelin-core/src/ts/identity.rs similarity index 100% rename from crates/voelin-core/src/identity.rs rename to crates/voelin-core/src/ts/identity.rs diff --git a/crates/voelin-core/src/ts/mod.rs b/crates/voelin-core/src/ts/mod.rs new file mode 100644 index 0000000..f91b271 --- /dev/null +++ b/crates/voelin-core/src/ts/mod.rs @@ -0,0 +1,29 @@ +//! The TeamSpeak implementation of the session seam. +//! +//! Everything of the engine that is TeamSpeak's lives here, so that it can +//! leave this crate for the TeamSpeak gateway (`voelin-gateway-ts` of +//! VoelinGateWay) as one piece (`docs/session-seam.md`, H9): +//! +//! - `ts_link.rs` and `voice.rs` are the connection of `tsclientlib` +//! (chat, voice, files, pokes, offline messages, the stream task's +//! requests) with `book.rs`, its presence from the library's book; +//! - `ts_session/` makes a `voelin_proto::link::Session` of such a connection +//! ([`TsConnector`] is the `Connector` the engine registers for +//! `ts3server://` and `teamspeak://`); +//! - [`versions`] and [`identity`] are what a TeamSpeak client has to know +//! about itself: the signed compatibility versions it can claim, and the +//! identities (reading, importing from the official clients, the security +//! level). +//! +//! The TeamSpeak crates' types (`tsclientlib::Identity`, `Version`, ...) are +//! named in the public items of this module and nowhere else of the crate's +//! API. + +mod book; +pub mod identity; +mod ts_link; +pub(crate) mod ts_session; +pub mod versions; +mod voice; + +pub use ts_link::TsLink; diff --git a/crates/voelin-core/src/ts_link.rs b/crates/voelin-core/src/ts/ts_link.rs similarity index 93% rename from crates/voelin-core/src/ts_link.rs rename to crates/voelin-core/src/ts/ts_link.rs index d122cd2..0b5dae7 100644 --- a/crates/voelin-core/src/ts_link.rs +++ b/crates/voelin-core/src/ts/ts_link.rs @@ -1,7 +1,7 @@ //! [`TsLink`]: the TeamSpeak implementation of [`ServerLink`]. //! //! It connects as a normal TeamSpeak 3 or 6 client with `tsclientlib` and -//! runs the connection ([`crate::voice`]) with everything that rides on it: +//! 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 //! there, from the version it sends, and reported in @@ -14,8 +14,8 @@ use tokio::sync::mpsc; +use super::voice; use crate::link::{ConnectOptions, LinkCmd, LinkCtx, LinkEvent, ServerLink}; -use crate::voice; /// Connects to TeamSpeak 3 and 6 servers. The engine's default link. #[derive(Clone, Copy, Debug, Default)] diff --git a/crates/voelin-core/src/ts_session/driver.rs b/crates/voelin-core/src/ts/ts_session/driver.rs similarity index 100% rename from crates/voelin-core/src/ts_session/driver.rs rename to crates/voelin-core/src/ts/ts_session/driver.rs diff --git a/crates/voelin-core/src/ts_session/entities.rs b/crates/voelin-core/src/ts/ts_session/entities.rs similarity index 100% rename from crates/voelin-core/src/ts_session/entities.rs rename to crates/voelin-core/src/ts/ts_session/entities.rs diff --git a/crates/voelin-core/src/ts_session/ids.rs b/crates/voelin-core/src/ts/ts_session/ids.rs similarity index 100% rename from crates/voelin-core/src/ts_session/ids.rs rename to crates/voelin-core/src/ts/ts_session/ids.rs diff --git a/crates/voelin-core/src/ts_session/live_tests.rs b/crates/voelin-core/src/ts/ts_session/live_tests.rs similarity index 100% rename from crates/voelin-core/src/ts_session/live_tests.rs rename to crates/voelin-core/src/ts/ts_session/live_tests.rs diff --git a/crates/voelin-core/src/ts_session/media.rs b/crates/voelin-core/src/ts/ts_session/media.rs similarity index 100% rename from crates/voelin-core/src/ts_session/media.rs rename to crates/voelin-core/src/ts/ts_session/media.rs diff --git a/crates/voelin-core/src/ts_session/mod.rs b/crates/voelin-core/src/ts/ts_session/mod.rs similarity index 99% rename from crates/voelin-core/src/ts_session/mod.rs rename to crates/voelin-core/src/ts/ts_session/mod.rs index 994b9c9..34ab9b4 100644 --- a/crates/voelin-core/src/ts_session/mod.rs +++ b/crates/voelin-core/src/ts/ts_session/mod.rs @@ -43,11 +43,12 @@ use voelin_proto::link::{ use voelin_proto::v1::{self, response::Result as Answer}; use self::driver::{Cmd, Config, Driver, Parts, rejected}; +use crate::BackendInfo; use crate::link::{ Backends, BoxDuplex, ConnectOptions, LinkCmd, LinkCtx, LinkEvent, LocalConnected, LocalConnector, LocalCtx, ServerLink, StreamPort, }; -use crate::{BackendInfo, TsLink}; +use crate::ts::TsLink; /// The `Credential::Foreign` kind of a stored TeamSpeak identity. const IDENTITY_KIND: &str = "teamspeak"; @@ -756,7 +757,7 @@ mod tests { options.channel_password = Some("p w+%".into()); options.token = Some("tokenvalue".into()); options.identity = Some(tsclientlib::Identity::create()); - options.client_version = Some(crate::versions::native_version().unwrap()); + options.client_version = Some(crate::ts::versions::native_version().unwrap()); options.audio = false; let sent = params(&options); assert_eq!(sent.hello.password, "s3cret pass&word"); diff --git a/crates/voelin-core/src/versions.rs b/crates/voelin-core/src/ts/versions.rs similarity index 98% rename from crates/voelin-core/src/versions.rs rename to crates/voelin-core/src/ts/versions.rs index 76c11b0..98f2be4 100644 --- a/crates/voelin-core/src/versions.rs +++ b/crates/voelin-core/src/ts/versions.rs @@ -8,7 +8,7 @@ use anyhow::{Context, Result, bail}; use base64::prelude::*; use tsclientlib::Version; -const VERSIONS_CSV: &str = include_str!("../../proto/tsproto-structs/declarations/Versions.csv"); +const VERSIONS_CSV: &str = include_str!("../../../proto/tsproto-structs/declarations/Versions.csv"); /// The signed generic version of every platform, tsclientlib's default. const GENERIC_VERSION: &str = "3.?.? [Build: 5680278000]"; diff --git a/crates/voelin-core/src/voice.rs b/crates/voelin-core/src/ts/voice.rs similarity index 99% rename from crates/voelin-core/src/voice.rs rename to crates/voelin-core/src/ts/voice.rs index 180df63..b6b7055 100644 --- a/crates/voelin-core/src/voice.rs +++ b/crates/voelin-core/src/ts/voice.rs @@ -36,7 +36,7 @@ use voelin_audio::{EncodedVoice, TalkerId, VoiceCodec, VoicePacket}; use voelin_model::{Capabilities, ChannelId, ChatMessage, ChatTarget, ServerFlavor}; use voelin_stream::{ClientState, Request, StreamNotification}; -use crate::book::presence_from_book; +use super::book::presence_from_book; 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}; @@ -296,12 +296,12 @@ async fn run_inner( ) -> anyhow::Result<()> { let version = match &options.client_version { Some(version) => version.clone(), - None => crate::versions::native_version()?, + None => super::versions::native_version()?, }; let mut builder = Connection::build(options.address.clone()) .name(options.nickname.clone()) .version(version) - .metadata(crate::versions::client_metadata()); + .metadata(super::versions::client_metadata()); if let Some(identity) = &options.identity { builder = builder.identity(identity.clone()); } diff --git a/crates/voelin-ui/src/app.rs b/crates/voelin-ui/src/app.rs index 23c3ac9..70de12b 100644 --- a/crates/voelin-ui/src/app.rs +++ b/crates/voelin-ui/src/app.rs @@ -769,7 +769,7 @@ pub fn run(options: RunOptions) -> Result<()> { // with the sample data of VOELIN_DEMO_UI); the client's default // identity becomes ours while we have none the user chose. let imported = if prefs.get(&IDENTITY_IMPORT) && !switches.demo_ui { - voelin_core::identity::import_new(&store, &voelin_core::identity::discover()) + voelin_core::ts::identity::import_new(&store, &voelin_core::ts::identity::discover()) .unwrap_or_else(|e| { warn!(%e, "could not import TeamSpeak identities"); Default::default() diff --git a/crates/voelin-ui/src/identities.rs b/crates/voelin-ui/src/identities.rs index d08eef8..c626e74 100644 --- a/crates/voelin-ui/src/identities.rs +++ b/crates/voelin-ui/src/identities.rs @@ -1,7 +1,7 @@ //! The identity servers see us as: the store's default (schema 4, //! `Store::default_identity`), chosen under Settings → Profiles, and the //! import of the official clients' identities on start -//! (`voelin_core::identity::import_new`, app.rs). The rest of the Profiles +//! (`voelin_core::ts::identity::import_new`, app.rs). The rest of the Profiles //! page is in `settings_pages.rs`. use tracing::warn; diff --git a/crates/voelin-ui/src/servers.rs b/crates/voelin-ui/src/servers.rs index d433c47..87d62ca 100644 --- a/crates/voelin-ui/src/servers.rs +++ b/crates/voelin-ui/src/servers.rs @@ -5,7 +5,7 @@ use std::time::Instant; use slint::ComponentHandle; use tracing::{debug, info, warn}; -use voelin_core::identity::LaunchImport; +use voelin_core::ts::identity::LaunchImport; use voelin_core::{Command, JoinFailure, ObserveState, Source, VoiceOptions, VoiceState}; use voelin_model::ChannelId; use voelin_store::{Bookmark, QueryTransport}; @@ -18,7 +18,7 @@ use crate::vm::servers::{AfterConnect, JoinStep}; pub(crate) const CREATED_IDENTITY: &str = "Default"; /// What to tell the user about the identities imported from the official -/// clients at start ([`voelin_core::identity::import_new`]), if anything. +/// clients at start ([`voelin_core::ts::identity::import_new`]), if anything. pub(crate) fn imported_status(report: &LaunchImport) -> Option { let n = report.added.len(); let names = report.added.iter().map(|f| f.nickname.as_str()).collect::>().join(", "); @@ -122,7 +122,7 @@ impl App { } let mut options = VoiceOptions::new(&b.address, &b.nickname); if let Some(spec) = &b.client_version { - match voelin_core::versions::resolve(spec) { + match voelin_core::ts::versions::resolve(spec) { Ok(version) => options.client_version = version, Err(error) => { self.set_status(format!("Invalid client compatibility version: {error}")); @@ -154,7 +154,7 @@ impl App { .flatten() .map(|identity| identity.name) .filter(|name| { - ![CREATED_IDENTITY, voelin_core::identity::DEFAULT_NICKNAME] + ![CREATED_IDENTITY, voelin_core::ts::identity::DEFAULT_NICKNAME] .contains(&name.as_str()) }) .or_else(|| std::env::var("USER").or_else(|_| std::env::var("USERNAME")).ok()) @@ -750,7 +750,7 @@ impl App { #[cfg(test)] mod tests { - use voelin_core::identity::Found; + use voelin_core::ts::identity::Found; use super::*; use voelin_store::QueryConfig; diff --git a/crates/voelin-ui/src/settings_pages.rs b/crates/voelin-ui/src/settings_pages.rs index 8122c3e..ac0a128 100644 --- a/crates/voelin-ui/src/settings_pages.rs +++ b/crates/voelin-ui/src/settings_pages.rs @@ -55,7 +55,7 @@ pub(crate) struct Improving { pub(crate) struct Pages { pub improving: HashMap, /// Identities found in other clients' files, picked for import. - pub found: Vec<(voelin_core::identity::Found, bool)>, + pub found: Vec<(voelin_core::ts::identity::Found, bool)>, pub settings_filter: String, /// The gateway being administered. pub admin: Option, @@ -1112,7 +1112,7 @@ impl App { .map(|c| if c.is_alphanumeric() || c == '-' { c } else { '_' }) .collect::(); let path = dir.join(format!("{file}.ini")); - match voelin_core::identity::write_export(&path, &entry.name, &identity) { + match voelin_core::ts::identity::write_export(&path, &entry.name, &identity) { Ok(()) => self.set_identity_status(format!( "Exported to {} (it holds the private key: keep it safe).", path.display() @@ -1160,7 +1160,7 @@ impl App { .name("identity-level".into()) .spawn(move || { let better = - voelin_core::identity::improve_level(&identity, target, &cancel, |level| { + voelin_core::ts::identity::improve_level(&identity, target, &cancel, |level| { later(move |app| { if let Some(i) = app.pages.improving.get_mut(&id) { i.reached = i.reached.max(level); @@ -1197,8 +1197,8 @@ impl App { pub(crate) fn find_identities(&mut self) { let mut found = Vec::new(); let mut errors = Vec::new(); - for path in voelin_core::identity::discover() { - match voelin_core::identity::read(&path) { + for path in voelin_core::ts::identity::discover() { + match voelin_core::ts::identity::read(&path) { Ok(list) => found.extend(list), Err(e) => errors.push(e.to_string()), } @@ -1231,11 +1231,11 @@ impl App { pub(crate) fn import_identities(&mut self) { let picked: Vec<_> = self.pages.found.iter().filter(|(_, p)| *p).map(|(f, _)| f.clone()).collect(); - match voelin_core::identity::import(&self.store, &picked) { + match voelin_core::ts::identity::import(&self.store, &picked) { Ok(results) => { let added = results .iter() - .filter(|r| matches!(r, voelin_core::identity::Imported::Added(_))) + .filter(|r| matches!(r, voelin_core::ts::identity::Imported::Added(_))) .count(); self.set_identity_status(format!("{added} identities imported.")); } diff --git a/docs/audio.md b/docs/audio.md index 99c1b5d..f34f0ef 100644 --- a/docs/audio.md +++ b/docs/audio.md @@ -27,7 +27,7 @@ crosses its boundary are the plain types of `voelin_audio::packet`: The transport adapter converts between these and its wire format; for the TeamSpeak connection that is `out_audio` and `voice_packet` in -`voelin-core/src/voice.rs`, the only place that builds TeamSpeak audio packets +`voelin-core/src/ts/voice.rs`, the only place that builds TeamSpeak audio packets from `EncodedVoice` or reads them into `VoicePacket`s (codecs other than Opus are dropped there, as the jitter buffer never played them). The audio thread, the session and the mixer see only the types above, and so does the link's diff --git a/docs/identity.md b/docs/identity.md index bba53c9..468fce9 100644 --- a/docs/identity.md +++ b/docs/identity.md @@ -162,7 +162,7 @@ installs keep `settings.db` next to the executable; point `--from` at it. ## What Voelin does -`voelin_core::identity` reads and writes these forms; `voelinctl` drives it: +`voelin_core::ts::identity` reads and writes these forms; `voelinctl` drives it: ``` voelinctl identity import --auto [--dry-run] [--store ] @@ -175,7 +175,7 @@ voelinctl identity export [--store ] `/voelin/client.db`, so the CLI and the app share identities. **On every start** the app does the same as `import --auto` -(`voelin_core::identity::import_new`): identities found in the default +(`voelin_core::ts::identity::import_new`): identities found in the default locations that the client database does not have yet are added, the files are only read. The user should appear as on the official client, so the identity the official client uses by default (field 5 of its payload, below; diff --git a/tools/voelinctl/src/identity.rs b/tools/voelinctl/src/identity.rs index 366739e..1ba1fff 100644 --- a/tools/voelinctl/src/identity.rs +++ b/tools/voelinctl/src/identity.rs @@ -1,12 +1,12 @@ //! Load, create and store client identities as JSON files, and move them in -//! and out of the client database (`voelin_core::identity`). +//! and out of the client database (`voelin_core::ts::identity`). use std::fs; use std::path::{Path, PathBuf}; use anyhow::{Context, Result}; use tsclientlib::Identity; -use voelin_core::identity::{self as ident, Found, Imported}; +use voelin_core::ts::identity::{self as ident, Found, Imported}; use voelin_store::Store; pub fn default_path() -> PathBuf { diff --git a/tools/voelinctl/src/versions.rs b/tools/voelinctl/src/versions.rs index 8353b24..c76d3c9 100644 --- a/tools/voelinctl/src/versions.rs +++ b/tools/voelinctl/src/versions.rs @@ -1,3 +1,3 @@ //! Shared signed client versions and CLI argument resolution. -pub use voelin_core::versions::{client_metadata, known_versions, native_version, resolve}; +pub use voelin_core::ts::versions::{client_metadata, known_versions, native_version, resolve};