Skip to content

Commit 6498e7b

Browse files
authored
fix: adjust some logging and disconnect with peer when we don't have them in our local map and something is wrong (#739)
1 parent 6c11a03 commit 6498e7b

2 files changed

Lines changed: 30 additions & 10 deletions

File tree

recon/src/libp2p.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use ceramic_core::{EventId, PeerKey};
2424
use futures::{future::BoxFuture, FutureExt};
2525
use libp2p::{
2626
core::ConnectedPoint,
27-
swarm::{ConnectionId, NetworkBehaviour, NotifyHandler, ToSwarm},
27+
swarm::{CloseConnection, ConnectionId, NetworkBehaviour, NotifyHandler, ToSwarm},
2828
};
2929
use libp2p_identity::PeerId;
3030
use std::{
@@ -215,7 +215,7 @@ where
215215
fn on_connection_handler_event(
216216
&mut self,
217217
peer_id: libp2p_identity::PeerId,
218-
_connection_id: libp2p::swarm::ConnectionId,
218+
connection_id: libp2p::swarm::ConnectionId,
219219
event: libp2p::swarm::THandlerOutEvent<Self>,
220220
) {
221221
let ev = match event {
@@ -229,8 +229,11 @@ where
229229
status: info.status,
230230
})))
231231
} else {
232-
tracing::warn!(%peer_id, "peer not found in peers map when started synchronizing?");
233-
None
232+
tracing::warn!(%peer_id, ?connection_id, "peer not found in peers map when started synchronizing? closing connection");
233+
Some(ToSwarm::CloseConnection {
234+
peer_id,
235+
connection: CloseConnection::One(connection_id),
236+
})
234237
}
235238
}
236239

@@ -244,8 +247,11 @@ where
244247
status: info.status,
245248
})))
246249
} else {
247-
tracing::warn!(%peer_id, "peer not found in peers map when stopped synchronizing?");
248-
None
250+
tracing::warn!(%peer_id, ?connection_id, "peer not found in peers map when stopped synchronizing? closing connection");
251+
Some(ToSwarm::CloseConnection {
252+
peer_id,
253+
connection: CloseConnection::One(connection_id),
254+
})
249255
}
250256
}
251257

@@ -276,8 +282,11 @@ where
276282
status: info.status,
277283
})))
278284
} else {
279-
tracing::warn!(%peer_id, "peer not found in peers map when succeeded synchronizing?");
280-
None
285+
tracing::warn!(%peer_id, ?connection_id, "peer not found in peers map when succeeded synchronizing? closing connection");
286+
Some(ToSwarm::CloseConnection {
287+
peer_id,
288+
connection: CloseConnection::One(connection_id),
289+
})
281290
}
282291
}
283292

@@ -307,8 +316,11 @@ where
307316
status: info.status,
308317
})))
309318
} else {
310-
tracing::warn!(%peer_id, "peer not found in peers map when failed synchronizing?");
311-
None
319+
tracing::warn!(%peer_id, ?connection_id, "peer not found in peers map when failed synchronizing? closing connectoin");
320+
Some(ToSwarm::CloseConnection {
321+
peer_id,
322+
connection: CloseConnection::One(connection_id),
323+
})
312324
}
313325
}
314326
};

validation/src/verifier/event_verifier.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use ceramic_core::Jwk;
33
use ceramic_event::unvalidated::signed::{self, cacao::Capability};
44
use ipld_core::ipld::Ipld;
55
use ssi::{did_resolve::ResolutionInputMetadata, jws::Header};
6+
use tracing::debug;
67

78
use super::{
89
cacao_verifier::Verifier as _,
@@ -146,6 +147,13 @@ async fn resolve_did_verify_delegated(issuer: &str, delegated: &str, time: &AtTi
146147
.as_ref()
147148
.is_none_or(|c| !c.any(|c| c == delegated))
148149
{
150+
debug!(
151+
?controller_did,
152+
?issuer,
153+
?delegated,
154+
?time,
155+
"Failed to validate DID delegation"
156+
);
149157
bail!("invalid_jws: '{delegated}' not in controllers list for issuer: '{issuer}'")
150158
}
151159
Ok(())

0 commit comments

Comments
 (0)