Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[workspace]
resolver = "2"
members = ["reflection-app", "reflection-doc", "reflection-node"]

[patch.crates-io]
iroh-gossip = { git = "https://github.com/p2panda/iroh-gossip", rev = "533c34a2758518ece19c1de9f21bc40d61f9b5a5" }
4 changes: 3 additions & 1 deletion reflection-app/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,9 @@ impl ReflectionApplication {
let dialog = adw::AlertDialog::builder()
.heading(gettext("Delete Pad?"))
.body_use_markup(true)
.body(gettext("This pad may be stored on other devices, and will only be deleted from this one."))
.body(gettext(
"This pad may be stored on other devices, and will only be deleted from this one.",
))
.default_response("confirm")
.close_response("cancel")
.build();
Expand Down
3 changes: 1 addition & 2 deletions reflection-app/src/open_dialog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ mod imp {
this.open_document_button
.set_label(&gettext("Switch to Existing Window"));
} else {
this.open_document_button
.set_label(&gettext("Open Pad"));
this.open_document_button.set_label(&gettext("Open Pad"));
}
}
));
Expand Down
24 changes: 23 additions & 1 deletion reflection-doc/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,23 @@ pub use hex::FromHexError;
use loro::{ExportMode, LoroDoc, LoroText, event::Diff};
use p2panda_core::cbor::{decode_cbor, encode_cbor};
use reflection_node::p2panda_core;
use reflection_node::topic::{SubscribableTopic, Subscription as TopicSubscription};
use reflection_node::topic::{
SubscribableTopic, Subscription as TopicSubscription,
SubscriptionError as TopicSubscriptionError,
};
use tracing::error;

use crate::author::Author;
use crate::authors::Authors;
use crate::identity::PublicKey;
use crate::service::Service;

#[derive(Debug, Copy, Clone, glib::ErrorDomain)]
#[error_domain(name = "reflection-document")]
enum DocumentError {
Failed,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, glib::Boxed)]
#[boxed_type(name = "ReflectionDocumentId", nullable)]
pub struct DocumentId([u8; 32]);
Expand Down Expand Up @@ -663,6 +672,9 @@ mod imp {
glib::types::Type::I32,
])
.build(),
Signal::builder("error")
.param_types([glib::Error::static_type()])
.build(),
]
})
}
Expand Down Expand Up @@ -934,4 +946,14 @@ impl SubscribableTopic for DocumentHandle {
});
}
}

fn error(&self, error: TopicSubscriptionError) {
if let Some(document) = self.0.upgrade() {
document.main_context().invoke(move || {
error!("Network error received: {error}");
let glib_error = glib::error::Error::new(DocumentError::Failed, &error.to_string());
document.emit_by_name::<()>("error", &[&glib_error]);
});
}
}
}
16 changes: 4 additions & 12 deletions reflection-doc/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ mod imp {
connection_mode
};

node.set_connection_mode(real_connection_mode)
.await
.unwrap();
if let Err(error) = node.set_connection_mode(real_connection_mode).await {
error!("Failed to startup network: {error}");
}
}
}

Expand Down Expand Up @@ -174,15 +174,7 @@ impl Service {
let private_key = self.private_key().0;
let network_id = Hash::new(b"reflection");
let path = self.data_dir().and_then(|data_dir| data_dir.path());
let node = Node::new(
private_key,
network_id,
path.as_deref(),
// gio::NetworkManager is slow to initialize the `network-available` property,
// so it might be incorrect therefore always start with no connection.
node::ConnectionMode::None,
)
.await?;
let node = Node::new(private_key, network_id, path.as_deref()).await?;

self.imp()
.node
Expand Down
14 changes: 7 additions & 7 deletions reflection-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ authors = [
thiserror = "2.0.17"
chrono = "0.4.42"
ciborium = "0.2.2"
p2panda-core = { git = "https://github.com/p2panda/p2panda", rev = "a83a80b2ce0733c9437ceeaae33503d3b3742436" }
p2panda-discovery = { git = "https://github.com/p2panda/p2panda", rev = "a83a80b2ce0733c9437ceeaae33503d3b3742436", package = "p2panda-discovery-next" }
p2panda-net = { git = "https://github.com/p2panda/p2panda", rev = "a83a80b2ce0733c9437ceeaae33503d3b3742436", package = "p2panda-net-next" }
p2panda-store = { git = "https://github.com/p2panda/p2panda", rev = "a83a80b2ce0733c9437ceeaae33503d3b3742436", features = ["sqlite"], default-features = false }
p2panda-stream = { git = "https://github.com/p2panda/p2panda", rev = "a83a80b2ce0733c9437ceeaae33503d3b3742436" }
p2panda-sync = { git = "https://github.com/p2panda/p2panda", rev = "a83a80b2ce0733c9437ceeaae33503d3b3742436", package = "p2panda-sync-next" }
p2panda-core = { git = "https://github.com/p2panda/p2panda", rev = "802319481b65f32e8061a36d8f5d99d7406e52f2" }
p2panda-discovery = { git = "https://github.com/p2panda/p2panda", rev = "802319481b65f32e8061a36d8f5d99d7406e52f2" }
p2panda-net = { git = "https://github.com/p2panda/p2panda", rev = "802319481b65f32e8061a36d8f5d99d7406e52f2" }
p2panda-store = { git = "https://github.com/p2panda/p2panda", rev = "802319481b65f32e8061a36d8f5d99d7406e52f2", features = ["sqlite"], default-features = false }
p2panda-stream = { git = "https://github.com/p2panda/p2panda", rev = "802319481b65f32e8061a36d8f5d99d7406e52f2" }
p2panda-sync = { git = "https://github.com/p2panda/p2panda", rev = "802319481b65f32e8061a36d8f5d99d7406e52f2" }
serde = { version = "1.0.228", features = ["derive"] }
serde_bytes = "0.11.19"
sqlx = { version = "0.8.6", features = ["runtime-tokio", "sqlite", "chrono"], default-features = false }
Expand All @@ -27,4 +27,4 @@ tracing = "0.1"
test-log = { version = "0.2.18", default-features = false, features = ["trace", "color"] }
hex = "0.4.3"
rand_chacha = { version = "0.9.0", features = ["os_rng"] }
iroh = "0.95.1"
iroh = "0.95.1"
8 changes: 4 additions & 4 deletions reflection-node/src/author_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::topic::SubscribableTopic;
use chrono::Utc;
use p2panda_core::cbor::{DecodeError, decode_cbor, encode_cbor};
use p2panda_core::{PrivateKey, PublicKey};
use p2panda_net::streams::EphemeralStream;
use p2panda_net::gossip::GossipHandle;
use tokio::sync::{Mutex, RwLock};
use tracing::error;

Expand Down Expand Up @@ -47,7 +47,7 @@ pub struct AuthorTracker<T> {
last_ping: Mutex<HashMap<PublicKey, Instant>>,
subscribable_topic: Arc<T>,
node: Arc<NodeInner>,
tx: RwLock<Option<EphemeralStream>>,
tx: RwLock<Option<GossipHandle>>,
}

impl<T: SubscribableTopic> AuthorTracker<T> {
Expand All @@ -60,7 +60,7 @@ impl<T: SubscribableTopic> AuthorTracker<T> {
})
}

pub async fn set_topic_tx(&self, tx: Option<EphemeralStream>) {
pub async fn set_topic_tx(&self, tx: Option<GossipHandle>) {
let mut tx_guard = self.tx.write().await;
// Send good bye message to the network
if let Some(tx) = tx_guard.as_ref() {
Expand Down Expand Up @@ -174,7 +174,7 @@ impl<T: SubscribableTopic> AuthorTracker<T> {
}
}

async fn send_message(private_key: &PrivateKey, tx: &EphemeralStream, message: AuthorMessage) {
async fn send_message(private_key: &PrivateKey, tx: &GossipHandle, message: AuthorMessage) {
// FIXME: We need to add the current time to the message,
// because iroh doesn't broadcast twice the same message message.
let author_message = match encode_cbor(&(&message, SystemTime::now())) {
Expand Down
1 change: 1 addition & 0 deletions reflection-node/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod author_tracker;
mod ephemerial_operation;
mod network;
pub mod node;
mod node_inner;
mod operation;
Expand Down
Loading
Loading