Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const GIT_COMMIT: &str = env!("GIT_COMMIT");
#[command(arg_required_else_help = true)]
struct Cli {
/// Color output: "auto" (detect TTY), "always", or "never"
#[arg(long, global = true, default_value = "auto")]
#[arg(long, global = true, env = "IM_COLOR", default_value = "auto")]
color: String,

/// Path to admin socket
Expand Down Expand Up @@ -66,6 +66,10 @@ enum Commands {
#[arg(short, long)]
watch: bool,
},

/// Print the local node's full IMID
Imid,

Debug {
#[command(subcommand)]
command: DebugCommands,
Expand Down Expand Up @@ -164,6 +168,12 @@ async fn cmd_debug_dump(color: String, toml: bool, admin_socket: Option<PathBuf>
Ok(())
}

async fn cmd_imid(admin_socket: Option<PathBuf>) -> Result<()> {
let dump = AdminClient::new(admin_socket).debug_dump().await?;
println!("{}", dump.derivation.my_imid);
Ok(())
}

async fn cmd_status(color: String, watch: bool, admin_socket: Option<PathBuf>) -> Result<()> {
configure_colors(&color);
cmd_status::run(admin_socket, watch).await
Expand Down Expand Up @@ -200,6 +210,7 @@ pub async fn run() -> Result<()> {
Some(Commands::Init(args)) => cmd_init(args, cli.admin_socket).await?,
Some(Commands::Join(args)) => cmd_join(args, cli.admin_socket).await?,
Some(Commands::Status { watch }) => cmd_status(cli.color, watch, cli.admin_socket).await?,
Some(Commands::Imid) => cmd_imid(cli.admin_socket).await?,
Some(Commands::Adhoc { command }) => match command {
AdhocCommands::Init(args) => cmd_init(args, cli.admin_socket).await?,
AdhocCommands::Join(args) => cmd_join(args, cli.admin_socket).await?,
Expand Down
14 changes: 11 additions & 3 deletions src/gossip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,20 @@ pub(crate) async fn gossip_loop(
r = change_sig.changed() => r.assert(),
_ = interval.tick() => {}
}
let message_generation = state.message_generation().await;
debug!(message_generation, "gossip loop");

// Acknowledge the change signal up front, before reading the
// derivation and message generation below. A local signed-state change
// (the manager signing intent into endorsements) updates the trust
// derivation and bumps the message generation as two separate steps
// observed by separate tasks. Marking the signal seen first means any
// notification that lands while we read those values leaves the signal
// unseen, so the next `changed()` re-wakes us instead of dropping the
// update until the periodic tick.
change_sig.borrow_and_update();
interval.reset();

let message_generation = state.message_generation().await;
debug!(message_generation, "gossip loop");

let peers: Vec<Imid> = te
.derivation()
.imid_to_ip
Expand Down
10 changes: 2 additions & 8 deletions src/imid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,6 @@ impl Imid {
ServerName::try_from(self.to_dns_name()).assert()
}

/// Get raw bytes (33-byte SEC1 compressed public key)
#[cfg(test)]
#[must_use]
fn to_bytes(&self) -> Vec<u8> {
self.public_key.to_encoded_point(true).as_bytes().to_vec()
}

/// Create IMID from raw bytes (33-byte SEC1 compressed public key)
pub fn from_bytes(bytes: &[u8]) -> Result<Self> {
let public_key = PublicKey::from_sec1_bytes(bytes)
Expand Down Expand Up @@ -594,7 +587,8 @@ mod tests {
let keypair = ImidKeypair::generate();
let imid = keypair.to_imid();

let bytes = imid.to_bytes();
// 33-byte SEC1 compressed public key, the wire form `from_bytes` parses.
let bytes = imid.public_key.to_encoded_point(true).as_bytes().to_vec();
assert_eq!(bytes.len(), 33, "compressed SEC1 key should be 33 bytes");

let recovered_imid = Imid::from_bytes(&bytes).assert();
Expand Down
Loading