Skip to content

Commit f2bfa5f

Browse files
committed
initial implementation pass
1 parent c17a205 commit f2bfa5f

File tree

29 files changed

+280
-450
lines changed

29 files changed

+280
-450
lines changed

Cargo.lock

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/client-core/gateways-storage/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ rust-version.workspace = true
1010
[dependencies]
1111
async-trait.workspace = true
1212
serde = { workspace = true, features = ["derive"] }
13+
serde_json.workspace = true
1314
thiserror.workspace = true
1415
time.workspace = true
1516
tokio = { workspace = true, features = ["sync"] }
@@ -20,10 +21,11 @@ zeroize = { workspace = true, features = ["zeroize_derive"] }
2021
nym-crypto = { path = "../../crypto", features = ["asymmetric"] }
2122
nym-gateway-requests = { path = "../../gateway-requests" }
2223
nym-gateway-client = { path = "../../client-libs/gateway-client" }
24+
nym-topology = { path = "../../topology", features = ["persistence"] }
2325

2426
[target."cfg(not(target_arch = \"wasm32\"))".dependencies.sqlx]
2527
workspace = true
26-
features = ["runtime-tokio-rustls", "sqlite", "macros", "migrate", "time"]
28+
features = ["runtime-tokio-rustls", "sqlite", "macros", "migrate", "time", "json"]
2729
optional = true
2830

2931
[build-dependencies]
@@ -34,6 +36,7 @@ sqlx = { workspace = true, features = [
3436
"sqlite",
3537
"macros",
3638
"migrate",
39+
"json",
3740
] }
3841

3942
[features]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2025 - Nym Technologies SA <[email protected]>
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
CREATE TABLE remote_gateway_details_temp
7+
(
8+
gateway_id_bs58 TEXT NOT NULL UNIQUE PRIMARY KEY REFERENCES registered_gateway (gateway_id_bs58),
9+
derived_aes256_gcm_siv_key BLOB NOT NULL,
10+
gateway_details TEXT NOT NULL CHECK (json_valid(gateway_details)),
11+
expiration_timestamp DATETIME NOT NULL
12+
);
13+
14+
-- keep none, the gateways listener URL does not contain the gateway details information
15+
-- INSERT INTO remote_gateway_details_temp SELECT gateway_id_bs58, derived_aes256_gcm_siv_key, gateway_listener, NULL, datetime(0, 'unixepoch') FROM remote_gateway_details WHERE derived_aes256_gcm_siv_key IS NOT NULL;
16+
17+
DROP TABLE remote_gateway_details;
18+
ALTER TABLE remote_gateway_details_temp RENAME TO remote_gateway_details;
19+
20+
-- delete registrations with no key
21+
DELETE FROM registered_gateway WHERE gateway_id_bs58 NOT IN ( SELECT gateway_id_bs58 FROM remote_gateway_details);

common/client-core/gateways-storage/src/backend/fs_backend/manager.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,16 @@ impl StorageManager {
156156
&self,
157157
remote: &RawRemoteGatewayDetails,
158158
) -> Result<(), sqlx::Error> {
159+
let details =
160+
serde_json::to_string(&remote.published_data.gateway_details).expect("AHHHHHHHHH");
159161
sqlx::query!(
160162
r#"
161-
INSERT INTO remote_gateway_details(gateway_id_bs58, derived_aes256_gcm_siv_key, gateway_listener, fallback_listener, expiration_timestamp)
162-
VALUES (?, ?, ?, ?, ?)
163+
INSERT INTO remote_gateway_details(gateway_id_bs58, derived_aes256_gcm_siv_key, gateway_details, expiration_timestamp)
164+
VALUES (?, ?, ?, ?)
163165
"#,
164166
remote.gateway_id_bs58,
165167
remote.derived_aes256_gcm_siv_key,
166-
remote.published_data.gateway_listener,
167-
remote.published_data.fallback_listener,
168+
details,
168169
remote.published_data.expiration_timestamp
169170
)
170171
.execute(&self.connection_pool)
@@ -177,12 +178,12 @@ impl StorageManager {
177178
gateway_id_bs58: &str,
178179
published_data: &RawGatewayPublishedData,
179180
) -> Result<(), sqlx::Error> {
181+
let details = serde_json::to_string(&published_data.gateway_details).expect("AHHHHHHHHH");
180182
sqlx::query!(
181183
r#"
182-
UPDATE remote_gateway_details SET gateway_listener = ?, fallback_listener = ?, expiration_timestamp = ? WHERE gateway_id_bs58 = ?
184+
UPDATE remote_gateway_details SET gateway_details = ?, expiration_timestamp = ? WHERE gateway_id_bs58 = ?
183185
"#,
184-
published_data.gateway_listener,
185-
published_data.fallback_listener,
186+
details,
186187
published_data.expiration_timestamp,
187188
gateway_id_bs58
188189
)

common/client-core/gateways-storage/src/error.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use nym_crypto::asymmetric::ed25519::Ed25519RecoveryError;
55
use nym_gateway_requests::shared_key::SharedKeyConversionError;
6+
use serde_json::Error as JsonError;
67
use thiserror::Error;
78

89
#[derive(Debug, Error)]
@@ -29,23 +30,11 @@ pub enum BadGateway {
2930
#[error("could not find any valid shared keys for gateway {gateway_id}")]
3031
MissingSharedKey { gateway_id: String },
3132

32-
#[error(
33-
"the listening address of gateway {gateway_id} ({raw_listener}) is malformed: {source}"
34-
)]
35-
MalformedListener {
36-
gateway_id: String,
37-
38-
raw_listener: String,
39-
40-
#[source]
41-
source: url::ParseError,
42-
},
43-
44-
#[error("the listening address ({raw_listener}) is malformed: {source}")]
45-
MalformedListenerNoId {
46-
raw_listener: String,
33+
#[error("the listening address ({raw_details}) is malformed: {source}")]
34+
MalformedDetailsNoId {
35+
raw_details: String,
4736

4837
#[source]
49-
source: url::ParseError,
38+
source: JsonError,
5039
},
5140
}

common/client-core/gateways-storage/src/types.rs

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33

44
use crate::BadGateway;
55
use nym_crypto::asymmetric::ed25519;
6-
use nym_gateway_client::client::GatewayListeners;
76
use nym_gateway_requests::shared_key::SharedSymmetricKey;
7+
use nym_topology::EntryDetails;
88
use serde::{Deserialize, Serialize};
99
use std::fmt::{Display, Formatter};
1010
use std::str::FromStr;
1111
use std::sync::Arc;
1212
use time::Duration;
1313
use time::OffsetDateTime;
14-
use url::Url;
1514
use zeroize::{Zeroize, ZeroizeOnDrop};
1615

1716
pub const REMOTE_GATEWAY_TYPE: &str = "remote";
@@ -172,14 +171,14 @@ pub struct RegisteredGateway {
172171

173172
#[derive(Debug, Clone)]
174173
pub struct GatewayPublishedData {
175-
pub listeners: GatewayListeners,
174+
pub details: EntryDetails,
176175
pub expiration_timestamp: OffsetDateTime,
177176
}
178177

179178
impl GatewayPublishedData {
180-
pub fn new(listeners: GatewayListeners) -> GatewayPublishedData {
179+
pub fn new(details: EntryDetails) -> GatewayPublishedData {
181180
GatewayPublishedData {
182-
listeners,
181+
details,
183182
expiration_timestamp: OffsetDateTime::now_utc() + GATEWAY_DETAILS_TTL,
184183
}
185184
}
@@ -188,16 +187,16 @@ impl GatewayPublishedData {
188187
#[derive(Debug, Serialize, Deserialize, Clone)]
189188
#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
190189
pub struct RawGatewayPublishedData {
191-
pub gateway_listener: String,
192-
pub fallback_listener: Option<String>,
190+
#[cfg_attr(feature = "sqlx", sqlx(json))]
191+
pub gateway_details: EntryDetails,
193192
pub expiration_timestamp: OffsetDateTime,
194193
}
195194

196195
impl<'a> From<&'a GatewayPublishedData> for RawGatewayPublishedData {
197196
fn from(value: &'a GatewayPublishedData) -> Self {
198197
Self {
199-
gateway_listener: value.listeners.primary.to_string(),
200-
fallback_listener: value.listeners.fallback.as_ref().map(|uri| uri.to_string()),
198+
// fallback_listener: value.listeners.fallback.as_ref().map(|uri| uri.to_string()),
199+
gateway_details: value.details.clone(),
201200
expiration_timestamp: value.expiration_timestamp,
202201
}
203202
}
@@ -207,28 +206,15 @@ impl TryFrom<RawGatewayPublishedData> for GatewayPublishedData {
207206
type Error = BadGateway;
208207

209208
fn try_from(value: RawGatewayPublishedData) -> Result<Self, Self::Error> {
210-
let gateway_listener: Url = Url::parse(&value.gateway_listener).map_err(|source| {
211-
BadGateway::MalformedListenerNoId {
212-
raw_listener: value.gateway_listener.clone(),
213-
source,
214-
}
215-
})?;
216-
let fallback_listener = value
217-
.fallback_listener
218-
.as_ref()
219-
.map(|uri| {
220-
Url::parse(uri).map_err(|source| BadGateway::MalformedListenerNoId {
221-
raw_listener: uri.to_owned(),
222-
source,
223-
})
224-
})
225-
.transpose()?;
209+
// let details = serde_json::from_str(&value.gateway_listener).map_err(|source| {
210+
// BadGateway::MalformedDetailsNoId {
211+
// raw_details: value.gateway_listener.clone(),
212+
// source,
213+
// }
214+
// })?;
226215

227216
Ok(GatewayPublishedData {
228-
listeners: GatewayListeners {
229-
primary: gateway_listener,
230-
fallback: fallback_listener,
231-
},
217+
details: value.gateway_details,
232218
expiration_timestamp: value.expiration_timestamp,
233219
})
234220
}

common/client-core/src/cli_helpers/client_add_gateway.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ where
8787
user_chosen_gateway_id.map(|id| id.to_base58_string()),
8888
Some(common_args.latency_based_selection),
8989
common_args.force_tls_gateway,
90-
false,
9190
);
9291
tracing::debug!("Gateway selection specification: {selection_spec:?}");
9392

@@ -168,7 +167,6 @@ where
168167
identity: gateway_details.gateway_id,
169168
active: common_args.set_active,
170169
typ: gateway_registration.details.typ().to_string(),
171-
endpoint: Some(gateway_details.published_data.listeners.primary.clone()),
172-
fallback_endpoint: gateway_details.published_data.listeners.fallback.clone(),
170+
endpoint: Some(gateway_details.published_data.details.clone()),
173171
})
174172
}

common/client-core/src/cli_helpers/client_init.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ where
140140
user_chosen_gateway_id.map(|id| id.to_base58_string()),
141141
Some(common_args.latency_based_selection),
142142
common_args.force_tls_gateway,
143-
false,
144143
);
145144
tracing::debug!("Gateway selection specification: {selection_spec:?}");
146145

common/client-core/src/cli_helpers/client_list_gateways.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,14 @@ where
5656
identity: remote_details.gateway_id,
5757
active: active_gateway == Some(remote_details.gateway_id),
5858
typ: GatewayType::Remote.to_string(),
59-
endpoint: Some(remote_details.published_data.listeners.primary.clone()),
60-
fallback_endpoint: remote_details.published_data.listeners.fallback.clone(),
59+
endpoint: Some(remote_details.published_data.details.clone()),
6160
}),
6261
GatewayDetails::Custom(_) => info.push(GatewayInfo {
6362
registration: gateway.registration_timestamp,
6463
identity: gateway.details.gateway_id(),
6564
active: active_gateway == Some(gateway.details.gateway_id()),
6665
typ: gateway.details.typ().to_string(),
6766
endpoint: None,
68-
fallback_endpoint: None,
6967
}),
7068
};
7169
}

common/client-core/src/cli_helpers/types.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use nym_crypto::asymmetric::ed25519;
5+
use nym_topology::EntryDetails;
56
use serde::{Deserialize, Serialize};
67
use std::fmt::{Display, Formatter};
78
use time::OffsetDateTime;
8-
use url::Url;
99

1010
#[derive(Serialize, Deserialize)]
1111
pub struct GatewayInfo {
@@ -14,8 +14,7 @@ pub struct GatewayInfo {
1414
pub active: bool,
1515

1616
pub typ: String,
17-
pub endpoint: Option<Url>,
18-
pub fallback_endpoint: Option<Url>,
17+
pub endpoint: Option<EntryDetails>,
1918
}
2019

2120
impl Display for GatewayInfo {
@@ -31,9 +30,6 @@ impl Display for GatewayInfo {
3130
if let Some(endpoint) = &self.endpoint {
3231
write!(f, " endpoint: {endpoint}")?;
3332
}
34-
if let Some(fallback_endpoint) = &self.fallback_endpoint {
35-
write!(f, " fallback: {fallback_endpoint}")?;
36-
}
3733
Ok(())
3834
}
3935
}

0 commit comments

Comments
 (0)