Skip to content

Commit 4fd6489

Browse files
author
no30bit
committed
wip
1 parent 86bba7f commit 4fd6489

File tree

4 files changed

+37
-18
lines changed

4 files changed

+37
-18
lines changed

hermes/bin/src/cli/playground.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn init_ipfs(temp_dir: &TempDir) -> anyhow::Result<()> {
115115
ipfs::bootstrap(ipfs::Config {
116116
base_dir: ipfs_dir.as_path(),
117117
// enable bootstrapping the IPFS node to default addresses
118-
default_bootstrap: true,
118+
default_bootstrap: false,
119119
})
120120
}
121121

hermes/bin/src/ipfs/api.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,19 @@ pub(crate) fn hermes_ipfs_subscribe(
153153
app_name: &ApplicationName,
154154
topic: PubsubTopic,
155155
) -> Result<bool, Errno> {
156+
dbg!();
156157
let ipfs = HERMES_IPFS.get().ok_or(Errno::ServiceUnavailable)?;
157158
tracing::debug!(app_name = %app_name, pubsub_topic = %topic, "subscribing to PubSub topic");
159+
dbg!();
158160
if ipfs.apps.topic_subscriptions_contains(kind, &topic) {
159161
tracing::debug!(app_name = %app_name, pubsub_topic = %topic, "topic subscription stream already exists");
160162
} else {
163+
dbg!();
161164
let handle = ipfs.pubsub_subscribe(kind, &topic)?;
165+
dbg!();
162166
ipfs.apps.added_topic_stream(kind, topic.clone(), handle);
163167
tracing::debug!(app_name = %app_name, pubsub_topic = %topic, "added subscription topic stream");
168+
dbg!();
164169
}
165170
ipfs.apps
166171
.added_app_topic_subscription(kind, app_name.clone(), topic);

hermes/bin/src/ipfs/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ pub fn bootstrap(config: Config) -> anyhow::Result<()> {
7979

8080
/// Hermes IPFS Internal Node
8181
pub(crate) struct HermesIpfsNode<N>
82-
where N: hermes_ipfs::rust_ipfs::NetworkBehaviour<ToSwarm = Infallible> + Send + Sync
82+
where
83+
N: hermes_ipfs::rust_ipfs::NetworkBehaviour<ToSwarm = Infallible> + Send + Sync,
8384
{
8485
/// Send events to the IPFS node.
8586
sender: Option<mpsc::Sender<IpfsCommand>>,
@@ -90,7 +91,8 @@ where N: hermes_ipfs::rust_ipfs::NetworkBehaviour<ToSwarm = Infallible> + Send +
9091
}
9192

9293
impl<N> HermesIpfsNode<N>
93-
where N: hermes_ipfs::rust_ipfs::NetworkBehaviour<ToSwarm = Infallible> + Send + Sync
94+
where
95+
N: hermes_ipfs::rust_ipfs::NetworkBehaviour<ToSwarm = Infallible> + Send + Sync,
9496
{
9597
/// Create, initialize, and bootstrap a new `HermesIpfsNode`
9698
pub(crate) fn init(
@@ -326,11 +328,13 @@ where N: hermes_ipfs::rust_ipfs::NetworkBehaviour<ToSwarm = Infallible> + Send +
326328
topic: &PubsubTopic,
327329
) -> Result<JoinHandle<()>, Errno> {
328330
let (cmd_tx, cmd_rx) = oneshot::channel();
331+
dbg!();
329332
self.sender
330333
.as_ref()
331334
.ok_or(Errno::PubsubSubscribeError)?
332-
.blocking_send(IpfsCommand::Subscribe(topic.clone(), kind, cmd_tx))
335+
.blocking_send(IpfsCommand::Subscribe(dbg!(topic).clone(), kind, cmd_tx))
333336
.map_err(|_| Errno::PubsubSubscribeError)?;
337+
dbg!();
334338
cmd_rx
335339
.blocking_recv()
336340
.map_err(|_| Errno::PubsubSubscribeError)?

hermes/bin/src/ipfs/task.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,22 @@ pub(crate) async fn ipfs_command_handler(
138138
send_response(result, tx);
139139
},
140140
IpfsCommand::Subscribe(topic, kind, tx) => {
141+
dbg!();
141142
let stream = hermes_node
142143
.pubsub_subscribe(&topic)
143144
.await
144145
.map_err(|_| Errno::PubsubSubscribeError)?;
145-
let message_handler = TopicMessageHandler::new(&topic, match kind {
146-
SubscriptionKind::Default => topic_message_handler,
147-
SubscriptionKind::DocSync => doc_sync_topic_message_handler,
148-
});
146+
dbg!();
147+
148+
let message_handler = TopicMessageHandler::new(
149+
&topic,
150+
match kind {
151+
SubscriptionKind::Default => topic_message_handler,
152+
SubscriptionKind::DocSync => doc_sync_topic_message_handler,
153+
},
154+
);
155+
dbg!();
156+
149157
let subscription_handler =
150158
TopicSubscriptionStatusHandler::new(&topic, topic_subscription_handler);
151159
let handle = hermes_ipfs::subscription_stream_task(
@@ -183,12 +191,10 @@ pub(crate) async fn ipfs_command_handler(
183191
},
184192
IpfsCommand::Identity(peer_id, tx) => {
185193
let peer_id = match peer_id {
186-
Some(peer_id) => {
187-
Some(
188-
hermes_ipfs::PeerId::from_str(&peer_id)
189-
.map_err(|_| Errno::InvalidPeerId)?,
190-
)
191-
},
194+
Some(peer_id) => Some(
195+
hermes_ipfs::PeerId::from_str(&peer_id)
196+
.map_err(|_| Errno::InvalidPeerId)?,
197+
),
192198
None => None,
193199
};
194200

@@ -207,7 +213,8 @@ pub(crate) async fn ipfs_command_handler(
207213

208214
/// A handler for messages from the IPFS pubsub topic
209215
pub(super) struct TopicMessageHandler<T>
210-
where T: Fn(hermes_ipfs::rust_ipfs::GossipsubMessage, String) + Send + Sync + 'static
216+
where
217+
T: Fn(hermes_ipfs::rust_ipfs::GossipsubMessage, String) + Send + Sync + 'static,
211218
{
212219
/// The topic.
213220
topic: String,
@@ -217,7 +224,8 @@ where T: Fn(hermes_ipfs::rust_ipfs::GossipsubMessage, String) + Send + Sync + 's
217224
}
218225

219226
impl<T> TopicMessageHandler<T>
220-
where T: Fn(hermes_ipfs::rust_ipfs::GossipsubMessage, String) + Send + Sync + 'static
227+
where
228+
T: Fn(hermes_ipfs::rust_ipfs::GossipsubMessage, String) + Send + Sync + 'static,
221229
{
222230
/// Creates the new handler.
223231
pub fn new(
@@ -241,7 +249,8 @@ where T: Fn(hermes_ipfs::rust_ipfs::GossipsubMessage, String) + Send + Sync + 's
241249

242250
/// A handler for subscribe/unsubscribe events from the IPFS pubsub topic
243251
pub(super) struct TopicSubscriptionStatusHandler<T>
244-
where T: Fn(hermes_ipfs::SubscriptionStatusEvent, String) + Send + Sync + 'static
252+
where
253+
T: Fn(hermes_ipfs::SubscriptionStatusEvent, String) + Send + Sync + 'static,
245254
{
246255
/// The topic.
247256
topic: String,
@@ -251,7 +260,8 @@ where T: Fn(hermes_ipfs::SubscriptionStatusEvent, String) + Send + Sync + 'stati
251260
}
252261

253262
impl<T> TopicSubscriptionStatusHandler<T>
254-
where T: Fn(hermes_ipfs::SubscriptionStatusEvent, String) + Send + Sync + 'static
263+
where
264+
T: Fn(hermes_ipfs::SubscriptionStatusEvent, String) + Send + Sync + 'static,
255265
{
256266
/// Creates the new handler.
257267
pub fn new(

0 commit comments

Comments
 (0)