Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/lexnv/stable-connections' into l…
Browse files Browse the repository at this point in the history
…exnv/holistic-litep2p-test
  • Loading branch information
lexnv committed Oct 3, 2024
2 parents c5cf9e7 + e32b925 commit c3491ff
Show file tree
Hide file tree
Showing 9 changed files with 410 additions and 31 deletions.
8 changes: 7 additions & 1 deletion src/protocol/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ impl ConnectionHandle {
protocol: protocol.clone(),
fallback_names,
substream_id,
connection_id: self.connection_id.clone(),
permit,
})
.map_err(|error| match error {
Expand All @@ -141,10 +142,15 @@ impl ConnectionHandle {
TrySendError::Closed(_) => Error::ConnectionClosed,
})
}

/// Check if the connection is active.
pub fn is_active(&self) -> bool {
matches!(self.connection, ConnectionType::Active(_))
}
}

/// Type which allows the connection to be kept open.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Permit {
/// Active connection.
_connection: Sender<ProtocolCommand>,
Expand Down
2 changes: 2 additions & 0 deletions src/protocol/notification/tests/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ async fn remote_opens_multiple_inbound_substreams() {
SubstreamId::from(0usize),
Box::new(DummySubstream::new()),
),
connection_id: ConnectionId::from(0usize),
})
.await
.unwrap();
Expand Down Expand Up @@ -511,6 +512,7 @@ async fn remote_opens_multiple_inbound_substreams() {
SubstreamId::from(0usize),
Box::new(substream),
),
connection_id: ConnectionId::from(0usize),
})
.await
.unwrap();
Expand Down
10 changes: 9 additions & 1 deletion src/protocol/protocol_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ pub enum InnerTransportEvent {
/// distinguish between different outbound substreams.
direction: Direction,

/// Connection ID.
connection_id: ConnectionId,

/// Substream.
substream: Substream,
},
Expand Down Expand Up @@ -149,6 +152,7 @@ impl From<InnerTransportEvent> for TransportEvent {
fallback,
direction,
substream,
..
} => TransportEvent::SubstreamOpened {
peer,
protocol,
Expand All @@ -164,7 +168,7 @@ impl From<InnerTransportEvent> for TransportEvent {
}

/// Events emitted by the installed protocols to transport.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum ProtocolCommand {
/// Open substream.
OpenSubstream {
Expand Down Expand Up @@ -192,6 +196,9 @@ pub enum ProtocolCommand {
/// and associate incoming substreams with whatever logic it has.
substream_id: SubstreamId,

/// Connection ID.
connection_id: ConnectionId,

/// Connection permit.
///
/// `Permit` allows the connection to be kept open while the permit is held and it is given
Expand Down Expand Up @@ -300,6 +307,7 @@ impl ProtocolSet {
fallback,
direction,
substream,
connection_id: self.connection.connection_id().clone(),
};

protocol_context
Expand Down
Loading

0 comments on commit c3491ff

Please sign in to comment.