Compare commits
6
Commits
93dc8f02fb
...
v0.2.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cced546cd5 | ||
|
|
52c2f7f7fe | ||
|
|
9b9f5d9ce5 | ||
|
|
1f9539ffd7 | ||
|
|
d854a4d4e0 | ||
|
|
6175423b0c |
No files matched your search
Generated
+1
-1
@@ -1565,7 +1565,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "furumi_tui"
|
||||
version = "0.2.2"
|
||||
version = "0.2.4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"blake3",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "furumi_tui"
|
||||
version = "0.2.3"
|
||||
version = "0.2.4"
|
||||
edition = "2024"
|
||||
rust-version = "1.97"
|
||||
description = "A federated P2P player for personal music libraries"
|
||||
|
||||
+14
-1
@@ -263,6 +263,7 @@ pub async fn run(
|
||||
state.device_playback.self_device_name = device_name.clone();
|
||||
state.device_playback.active_device_id = Some(device_id);
|
||||
state.device_playback.active_device_name = Some(device_name);
|
||||
state.device_playback.startup_takeover_pending = true;
|
||||
}
|
||||
let player_events = event_tx.clone();
|
||||
let mut runtime = Runtime {
|
||||
@@ -276,7 +277,7 @@ pub async fn run(
|
||||
library_network_refreshing: Arc::new(std::sync::atomic::AtomicBool::new(false)),
|
||||
library_network_cursors: Arc::new(std::sync::Mutex::new(std::collections::HashMap::new())),
|
||||
library_network_done: Arc::new(std::sync::Mutex::new(std::collections::HashSet::new())),
|
||||
library_network_mode: crate::config::settings::LibrarySourceMode::Local,
|
||||
library_network_mode: state.global.filters.source_mode,
|
||||
library_network_art_fetching: Arc::new(std::sync::atomic::AtomicBool::new(false)),
|
||||
library_network_art_attempted: Arc::new(std::sync::Mutex::new(
|
||||
std::collections::HashSet::new(),
|
||||
@@ -2811,6 +2812,18 @@ fn handle_device_playback_snapshot(
|
||||
if !snapshot.active {
|
||||
return;
|
||||
}
|
||||
// Starting a player is an explicit claim of the active role. Import the
|
||||
// current queue/position from the previously active peer, then announce a
|
||||
// normal handoff so that the old owner becomes a control device. This is
|
||||
// intentionally one-shot: subsequent snapshots use the regular lease and
|
||||
// explicit-transfer rules.
|
||||
if state.device_playback.startup_takeover_pending {
|
||||
state.device_playback.startup_takeover_pending = false;
|
||||
become_control_device(state, runtime, snapshot);
|
||||
transfer_active_to_this_device(state, runtime);
|
||||
state.status_message = Some("playback moved to this newly started player".to_string());
|
||||
return;
|
||||
}
|
||||
if local_active_lease_protected(state, now) {
|
||||
tracing::debug!(
|
||||
remote = %snapshot.device_id,
|
||||
|
||||
@@ -1240,6 +1240,9 @@ pub struct DevicePlaybackState {
|
||||
pub remote: BTreeMap<String, crate::devices::PlaybackSnapshot>,
|
||||
pub last_remote_snapshot: Option<crate::devices::PlaybackSnapshot>,
|
||||
pub jam_host: bool,
|
||||
/// A freshly started TUI owns playback by protocol. The first active
|
||||
/// snapshot discovered during startup is imported and handed off here.
|
||||
pub startup_takeover_pending: bool,
|
||||
}
|
||||
|
||||
impl DevicePlaybackState {
|
||||
|
||||
@@ -158,25 +158,25 @@ fn source_mode_cycles_on_library_playlists_and_queue_tabs() {
|
||||
update(&mut state, Action::CycleSourceMode),
|
||||
Some(Effect::SourceModeChanged)
|
||||
);
|
||||
assert_eq!(state.global.filters.source_mode, LibrarySourceMode::My);
|
||||
assert_eq!(state.global.filters.source_mode, LibrarySourceMode::Local);
|
||||
|
||||
state.active_tab = Tab::Playlists;
|
||||
assert_eq!(
|
||||
update(&mut state, Action::CycleSourceMode),
|
||||
Some(Effect::SourceModeChanged)
|
||||
);
|
||||
assert_eq!(state.global.filters.source_mode, LibrarySourceMode::Global);
|
||||
assert_eq!(state.global.filters.source_mode, LibrarySourceMode::My);
|
||||
|
||||
state.active_tab = Tab::Queue;
|
||||
assert_eq!(
|
||||
update(&mut state, Action::CycleSourceMode),
|
||||
Some(Effect::SourceModeChanged)
|
||||
);
|
||||
assert_eq!(state.global.filters.source_mode, LibrarySourceMode::Local);
|
||||
assert_eq!(state.global.filters.source_mode, LibrarySourceMode::Global);
|
||||
|
||||
state.active_tab = Tab::Federation;
|
||||
assert_eq!(update(&mut state, Action::CycleSourceMode), None);
|
||||
assert_eq!(state.global.filters.source_mode, LibrarySourceMode::Local);
|
||||
assert_eq!(state.global.filters.source_mode, LibrarySourceMode::Global);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -4,9 +4,9 @@ use serde::{Deserialize, Serialize};
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum LibrarySourceMode {
|
||||
#[default]
|
||||
Local,
|
||||
My,
|
||||
#[default]
|
||||
Global,
|
||||
}
|
||||
|
||||
@@ -128,6 +128,6 @@ hide_featured_only = true
|
||||
|
||||
assert_eq!(settings.volume, 100);
|
||||
assert!(settings.library.hide_featured_only);
|
||||
assert_eq!(settings.library.source_mode, LibrarySourceMode::Local);
|
||||
assert_eq!(settings.library.source_mode, LibrarySourceMode::Global);
|
||||
}
|
||||
}
|
||||
+59
-22
@@ -31,6 +31,9 @@ const PAIRING_RETRY_DELAY: Duration = Duration::from_secs(1);
|
||||
const RESPONSE_DRAIN_TIMEOUT: Duration = Duration::from_secs(2);
|
||||
const SYNC_INTERVAL: Duration = Duration::from_secs(2);
|
||||
const MAX_LINE: usize = 8 * 1024 * 1024;
|
||||
/// Playback control is ephemeral. Keeping old full-queue commands in a new
|
||||
/// peer's catch-up batch can make the initial pairing frame arbitrarily large.
|
||||
const PLAYBACK_COMMAND_TTL_MS: i64 = 5 * 60 * 1_000;
|
||||
const MAX_OPS_PER_BATCH: usize = 1000;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -1249,8 +1252,7 @@ impl DeviceSync {
|
||||
device: &StoredDevice,
|
||||
transport_stats: Arc<crate::federation::TransportStats>,
|
||||
) -> Result<()> {
|
||||
let ticket: PeerTicket = device.endpoint_ticket.parse()?;
|
||||
let peer = service.connect(ticket).await?;
|
||||
let peer = resolve_device_peer(&service, device).await?;
|
||||
let own_ticket = service.ticket().await?.to_string();
|
||||
let identity = self.ensure_identity()?;
|
||||
let profile = self.own_profile(&own_ticket)?;
|
||||
@@ -2174,25 +2176,39 @@ impl DeviceSync {
|
||||
LEFT JOIN sync_peer_acks a
|
||||
ON a.peer_device_id = ?1 AND a.origin_device_id = o.origin_device_id
|
||||
WHERE o.seq > COALESCE(a.max_seq, 0)
|
||||
ORDER BY o.hlc_ms, o.op_id
|
||||
LIMIT ?2",
|
||||
)?;
|
||||
let rows = stmt.query_map(params![peer_device_id, MAX_OPS_PER_BATCH as i64], |row| {
|
||||
let payload_json: String = row.get(4)?;
|
||||
Ok(SyncOpWire {
|
||||
op_id: row.get(0)?,
|
||||
origin_device_id: row.get(1)?,
|
||||
seq: row.get(2)?,
|
||||
hlc_ms: row.get(3)?,
|
||||
payload: serde_json::from_str(&payload_json).map_err(|err| {
|
||||
rusqlite::Error::FromSqlConversionFailure(
|
||||
4,
|
||||
rusqlite::types::Type::Text,
|
||||
Box::new(err),
|
||||
AND (
|
||||
o.kind != 'playback_command'
|
||||
OR (
|
||||
o.hlc_ms >= ?2
|
||||
AND json_extract(o.payload_json, '$.target_device_id') = ?1
|
||||
)
|
||||
})?,
|
||||
})
|
||||
})?;
|
||||
)
|
||||
ORDER BY o.hlc_ms, o.op_id
|
||||
LIMIT ?3",
|
||||
)?;
|
||||
let rows = stmt.query_map(
|
||||
params![
|
||||
peer_device_id,
|
||||
now_ms().saturating_sub(PLAYBACK_COMMAND_TTL_MS),
|
||||
MAX_OPS_PER_BATCH as i64
|
||||
],
|
||||
|row| {
|
||||
let payload_json: String = row.get(4)?;
|
||||
Ok(SyncOpWire {
|
||||
op_id: row.get(0)?,
|
||||
origin_device_id: row.get(1)?,
|
||||
seq: row.get(2)?,
|
||||
hlc_ms: row.get(3)?,
|
||||
payload: serde_json::from_str(&payload_json).map_err(|err| {
|
||||
rusqlite::Error::FromSqlConversionFailure(
|
||||
4,
|
||||
rusqlite::types::Type::Text,
|
||||
Box::new(err),
|
||||
)
|
||||
})?,
|
||||
})
|
||||
},
|
||||
)?;
|
||||
Ok(rows.collect::<rusqlite::Result<Vec<_>>>()?)
|
||||
}
|
||||
|
||||
@@ -2380,7 +2396,7 @@ impl DeviceSync {
|
||||
let own = self.ensure_identity()?.device_id;
|
||||
let conn = lock(&self.conn);
|
||||
let mut stmt = conn.prepare(
|
||||
"SELECT device_id, endpoint_ticket
|
||||
"SELECT device_id, endpoint_id, endpoint_ticket
|
||||
FROM sync_devices
|
||||
WHERE trusted_at_ms IS NOT NULL
|
||||
AND revoked_at_ms IS NULL
|
||||
@@ -2390,7 +2406,8 @@ impl DeviceSync {
|
||||
let rows = stmt.query_map([own], |row| {
|
||||
Ok(StoredDevice {
|
||||
device_id: row.get(0)?,
|
||||
endpoint_ticket: row.get(1)?,
|
||||
endpoint_id: row.get(1)?,
|
||||
endpoint_ticket: row.get(2)?,
|
||||
})
|
||||
})?;
|
||||
Ok(rows.collect::<rusqlite::Result<Vec<_>>>()?)
|
||||
@@ -2642,9 +2659,29 @@ impl DeviceSync {
|
||||
#[derive(Debug)]
|
||||
struct StoredDevice {
|
||||
device_id: String,
|
||||
endpoint_id: String,
|
||||
endpoint_ticket: String,
|
||||
}
|
||||
|
||||
async fn resolve_device_peer(
|
||||
service: &MusicDhtService,
|
||||
device: &StoredDevice,
|
||||
) -> Result<music_dht::EndpointId> {
|
||||
if let Ok(peer) = device.endpoint_id.parse::<music_dht::EndpointId>()
|
||||
&& (service.connected_peers().contains(&peer)
|
||||
|| service
|
||||
.known_peers()
|
||||
.iter()
|
||||
.any(|contact| contact.peer_id == peer))
|
||||
{
|
||||
// The live DHT contact carries a ticket for the current schema. The
|
||||
// persisted device ticket may predate a schema upgrade.
|
||||
return Ok(peer);
|
||||
}
|
||||
let ticket: PeerTicket = device.endpoint_ticket.parse()?;
|
||||
service.connect(ticket).await.map_err(Into::into)
|
||||
}
|
||||
|
||||
pub async fn serve_peers(
|
||||
mut acceptor: StreamAcceptor,
|
||||
sync: Arc<DeviceSync>,
|
||||
|
||||
@@ -228,6 +228,58 @@ fn playback_command_is_targeted_and_deduplicated() {
|
||||
assert!(rx.try_recv().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn playback_commands_are_caught_up_only_by_their_target_while_fresh() {
|
||||
let sync = test_sync();
|
||||
let command = PlaybackCommand::SetState {
|
||||
state: PlaybackStateWire {
|
||||
queue: Vec::new(),
|
||||
queue_pos: 0,
|
||||
playing: false,
|
||||
paused: false,
|
||||
idle_since_ms: None,
|
||||
position_secs: 0.0,
|
||||
volume: 42,
|
||||
shuffle: false,
|
||||
repeat: PlaybackRepeat::Off,
|
||||
},
|
||||
seek: false,
|
||||
};
|
||||
sync.record_playback_command("dev_target", command.clone())
|
||||
.unwrap();
|
||||
sync.record_playback_command("dev_other", command).unwrap();
|
||||
|
||||
let target_ops = sync.ops_for_peer("dev_target").unwrap();
|
||||
assert_eq!(
|
||||
target_ops
|
||||
.iter()
|
||||
.filter(|op| matches!(op.payload, SyncOpPayload::PlaybackCommand { .. }))
|
||||
.count(),
|
||||
1
|
||||
);
|
||||
assert!(
|
||||
sync.ops_for_peer("dev_unknown")
|
||||
.unwrap()
|
||||
.iter()
|
||||
.all(|op| !matches!(op.payload, SyncOpPayload::PlaybackCommand { .. }))
|
||||
);
|
||||
|
||||
lock(&sync.conn)
|
||||
.execute(
|
||||
"UPDATE sync_ops
|
||||
SET hlc_ms = ?1
|
||||
WHERE kind = 'playback_command'",
|
||||
[now_ms().saturating_sub(PLAYBACK_COMMAND_TTL_MS + 1)],
|
||||
)
|
||||
.unwrap();
|
||||
assert!(
|
||||
sync.ops_for_peer("dev_target")
|
||||
.unwrap()
|
||||
.iter()
|
||||
.all(|op| !matches!(op.payload, SyncOpPayload::PlaybackCommand { .. }))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn newer_device_trust_reactivates_revoked_device() {
|
||||
let sync = test_sync();
|
||||
|
||||
Reference in new issue
Block a user