Debug
This commit is contained in:
parent
aefcae977f
commit
2c5b3258b3
3 changed files with 33 additions and 4 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1036,6 +1036,7 @@ dependencies = [
|
||||||
name = "mtp-host"
|
name = "mtp-host"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"log",
|
||||||
"mtp-codec",
|
"mtp-codec",
|
||||||
"mtp-common",
|
"mtp-common",
|
||||||
"mtp-crypto",
|
"mtp-crypto",
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ mtp-transport = { path = "../transport", features = ["host"] }
|
||||||
mtp-crypto = { path = "../crypto", optional = true }
|
mtp-crypto = { path = "../crypto", optional = true }
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
|
log = "0.4"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
crypto = ["dep:mtp-crypto", "mtp-codec/crypto"]
|
crypto = ["dep:mtp-crypto", "mtp-codec/crypto"]
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,13 @@ impl MTPHost {
|
||||||
* incompatible.
|
* incompatible.
|
||||||
*/
|
*/
|
||||||
pub async fn accept(&mut self) -> Option<MTPConnection> {
|
pub async fn accept(&mut self) -> Option<MTPConnection> {
|
||||||
let (sender, receiver) = self.transport.next().await?;
|
let (sender, receiver) = match self.transport.next().await {
|
||||||
|
Some(pair) => pair,
|
||||||
|
None => {
|
||||||
|
log::warn!("accept: transport.next() returned None (listener closed)");
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(feature = "crypto")]
|
#[cfg(feature = "crypto")]
|
||||||
if self.config.require_authentication {
|
if self.config.require_authentication {
|
||||||
|
|
@ -92,7 +98,13 @@ impl MTPHost {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the first message (always encoded with reserved types).
|
// Read the first message (always encoded with reserved types).
|
||||||
let first_msg = receiver.receive().await.ok()?;
|
let first_msg = match receiver.receive().await {
|
||||||
|
Ok(m) => m,
|
||||||
|
Err(e) => {
|
||||||
|
log::warn!("accept: receive failed: {e:?}");
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Extract the client's version from the first message.
|
* Extract the client's version from the first message.
|
||||||
|
|
@ -101,9 +113,24 @@ impl MTPHost {
|
||||||
*
|
*
|
||||||
* Then negotiate the version for single-version clients
|
* Then negotiate the version for single-version clients
|
||||||
*/
|
*/
|
||||||
let client_version = extract_version(&first_msg)?;
|
let client_version = match extract_version(&first_msg) {
|
||||||
|
Some(v) => v,
|
||||||
|
None => {
|
||||||
|
log::warn!(
|
||||||
|
"accept: extract_version failed on msg type {:?}",
|
||||||
|
first_msg.get_type()
|
||||||
|
);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let negotiated = self.registry.negotiate(&[client_version])?;
|
let negotiated = match self.registry.negotiate(&[client_version.clone()]) {
|
||||||
|
Some(v) => v,
|
||||||
|
None => {
|
||||||
|
log::warn!("accept: negotiate failed for client version {client_version:?}");
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let codec = VersionedCodec::new(self.registry.clone());
|
let codec = VersionedCodec::new(self.registry.clone());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue