Skip to content

Commit f12297f

Browse files
committed
feat(relay): add support for DMQ messages
1 parent be9c001 commit f12297f

File tree

4 files changed

+43
-19
lines changed

4 files changed

+43
-19
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-relay/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repository = { workspace = true }
1111

1212
[features]
1313
bundle_tls = ["reqwest/native-tls-vendored"]
14-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
14+
future_dmq = ["dep:mithril-dmq"]
1515

1616
[dependencies]
1717
anyhow = { workspace = true }
@@ -35,6 +35,7 @@ libp2p = { version = "0.55.0", features = [
3535
"yamux",
3636
] }
3737
mithril-common = { path = "../mithril-common", features = ["full"] }
38+
mithril-dmq = { path = "../internal/mithril-dmq", optional = true }
3839
mithril-doc = { path = "../internal/mithril-doc" }
3940
mithril-test-http-server = { path = "../internal/tests/mithril-test-http-server" }
4041
reqwest = { workspace = true, features = [

mithril-relay/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ pub use relay::SignerRelayMode;
1616

1717
/// The P2P topic names used by Mithril
1818
pub mod mithril_p2p_topic {
19-
/// The topic name where signer registrations are published
20-
pub const SIGNERS: &str = "mithril/signers";
19+
/// The topic name where HTTP signer registrations are published
20+
pub const SIGNERS_HTTP: &str = "mithril/signers/http";
2121

22-
/// The topic name where signatures are published
23-
pub const SIGNATURES: &str = "mithril/signatures";
22+
/// The topic name where HTTP signatures are published
23+
pub const SIGNATURES_HTTP: &str = "mithril/signatures/http";
24+
25+
/// The topic name where DMQ signatures are published
26+
pub const SIGNATURES_DMQ: &str = "mithril/signatures/dmq";
2427
}
2528

2629
#[cfg(test)]

mithril-relay/src/p2p/peer.rs

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use mithril_common::{
1414
logging::LoggerExtensions,
1515
messages::{RegisterSignatureMessageHttp, RegisterSignerMessage},
1616
};
17+
use mithril_dmq::DmqMessage;
1718
use serde::{Deserialize, Serialize};
1819
use slog::{Logger, debug, info};
1920
use std::{collections::HashMap, time::Duration};
@@ -63,11 +64,14 @@ pub type TopicName = String;
6364
/// The broadcast message received from a Gossip sub event
6465
#[derive(Serialize, Deserialize)]
6566
pub enum BroadcastMessage {
66-
/// A signer registration message received from the Gossip sub
67-
RegisterSigner(RegisterSignerMessage),
67+
/// A HTTP signer registration message received from the Gossip sub
68+
RegisterSignerHttp(RegisterSignerMessage),
6869

69-
/// A signature registration message received from the Gossip sub
70-
RegisterSignature(RegisterSignatureMessageHttp),
70+
/// A HTTP signature registration message received from the Gossip sub
71+
RegisterSignatureHttp(RegisterSignatureMessageHttp),
72+
73+
/// A DMQ signature registration message received from the Gossip sub
74+
RegisterSignatureDmq(DmqMessage),
7175
}
7276

7377
/// A peer in the P2P network
@@ -95,12 +99,16 @@ impl Peer {
9599
fn build_topics() -> HashMap<TopicName, gossipsub::IdentTopic> {
96100
HashMap::from([
97101
(
98-
mithril_p2p_topic::SIGNATURES.into(),
99-
gossipsub::IdentTopic::new(mithril_p2p_topic::SIGNATURES),
102+
mithril_p2p_topic::SIGNATURES_HTTP.into(),
103+
gossipsub::IdentTopic::new(mithril_p2p_topic::SIGNATURES_HTTP),
104+
),
105+
(
106+
mithril_p2p_topic::SIGNATURES_DMQ.into(),
107+
gossipsub::IdentTopic::new(mithril_p2p_topic::SIGNATURES_DMQ),
100108
),
101109
(
102-
mithril_p2p_topic::SIGNERS.into(),
103-
gossipsub::IdentTopic::new(mithril_p2p_topic::SIGNERS),
110+
mithril_p2p_topic::SIGNERS_HTTP.into(),
111+
gossipsub::IdentTopic::new(mithril_p2p_topic::SIGNERS_HTTP),
104112
),
105113
])
106114
}
@@ -217,14 +225,25 @@ impl Peer {
217225
}
218226
}
219227

220-
/// Publish a signature on the P2P pubsub
221-
pub fn publish_signature(
228+
/// Publish a HTTP signature on the P2P pubsub
229+
pub fn publish_signature_http(
222230
&mut self,
223231
message: &RegisterSignatureMessageHttp,
224232
) -> StdResult<gossipsub::MessageId> {
225233
self.publish_broadcast_message(
226-
&BroadcastMessage::RegisterSignature(message.to_owned()),
227-
mithril_p2p_topic::SIGNATURES,
234+
&BroadcastMessage::RegisterSignatureHttp(message.to_owned()),
235+
mithril_p2p_topic::SIGNATURES_HTTP,
236+
)
237+
}
238+
239+
/// Publish a DMQ signature on the P2P pubsub
240+
pub fn publish_signature_dmq(
241+
&mut self,
242+
message: &DmqMessage,
243+
) -> StdResult<gossipsub::MessageId> {
244+
self.publish_broadcast_message(
245+
&BroadcastMessage::RegisterSignatureDmq(message.to_owned()),
246+
mithril_p2p_topic::SIGNATURES_DMQ,
228247
)
229248
}
230249

@@ -270,8 +289,8 @@ impl Peer {
270289
message: &RegisterSignerMessage,
271290
) -> StdResult<gossipsub::MessageId> {
272291
self.publish_broadcast_message(
273-
&BroadcastMessage::RegisterSigner(message.to_owned()),
274-
mithril_p2p_topic::SIGNERS,
292+
&BroadcastMessage::RegisterSignerHttp(message.to_owned()),
293+
mithril_p2p_topic::SIGNERS_HTTP,
275294
)
276295
}
277296

0 commit comments

Comments
 (0)