Skip to content

Commit

Permalink
Adapt usage of PushService now that it's not a trait anymore (#272)
Browse files Browse the repository at this point in the history
* Change usage of HyperPushService to PushService
* Print all type of content body in presage-cli --receive
* Point to libsignal-service-rs 701ee93358b3fce75e26489b530e807a76254166
  • Loading branch information
gferon authored Oct 17, 2024
1 parent 204c677 commit ca955c7
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 33 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ resolver = "2"
curve25519-dalek = { git = 'https://github.com/signalapp/curve25519-dalek', tag = 'signal-curve25519-4.1.3' }

# [patch."https://github.com/whisperfish/libsignal-service-rs.git"]
# libsignal-service = { path = "../libsignal-service-rs/libsignal-service" }
# libsignal-service-hyper = { path = "../libsignal-service-rs/libsignal-service-hyper" }
# libsignal-service = { path = "../libsignal-service-rs" }
22 changes: 19 additions & 3 deletions presage-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ use presage::libsignal_service::zkgroup::GroupMasterKeyBytes;
use presage::libsignal_service::ServiceAddress;
use presage::libsignal_service::{groups_v2::Group, prelude::ProfileKey};
use presage::manager::ReceivingMode;
use presage::proto::receipt_message;
use presage::proto::EditMessage;
use presage::proto::ReceiptMessage;
use presage::proto::SyncMessage;
use presage::store::ContentExt;
use presage::{
Expand Down Expand Up @@ -403,6 +405,7 @@ fn print_message<S: Store>(
data_message: Some(data_message),
..
}) => format_data_message(&thread, data_message).map(|body| Msg::Received(&thread, body)),
ContentBody::EditMessage(EditMessage { .. }) => None,
ContentBody::SynchronizeMessage(SyncMessage {
sent:
Some(Sent {
Expand All @@ -423,11 +426,24 @@ fn print_message<S: Store>(
}),
..
}) => format_data_message(&thread, data_message).map(|body| Msg::Sent(&thread, body)),
ContentBody::SynchronizeMessage(SyncMessage { .. }) => None,
ContentBody::CallMessage(_) => Some(Msg::Received(&thread, "is calling!".into())),
ContentBody::TypingMessage(_) => Some(Msg::Received(&thread, "is typing...".into())),
content_body => {
warn!(?content_body, "unsupported message");
None
ContentBody::ReceiptMessage(ReceiptMessage {
r#type: receipt_type,
timestamp,
}) => Some(Msg::Received(
&thread,
format!(
"got {:?} receipt for messages sent at {timestamp:?}",
receipt_message::Type::try_from(receipt_type.unwrap_or_default()).unwrap()
),
)),
ContentBody::StoryMessage(story) => {
Some(Msg::Received(&thread, format!("new story: {story:?}")))
}
ContentBody::PniSignatureMessage(_) => {
Some(Msg::Received(&thread, "got PNI signature message".into()))
}
} {
let ts = content.timestamp();
Expand Down
3 changes: 1 addition & 2 deletions presage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ edition = "2021"
license = "AGPL-3.0-only"

[dependencies]
libsignal-service = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "f99ff8324378ea653dbd5aa0c5d55e4414b34e23" }
libsignal-service-hyper = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "f99ff8324378ea653dbd5aa0c5d55e4414b34e23" }
libsignal-service = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "701ee93358b3fce75e26489b530e807a76254166" }

base64 = "0.22"
futures = "0.3"
Expand Down
7 changes: 3 additions & 4 deletions presage/src/manager/confirmation.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use libsignal_service::configuration::{ServiceConfiguration, SignalServers};
use libsignal_service::messagepipe::ServiceCredentials;
use libsignal_service::prelude::phonenumber::PhoneNumber;
use libsignal_service::prelude::PushService;
use libsignal_service::protocol::IdentityKeyPair;
use libsignal_service::provisioning::generate_registration_id;
use libsignal_service::push_service::{
AccountAttributes, DeviceCapabilities, PushService, RegistrationMethod, ServiceIds,
VerifyAccountResponse,
AccountAttributes, DeviceCapabilities, RegistrationMethod, ServiceIds, VerifyAccountResponse,
};
use libsignal_service::zkgroup::profiles::ProfileKey;
use libsignal_service::AccountManager;
use libsignal_service_hyper::push_service::HyperPushService;
use rand::RngCore;
use tracing::trace;

Expand Down Expand Up @@ -61,7 +60,7 @@ impl<S: Store> Manager<S, Confirmation> {
};

let service_configuration: ServiceConfiguration = signal_servers.into();
let mut identified_push_service = HyperPushService::new(
let mut identified_push_service = PushService::new(
service_configuration,
Some(credentials),
crate::USER_AGENT.to_string(),
Expand Down
4 changes: 2 additions & 2 deletions presage/src/manager/linking.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use futures::channel::{mpsc, oneshot};
use futures::{future, StreamExt};
use libsignal_service::configuration::{ServiceConfiguration, SignalServers};
use libsignal_service::prelude::PushService;
use libsignal_service::protocol::IdentityKeyPair;
use libsignal_service::provisioning::{
link_device, NewDeviceRegistration, SecondaryDeviceProvisioning,
};
use libsignal_service_hyper::push_service::HyperPushService;
use rand::distributions::{Alphanumeric, DistString};
use rand::rngs::StdRng;
use rand::{RngCore, SeedableRng};
Expand Down Expand Up @@ -76,7 +76,7 @@ impl<S: Store> Manager<S, Linking> {

let service_configuration: ServiceConfiguration = signal_servers.into();
let push_service =
HyperPushService::new(service_configuration, None, crate::USER_AGENT.to_string());
PushService::new(service_configuration, None, crate::USER_AGENT.to_string());

let (tx, mut rx) = mpsc::channel(1);

Expand Down
34 changes: 16 additions & 18 deletions presage/src/manager/registered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use libsignal_service::websocket::SignalWebSocket;
use libsignal_service::zkgroup::groups::{GroupMasterKey, GroupSecretParams};
use libsignal_service::zkgroup::profiles::ProfileKey;
use libsignal_service::{cipher, AccountManager, Profile, ServiceAddress};
use libsignal_service_hyper::push_service::HyperPushService;
use rand::rngs::StdRng;
use rand::SeedableRng;
use serde::{Deserialize, Serialize};
Expand All @@ -49,7 +48,7 @@ use crate::store::{ContentsStore, Sticker, StickerPack, StickerPackManifest, Sto
use crate::{AvatarBytes, Error, Manager};

type ServiceCipher<S> = cipher::ServiceCipher<S, StdRng>;
type MessageSender<S> = libsignal_service::prelude::MessageSender<HyperPushService, S, StdRng>;
type MessageSender<S> = libsignal_service::prelude::MessageSender<S, StdRng>;

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum RegistrationType {
Expand All @@ -60,8 +59,8 @@ pub enum RegistrationType {
/// Manager state when the client is registered and can send and receive messages from Signal
#[derive(Clone)]
pub struct Registered {
pub(crate) identified_push_service: OnceLock<HyperPushService>,
pub(crate) unidentified_push_service: OnceLock<HyperPushService>,
pub(crate) identified_push_service: OnceLock<PushService>,
pub(crate) unidentified_push_service: OnceLock<PushService>,
pub(crate) identified_websocket: Arc<Mutex<Option<SignalWebSocket>>>,
pub(crate) unidentified_websocket: Arc<Mutex<Option<SignalWebSocket>>>,
pub(crate) unidentified_sender_certificate: Option<SenderCertificate>,
Expand Down Expand Up @@ -174,11 +173,11 @@ impl<S: Store> Manager<S, Registered> {
/// Returns a clone of a cached push service (with credentials).
///
/// If no service is yet cached, it will create and cache one.
fn identified_push_service(&self) -> HyperPushService {
fn identified_push_service(&self) -> PushService {
self.state
.identified_push_service
.get_or_init(|| {
HyperPushService::new(
PushService::new(
self.state.service_configuration(),
self.credentials(),
crate::USER_AGENT.to_string(),
Expand All @@ -190,11 +189,11 @@ impl<S: Store> Manager<S, Registered> {
/// Returns a clone of a cached push service (without credentials).
///
/// If no service is yet cached, it will create and cache one.
fn unidentified_push_service(&self) -> HyperPushService {
fn unidentified_push_service(&self) -> PushService {
self.state
.unidentified_push_service
.get_or_init(|| {
HyperPushService::new(
PushService::new(
self.state.service_configuration(),
None,
crate::USER_AGENT.to_string(),
Expand Down Expand Up @@ -590,9 +589,7 @@ impl<S: Store> Manager<S, Registered> {
self.receive_messages_stream(mode).await
}

fn groups_manager(
&self,
) -> Result<GroupsManager<HyperPushService, InMemoryCredentialsCache>, Error<S::Error>> {
fn groups_manager(&self) -> Result<GroupsManager<InMemoryCredentialsCache>, Error<S::Error>> {
let service_configuration = self.state.service_configuration();
let server_public_params = service_configuration.zkgroup_server_public_params;

Expand All @@ -613,11 +610,11 @@ impl<S: Store> Manager<S, Registered> {
) -> Result<impl Stream<Item = Content>, Error<S::Error>> {
struct StreamState<Receiver, Store, AciStore> {
encrypted_messages: Receiver,
message_receiver: MessageReceiver<HyperPushService>,
message_receiver: MessageReceiver,
service_cipher: ServiceCipher<AciStore>,
push_service: HyperPushService,
push_service: PushService,
store: Store,
groups_manager: GroupsManager<HyperPushService, InMemoryCredentialsCache>,
groups_manager: GroupsManager<InMemoryCredentialsCache>,
mode: ReceivingMode,
}

Expand Down Expand Up @@ -1265,6 +1262,7 @@ impl<S: Store> Manager<S, Registered> {
&store.aci_protocol_store(),
&store.pni_protocol_store(),
credentials,
None,
)
.await?;
Ok(())
Expand Down Expand Up @@ -1351,7 +1349,7 @@ pub enum ReceivingMode {

async fn upsert_group<S: Store>(
store: &S,
groups_manager: &mut GroupsManager<HyperPushService, InMemoryCredentialsCache>,
groups_manager: &mut GroupsManager<InMemoryCredentialsCache>,
master_key_bytes: &[u8],
revision: &u32,
) -> Result<Option<Group>, Error<S::Error>> {
Expand Down Expand Up @@ -1388,7 +1386,7 @@ async fn upsert_group<S: Store>(
/// Download and decrypt a sticker manifest
async fn download_sticker_pack<C: ContentsStore>(
mut store: C,
mut push_service: HyperPushService,
mut push_service: PushService,
operation: &StickerPackOperation,
) -> Result<StickerPack, Error<C::ContentsStoreError>> {
debug!("downloading sticker pack");
Expand Down Expand Up @@ -1438,7 +1436,7 @@ async fn download_sticker_pack<C: ContentsStore>(
/// Downloads and decrypts a single sticker
async fn download_sticker<C: ContentsStore>(
_store: &mut C,
push_service: &mut HyperPushService,
push_service: &mut PushService,
pack_id: &[u8],
pack_key: &[u8],
sticker_id: u32,
Expand All @@ -1464,7 +1462,7 @@ async fn download_sticker<C: ContentsStore>(
/// This is required when storing outgoing messages, as in this case the appropriate storage place cannot be derived from the message itself.
async fn save_message<S: Store>(
store: &mut S,
push_service: &mut HyperPushService,
push_service: &mut PushService,
message: Content,
override_thread: Option<Thread>,
) -> Result<(), Error<S::Error>> {
Expand Down
3 changes: 1 addition & 2 deletions presage/src/manager/registration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use libsignal_service::configuration::{ServiceConfiguration, SignalServers};
use libsignal_service::prelude::phonenumber::PhoneNumber;
use libsignal_service::push_service::{PushService, VerificationTransport};
use libsignal_service_hyper::push_service::HyperPushService;
use rand::distributions::{Alphanumeric, DistString};
use rand::rngs::StdRng;
use rand::SeedableRng;
Expand Down Expand Up @@ -86,7 +85,7 @@ impl<S: Store> Manager<S, Registration> {

let service_configuration: ServiceConfiguration = signal_servers.into();
let mut push_service =
HyperPushService::new(service_configuration, None, crate::USER_AGENT.to_string());
PushService::new(service_configuration, None, crate::USER_AGENT.to_string());

trace!("creating registration verification session");

Expand Down

0 comments on commit ca955c7

Please sign in to comment.