Skip to content

Commit 1f88013

Browse files
authored
feat(sync): short-hex Debug for peer from (#98)
## Description Remote peer identity in `Debug` for `InsertOrigin::Sync` and `Event::RemoteInsert` was printed as a `[u8; 32]` integer list, unlike other logs that use compact hex. This switches those fields to `derive_more::Debug` with `hex::encode` of the **first 5 bytes**, matching `iroh_base::PublicKey::fmt_short()` / `EndpointId` logging style. Also updates the `PeerIdBytes` doc line to refer to **`EndpointId`**, and refreshes the TODO to suggest `iroh::EndpointId` (re-exported from `iroh-base`) instead of outdated `PeerId` / `iroh-net` wording. ## Breaking Changes None. ## Notes & open questions Using `iroh::EndpointId` instead of `PeerIdBytes` (`[u8; 32]`) would be a breaking public API change but give us stronger typing, validation and built-in helpers (`fmt_short`, etc.). Happy to open a follow-up PR with that. ## Change checklist - [x] Self-review. - [x] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [ ] Tests if relevant. - [x] All breaking changes documented.
1 parent 722c200 commit 1f88013

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/sync.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ use crate::{
3434
/// Can be serialized to bytes with [serde] to transfer between peers.
3535
pub type ProtocolMessage = crate::ranger::Message<SignedEntry>;
3636

37-
/// Byte representation of a `PeerId` from `iroh-net`.
38-
// TODO: PeerId is in iroh-net which iroh-docs doesn't depend on. Add iroh-base crate with `PeerId`.
37+
/// Byte representation of an iroh `EndpointId`.
38+
// TODO: Consider `iroh::EndpointId` instead of raw bytes (`iroh` re-exports it from `iroh-base`).
3939
pub type PeerIdBytes = [u8; 32];
4040

4141
/// Max time in the future from our wall clock time that we accept entries for.
@@ -47,7 +47,7 @@ pub type ContentStatusCallback =
4747
Arc<dyn Fn(Hash) -> n0_future::boxed::BoxFuture<ContentStatus> + Send + Sync + 'static>;
4848

4949
/// Event emitted by sync when entries are added.
50-
#[derive(Debug, Clone)]
50+
#[derive(derive_more::Debug, Clone)]
5151
pub enum Event {
5252
/// A local entry has been added.
5353
LocalInsert {
@@ -63,6 +63,8 @@ pub enum Event {
6363
/// Inserted entry.
6464
entry: SignedEntry,
6565
/// Peer that provided the inserted entry.
66+
/// Debug matches [`iroh::PublicKey::fmt_short`] (first 5 bytes, lower hex).
67+
#[debug("{}", hex::encode(&from[..5]))]
6668
from: PeerIdBytes,
6769
/// Whether download policies require the content to be downloaded.
6870
should_download: bool,
@@ -72,13 +74,15 @@ pub enum Event {
7274
}
7375

7476
/// Whether an entry was inserted locally or by a remote peer.
75-
#[derive(Debug, Clone)]
77+
#[derive(derive_more::Debug, Clone)]
7678
pub enum InsertOrigin {
7779
/// The entry was inserted locally.
7880
Local,
7981
/// The entry was received from the remote node identified by [`PeerIdBytes`].
8082
Sync {
8183
/// The peer from which we received this entry.
84+
/// Debug matches [`iroh::PublicKey::fmt_short`] (first 5 bytes, lower hex).
85+
#[debug("{}", hex::encode(&from[..5]))]
8286
from: PeerIdBytes,
8387
/// Whether the peer claims to have the content blob for this entry.
8488
remote_content_status: ContentStatus,

0 commit comments

Comments
 (0)