This commit is contained in:
parent
cf3cccd3ca
commit
04760fd88d
15 changed files with 136 additions and 20 deletions
|
|
@ -2,6 +2,7 @@
|
|||
use mtp_codec::{CommunicationType, DataType, DataValue};
|
||||
use mtp_codec::{CommunicationValue, Version, registry::VersionedCodec};
|
||||
use mtp_common::CommunicationError;
|
||||
use std::net::SocketAddr;
|
||||
#[cfg(feature = "pipes")]
|
||||
use std::sync::Arc;
|
||||
#[cfg(feature = "pipes")]
|
||||
|
|
@ -63,6 +64,9 @@ pub struct MTPConnection<
|
|||
/// them, so they always use the root path. Alternative hosts can retain
|
||||
/// the CONNECT request path when constructing an MTP connection.
|
||||
pub path: String,
|
||||
/// The address of the peer that established this connection, when exposed
|
||||
/// by the underlying transport.
|
||||
pub remote_addr: Option<SocketAddr>,
|
||||
#[cfg(feature = "pipes")]
|
||||
pub(crate) app_rx: Mutex<mpsc::Receiver<Result<CommunicationValue, CommunicationError>>>,
|
||||
#[cfg(feature = "pipes")]
|
||||
|
|
@ -101,6 +105,26 @@ where
|
|||
receiver: R,
|
||||
path: String,
|
||||
description: Option<String>,
|
||||
) -> Self {
|
||||
Self::from_transport_parts_with_remote_addr(
|
||||
version,
|
||||
codec,
|
||||
sender,
|
||||
receiver,
|
||||
path,
|
||||
description,
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn from_transport_parts_with_remote_addr(
|
||||
version: Version,
|
||||
codec: VersionedCodec,
|
||||
sender: S,
|
||||
receiver: R,
|
||||
path: String,
|
||||
description: Option<String>,
|
||||
remote_addr: Option<SocketAddr>,
|
||||
) -> Self {
|
||||
let policy = Arc::new(Policy::default());
|
||||
let (app_tx, app_rx) = mpsc::channel(policy.receiver_queue_capacity);
|
||||
|
|
@ -123,6 +147,7 @@ where
|
|||
sender,
|
||||
receiver,
|
||||
path,
|
||||
remote_addr,
|
||||
app_rx: Mutex::new(app_rx),
|
||||
pipe_req_rx: Mutex::new(pipe_req_rx),
|
||||
pipe_dispatcher: dispatcher,
|
||||
|
|
@ -147,6 +172,26 @@ impl<S, R, P> MTPConnection<S, R, P> {
|
|||
receiver: R,
|
||||
path: String,
|
||||
description: Option<String>,
|
||||
) -> Self {
|
||||
Self::from_transport_parts_with_remote_addr(
|
||||
version,
|
||||
codec,
|
||||
sender,
|
||||
receiver,
|
||||
path,
|
||||
description,
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn from_transport_parts_with_remote_addr(
|
||||
version: Version,
|
||||
codec: VersionedCodec,
|
||||
sender: S,
|
||||
receiver: R,
|
||||
path: String,
|
||||
description: Option<String>,
|
||||
remote_addr: Option<SocketAddr>,
|
||||
) -> Self {
|
||||
Self {
|
||||
version,
|
||||
|
|
@ -154,6 +199,7 @@ impl<S, R, P> MTPConnection<S, R, P> {
|
|||
sender,
|
||||
receiver,
|
||||
path,
|
||||
remote_addr,
|
||||
description,
|
||||
_pipe_stream: std::marker::PhantomData,
|
||||
_dispatcher_task: tokio::spawn(async {}),
|
||||
|
|
|
|||
|
|
@ -323,6 +323,7 @@ impl HandshakeContext {
|
|||
codec: VersionedCodec,
|
||||
description: Option<String>,
|
||||
) -> MTPConnection {
|
||||
let remote_addr = sender.handle().remote_addr();
|
||||
receiver.set_max_message_size(self.config.policy.max_message_size);
|
||||
#[cfg(feature = "pipes")]
|
||||
{
|
||||
|
|
@ -357,6 +358,7 @@ impl HandshakeContext {
|
|||
sender,
|
||||
receiver,
|
||||
path: "/".to_string(),
|
||||
remote_addr,
|
||||
app_rx: tokio::sync::Mutex::new(app_rx),
|
||||
pipe_req_rx: tokio::sync::Mutex::new(pipe_req_rx),
|
||||
pipe_dispatcher: dispatcher,
|
||||
|
|
@ -379,6 +381,7 @@ impl HandshakeContext {
|
|||
sender,
|
||||
receiver,
|
||||
path: "/".to_string(),
|
||||
remote_addr,
|
||||
_pipe_stream: std::marker::PhantomData,
|
||||
description,
|
||||
_dispatcher_task: task,
|
||||
|
|
@ -399,6 +402,7 @@ impl HandshakeContext {
|
|||
client_id: u64,
|
||||
client_public_key: Option<mtp_crypto::PublicKeyBundle>,
|
||||
) -> MTPConnection {
|
||||
let remote_addr = sender.handle().remote_addr();
|
||||
receiver.set_max_message_size(self.config.policy.max_message_size);
|
||||
#[cfg(feature = "pipes")]
|
||||
{
|
||||
|
|
@ -433,6 +437,7 @@ impl HandshakeContext {
|
|||
sender,
|
||||
receiver,
|
||||
path: "/".to_string(),
|
||||
remote_addr,
|
||||
app_rx: tokio::sync::Mutex::new(app_rx),
|
||||
pipe_req_rx: tokio::sync::Mutex::new(pipe_req_rx),
|
||||
pipe_dispatcher: dispatcher,
|
||||
|
|
@ -458,6 +463,7 @@ impl HandshakeContext {
|
|||
sender,
|
||||
receiver,
|
||||
path: "/".to_string(),
|
||||
remote_addr,
|
||||
_pipe_stream: std::marker::PhantomData,
|
||||
description,
|
||||
_dispatcher_task: task,
|
||||
|
|
|
|||
Loading…
Reference in a new issue