feat: add ephemeral and meta fields
This commit is contained in:
parent
27597d76b5
commit
d090d9cdd8
|
@ -1674,7 +1674,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
|||
|
||||
[[package]]
|
||||
name = "waku-bindings"
|
||||
version = "0.1.0-rc.2"
|
||||
version = "0.1.0-rc.3"
|
||||
dependencies = [
|
||||
"aes-gcm",
|
||||
"base64 0.21.0",
|
||||
|
@ -1697,7 +1697,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "waku-sys"
|
||||
version = "0.1.0-rc.2"
|
||||
version = "0.1.0-rc.3"
|
||||
dependencies = [
|
||||
"bindgen",
|
||||
]
|
||||
|
|
|
@ -193,12 +193,15 @@ fn run_app<B: Backend>(
|
|||
let message_content: String = app.input.drain(..).collect();
|
||||
let message = Chat2Message::new(&app.nick, &message_content);
|
||||
let mut buff = Vec::new();
|
||||
let meta = Vec::new();
|
||||
Message::encode(&message, &mut buff)?;
|
||||
let waku_message = WakuMessage::new(
|
||||
buff,
|
||||
TOY_CHAT_CONTENT_TOPIC.clone(),
|
||||
1,
|
||||
Utc::now().timestamp_nanos() as usize,
|
||||
meta,
|
||||
false
|
||||
);
|
||||
if let Err(e) =
|
||||
app.node_handle
|
||||
|
|
|
@ -89,25 +89,33 @@ pub struct WakuMessage {
|
|||
version: WakuMessageVersion,
|
||||
/// Unix timestamp in nanoseconds
|
||||
timestamp: usize,
|
||||
#[serde(with = "base64_serde")]
|
||||
meta: Vec<u8>,
|
||||
ephemeral: bool,
|
||||
// TODO: implement RLN fields
|
||||
#[serde(flatten)]
|
||||
_extras: serde_json::Value,
|
||||
}
|
||||
|
||||
impl WakuMessage {
|
||||
pub fn new<PAYLOAD: AsRef<[u8]>>(
|
||||
pub fn new<PAYLOAD: AsRef<[u8]>, META: AsRef<[u8]>>(
|
||||
payload: PAYLOAD,
|
||||
content_topic: WakuContentTopic,
|
||||
version: WakuMessageVersion,
|
||||
timestamp: usize,
|
||||
meta: META,
|
||||
ephemeral: bool
|
||||
) -> Self {
|
||||
let payload = payload.as_ref().to_vec();
|
||||
let meta = meta.as_ref().to_vec();
|
||||
|
||||
Self {
|
||||
payload,
|
||||
content_topic,
|
||||
version,
|
||||
timestamp,
|
||||
meta,
|
||||
ephemeral,
|
||||
_extras: Default::default(),
|
||||
}
|
||||
}
|
||||
|
@ -128,6 +136,14 @@ impl WakuMessage {
|
|||
self.timestamp
|
||||
}
|
||||
|
||||
pub fn meta(&self) -> &[u8] {
|
||||
&self.meta
|
||||
}
|
||||
|
||||
pub fn ephemeral(&self) -> bool {
|
||||
self.ephemeral
|
||||
}
|
||||
|
||||
/// Try decode the message with an expected symmetric key
|
||||
///
|
||||
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_decode_symmetricchar-messagejson-char-symmetrickey)
|
||||
|
@ -555,7 +571,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn deserialize_waku_message() {
|
||||
let message = "{\"payload\":\"SGkgZnJvbSDwn6aAIQ==\",\"contentTopic\":\"/toychat/2/huilong/proto\",\"timestamp\":1665580926660}";
|
||||
let message = "{\"payload\":\"SGkgZnJvbSDwn6aAIQ==\",\"contentTopic\":\"/toychat/2/huilong/proto\",\"timestamp\":1665580926660,\"ephemeral\":true,\"meta\":\"SGkgZnJvbSDwn6aAIQ==\"}";
|
||||
let _: WakuMessage = serde_json::from_str(message).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,6 +119,8 @@ async fn test_echo_messages(
|
|||
.as_millis()
|
||||
.try_into()
|
||||
.unwrap(),
|
||||
Vec::new(),
|
||||
false
|
||||
);
|
||||
|
||||
let (tx, mut rx) = mpsc::channel(1);
|
||||
|
|
Loading…
Reference in New Issue