Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: FM-321 move orb relay client #340

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
db89c67
Orb Relay support (#1297)
andronat Sep 25, 2024
8e42076
orb-relay-client: Fix reliability issues and hash session_id (#1300)
andronat Sep 25, 2024
bb6e4ef
Skip messages that come from an unexpected src_id (#1301)
andronat Sep 25, 2024
07b04bf
User Feedback on unsuccessful signups (#1295)
karelispanagiotis Sep 26, 2024
7ceb5e3
Use BTree to order keys (#1303)
andronat Sep 26, 2024
4ba10d3
Make Orb-ID announcement more reliable (#1305)
andronat Sep 27, 2024
16fbba7
Add additional orb-relay messages (#1309)
karelispanagiotis Sep 27, 2024
34f5b06
Implement a simple client-side heartbeat (#1314)
andronat Oct 1, 2024
a6e1055
Remove hashing of dst_id (#1316)
andronat Oct 1, 2024
3f6c008
Report CaptureStarted (#1324)
andronat Oct 3, 2024
e804f95
Move to new orb-relay architecture (#1329)
andronat Oct 6, 2024
19048bb
Fix message ordering and protobuf namespace (#1332)
andronat Oct 7, 2024
b70381c
foss: add LICENSE, license-file, repository, edition (#1340)
TheButlah Oct 9, 2024
77fecbb
Decode msgs for type Any to known types (#1353)
andronat Oct 12, 2024
a780539
foss: Add automated license check (#1370)
TheButlah Oct 15, 2024
65587eb
Fix an orb-relay crash in case connection dies (#1400)
andronat Nov 8, 2024
11ca5aa
Spam a specific msg while waiting for another (#1398)
andronat Nov 8, 2024
587f366
Switch to `tracing` with `tracing-journald` (#1392)
valff Dec 5, 2024
db55591
moved orb-relay-client from priv-orb-core with history
Dec 25, 2024
bc32827
cargo fmt
Dec 25, 2024
67ed8d7
PR requested updates
Dec 28, 2024
748ac03
use SecretString for auth fields
Dec 29, 2024
4f8f4da
cargo toml
Dec 30, 2024
eacc015
orb-core recently got workspace support
Dec 30, 2024
af7ac5b
removed keys
Dec 30, 2024
760f366
clippy fix
Dec 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

# IDE stuff
.idea/
.vscode/

# Allow developers to use python pre-commit locally
/.pre-commit-config.yaml
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions relay-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
[package]
name = "orb-relay-client"
version = "0.1.0"
edition.workspace = true
publish = false

# orb-core can't consume crates that use workspace inheritance :(
edition = "2021"
license = "MIT OR (Apache-2.0 WITH LLVM-exception)"
repository = "https://github.com/worldcoin/orb-software"
rust-version = "1.82.0"
paulquinn00 marked this conversation as resolved.
Show resolved Hide resolved

[dependencies]
clap = { version = "4", features = ["derive"] }
eyre.workspace = true
json5 = "0.4"
orb-relay-messages.workspace = true
orb-security-utils = { workspace = true, features = ["reqwest"] }
orb-telemetry.workspace = true
rand = "0.8"
serde_json.workspace = true
secrecy.workspace = true
sha2 = "0.10"
tokio-stream.workspace = true
tokio-util.workspace = true
tokio.workspace = true
tracing-subscriber = "0.3"
tracing-subscriber.workspace = true
tracing.workspace = true
2 changes: 1 addition & 1 deletion relay-client/src/bin/decode-msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() -> Result<()> {

fn decode_payload(json: &str) -> Result<String> {
println!("json: {}", json);
let v: Value = json5::from_str(json)?;
let v: Value = serde_json::from_str(json)?;
let any = Any {
type_url: v["type_url"]
.as_str()
Expand Down
30 changes: 15 additions & 15 deletions relay-client/src/bin/manual-test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(dead_code)]

use clap::Parser;
use eyre::{Ok, Result};
use orb_relay_client::{client::Client, debug_any, PayloadMatcher};
Expand Down Expand Up @@ -56,7 +54,9 @@ struct Args {

#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::fmt().init();
orb_telemetry::TelemetryConfig::new()
.with_journald("worldcoin-relay-client")
.init();

let args = Args::parse();

Expand Down Expand Up @@ -120,7 +120,7 @@ async fn app_to_orb() -> Result<()> {

let now = Instant::now();
'ext: loop {
#[allow(clippy::never_loop)]
#[expect(clippy::never_loop)]
for msg in orb_client.get_buffered_messages().await {
tracing::info!(
"Received message: from: {:?}, to: {:?}, seq: {:?}, payload: {:?}",
Expand Down Expand Up @@ -160,7 +160,7 @@ async fn app_to_orb() -> Result<()> {

let now = Instant::now();
'ext: loop {
#[allow(clippy::never_loop)]
#[expect(clippy::never_loop)]
for msg in orb_client.get_buffered_messages().await {
tracing::info!(
"Received message: from: {:?}, to: {:?}, seq: {:?}, payload: {:?}",
Expand Down Expand Up @@ -234,7 +234,7 @@ async fn orb_to_app() -> Result<()> {

let now = Instant::now();
'ext: loop {
#[allow(clippy::never_loop)]
#[expect(clippy::never_loop)]
for msg in app_client.get_buffered_messages().await {
tracing::info!(
"Received message: from: {:?}, to: {:?}, seq: {:?}, payload: {:?}",
Expand Down Expand Up @@ -274,7 +274,7 @@ async fn orb_to_app() -> Result<()> {

let now = Instant::now();
'ext: loop {
#[allow(clippy::never_loop)]
#[expect(clippy::never_loop)]
for msg in app_client.get_buffered_messages().await {
tracing::info!(
"Received message: from: {:?}, to: {:?}, seq: {:?}, payload: {:?}",
Expand Down Expand Up @@ -342,7 +342,7 @@ async fn orb_to_app_with_state_request() -> Result<()> {

let now = Instant::now();
'ext: loop {
#[allow(clippy::never_loop)]
#[expect(clippy::never_loop)]
for msg in app_client.get_buffered_messages().await {
tracing::info!(
"Received message: from: {:?}, to: {:?}, seq: {:?}, payload: {:?}",
Expand Down Expand Up @@ -376,7 +376,7 @@ async fn orb_to_app_with_state_request() -> Result<()> {

let now = Instant::now();
'ext: loop {
#[allow(clippy::never_loop)]
#[expect(clippy::never_loop)]
for msg in app_client.get_buffered_messages().await {
tracing::info!(
"Received message: from: {:?}, to: {:?}, seq: {:?}, payload: {:?}",
Expand Down Expand Up @@ -404,7 +404,7 @@ async fn orb_to_app_with_state_request() -> Result<()> {

let now = Instant::now();
'ext: loop {
#[allow(clippy::never_loop)]
#[expect(clippy::never_loop)]
for msg in app_client.get_buffered_messages().await {
tracing::info!(
"Received message: from: {:?}, to: {:?}, seq: {:?}, payload: {:?}",
Expand Down Expand Up @@ -476,7 +476,7 @@ async fn orb_to_app_blocking_send() -> Result<()> {

let now = Instant::now();
'ext: loop {
#[allow(clippy::never_loop)]
#[expect(clippy::never_loop)]
for msg in app_client.get_buffered_messages().await {
tracing::info!(
"Received message: from: {:?}, to: {:?}, seq: {:?}, payload: {:?}",
Expand Down Expand Up @@ -519,7 +519,7 @@ async fn orb_to_app_blocking_send() -> Result<()> {

let now = Instant::now();
'ext: loop {
#[allow(clippy::never_loop)]
#[expect(clippy::never_loop)]
for msg in app_client.get_buffered_messages().await {
tracing::info!(
"Received message: from: {:?}, to: {:?}, seq: {:?}, payload: {:?}",
Expand Down Expand Up @@ -595,7 +595,7 @@ async fn orb_to_app_with_clients_created_later_and_delay() -> Result<()> {

let now = Instant::now();
'ext: loop {
#[allow(clippy::never_loop)]
#[expect(clippy::never_loop)]
for msg in app_client.get_buffered_messages().await {
tracing::info!(
"Received message: from: {:?}, to: {:?}, seq: {:?}, payload: {:?}",
Expand Down Expand Up @@ -657,7 +657,7 @@ async fn stage_consumer_app() -> Result<()> {
tracing::info!("Time took to connect: {}ms", now.elapsed().as_millis());

loop {
#[allow(clippy::never_loop)]
#[expect(clippy::never_loop)]
for msg in app_client.get_buffered_messages().await {
tracing::info!(
"Received message: from: {:?}, to: {:?}, seq: {:?}, payload: {:?}",
Expand Down Expand Up @@ -715,7 +715,7 @@ async fn stage_producer_from_app_start_orb_signup() -> Result<()> {
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;

loop {
#[allow(clippy::never_loop)]
#[expect(clippy::never_loop)]
for msg in app_client.get_buffered_messages().await {
tracing::info!(
"Received message: from: {:?}, to: {:?}, seq: {:?}, payload: {:?}",
Expand Down
40 changes: 24 additions & 16 deletions relay-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use orb_security_utils::reqwest::{
GTS_ROOT_R1_CERT, GTS_ROOT_R2_CERT, GTS_ROOT_R3_CERT, GTS_ROOT_R4_CERT,
SFS_ROOT_G2_CERT,
};
use secrecy::{ExposeSecret, SecretString};
use std::{
any::type_name,
collections::{BTreeMap, VecDeque},
Expand All @@ -38,15 +39,15 @@ use tokio_util::sync::CancellationToken;

#[derive(Debug, Clone)]
pub struct TokenAuth {
token: String,
token: SecretString,
}

#[derive(Debug, Clone)]
pub struct ZkpAuth {
paulquinn00 marked this conversation as resolved.
Show resolved Hide resolved
root: String,
signal: String,
nullifier_hash: String,
proof: String,
root: SecretString,
signal: SecretString,
nullifier_hash: SecretString,
proof: SecretString,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -164,7 +165,9 @@ impl Client {
) -> Self {
Self::new(
url,
Auth::Token(TokenAuth { token }),
Auth::Token(TokenAuth {
token: token.into(),
}),
orb_id,
session_id,
Mode::Orb,
Expand All @@ -181,7 +184,9 @@ impl Client {
) -> Self {
Self::new(
url,
Auth::Token(TokenAuth { token }),
Auth::Token(TokenAuth {
token: token.into(),
}),
session_id,
orb_id,
Mode::App,
Expand All @@ -202,10 +207,10 @@ impl Client {
Self::new(
url,
Auth::ZKP(ZkpAuth {
root,
signal,
nullifier_hash,
proof,
root: root.into(),
signal: signal.into(),
nullifier_hash: nullifier_hash.into(),
proof: proof.into(),
}),
session_id,
orb_id,
Expand Down Expand Up @@ -665,6 +670,7 @@ impl<'a> PollerAgent<'a> {
Ok((response_stream, sender_tx))
}

paulquinn00 marked this conversation as resolved.
Show resolved Hide resolved
// TODO: See if we can move this setup into `orb-security-utils`.
fn create_tls_config() -> ClientTlsConfig {
ClientTlsConfig::new().ca_certificates(vec![
Certificate::from_pem(AWS_ROOT_CA1_CERT),
Expand Down Expand Up @@ -693,12 +699,14 @@ impl<'a> PollerAgent<'a> {
},
}),
auth_method: Some(match &self.config.auth {
Auth::Token(t) => AuthMethod::Token(t.token.clone()),
Auth::Token(t) => {
AuthMethod::Token(t.token.expose_secret().to_string())
}
Auth::ZKP(z) => AuthMethod::ZkpAuthRequest(ZkpAuthRequest {
root: z.root.clone(),
signal: z.signal.clone(),
nullifier_hash: z.nullifier_hash.clone(),
proof: z.proof.clone(),
root: z.root.expose_secret().to_string(),
signal: z.signal.expose_secret().to_string(),
nullifier_hash: z.nullifier_hash.expose_secret().to_string(),
proof: z.proof.expose_secret().to_string(),
}),
}),
})),
Expand Down
2 changes: 0 additions & 2 deletions relay-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use orb_relay_messages::{common, prost::Name, prost_types::Any, self_serve};

pub mod client;

#[allow(missing_docs)]
pub trait PayloadMatcher {
type Output;
fn matches(payload: &Any) -> Option<Self::Output>;
Expand Down Expand Up @@ -67,7 +66,6 @@ impl PayloadMatcher for self_serve::orb::v1::SignupEnded {
}
}

#[allow(missing_docs)]
pub trait IntoPayload {
fn into_payload(self) -> Any;
}
Expand Down
Loading