mirror of
https://github.com/logos-messaging/logos-messaging-rust-bindings.git
synced 2026-01-07 00:13:10 +00:00
Pipe protocol id
This commit is contained in:
parent
94e643a250
commit
592338b35b
@ -18,6 +18,35 @@ pub type PeerId = String;
|
|||||||
/// Waku message id, hex encoded sha256 digest of the message
|
/// Waku message id, hex encoded sha256 digest of the message
|
||||||
pub type MessageId = String;
|
pub type MessageId = String;
|
||||||
|
|
||||||
|
/// Protocol identifiers
|
||||||
|
#[non_exhaustive]
|
||||||
|
pub enum ProtocolId {
|
||||||
|
Store,
|
||||||
|
Lightpush,
|
||||||
|
Filter,
|
||||||
|
Relay,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ProtocolId {
|
||||||
|
pub fn as_string_with_version(&self, version: &str) -> String {
|
||||||
|
format!("{}/{}", self, version)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for ProtocolId {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
let tag = match self {
|
||||||
|
ProtocolId::Store => "/vac/waku/store",
|
||||||
|
ProtocolId::Lightpush => "/vac/waku/lightpush",
|
||||||
|
ProtocolId::Filter => "/vac/waku/filter",
|
||||||
|
ProtocolId::Relay => "/vac/waku/relay",
|
||||||
|
#[allow(unreachable_patterns)]
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
write!(f, "{}", tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// JsonResponse wrapper.
|
/// JsonResponse wrapper.
|
||||||
/// `go-waku` ffi returns this type as a `char *` as per the [specification](https://rfc.vac.dev/spec/36/#jsonresponse-type)
|
/// `go-waku` ffi returns this type as a `char *` as per the [specification](https://rfc.vac.dev/spec/36/#jsonresponse-type)
|
||||||
/// This is internal, as it is better to use rust plain `Result` type.
|
/// This is internal, as it is better to use rust plain `Result` type.
|
||||||
|
|||||||
@ -13,7 +13,7 @@ pub use node::{
|
|||||||
|
|
||||||
pub use general::{
|
pub use general::{
|
||||||
ContentFilter, DecodedPayload, Encoding, FilterSubscription, MessageId, MessageIndex,
|
ContentFilter, DecodedPayload, Encoding, FilterSubscription, MessageId, MessageIndex,
|
||||||
PagingOptions, PeerId, StoreQuery, StoreResponse, WakuContentTopic, WakuMessage,
|
PagingOptions, PeerId, ProtocolId, StoreQuery, StoreResponse, WakuContentTopic, WakuMessage,
|
||||||
WakuMessageVersion, WakuPubSubTopic,
|
WakuMessageVersion, WakuPubSubTopic,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -12,24 +12,24 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct WakuNodeConfig {
|
pub struct WakuNodeConfig {
|
||||||
/// Listening IP address. Default `0.0.0.0`
|
/// Listening IP address. Default `0.0.0.0`
|
||||||
host: Option<std::net::IpAddr>,
|
pub host: Option<std::net::IpAddr>,
|
||||||
/// Libp2p TCP listening port. Default `60000`. Use `0` for **random**
|
/// Libp2p TCP listening port. Default `60000`. Use `0` for **random**
|
||||||
port: Option<usize>,
|
pub port: Option<usize>,
|
||||||
/// External address to advertise to other nodes. Can be ip4, ip6 or dns4, dns6.
|
/// External address to advertise to other nodes. Can be ip4, ip6 or dns4, dns6.
|
||||||
/// If null, the multiaddress(es) generated from the ip and port specified in the config (or default ones) will be used.
|
/// If null, the multiaddress(es) generated from the ip and port specified in the config (or default ones) will be used.
|
||||||
/// Default: null
|
/// Default: null
|
||||||
advertise_addr: Option<Multiaddr>,
|
pub advertise_addr: Option<Multiaddr>,
|
||||||
/// Secp256k1 private key in Hex format (`0x123...abc`). Default random
|
/// Secp256k1 private key in Hex format (`0x123...abc`). Default random
|
||||||
#[serde(with = "secret_key_serde")]
|
#[serde(with = "secret_key_serde")]
|
||||||
node_key: Option<SecretKey>,
|
pub node_key: Option<SecretKey>,
|
||||||
/// Interval in seconds for pinging peers to keep the connection alive. Default `20`
|
/// Interval in seconds for pinging peers to keep the connection alive. Default `20`
|
||||||
keep_alive_interval: Option<usize>,
|
pub keep_alive_interval: Option<usize>,
|
||||||
/// Enable relay protocol. Default `true`
|
/// Enable relay protocol. Default `true`
|
||||||
relay: Option<bool>,
|
pub relay: Option<bool>,
|
||||||
/// The minimum number of peers required on a topic to allow broadcasting a message. Default `0`
|
/// The minimum number of peers required on a topic to allow broadcasting a message. Default `0`
|
||||||
min_peers_to_publish: Option<usize>,
|
pub min_peers_to_publish: Option<usize>,
|
||||||
/// Enable filter protocol. Default `false`
|
/// Enable filter protocol. Default `false`
|
||||||
filter: Option<bool>,
|
pub filter: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
mod secret_key_serde {
|
mod secret_key_serde {
|
||||||
|
|||||||
@ -18,8 +18,8 @@ use std::time::Duration;
|
|||||||
// crates
|
// crates
|
||||||
// internal
|
// internal
|
||||||
use crate::general::{
|
use crate::general::{
|
||||||
FilterSubscription, MessageId, PeerId, Result, StoreQuery, StoreResponse, WakuMessage,
|
FilterSubscription, MessageId, PeerId, ProtocolId, Result, StoreQuery, StoreResponse,
|
||||||
WakuPubSubTopic,
|
WakuMessage, WakuPubSubTopic,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use config::WakuNodeConfig;
|
pub use config::WakuNodeConfig;
|
||||||
@ -73,7 +73,7 @@ impl<State: WakuNodeState> WakuNodeHandle<State> {
|
|||||||
/// Add a node multiaddress and protocol to the waku node’s peerstore
|
/// Add a node multiaddress and protocol to the waku node’s peerstore
|
||||||
///
|
///
|
||||||
/// wrapper around [`peers::waku_add_peers`]
|
/// wrapper around [`peers::waku_add_peers`]
|
||||||
pub fn add_peer(&self, address: Multiaddr, protocol_id: usize) -> Result<PeerId> {
|
pub fn add_peer(&self, address: Multiaddr, protocol_id: ProtocolId) -> Result<PeerId> {
|
||||||
peers::waku_add_peers(address, protocol_id)
|
peers::waku_add_peers(address, protocol_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,11 +7,11 @@ use std::time::Duration;
|
|||||||
use multiaddr::Multiaddr;
|
use multiaddr::Multiaddr;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
// internal
|
// internal
|
||||||
use crate::general::{JsonResponse, PeerId, Result};
|
use crate::general::{JsonResponse, PeerId, ProtocolId, Result};
|
||||||
|
|
||||||
/// Add a node multiaddress and protocol to the waku node’s peerstore.
|
/// Add a node multiaddress and protocol to the waku node’s peerstore.
|
||||||
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_add_peerchar-address-char-protocolid)
|
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_add_peerchar-address-char-protocolid)
|
||||||
pub fn waku_add_peers(address: Multiaddr, protocol_id: usize) -> Result<PeerId> {
|
pub fn waku_add_peers(address: Multiaddr, protocol_id: ProtocolId) -> Result<PeerId> {
|
||||||
let response = unsafe {
|
let response = unsafe {
|
||||||
CStr::from_ptr(waku_sys::waku_add_peer(
|
CStr::from_ptr(waku_sys::waku_add_peer(
|
||||||
CString::new(address.to_string())
|
CString::new(address.to_string())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user