mirror of
https://github.com/logos-messaging/logos-messaging-rust-bindings.git
synced 2026-01-04 15:03:08 +00:00
Fix lightpush
This commit is contained in:
parent
39ee1edc45
commit
e54d744471
@ -86,6 +86,9 @@ pub struct WakuMessage {
|
||||
version: WakuMessageVersion,
|
||||
/// Unix timestamp in nanoseconds
|
||||
timestamp: usize,
|
||||
// TODO: implement RLN fields
|
||||
#[serde(flatten)]
|
||||
_extras: serde_json::Value,
|
||||
}
|
||||
|
||||
impl WakuMessage {
|
||||
@ -96,11 +99,13 @@ impl WakuMessage {
|
||||
timestamp: usize,
|
||||
) -> Self {
|
||||
let payload = payload.as_ref().to_vec();
|
||||
|
||||
Self {
|
||||
payload,
|
||||
content_topic,
|
||||
version,
|
||||
timestamp,
|
||||
_extras: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -14,10 +14,13 @@ use crate::node::waku_dafault_pubsub_topic;
|
||||
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_lightpush_publishchar-messagejson-char-topic-char-peerid-int-timeoutms)
|
||||
pub fn waku_lightpush_publish(
|
||||
message: &WakuMessage,
|
||||
pubsub_topic: WakuPubSubTopic,
|
||||
pubsub_topic: Option<WakuPubSubTopic>,
|
||||
peer_id: PeerId,
|
||||
timeout: Duration,
|
||||
timeout: Option<Duration>,
|
||||
) -> Result<MessageId> {
|
||||
let pubsub_topic = pubsub_topic
|
||||
.unwrap_or_else(waku_dafault_pubsub_topic)
|
||||
.to_string();
|
||||
let result = unsafe {
|
||||
CStr::from_ptr(waku_sys::waku_lightpush_publish(
|
||||
CString::new(
|
||||
@ -33,9 +36,13 @@ pub fn waku_lightpush_publish(
|
||||
.expect("CString should build properly from peer id")
|
||||
.into_raw(),
|
||||
timeout
|
||||
.as_millis()
|
||||
.try_into()
|
||||
.expect("Duration as milliseconds should fit in a i32"),
|
||||
.map(|timeout| {
|
||||
timeout
|
||||
.as_millis()
|
||||
.try_into()
|
||||
.expect("Duration as milliseconds should fit in a i32")
|
||||
})
|
||||
.unwrap_or(0),
|
||||
))
|
||||
}
|
||||
.to_str()
|
||||
@ -55,9 +62,9 @@ pub fn waku_lightpush_publish_encrypt_asymmetric(
|
||||
peer_id: PeerId,
|
||||
public_key: &PublicKey,
|
||||
signing_key: Option<&SecretKey>,
|
||||
timeout: Duration,
|
||||
timeout: Option<Duration>,
|
||||
) -> Result<MessageId> {
|
||||
let pk = hex::encode(public_key.serialize());
|
||||
let pk = hex::encode(public_key.serialize_uncompressed());
|
||||
let sk = signing_key
|
||||
.map(|signing_key| hex::encode(signing_key.secret_bytes()))
|
||||
.unwrap_or_else(String::new);
|
||||
@ -85,9 +92,13 @@ pub fn waku_lightpush_publish_encrypt_asymmetric(
|
||||
.expect("CString should build properly from hex encoded signing key")
|
||||
.into_raw(),
|
||||
timeout
|
||||
.as_millis()
|
||||
.try_into()
|
||||
.expect("Duration as milliseconds should fit in a i32"),
|
||||
.map(|timeout| {
|
||||
timeout
|
||||
.as_millis()
|
||||
.try_into()
|
||||
.expect("Duration as milliseconds should fit in a i32")
|
||||
})
|
||||
.unwrap_or(0),
|
||||
))
|
||||
.to_str()
|
||||
.expect("Response should always succeed to load to a &str")
|
||||
@ -105,7 +116,7 @@ pub fn waku_lightpush_publish_encrypt_symmetric(
|
||||
peer_id: PeerId,
|
||||
symmetric_key: &Key<Aes256Gcm>,
|
||||
signing_key: Option<&SecretKey>,
|
||||
timeout: Duration,
|
||||
timeout: Option<Duration>,
|
||||
) -> Result<MessageId> {
|
||||
let symk = hex::encode(symmetric_key.as_slice());
|
||||
let sk = signing_key
|
||||
@ -135,9 +146,13 @@ pub fn waku_lightpush_publish_encrypt_symmetric(
|
||||
.expect("CString should build properly from hex encoded signing key")
|
||||
.into_raw(),
|
||||
timeout
|
||||
.as_millis()
|
||||
.try_into()
|
||||
.expect("Duration as milliseconds should fit in a i32"),
|
||||
.map(|timeout| {
|
||||
timeout
|
||||
.as_millis()
|
||||
.try_into()
|
||||
.expect("Duration as milliseconds should fit in a i32")
|
||||
})
|
||||
.unwrap_or(0),
|
||||
))
|
||||
.to_str()
|
||||
.expect("Response should always succeed to load to a &str")
|
||||
|
||||
@ -230,6 +230,7 @@ impl WakuNodeHandle<Running> {
|
||||
///
|
||||
/// wrapper around [`store::waku_store_query`]
|
||||
pub fn store_query(
|
||||
&self,
|
||||
query: &StoreQuery,
|
||||
peer_id: PeerId,
|
||||
timeout: Duration,
|
||||
@ -241,10 +242,11 @@ impl WakuNodeHandle<Running> {
|
||||
///
|
||||
/// wrapper around [`lightpush::waku_lightpush_publish`]
|
||||
pub fn lightpush_publish(
|
||||
&self,
|
||||
message: &WakuMessage,
|
||||
pubsub_topic: WakuPubSubTopic,
|
||||
pubsub_topic: Option<WakuPubSubTopic>,
|
||||
peer_id: PeerId,
|
||||
timeout: Duration,
|
||||
timeout: Option<Duration>,
|
||||
) -> Result<MessageId> {
|
||||
lightpush::waku_lightpush_publish(message, pubsub_topic, peer_id, timeout)
|
||||
}
|
||||
@ -253,12 +255,13 @@ impl WakuNodeHandle<Running> {
|
||||
///
|
||||
/// wrapper around [`lightpush::waku_lightpush_publish_encrypt_asymmetric`]
|
||||
pub fn lightpush_publish_encrypt_asymmetric(
|
||||
&self,
|
||||
message: &WakuMessage,
|
||||
pubsub_topic: Option<WakuPubSubTopic>,
|
||||
peer_id: PeerId,
|
||||
public_key: &PublicKey,
|
||||
signing_key: Option<&SecretKey>,
|
||||
timeout: Duration,
|
||||
timeout: Option<Duration>,
|
||||
) -> Result<MessageId> {
|
||||
lightpush::waku_lightpush_publish_encrypt_asymmetric(
|
||||
message,
|
||||
@ -274,12 +277,13 @@ impl WakuNodeHandle<Running> {
|
||||
///
|
||||
/// wrapper around [`lightpush::waku_lightpush_publish_encrypt_symmetric`]
|
||||
pub fn lightpush_publish_encrypt_symmetric(
|
||||
&self,
|
||||
message: &WakuMessage,
|
||||
pubsub_topic: Option<WakuPubSubTopic>,
|
||||
peer_id: PeerId,
|
||||
symmetric_key: &Key<Aes256Gcm>,
|
||||
signing_key: Option<&SecretKey>,
|
||||
timeout: Duration,
|
||||
timeout: Option<Duration>,
|
||||
) -> Result<MessageId> {
|
||||
lightpush::waku_lightpush_publish_encrypt_symmetric(
|
||||
message,
|
||||
@ -295,6 +299,7 @@ impl WakuNodeHandle<Running> {
|
||||
///
|
||||
/// wrapper around [`filter::waku_filter_subscribe`]
|
||||
pub fn filter_subscribe(
|
||||
&self,
|
||||
filter_subscription: &FilterSubscription,
|
||||
peer_id: PeerId,
|
||||
timeout: Duration,
|
||||
@ -306,6 +311,7 @@ impl WakuNodeHandle<Running> {
|
||||
///
|
||||
/// wrapper around [`filter::waku_filter_unsubscribe`]
|
||||
pub fn filter_unsubscribe(
|
||||
&self,
|
||||
filter_subscription: &FilterSubscription,
|
||||
timeout: Duration,
|
||||
) -> Result<()> {
|
||||
|
||||
@ -106,6 +106,36 @@ pub fn main() -> Result<(), String> {
|
||||
node.relay_publish_encrypt_asymmetric(&message, None, &pk, Some(&sk), None)?;
|
||||
node.relay_publish_encrypt_symmetric(&message, None, &ssk, Some(&sk), None)?;
|
||||
|
||||
let peer_id = node
|
||||
.peers()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|peer| peer.peer_id())
|
||||
.filter(|id| id.as_str() != node.peer_id().unwrap().as_str())
|
||||
.next()
|
||||
.unwrap()
|
||||
.clone();
|
||||
|
||||
node.lightpush_publish(&message, None, peer_id.clone(), None)?;
|
||||
node.lightpush_publish_encrypt_asymmetric(&message, None, peer_id.clone(), &pk, None, None)?;
|
||||
node.lightpush_publish_encrypt_asymmetric(
|
||||
&message,
|
||||
None,
|
||||
peer_id.clone(),
|
||||
&pk,
|
||||
Some(&sk),
|
||||
None,
|
||||
)?;
|
||||
node.lightpush_publish_encrypt_symmetric(&message, None, peer_id.clone(), &ssk, None, None)?;
|
||||
node.lightpush_publish_encrypt_symmetric(
|
||||
&message,
|
||||
None,
|
||||
peer_id.clone(),
|
||||
&ssk,
|
||||
Some(&sk),
|
||||
None,
|
||||
)?;
|
||||
|
||||
std::thread::sleep(Duration::from_secs(2));
|
||||
node.stop()?;
|
||||
Ok(())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user