Skip to content

Commit

Permalink
Merge pull request #314 from whisperfish/add-destination-to-metadata
Browse files Browse the repository at this point in the history
Add destination ServiceAddress to Metadata
  • Loading branch information
rubdos committed Aug 3, 2024
2 parents bcb2821 + 5262cd9 commit c3f809a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions libsignal-service/src/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ where
)
.await?;
let metadata = Metadata {
destination: envelope.destination_address(),
sender: envelope.source_address(),
sender_device: envelope.source_device(),
timestamp: envelope.server_timestamp(),
Expand Down Expand Up @@ -201,6 +202,7 @@ where
Type::PlaintextContent => {
tracing::warn!(?envelope, "Envelope with plaintext content. This usually indicates a decryption retry.");
let metadata = Metadata {
destination: envelope.destination_address(),
sender: envelope.source_address(),
sender_device: envelope.source_device(),
timestamp: envelope.server_timestamp(),
Expand All @@ -221,6 +223,7 @@ where
)
.await?;
let metadata = Metadata {
destination: envelope.destination_address(),
sender: envelope.source_address(),
sender_device: envelope.source_device(),
timestamp: envelope.timestamp(),
Expand Down Expand Up @@ -290,6 +293,7 @@ where
};

let metadata = Metadata {
destination: envelope.destination_address(),
sender,
sender_device: device_id.into(),
timestamp: envelope.timestamp(),
Expand Down
1 change: 1 addition & 0 deletions libsignal-service/src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mod story_message;
#[derive(Clone, Debug)]
pub struct Metadata {
pub sender: crate::ServiceAddress,
pub destination: crate::ServiceAddress,
pub sender_device: u32,
pub timestamp: u64,
pub needs_receipt: bool,
Expand Down
10 changes: 9 additions & 1 deletion libsignal-service/src/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,18 @@ impl Envelope {
pub fn source_address(&self) -> ServiceAddress {
match self.source_service_id.as_deref() {
Some(service_id) => ServiceAddress::try_from(service_id)
.expect("invalid ProtocolAddress UUID or prefix"),
.expect("invalid source ProtocolAddress UUID or prefix"),
None => panic!("source_service_id is set"),
}
}

pub fn destination_address(&self) -> ServiceAddress {
match self.destination_service_id.as_deref() {
Some(service_id) => ServiceAddress::try_from(service_id)
.expect("invalid destination ProtocolAddress UUID or prefix"),
None => panic!("destination_address is set"),
}
}
}

#[derive(serde::Serialize, serde::Deserialize)]
Expand Down
2 changes: 0 additions & 2 deletions libsignal-service/src/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ impl<Service: PushService> MessageReceiver<Service> {
&mut self,
allow_stories: bool,
) -> Result<Vec<Envelope>, ServiceError> {
use std::convert::TryFrom;

let entities = self.service.get_messages(allow_stories).await?;
let entities = entities
.into_iter()
Expand Down

0 comments on commit c3f809a

Please sign in to comment.