Skip to content

Commit e3aa553

Browse files
committed
WIP: Use new p2panda high-level API
1 parent 876afa7 commit e3aa553

25 files changed

+821
-1528
lines changed

Cargo.lock

Lines changed: 39 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

reflection-doc/Cargo.toml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ authors = [
88
]
99

1010
[dependencies]
11-
reflection-node = { path = "../reflection-node" }
1211
anyhow = "1.0.101"
13-
async-channel = "2.5.0"
14-
glib = "0.21"
1512
gio = "0.21"
13+
glib = "0.21"
14+
hex = "0.4.3"
15+
indexmap = "2.13.0"
1616
loro = { tag = "loro-crdt@1.10.6", git = "https://github.com/loro-dev/loro.git" }
17+
p2panda-core = { git = "https://github.com/p2panda/p2panda", rev = "534363cfc33d2e3275748bf8b0a9307e6eb261c0" }
18+
rand = "0.10.0"
19+
reflection-node = { path = "../reflection-node" }
20+
serde = { version = "1.0.228", features = ["derive"] }
1721
thiserror = "2.0.18"
1822
tracing = "0.1"
23+
24+
[dev-dependencies]
1925
test-log = { version = "0.2.19", default-features = false, features = ["trace", "color"] }
20-
serde = { version = "1.0.228", features = ["derive"] }
21-
rand = "0.10.0"
22-
hex = "0.4.3"
23-
indexmap = "2.13.0"

reflection-doc/src/document.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ use glib::{Properties, clone};
99
pub use hex::FromHexError;
1010
use loro::{ExportMode, LoroDoc, LoroText, event::Diff};
1111
use p2panda_core::cbor::{decode_cbor, encode_cbor};
12-
use reflection_node::p2panda_core;
13-
use reflection_node::topic::{
14-
SubscribableTopic, Subscription as TopicSubscription,
15-
SubscriptionError as TopicSubscriptionError,
16-
};
12+
use p2panda_core::{self, Topic};
13+
use reflection_node::subscription::Subscription as TopicSubscription;
14+
use reflection_node::traits::{SubscribableTopic, SubscriptionError as TopicSubscriptionError};
1715
use tracing::error;
1816

1917
use crate::author::Author;
@@ -37,6 +35,18 @@ impl From<[u8; 32]> for DocumentId {
3735
}
3836
}
3937

38+
impl From<Topic> for DocumentId {
39+
fn from(value: Topic) -> Self {
40+
Self(value.to_bytes())
41+
}
42+
}
43+
44+
impl From<DocumentId> for Topic {
45+
fn from(value: DocumentId) -> Self {
46+
Topic::from(value.0)
47+
}
48+
}
49+
4050
impl fmt::Display for DocumentId {
4151
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4252
f.write_str(&self.to_hex())
@@ -298,7 +308,7 @@ mod imp {
298308
#[weak]
299309
subscription,
300310
async move {
301-
if let Err(error) = subscription.send_ephemeral(cursor_bytes).await {
311+
if let Err(error) = subscription.publish_ephemeral(cursor_bytes).await {
302312
error!("Failed to send cursor position: {}", error);
303313
}
304314
}
@@ -495,7 +505,7 @@ mod imp {
495505
subscription,
496506
async move {
497507
// Broadcast a "text delta" to all peers
498-
if let Err(error) = subscription.send_delta(delta_bytes).await {
508+
if let Err(error) = subscription.publish_delta(delta_bytes).await {
499509
error!(
500510
"Failed to send delta of document to the network: {}",
501511
error
@@ -828,7 +838,7 @@ impl Document {
828838
.export(ExportMode::Snapshot)
829839
.expect("encoded crdt snapshot");
830840

831-
if let Err(error) = subscription.send_snapshot(snapshot_bytes).await {
841+
if let Err(error) = subscription.publish_snapshot(snapshot_bytes).await {
832842
error!(
833843
"Failed to send snapshot of document to the network: {}",
834844
error
@@ -872,7 +882,7 @@ impl Document {
872882
.expect("crdt_doc to be set")
873883
.export(ExportMode::Snapshot)
874884
.expect("encoded crdt snapshot");
875-
if let Err(error) = subscription.send_snapshot(snapshot_bytes).await {
885+
if let Err(error) = subscription.publish_snapshot(snapshot_bytes).await {
876886
error!(
877887
"Failed to send snapshot of document to the network: {}",
878888
error

reflection-doc/src/documents.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl Documents {
7070
pub(crate) async fn load(&self, service: &Service) -> Result<(), StartupError> {
7171
let public_key = service.private_key().public_key();
7272

73-
let documents = service.node().topics::<DocumentId>().await?;
73+
let documents = service.node().topics().await?;
7474

7575
let mut list = self.imp().list.write().unwrap();
7676
assert!(list.is_empty());
@@ -102,14 +102,14 @@ impl Documents {
102102

103103
let obj = Document::with_state(
104104
service,
105-
Some(&document.id),
105+
Some(&document.id.into()),
106106
document.name.as_deref(),
107107
last_accessed.as_ref(),
108108
);
109109

110110
obj.authors().load(authors);
111111

112-
list.insert(document.id, obj);
112+
list.insert(document.id.into(), obj);
113113
}
114114

115115
drop(list);

reflection-doc/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ pub mod documents;
55
pub mod service;
66

77
pub mod identity {
8+
use std::fmt;
89
use std::hash::Hash;
910

10-
use reflection_node::p2panda_core;
11-
pub use reflection_node::p2panda_core::identity::IdentityError;
12-
use std::fmt;
11+
use p2panda_core;
12+
pub use p2panda_core::identity::IdentityError;
1313

1414
#[derive(Clone, Debug, glib::Boxed)]
1515
#[boxed_type(name = "ReflectionPrivateKey", nullable)]

reflection-doc/src/service.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1+
use std::sync::{Mutex, OnceLock};
2+
13
use gio::prelude::{FileExt, ListModelExtManual, NetworkMonitorExt};
24
use glib::object::ObjectExt;
35
use glib::subclass::prelude::*;
46
use glib::{Properties, clone};
5-
use reflection_node::p2panda_core::Hash;
6-
use std::sync::{Mutex, OnceLock};
7+
use p2panda_core::Hash;
8+
use reflection_node::node;
9+
use reflection_node::node::{Node, NodeError};
10+
use reflection_node::subscription::SubscriptionError;
711
use thiserror::Error;
812
use tracing::error;
913

14+
use crate::document::{Document, DocumentId};
15+
use crate::documents::Documents;
1016
use crate::identity::PrivateKey;
11-
use crate::{
12-
document::{Document, DocumentId},
13-
documents::Documents,
14-
};
15-
use reflection_node::{
16-
node,
17-
node::{Node, NodeError},
18-
topic::TopicError,
19-
};
2017

2118
#[derive(Error, Debug)]
2219
pub enum StartupError {
2320
#[error(transparent)]
2421
Node(#[from] NodeError),
2522
#[error(transparent)]
26-
Topic(#[from] TopicError),
23+
Topic(#[from] SubscriptionError),
2724
}
2825

2926
#[derive(Debug, Copy, Clone, PartialEq, Eq, glib::Enum, Default)]

reflection-node/Cargo.toml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,16 @@ authors = [
99
]
1010

1111
[dependencies]
12-
thiserror = "2.0.18"
1312
chrono = "0.4.43"
14-
ciborium = "0.2.2"
15-
p2panda-core = { git = "https://github.com/p2panda/p2panda", rev = "a1308c116c1bd345f2cd6af7df41d2a6e0a4a682" }
16-
p2panda-discovery = { git = "https://github.com/p2panda/p2panda", rev = "a1308c116c1bd345f2cd6af7df41d2a6e0a4a682" }
17-
p2panda-net = { git = "https://github.com/p2panda/p2panda", rev = "a1308c116c1bd345f2cd6af7df41d2a6e0a4a682" }
18-
p2panda-store = { git = "https://github.com/p2panda/p2panda", rev = "a1308c116c1bd345f2cd6af7df41d2a6e0a4a682", features = ["sqlite"], default-features = false }
19-
p2panda-stream = { git = "https://github.com/p2panda/p2panda", rev = "a1308c116c1bd345f2cd6af7df41d2a6e0a4a682" }
20-
p2panda-sync = { git = "https://github.com/p2panda/p2panda", rev = "a1308c116c1bd345f2cd6af7df41d2a6e0a4a682" }
13+
p2panda = { git = "https://github.com/p2panda/p2panda", rev = "534363cfc33d2e3275748bf8b0a9307e6eb261c0" }
14+
p2panda-core = { git = "https://github.com/p2panda/p2panda", rev = "534363cfc33d2e3275748bf8b0a9307e6eb261c0" }
15+
p2panda-store = { git = "https://github.com/p2panda/p2panda", rev = "534363cfc33d2e3275748bf8b0a9307e6eb261c0" }
2116
serde = { version = "1.0.228", features = ["derive"] }
22-
serde_bytes = "0.11.19"
2317
sqlx = { version = "0.8.6", features = ["runtime-tokio", "sqlite", "chrono"], default-features = false }
18+
thiserror = "2.0.18"
2419
tokio = { version = "1.49.0", features = ["rt", "sync"] }
2520
tokio-stream = "0.1.18"
2621
tracing = "0.1"
22+
23+
[dev-dependencies]
2724
test-log = { version = "0.2.19", default-features = false, features = ["trace", "color"] }
28-
hex = "0.4.3"
29-
rand_chacha = "0.10.0"

reflection-node/migrations/20250418140035_create_tables.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ CREATE TABLE IF NOT EXISTS topics (
1010
id TEXT NOT NULL PRIMARY KEY,
1111
name TEXT,
1212
last_accessed INTEGER
13-
);
13+
);

0 commit comments

Comments
 (0)