feat: change to paired-v2.json

This commit is contained in:
Tien Do Nam
2026-08-03 00:20:45 +02:00
parent f24dcbd949
commit 62d5ca9687
5 changed files with 16 additions and 16 deletions
+1 -1
View File
@@ -5,9 +5,9 @@ use super::App;
use crate::ui::Category;
use crate::util::{self, SpeedMeter};
use localsend::http::client::v2::LsHttpClientV2;
use localsend::model::discovery::ProtocolType;
use localsend::http::server::common::save::FileUploadTarget;
use localsend::http::server::v2::{PrepareUploadDecisionV2, ServerEventV2, SessionEndReasonV2};
use localsend::model::discovery::ProtocolType;
use localsend::model::transfer::FileDto;
use std::collections::{HashMap, HashSet};
use std::sync::Arc;
+1 -1
View File
@@ -7,8 +7,8 @@ use futures_util::StreamExt;
use localsend::discovery::StatefulDevice;
use localsend::http::client::ClientError;
use localsend::http::client::v2::LsHttpClientV2;
use localsend::model::discovery::ProtocolType;
use localsend::http::dto_v2::PrepareUploadRequestDtoV2;
use localsend::model::discovery::ProtocolType;
use localsend::model::transfer::{FileContent, FileDto};
use localsend::reqwest;
use std::collections::HashMap;
+1 -1
View File
@@ -3,10 +3,10 @@
use anyhow::Context;
use localsend::crypto::cert::fingerprint_from_cert_der;
use localsend::http::dto_v2::RegisterDtoV2;
use localsend::model::discovery::{PROTOCOL_VERSION_V2, ProtocolType};
use localsend::http::server::TlsConfig;
use localsend::http::state::ClientInfo;
use localsend::model::discovery::DeviceType;
use localsend::model::discovery::{PROTOCOL_VERSION_V2, ProtocolType};
use localsend::multicast::MulticastDevice;
use std::path::Path;
+2 -2
View File
@@ -6,7 +6,7 @@
//! is written on the first run.
//! - `identity.pem` ([`identity`]): this device's certificate and private
//! key.
//! - `paired.json` ([`paired`]): paired devices; machine-written.
//! - `paired-v2.json` ([`paired`]): paired devices; machine-written.
mod config;
mod identity;
@@ -33,7 +33,7 @@ pub struct Repository {
pub identity: Arc<Identity>,
/// Devices whose transfer requests are auto-accepted; persisted across
/// runs as `paired.json`.
/// runs as `paired-v2.json`.
pub paired: PairedDevices,
}
+11 -11
View File
@@ -1,17 +1,18 @@
//! `paired.json`: paired devices; machine-written.
use anyhow::Context;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::io::ErrorKind;
use std::path::{Path, PathBuf};
/// Current schema version of `paired.json`. On a schema change,
/// bump this and migrate the old versions in [`PairedDevices::load`].
/// Current schema version of `paired-v2.json`. On a schema change within
/// this file, bump this and migrate the old versions in
/// [`PairedDevices::load`].
///
/// Planned v2: trust the peer's permanent ed25519 public key (see
/// `crypto::token` in the core crate) instead of its certificate
/// fingerprint; certificates (RSA) then become ephemeral.
/// The file name tracks the trust model, not this schema version: a new
/// trust model gets a new file, so a downgraded build still finds its own
/// file intact. Planned `paired-v3.json`: trust the peer's permanent
/// ed25519 public key (see `crypto::token` in the core crate) instead of
/// its certificate fingerprint; certificates (RSA) then become ephemeral.
const PAIRED_DEVICES_VERSION: u32 = 1;
#[derive(Serialize, Deserialize)]
@@ -19,15 +20,14 @@ pub struct PairedDevice {
pub alias: String,
}
/// The on-disk format of `paired.json`.
/// The on-disk format of `paired-v2.json`,
/// keyed by certificate fingerprint.
#[derive(Serialize, Deserialize)]
struct PairedDevicesFile {
version: u32,
devices: BTreeMap<String, PairedDevice>,
}
/// The paired devices from `paired.json`, keyed by certificate
/// fingerprint. Their transfer requests are accepted without asking.
pub struct PairedDevices {
path: PathBuf,
file: PairedDevicesFile,
@@ -35,7 +35,7 @@ pub struct PairedDevices {
impl PairedDevices {
pub fn load(dir: &Path) -> anyhow::Result<Self> {
let path = dir.join("paired.json");
let path = dir.join("paired-v2.json");
let devices = match std::fs::read_to_string(&path) {
Ok(text) => {
// Read the version on its own first: old versions are parsed