fix Windows Direct service reachability
This commit is contained in:
@@ -94,6 +94,24 @@ pub fn new_session_token() -> String {
|
||||
URL_SAFE_NO_PAD.encode(bytes)
|
||||
}
|
||||
|
||||
/// Decode an authenticated Direct discovery datagram. `Some(None)` preserves
|
||||
/// compatibility with older Android builds that did not include a device name.
|
||||
pub fn discovery_device(text: &str, session: &str) -> Option<Option<String>> {
|
||||
let prefix = format!("QFTDISC2:{session}");
|
||||
if text == prefix {
|
||||
return Some(None);
|
||||
}
|
||||
let encoded = text.strip_prefix(&(prefix + ":"))?;
|
||||
let bytes = URL_SAFE_NO_PAD.decode(encoded).ok()?;
|
||||
let name = String::from_utf8(bytes).ok()?;
|
||||
let clean: String = name
|
||||
.chars()
|
||||
.filter(|c| !c.is_control())
|
||||
.take(80)
|
||||
.collect();
|
||||
(!clean.trim().is_empty()).then_some(Some(clean))
|
||||
}
|
||||
|
||||
/// Keep one random AP identity per Windows device so Android can remember the
|
||||
/// user's approval for that exact local-only network. The AP itself is only
|
||||
/// active while QFT receive mode is running; the file-transfer session token is
|
||||
@@ -237,6 +255,18 @@ pub fn local_ipv4_endpoints(port: u16) -> Vec<String> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn discovery_request_reports_android_name_and_accepts_legacy_format() {
|
||||
let session = "abcdefghijklmnopqrstuvwxyz012345";
|
||||
let name = URL_SAFE_NO_PAD.encode("HUAWEI CDY-AN90".as_bytes());
|
||||
assert_eq!(
|
||||
discovery_device(&format!("QFTDISC2:{session}:{name}"), session),
|
||||
Some(Some("HUAWEI CDY-AN90".into()))
|
||||
);
|
||||
assert_eq!(discovery_device(&format!("QFTDISC2:{session}"), session), Some(None));
|
||||
assert_eq!(discovery_device("QFTDISC2:wrong", session), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn download_pairing_uses_dedicated_short_prefix() {
|
||||
let payload = PairingPayload {
|
||||
|
||||
Reference in New Issue
Block a user