Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 56 additions & 3 deletions src/protocol/transport_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,11 @@ impl TransportService {
tracing::debug!(
target: LOG_TARGET,
?peer,
protocol = %self.protocol,
?endpoint,
?connection_id,
"connection established",
protocol = %self.protocol,
current_state = ?self.connections.get(&peer),
"on connection established",
);

match self.connections.get_mut(&peer) {
Expand All @@ -353,19 +354,38 @@ impl TransportService {
?peer,
?connection_id,
?endpoint,
protocol = %self.protocol,
"ignoring third connection",
);
None
}
None => {
self.keep_alive_tracker.on_connection_established(peer, connection_id);

tracing::trace!(
target: LOG_TARGET,
?peer,
?endpoint,
?connection_id,
protocol = %self.protocol,
"secondary connection established",
);

context.secondary = Some(handle);

None
}
},
None => {
tracing::trace!(
target: LOG_TARGET,
?peer,
?endpoint,
?connection_id,
protocol = %self.protocol,
"primary connection established",
);

self.connections.insert(peer, ConnectionContext::new(handle));

self.keep_alive_tracker.on_connection_established(peer, connection_id);
Expand All @@ -381,13 +401,23 @@ impl TransportService {
peer: PeerId,
connection_id: ConnectionId,
) -> Option<TransportEvent> {
tracing::debug!(
target: LOG_TARGET,
?peer,
?connection_id,
protocol = %self.protocol,
current_state = ?self.connections.get(&peer),
"on connection closed",
);

self.keep_alive_tracker.on_connection_closed(peer, connection_id);

let Some(context) = self.connections.get_mut(&peer) else {
tracing::warn!(
target: LOG_TARGET,
?peer,
?connection_id,
protocol = %self.protocol,
"connection closed to a non-existent peer",
);

Expand All @@ -398,7 +428,13 @@ impl TransportService {
// if the primary connection was closed, check if there exist a secondary connection
// and if it does, convert the secondary connection a primary connection
if context.primary.connection_id() == &connection_id {
tracing::trace!(target: LOG_TARGET, ?peer, ?connection_id, "primary connection closed");
tracing::trace!(
target: LOG_TARGET,
?peer,
?connection_id,
protocol = %self.protocol,
"primary connection closed"
);

match context.secondary.take() {
None => {
Expand All @@ -410,6 +446,7 @@ impl TransportService {
target: LOG_TARGET,
?peer,
?connection_id,
protocol = %self.protocol,
"switch to secondary connection",
);

Expand All @@ -425,6 +462,7 @@ impl TransportService {
target: LOG_TARGET,
?peer,
?connection_id,
protocol = %self.protocol,
"secondary connection closed",
);

Expand All @@ -436,6 +474,7 @@ impl TransportService {
?peer,
?connection_id,
?connection_state,
protocol = %self.protocol,
"connection closed but it doesn't exist",
);

Expand All @@ -448,6 +487,13 @@ impl TransportService {
///
/// Call fails if `Litep2p` doesn't have a known address for the peer.
pub fn dial(&mut self, peer: &PeerId) -> Result<(), ImmediateDialError> {
tracing::trace!(
target: LOG_TARGET,
?peer,
protocol = %self.protocol,
"Dial peer requested",
);

self.transport_handle.dial(peer)
}

Expand All @@ -460,6 +506,13 @@ impl TransportService {
/// since `Litep2p` internally keeps track of all peer addresses it has learned through user
/// calling this function, Kademlia peer discoveries and `Identify` responses.
pub fn dial_address(&mut self, address: Multiaddr) -> Result<(), ImmediateDialError> {
tracing::trace!(
target: LOG_TARGET,
?address,
protocol = %self.protocol,
"Dial address requested",
);

self.transport_handle.dial_address(address)
}

Expand Down
Loading