Take the gateway's identity as a blob and the query login as the engine's own type
Command::ObserveGateway.identity is a Box<IdentityBlob> (a TeamSpeak identity as the key store keeps it; voelin_core::ts::identity::to_blob and from_blob convert) and gateway::connect takes the blob too; gateway.rs reads it itself, and one it cannot read ends the observation with its reason instead of reaching the gateway. Command::ObserveQuery.connect is a QueryLogin (transport, address, user, secret, server port and id) that query.rs turns into voelin_query::Connect with the query crate's own line options, which is what the UI always passed. voelin_core re-exports IdentityBlob; voelin-identity is a dependency of voelin-core now, so Cargo.lock gains that edge (the crate was in the graph already, and no third-party package is added: THIRD_PARTY_NOTICES.md is unchanged). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a451f027f3
commit
be84874a09
11 files changed
+322
-39
No files matched your search
Generated
+1
@@ -9518,6 +9518,7 @@ dependencies = [
|
||||
"tsproto-types",
|
||||
"voelin-audio",
|
||||
"voelin-gateway-proto",
|
||||
"voelin-identity",
|
||||
"voelin-media",
|
||||
"voelin-model",
|
||||
"voelin-observer",
|
||||
|
||||
@@ -52,6 +52,9 @@ toml = "1.1.6"
|
||||
tracing = "0.1"
|
||||
voelin-audio = { path = "../voelin-audio", default-features = false }
|
||||
voelin-gateway-proto = { path = "../voelin-gateway-proto", features = ["client"] }
|
||||
# `IdentityBlob`, the identity of the API (a TeamSpeak identity as the key store
|
||||
# keeps it, or a Voelin key).
|
||||
voelin-identity = { workspace = true }
|
||||
voelin-media = { path = "../voelin-media", default-features = false }
|
||||
voelin-model = { workspace = true }
|
||||
voelin-observer = { path = "../voelin-observer" }
|
||||
|
||||
@@ -61,6 +61,7 @@ use voelin_gateway_proto::{
|
||||
HistoryEntry, HistoryQuery, PermRule, PermRuleInfo, PinInfo, RsvpStatus, StreamEntry,
|
||||
StreamSpec, TopicInfo, UserRef,
|
||||
};
|
||||
use voelin_identity::IdentityBlob;
|
||||
use voelin_model::{ChannelId, ChatTarget, Presence};
|
||||
use voelin_store::WriteOutcome;
|
||||
|
||||
@@ -91,13 +92,23 @@ pub(crate) enum GatewayEvent {
|
||||
Disconnected(Option<String>),
|
||||
}
|
||||
|
||||
/// The TeamSpeak identity of a blob, or why a gateway cannot be logged in to
|
||||
/// with it.
|
||||
fn login_identity(blob: &IdentityBlob) -> Result<tsclientlib::Identity, String> {
|
||||
crate::ts::identity::from_blob(blob).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// Connect to a gateway (`ws://…/v1` or `wss://…/v1`) and log in with a
|
||||
/// TeamSpeak identity.
|
||||
/// TeamSpeak identity (a blob of kind `teamspeak`, see
|
||||
/// [`crate::ts::identity::to_blob`]; one that is none is refused as
|
||||
/// [`ErrorCode::AuthFailed`], the way the gateway would).
|
||||
pub async fn connect(
|
||||
url: &str,
|
||||
identity: &tsclientlib::Identity,
|
||||
identity: &IdentityBlob,
|
||||
) -> Result<(GatewayClient, mpsc::UnboundedReceiver<Push>), ClientError> {
|
||||
connect_watched(url, identity, &Progress::default()).await
|
||||
let identity = login_identity(identity)
|
||||
.map_err(|message| ClientError::Gateway { code: ErrorCode::AuthFailed, message })?;
|
||||
connect_watched(url, &identity, &Progress::default()).await
|
||||
}
|
||||
|
||||
/// [`connect`], telling `progress` each step (for the log).
|
||||
@@ -114,10 +125,19 @@ async fn connect_watched(
|
||||
/// logs in.
|
||||
pub(crate) async fn run(
|
||||
mut urls: Vec<String>,
|
||||
identity: tsclientlib::Identity,
|
||||
identity: IdentityBlob,
|
||||
mut commands: mpsc::UnboundedReceiver<GatewayCmd>,
|
||||
events: mpsc::UnboundedSender<GatewayEvent>,
|
||||
) {
|
||||
// An identity that cannot be read will not be tomorrow: like a refused login.
|
||||
let identity = match login_identity(&identity) {
|
||||
Ok(identity) => identity,
|
||||
Err(reason) => {
|
||||
debug!(%reason, "gateway: the identity cannot be read");
|
||||
let _ = events.send(GatewayEvent::Disconnected(Some(reason)));
|
||||
return;
|
||||
}
|
||||
};
|
||||
// A gateway that is away (down, restarting, a network change, a proxy
|
||||
// in front of it that fails) or cannot log us in yet (it does not know
|
||||
// the identity before voice connected once, its server is restarting)
|
||||
@@ -274,20 +294,24 @@ pub(crate) struct Observed {
|
||||
}
|
||||
|
||||
impl Observed {
|
||||
pub(crate) fn new(urls: &[String], identity: &tsclientlib::Identity) -> Self {
|
||||
Self {
|
||||
urls: urls.to_vec(),
|
||||
key: identity.key().to_pub().to_ts(),
|
||||
counter: identity.counter(),
|
||||
nudged: None,
|
||||
pub(crate) fn new(urls: &[String], identity: &IdentityBlob) -> Self {
|
||||
let (key, counter) = Self::of(identity);
|
||||
Self { urls: urls.to_vec(), key, counter, nudged: None }
|
||||
}
|
||||
|
||||
/// The public key and the counter of an identity: an identity that cannot be
|
||||
/// read has neither (and so is the same as any other that cannot).
|
||||
fn of(identity: &IdentityBlob) -> (String, u64) {
|
||||
match login_identity(identity) {
|
||||
Ok(identity) => (identity.key().to_pub().to_ts(), identity.counter()),
|
||||
Err(_) => (String::new(), 0),
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether this is what is observed with.
|
||||
pub(crate) fn same(&self, urls: &[String], identity: &tsclientlib::Identity) -> bool {
|
||||
self.urls == urls
|
||||
&& self.counter == identity.counter()
|
||||
&& self.key == identity.key().to_pub().to_ts()
|
||||
pub(crate) fn same(&self, urls: &[String], identity: &IdentityBlob) -> bool {
|
||||
let (key, counter) = Self::of(identity);
|
||||
self.urls == urls && self.counter == counter && self.key == key
|
||||
}
|
||||
|
||||
/// Whether to try again now ([`GatewayCmd::RetryNow`]): not twice
|
||||
@@ -1182,15 +1206,16 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn the_same_observation_is_nudged_at_most_every_5_s() {
|
||||
let blob = crate::ts::identity::to_blob;
|
||||
let identity = tsclientlib::Identity::create();
|
||||
let urls = vec!["ws://gw.example.test:7788/v1".to_owned()];
|
||||
let mut observed = Observed::new(&urls, &identity);
|
||||
assert!(observed.same(&urls, &identity));
|
||||
assert!(!observed.same(&["wss://gw.example.test/v1".to_owned()], &identity));
|
||||
assert!(!observed.same(&urls, &tsclientlib::Identity::create()));
|
||||
let mut observed = Observed::new(&urls, &blob(&identity));
|
||||
assert!(observed.same(&urls, &blob(&identity)));
|
||||
assert!(!observed.same(&["wss://gw.example.test/v1".to_owned()], &blob(&identity)));
|
||||
assert!(!observed.same(&urls, &blob(&tsclientlib::Identity::create())));
|
||||
// Its security level raised: logged in with the new counter.
|
||||
let raised = tsclientlib::Identity::new(identity.key().clone(), identity.counter() + 1);
|
||||
assert!(!observed.same(&urls, &raised));
|
||||
assert!(!observed.same(&urls, &blob(&raised)));
|
||||
let now = Instant::now();
|
||||
assert!(observed.nudge_at(now));
|
||||
assert!(!observed.nudge_at(now + Duration::from_secs(4)));
|
||||
|
||||
@@ -93,11 +93,13 @@ pub use link::ConnectOptions;
|
||||
pub use link::ConnectOptions as VoiceOptions;
|
||||
pub use link::ServerLink;
|
||||
pub use offline::{OfflineMessage, OfflineMessageInfo};
|
||||
pub use query::{QueryLogin, QueryTransport};
|
||||
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::TsLink;
|
||||
pub use voelin_identity::IdentityBlob;
|
||||
/// 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).
|
||||
@@ -127,12 +129,15 @@ pub enum Command {
|
||||
ObserveGateway {
|
||||
session: SessionId,
|
||||
urls: Vec<String>,
|
||||
identity: Box<tsclientlib::Identity>,
|
||||
/// The TeamSpeak identity to log in with ([`ts::identity::to_blob`]).
|
||||
/// One that is none, or cannot be read, ends the observation with
|
||||
/// its reason.
|
||||
identity: Box<IdentityBlob>,
|
||||
},
|
||||
/// Invisible presence and relay chat with own ServerQuery credentials.
|
||||
ObserveQuery {
|
||||
session: SessionId,
|
||||
connect: Box<voelin_query::Connect>,
|
||||
connect: Box<QueryLogin>,
|
||||
},
|
||||
StopObserving {
|
||||
session: SessionId,
|
||||
|
||||
@@ -1,11 +1,77 @@
|
||||
//! The query source: own ServerQuery credentials, in-process observer and relays.
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use tokio::sync::{broadcast, mpsc};
|
||||
use voelin_model::{ChatMessage, ChatTarget, Presence};
|
||||
use voelin_observer::{
|
||||
Observer, ObserverConfig, ObserverEvent, RelayConfig, RelayEvent, RelayPool,
|
||||
};
|
||||
|
||||
/// How a ServerQuery connection talks to the server.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum QueryTransport {
|
||||
/// The raw text protocol (TeamSpeak 3; port 10011).
|
||||
Raw,
|
||||
/// SSH.
|
||||
Ssh,
|
||||
/// The HTTP query (TeamSpeak 6; a WebQuery API key is the secret).
|
||||
Http,
|
||||
}
|
||||
|
||||
/// The user's own ServerQuery credentials for a server
|
||||
/// ([`Command::ObserveQuery`](crate::Command::ObserveQuery)): what the
|
||||
/// engine logs in with to observe a server invisibly and to relay its
|
||||
/// channels' chat. The connection's own tuning (flood protection, timeouts)
|
||||
/// is the engine's.
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct QueryLogin {
|
||||
pub transport: QueryTransport,
|
||||
/// `host:port` of the query interface.
|
||||
pub address: String,
|
||||
/// The login name (raw and SSH; ignored for HTTP).
|
||||
pub user: String,
|
||||
/// The password (raw and SSH) or API key (HTTP, optional for guest access).
|
||||
pub secret: Option<String>,
|
||||
/// Select the virtual server by its voice port...
|
||||
pub server_port: Option<u16>,
|
||||
/// ...or by id (the first server when neither is given).
|
||||
pub server_id: Option<u32>,
|
||||
}
|
||||
|
||||
impl fmt::Debug for QueryLogin {
|
||||
// The secret is kept out of logs.
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("QueryLogin")
|
||||
.field("transport", &self.transport)
|
||||
.field("address", &self.address)
|
||||
.field("user", &self.user)
|
||||
.field("secret", &self.secret.as_ref().map(|_| "[secret]"))
|
||||
.field("server_port", &self.server_port)
|
||||
.field("server_id", &self.server_id)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl QueryLogin {
|
||||
/// The connection the observer and the relays open.
|
||||
fn connect(&self) -> voelin_query::Connect {
|
||||
voelin_query::Connect {
|
||||
transport: match self.transport {
|
||||
QueryTransport::Raw => voelin_query::Transport::Raw,
|
||||
QueryTransport::Ssh => voelin_query::Transport::Ssh,
|
||||
QueryTransport::Http => voelin_query::Transport::Http,
|
||||
},
|
||||
addr: self.address.clone(),
|
||||
user: self.user.clone(),
|
||||
secret: self.secret.clone(),
|
||||
server_port: self.server_port,
|
||||
server_id: self.server_id,
|
||||
line: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) enum QueryCmd {
|
||||
OpenChat(ChatTarget),
|
||||
CloseChat(ChatTarget),
|
||||
@@ -21,10 +87,11 @@ pub(crate) enum QueryEvent {
|
||||
}
|
||||
|
||||
pub(crate) async fn run(
|
||||
connect: voelin_query::Connect,
|
||||
login: QueryLogin,
|
||||
mut commands: mpsc::UnboundedReceiver<QueryCmd>,
|
||||
events: mpsc::UnboundedSender<QueryEvent>,
|
||||
) {
|
||||
let connect = login.connect();
|
||||
let observer = Observer::spawn(ObserverConfig::new(connect.clone()));
|
||||
let relays = RelayPool::new(RelayConfig::new(connect));
|
||||
let mut observed = observer.subscribe();
|
||||
@@ -88,3 +155,53 @@ pub(crate) async fn run(
|
||||
relays.close_all().await;
|
||||
let _ = events.send(QueryEvent::Disconnected);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_login_is_the_connection_the_query_crate_opens() {
|
||||
let login = QueryLogin {
|
||||
transport: QueryTransport::Ssh,
|
||||
address: "ts.example.com:10022".into(),
|
||||
user: "serveradmin".into(),
|
||||
secret: Some("hunter2".into()),
|
||||
server_port: Some(9987),
|
||||
server_id: Some(3),
|
||||
};
|
||||
let connect = login.connect();
|
||||
assert_eq!(connect.transport, voelin_query::Transport::Ssh);
|
||||
assert_eq!(
|
||||
(connect.addr.as_str(), connect.user.as_str(), connect.secret.as_deref()),
|
||||
("ts.example.com:10022", "serveradmin", Some("hunter2"))
|
||||
);
|
||||
assert_eq!((connect.server_port, connect.server_id), (Some(9987), Some(3)));
|
||||
for (ours, theirs) in [
|
||||
(QueryTransport::Raw, voelin_query::Transport::Raw),
|
||||
(QueryTransport::Http, voelin_query::Transport::Http),
|
||||
] {
|
||||
let connect = QueryLogin { transport: ours, ..login.clone() }.connect();
|
||||
assert_eq!(connect.transport, theirs);
|
||||
}
|
||||
// The line options are the query crate's defaults, as the UI always
|
||||
// gave them.
|
||||
let line = voelin_query::LineOptions::default();
|
||||
assert_eq!(connect.line.rate_limit, line.rate_limit);
|
||||
assert_eq!(connect.line.timeout, line.timeout);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_secret_stays_out_of_the_debug_text() {
|
||||
let login = QueryLogin {
|
||||
transport: QueryTransport::Raw,
|
||||
address: "h:1".into(),
|
||||
user: "u".into(),
|
||||
secret: Some("hunter2".into()),
|
||||
server_port: None,
|
||||
server_id: None,
|
||||
};
|
||||
let text = format!("{login:?}");
|
||||
assert!(!text.contains("hunter2") && text.contains("[secret]"), "{text}");
|
||||
}
|
||||
}
|
||||
@@ -576,7 +576,10 @@ impl Session {
|
||||
// source, the history is kept under the query address.
|
||||
if self.state.server_uid.is_none() {
|
||||
let port = connect.server_port.map(|p| format!("/{p}")).unwrap_or_default();
|
||||
self.learn_server_uid(format!("query:{}{port}", connect.addr), Source::Query);
|
||||
self.learn_server_uid(
|
||||
format!("query:{}{port}", connect.address),
|
||||
Source::Query,
|
||||
);
|
||||
self.open_histories();
|
||||
}
|
||||
let (cmd_tx, cmd_rx) = mpsc::unbounded_channel();
|
||||
|
||||
@@ -32,6 +32,7 @@ use std::{fs, str};
|
||||
use rusqlite::{Connection, OpenFlags, OptionalExtension};
|
||||
use tsclientlib::Identity;
|
||||
use voelin_gateway_proto::UniqueIds;
|
||||
use voelin_identity::IdentityBlob;
|
||||
use voelin_store::{IdentityOrigin, Store};
|
||||
|
||||
/// Name given to an identity whose source kept none.
|
||||
@@ -55,6 +56,9 @@ pub enum IdentityError {
|
||||
NoIdentity { path: String },
|
||||
#[error("client database: {0}")]
|
||||
Store(String),
|
||||
/// An [`IdentityBlob`] that is no TeamSpeak identity ([`from_blob`]).
|
||||
#[error("{0}")]
|
||||
Blob(String),
|
||||
}
|
||||
|
||||
impl IdentityError {
|
||||
@@ -230,6 +234,43 @@ pub fn import_new(store: &Store, paths: &[PathBuf]) -> Result<LaunchImport, Iden
|
||||
Ok(report)
|
||||
}
|
||||
|
||||
/// A TeamSpeak identity as the API takes it
|
||||
/// ([`VoiceOptions::identity`](crate::VoiceOptions::identity),
|
||||
/// [`Command::ObserveGateway`](crate::Command::ObserveGateway)) and the key
|
||||
/// store keeps it: kind `teamspeak`, the unique id TeamSpeak 3 servers know it
|
||||
/// by (also how [`voelin_store`] keys it), its security level, and the JSON
|
||||
/// the store writes.
|
||||
pub fn to_blob(identity: &Identity) -> IdentityBlob {
|
||||
// An identity is a key and two counters: writing it cannot fail. (A blob with
|
||||
// no JSON is refused when it is used, in words.)
|
||||
let json = serde_json::to_string(identity).unwrap_or_default();
|
||||
IdentityBlob::teamspeak(identity.key().to_pub().get_uid(), identity.level(), json)
|
||||
}
|
||||
|
||||
/// The TeamSpeak identity of a blob (the reverse of [`to_blob`]).
|
||||
pub fn from_blob(blob: &IdentityBlob) -> Result<Identity, IdentityError> {
|
||||
if !blob.is_teamspeak() {
|
||||
return Err(IdentityError::Blob(format!(
|
||||
"the identity is of kind {:?}, not a TeamSpeak one",
|
||||
blob.kind
|
||||
)));
|
||||
}
|
||||
serde_json::from_str(&blob.json).map_err(|e| {
|
||||
// Where the JSON is wrong, not what it says: it holds a private key.
|
||||
let what = match e.classify() {
|
||||
serde_json::error::Category::Syntax => "malformed",
|
||||
serde_json::error::Category::Eof => "cut short",
|
||||
serde_json::error::Category::Data => "not an identity",
|
||||
serde_json::error::Category::Io => "unreadable",
|
||||
};
|
||||
IdentityError::Blob(format!(
|
||||
"the TeamSpeak identity cannot be read: {what} at line {}, column {}",
|
||||
e.line(),
|
||||
e.column()
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
/// The TeamSpeak 3 `.ini` export of an identity, which the official client
|
||||
/// and every other tool reads.
|
||||
pub fn export(nickname: &str, identity: &Identity) -> String {
|
||||
@@ -548,6 +589,32 @@ mod tests {
|
||||
Identity::create()
|
||||
}
|
||||
|
||||
/// The blob of an identity is how the key store keeps it, and reads back as
|
||||
/// the same identity; what is no TeamSpeak identity is refused without
|
||||
/// quoting its JSON.
|
||||
#[test]
|
||||
fn an_identity_goes_through_its_blob() {
|
||||
let identity = synthetic();
|
||||
let blob = to_blob(&identity);
|
||||
assert!(blob.is_teamspeak());
|
||||
assert_eq!(blob.uid, identity.key().to_pub().get_uid());
|
||||
assert_eq!(blob.level, identity.level());
|
||||
assert_eq!(blob.json, serde_json::to_string(&identity).unwrap());
|
||||
let back = from_blob(&blob).unwrap();
|
||||
assert_eq!(serde_json::to_value(&back).unwrap(), serde_json::to_value(&identity).unwrap());
|
||||
|
||||
// Another kind.
|
||||
let other = IdentityBlob::new("voelin", "x", 0, blob.json.clone());
|
||||
let error = from_blob(&other).unwrap_err().to_string();
|
||||
assert!(error.contains("\"voelin\""), "{error}");
|
||||
// Not an identity: the text says where, and nothing of what it holds.
|
||||
for json in ["", "{", r#"{"key":"hunter2-key","counter":"hunter2"}"#, "[1]"] {
|
||||
let error = from_blob(&IdentityBlob::teamspeak("x", 0, json)).unwrap_err().to_string();
|
||||
assert!(error.starts_with("the TeamSpeak identity cannot be read"), "{error}");
|
||||
assert!(!error.contains("hunter2"), "{error}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn improve_level_keeps_the_key() {
|
||||
let identity = synthetic();
|
||||
|
||||
@@ -16,6 +16,7 @@ use tokio_tungstenite::tungstenite::handshake::server::{Request, Response};
|
||||
use voelin_core::gateway::{GatewayRequest, GatewayUpdate};
|
||||
use voelin_core::history::MessageSource;
|
||||
use voelin_core::settings::Settings;
|
||||
use voelin_core::ts::identity::to_blob;
|
||||
use voelin_core::{Command, Engine, Event, History, HistoryMessage, HistorySource, ObserveState};
|
||||
use voelin_gateway_proto::{
|
||||
ClientMsg, Envelope, ErrorCode, HistoryEntry, HistoryPage, PinInfo, ReactionCount, ServerMsg,
|
||||
@@ -448,7 +449,7 @@ fn observe(engine: &Engine, session: u64, gw: &FakeGateway) {
|
||||
engine.send(Command::ObserveGateway {
|
||||
session,
|
||||
urls: vec![gw.url.clone()],
|
||||
identity: Box::new(identity),
|
||||
identity: Box::new(to_blob(&identity)),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -742,7 +743,7 @@ async fn an_unreachable_gateway_is_tried_again_quietly() {
|
||||
engine.send(Command::ObserveGateway {
|
||||
session: 3,
|
||||
urls: vec![format!("ws://127.0.0.1:{port}/v1")],
|
||||
identity: Box::new(tsclientlib::Identity::create()),
|
||||
identity: Box::new(to_blob(&tsclientlib::Identity::create())),
|
||||
});
|
||||
// The first attempts fail (the next ones about 1 s, then 2 s later):
|
||||
// still connecting, and the user is told nothing.
|
||||
@@ -819,7 +820,7 @@ async fn the_next_published_gateway_is_used_when_one_fails() {
|
||||
engine.send(Command::ObserveGateway {
|
||||
session: 4,
|
||||
urls: vec![proxy, format!("ws://127.0.0.1:{closed}/v1"), gw.url.clone()],
|
||||
identity: Box::new(tsclientlib::Identity::create()),
|
||||
identity: Box::new(to_blob(&tsclientlib::Identity::create())),
|
||||
});
|
||||
// Within one round: sooner than the shortest wait after a failed round
|
||||
// (1 s, less 30 %).
|
||||
@@ -904,7 +905,7 @@ async fn a_login_the_gateway_cannot_do_yet_is_tried_again() {
|
||||
engine.send(Command::ObserveGateway {
|
||||
session,
|
||||
urls: vec![gw.url.clone()],
|
||||
identity: Box::new(tsclientlib::Identity::create()),
|
||||
identity: Box::new(to_blob(&tsclientlib::Identity::create())),
|
||||
});
|
||||
// After the first wait: about 1 s.
|
||||
quietly_until(&mut rx, session, Duration::from_secs(3), "observing", observing(session))
|
||||
@@ -932,6 +933,45 @@ async fn a_refused_login_ends_observing() {
|
||||
assert_eq!(gw.logins(), 1);
|
||||
}
|
||||
|
||||
/// An identity that cannot be read will not be better tomorrow: like a refused
|
||||
/// login, observing ends, and the gateway is not even asked.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn an_identity_that_cannot_be_read_ends_observing_without_a_login() {
|
||||
let gw = FakeGateway::start().await;
|
||||
let engine = Engine::start();
|
||||
let mut rx = engine.subscribe();
|
||||
let not_an_identity = voelin_core::IdentityBlob::teamspeak("x", 0, "not an identity");
|
||||
engine.send(Command::ObserveGateway {
|
||||
session: 10,
|
||||
urls: vec![gw.url.clone()],
|
||||
identity: Box::new(not_an_identity),
|
||||
});
|
||||
wait(&mut rx, "connecting", |e| match e {
|
||||
Event::State { session: 10, state } if state.observe == ObserveState::Connecting => {
|
||||
Some(())
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
wait(&mut rx, "observing off", |e| match e {
|
||||
Event::State { session: 10, state } if state.observe == ObserveState::Off => Some(()),
|
||||
_ => None,
|
||||
})
|
||||
.await;
|
||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
||||
assert_eq!(gw.logins(), 0);
|
||||
// The public entry refuses it the same way.
|
||||
let error = voelin_core::gateway::connect(
|
||||
&gw.url,
|
||||
&voelin_core::IdentityBlob::new("voelin", "x", 0, "{}"),
|
||||
)
|
||||
.await
|
||||
.err()
|
||||
.expect("a refusal");
|
||||
assert_eq!(error.code(), Some(ErrorCode::AuthFailed), "{error}");
|
||||
assert_eq!(gw.logins(), 0);
|
||||
}
|
||||
|
||||
/// Selecting the server again while its gateway is still connecting does
|
||||
/// not start it over, and ends the wait for the next attempt.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
@@ -944,7 +984,7 @@ async fn asking_again_while_connecting_tries_at_once() {
|
||||
let ask = || Command::ObserveGateway {
|
||||
session: 9,
|
||||
urls: vec![gw.url.clone()],
|
||||
identity: Box::new(identity.clone()),
|
||||
identity: Box::new(to_blob(&identity)),
|
||||
};
|
||||
engine.send(ask());
|
||||
// Three logins fail (waits of about 1 and 2 s); the next wait is about 5 s.
|
||||
|
||||
@@ -5,7 +5,10 @@ use std::time::Duration;
|
||||
|
||||
use tokio::sync::broadcast::Receiver;
|
||||
use tokio::time::{Instant, timeout_at};
|
||||
use voelin_core::{Command, Engine, Event, ObserveState, Source, VoiceOptions, VoiceState};
|
||||
use voelin_core::{
|
||||
Command, Engine, Event, ObserveState, QueryLogin, QueryTransport, Source, VoiceOptions,
|
||||
VoiceState,
|
||||
};
|
||||
use voelin_model::ChatTarget;
|
||||
|
||||
fn live() -> bool {
|
||||
@@ -45,7 +48,7 @@ async fn engine_roundtrip(voice_addr: &str, query: voelin_query::Connect) {
|
||||
.await;
|
||||
|
||||
// Session 2: invisible, through own query credentials.
|
||||
engine.send(Command::ObserveQuery { session: 2, connect: Box::new(query) });
|
||||
engine.send(Command::ObserveQuery { session: 2, connect: Box::new(login(&query)) });
|
||||
let (mut observing, mut sees_voice_client) = (false, false);
|
||||
wait_for(&mut events, "query presence with the voice client", |e| {
|
||||
match e {
|
||||
@@ -93,6 +96,22 @@ async fn engine_roundtrip(voice_addr: &str, query: voelin_query::Connect) {
|
||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
||||
}
|
||||
|
||||
/// The credentials of a query connection, as the engine takes them.
|
||||
fn login(connect: &voelin_query::Connect) -> QueryLogin {
|
||||
QueryLogin {
|
||||
transport: match connect.transport {
|
||||
voelin_query::Transport::Raw => QueryTransport::Raw,
|
||||
voelin_query::Transport::Ssh => QueryTransport::Ssh,
|
||||
voelin_query::Transport::Http => QueryTransport::Http,
|
||||
},
|
||||
address: connect.addr.clone(),
|
||||
user: connect.user.clone(),
|
||||
secret: connect.secret.clone(),
|
||||
server_port: connect.server_port,
|
||||
server_id: connect.server_id,
|
||||
}
|
||||
}
|
||||
|
||||
fn query(transport: voelin_query::Transport, addr: &str) -> voelin_query::Connect {
|
||||
voelin_query::Connect {
|
||||
transport,
|
||||
|
||||
@@ -279,7 +279,9 @@ impl App {
|
||||
self.engine.send(Command::ObserveGateway {
|
||||
session,
|
||||
urls,
|
||||
identity: Box::new(self.identity_for(Some(b.id))),
|
||||
identity: Box::new(voelin_core::ts::identity::to_blob(
|
||||
&self.identity_for(Some(b.id)),
|
||||
)),
|
||||
});
|
||||
}
|
||||
return;
|
||||
@@ -291,25 +293,26 @@ impl App {
|
||||
self.engine.send(Command::ObserveGateway {
|
||||
session,
|
||||
urls,
|
||||
identity: Box::new(self.identity_for(Some(b.id))),
|
||||
identity: Box::new(voelin_core::ts::identity::to_blob(
|
||||
&self.identity_for(Some(b.id)),
|
||||
)),
|
||||
});
|
||||
// Still the one the server publishes?
|
||||
self.discover_gateway(b.id);
|
||||
} else if let Some(q) = &b.query {
|
||||
let secret = self.secrets.get(&b.query_password_key()).ok().flatten();
|
||||
let transport = match q.transport {
|
||||
QueryTransport::Raw => voelin_query::Transport::Raw,
|
||||
QueryTransport::Ssh => voelin_query::Transport::Ssh,
|
||||
QueryTransport::Http => voelin_query::Transport::Http,
|
||||
QueryTransport::Raw => voelin_core::QueryTransport::Raw,
|
||||
QueryTransport::Ssh => voelin_core::QueryTransport::Ssh,
|
||||
QueryTransport::Http => voelin_core::QueryTransport::Http,
|
||||
};
|
||||
let connect = voelin_query::Connect {
|
||||
let connect = voelin_core::QueryLogin {
|
||||
transport,
|
||||
addr: format!("{}:{}", q.host, q.port),
|
||||
address: format!("{}:{}", q.host, q.port),
|
||||
user: q.user.clone(),
|
||||
secret,
|
||||
server_port: q.server_port,
|
||||
server_id: None,
|
||||
line: Default::default(),
|
||||
};
|
||||
self.engine.send(Command::ObserveQuery { session, connect: Box::new(connect) });
|
||||
} else {
|
||||
|
||||
@@ -100,7 +100,7 @@ pub async fn run(args: GatewayArgs) -> Result<()> {
|
||||
engine.send(Command::ObserveGateway {
|
||||
session: SESSION,
|
||||
urls: vec![args.url.clone()],
|
||||
identity: Box::new(identity.clone()),
|
||||
identity: Box::new(voelin_core::ts::identity::to_blob(&identity)),
|
||||
});
|
||||
if let Some(addr) = &args.voice {
|
||||
let mut options = VoiceOptions::new(addr, &args.nick);
|
||||
|
||||
Reference in new issue
Block a user