Skip to content

Commit 4bc2c55

Browse files
committed
WIP: SP for replication testing
1 parent 342323e commit 4bc2c55

File tree

4 files changed

+44
-10
lines changed

4 files changed

+44
-10
lines changed

rust-tui/src/bin/integration_test.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async fn main() -> Result<()> {
4545

4646
ditto.update_transport_config(|config| {
4747
config.enable_all_peer_to_peer();
48-
config.connect.websocket_urls.insert(websocket_url);
48+
config.connect.websocket_urls.insert(websocket_url.clone());
4949
});
5050

5151
// Disable sync with v3 peers and DQL strict mode
@@ -60,7 +60,8 @@ async fn main() -> Result<()> {
6060
println!("✅ Created Ditto instance and started sync");
6161

6262
// Create todolist instance (loads the app)
63-
let todolist = Todolist::new(ditto)?;
63+
let client_name = env::var("DITTO_CLIENT_NAME").ok();
64+
let todolist = Todolist::new(ditto, websocket_url, client_name)?;
6465
println!("📝 App loaded - Created todolist instance");
6566

6667
// Wait for sync and check for the seeded task

rust-tui/src/bin/main.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ pub struct Cli {
2424
#[clap(long, env = "DITTO_WEBSOCKET_URL")]
2525
websocket_url: String,
2626

27+
/// Optional client name to display in the TUI
28+
#[clap(long, env = "DITTO_CLIENT_NAME")]
29+
client_name: Option<String>,
30+
2731
/// Path to write logs on disk
2832
#[clap(long, default_value = "/tmp/ditto-quickstart.log")]
2933
log: PathBuf,
@@ -56,11 +60,17 @@ async fn main() -> Result<()> {
5660
cli.app_id,
5761
cli.token,
5862
cli.custom_auth_url,
59-
cli.websocket_url,
63+
cli.websocket_url.clone(),
6064
)
6165
.await?;
62-
let _tui_task = TuiTask::try_spawn(shutdown.clone(), terminal, ditto)
63-
.context("failed to start tui task")?;
66+
let _tui_task = TuiTask::try_spawn(
67+
shutdown.clone(),
68+
terminal,
69+
ditto,
70+
cli.websocket_url,
71+
cli.client_name,
72+
)
73+
.context("failed to start tui task")?;
6474
tracing::info!(success = true, "Initialized!");
6575

6676
// Wait for shutdown trigger
@@ -117,8 +127,11 @@ async fn try_init_ditto(
117127
.build()?;
118128

119129
ditto.update_transport_config(|config| {
120-
config.enable_all_peer_to_peer();
121-
//set websocket url
130+
// Explicitly disable all peer-to-peer transports - only use Big Peer
131+
config.peer_to_peer.bluetooth_le.enabled = false;
132+
config.peer_to_peer.lan.enabled = false;
133+
134+
// Keep only the WebSocket connection to Big Peer
122135
config.connect.websocket_urls.insert(websocket_url);
123136
});
124137

rust-tui/src/tui/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ impl TuiTask {
2626
shutdown: Shutdown,
2727
terminal: Terminal<CrosstermBackend<Stdout>>,
2828
ditto: Ditto,
29+
websocket_url: String,
30+
client_name: Option<String>,
2931
) -> Result<TuiTask> {
30-
let todolist_state = Todolist::new(ditto)?;
32+
let todolist_state = Todolist::new(ditto, websocket_url, client_name)?;
3133
let task_context = TuiContext {
3234
terminal,
3335
shutdown,

rust-tui/src/tui/todolist.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ pub struct Todolist {
3737
/// Subscriptions cause Ditto to sync selected data from other peers
3838
pub tasks_subscription: Arc<SyncSubscription>,
3939

40+
// Connection info for display
41+
/// The WebSocket URL this client is connected to
42+
pub websocket_url: String,
43+
44+
/// Optional client name for display purposes
45+
pub client_name: Option<String>,
46+
4047
// TUI state below
4148
pub mode: TodoMode,
4249

@@ -82,7 +89,7 @@ impl TodoItem {
8289
}
8390

8491
impl Todolist {
85-
pub fn new(ditto: Ditto) -> Result<Self> {
92+
pub fn new(ditto: Ditto, websocket_url: String, client_name: Option<String>) -> Result<Self> {
8693
let (tasks_tx, tasks_rx) = watch::channel(Vec::new());
8794

8895
// Register a subscription, which determines what data syncs to this peer
@@ -110,6 +117,8 @@ impl Todolist {
110117
tasks_rx,
111118
tasks_observer,
112119
tasks_subscription,
120+
websocket_url,
121+
client_name,
113122
mode: TodoMode::Normal,
114123
create_task_title: None,
115124
edit_task: None,
@@ -155,6 +164,14 @@ impl Todolist {
155164
.into_iter()
156165
.collect::<Line>();
157166

167+
// Format connection info: "client_name@websocket_url" or just "websocket_url"
168+
let connection_info = if let Some(ref client_name) = self.client_name {
169+
format!(" {}@{} ", client_name, self.websocket_url)
170+
} else {
171+
format!(" {} ", self.websocket_url)
172+
};
173+
let connection_line = Line::raw(connection_info).cyan();
174+
158175
let table = Table::new(rows, Constraint::from_percentages([30, 70]))
159176
.header(header)
160177
.highlight_symbol("❯❯ ")
@@ -164,7 +181,8 @@ impl Todolist {
164181
.border_type(BorderType::Rounded)
165182
.title_top(Line::raw(" Tasks (j↓, k↑, ⏎ toggle done) ").left_aligned())
166183
.title_top(sync_line.right_aligned())
167-
.title_bottom(" (c: create) (d: delete) (e: edit) (q: quit) "),
184+
.title_bottom(Line::raw(" (c: create) (d: delete) (e: edit) (q: quit) ").left_aligned())
185+
.title_bottom(connection_line.right_aligned()),
168186
);
169187
StatefulWidget::render(table, area, buf, &mut self.table_state);
170188
}

0 commit comments

Comments
 (0)