From 1452621fa82e4501b16867cced8380a43a539a68 Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Mon, 3 Aug 2026 07:57:25 -0400 Subject: [PATCH] Name protocol versions by boundary --- src/app.rs | 4 ++-- src/app/tests.rs | 6 +++--- src/daemon.rs | 6 +++--- src/ipc.rs | 4 ++-- src/protocol.rs | 12 +++++++----- src/storage/tests.rs | 2 +- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/app.rs b/src/app.rs index 873c130..5ff7efc 100644 --- a/src/app.rs +++ b/src/app.rs @@ -5,7 +5,7 @@ use crate::{ config::{AppaConfig, ConfiguredFolder}, domain::{DeviceId, EntryKind, FolderRoster, MemberRole, RosterMember, is_conflict_artifact}, iroh::NodeHost, - protocol::{Invite, PROTOCOL_VERSION, decode_invite, encode_invite}, + protocol::{INVITATION_PROTOCOL_VERSION, Invite, decode_invite, encode_invite}, storage::{AppPaths, FolderConfig, ManifestRevision, PeerInfo, StateStore}, }; @@ -177,7 +177,7 @@ impl AppaService { node.wait_until_online_for(INVITE_ONLINE_WAIT_TIMEOUT) .await?; let mut invite = Invite { - protocol_version: PROTOCOL_VERSION, + protocol_version: INVITATION_PROTOCOL_VERSION, folder_id: folder.id, folder_name: folder.name.clone(), inviter_device_id: node.endpoint_address().id.to_string(), diff --git a/src/app/tests.rs b/src/app/tests.rs index 073542c..97a7c3b 100644 --- a/src/app/tests.rs +++ b/src/app/tests.rs @@ -14,7 +14,7 @@ use crate::{ iroh::FolderSession, }; -use super::{AppPaths, AppaService, ConfigAuditAction, Invite, PROTOCOL_VERSION}; +use super::{AppPaths, AppaService, ConfigAuditAction, INVITATION_PROTOCOL_VERSION, Invite}; const INITIAL_SYNC_ATTEMPTS: usize = 3; const INITIAL_SYNC_RETRY_DELAY: std::time::Duration = std::time::Duration::from_millis(100); @@ -191,7 +191,7 @@ async fn synchronizes_and_deletes_a_file_between_two_devices() -> anyhow::Result source_node.publish_manifest(source_manifest).await?; let invite = Invite { - protocol_version: PROTOCOL_VERSION, + protocol_version: INVITATION_PROTOCOL_VERSION, folder_id: source_config.id, folder_name: source_config.name.clone(), inviter_device_id: source_node.endpoint_address().id.to_string(), @@ -300,7 +300,7 @@ async fn preserves_both_versions_after_offline_edits() -> anyhow::Result<()> { source_node.publish_manifest(source_manifest).await?; let invite = Invite { - protocol_version: PROTOCOL_VERSION, + protocol_version: INVITATION_PROTOCOL_VERSION, folder_id: source_config.id, folder_name: source_config.name.clone(), inviter_device_id: source_node.endpoint_address().id.to_string(), diff --git a/src/daemon.rs b/src/daemon.rs index 4de73a4..d798f9b 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -10,7 +10,7 @@ use tokio::{ use crate::{ app::{AppaService, run::SyncRunner}, - ipc::{self, Command, PROTOCOL_VERSION, Request, Response}, + ipc::{self, Command, IPC_PROTOCOL_VERSION, Request, Response}, storage::AppPaths, }; @@ -61,11 +61,11 @@ async fn handle_connection( stream: &mut UnixStream, ) { let response = match read_request(stream).await { - Ok(request) if request.protocol_version == PROTOCOL_VERSION => { + Ok(request) if request.protocol_version == IPC_PROTOCOL_VERSION => { handle_command(service, sync_runner, request.command).await } Ok(request) => Response::Error(format!( - "unsupported Appa daemon protocol version {}; expected {PROTOCOL_VERSION}", + "unsupported Appa daemon protocol version {}; expected {IPC_PROTOCOL_VERSION}", request.protocol_version )), Err(error) => Response::Error(error.to_string()), diff --git a/src/ipc.rs b/src/ipc.rs index 69ff64d..013c5e2 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -14,7 +14,7 @@ use crate::{ storage::AppPaths, }; -pub const PROTOCOL_VERSION: u16 = 1; +pub const IPC_PROTOCOL_VERSION: u16 = 1; const MAX_MESSAGE_BYTES: usize = 1024 * 1024; const DAEMON_REQUEST_TIMEOUT: Duration = Duration::from_secs(8); @@ -232,7 +232,7 @@ impl DaemonClient { write_message( &mut stream, &Request { - protocol_version: PROTOCOL_VERSION, + protocol_version: IPC_PROTOCOL_VERSION, command, }, ) diff --git a/src/protocol.rs b/src/protocol.rs index 8c792b0..34c54df 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize}; use time::OffsetDateTime; /// Version of the signed invitation format and invitation validation rules. -pub const PROTOCOL_VERSION: u16 = 5; +pub const INVITATION_PROTOCOL_VERSION: u16 = 5; pub const INVITE_SCHEME: &str = "appa://"; #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] @@ -147,11 +147,11 @@ pub fn decode_invite(ticket: &str) -> anyhow::Result { } pub fn validate_invite(invite: &Invite) -> anyhow::Result<()> { - if invite.protocol_version != PROTOCOL_VERSION { + if invite.protocol_version != INVITATION_PROTOCOL_VERSION { anyhow::bail!( "invitation uses unsupported Appa protocol version {} (expected {})", invite.protocol_version, - PROTOCOL_VERSION + INVITATION_PROTOCOL_VERSION ); } if invite.expires_at < OffsetDateTime::now_utc() { @@ -174,7 +174,9 @@ mod tests { use time::Duration; use uuid::Uuid; - use super::{Invite, ManifestSummary, PROTOCOL_VERSION, decode_invite, encode_invite}; + use super::{ + INVITATION_PROTOCOL_VERSION, Invite, ManifestSummary, decode_invite, encode_invite, + }; #[test] fn rejects_an_invitation_changed_after_signing() -> anyhow::Result<()> { @@ -191,7 +193,7 @@ mod tests { )?; roster.sign(&identity)?; let mut invite = Invite { - protocol_version: PROTOCOL_VERSION, + protocol_version: INVITATION_PROTOCOL_VERSION, folder_id: roster.folder_id, folder_name: "notes".to_owned(), inviter_device_id: endpoint.id.to_string(), diff --git a/src/storage/tests.rs b/src/storage/tests.rs index 8cdb642..79461b0 100644 --- a/src/storage/tests.rs +++ b/src/storage/tests.rs @@ -256,7 +256,7 @@ fn test_invite(folder_id: uuid::Uuid) -> anyhow::Result )?; roster.sign(&owner)?; let mut invite = crate::protocol::Invite { - protocol_version: crate::protocol::PROTOCOL_VERSION, + protocol_version: crate::protocol::INVITATION_PROTOCOL_VERSION, folder_id, folder_name: "folder".to_owned(), inviter_device_id: endpoint.id.to_string(), -- 2.51.2