-
Notifications
You must be signed in to change notification settings - Fork 261
Client local storage for gateway details #6287
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright 2025 - Nym Technologies SA <[email protected]> | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| CREATE TABLE remote_gateway_details_temp | ||
| ( | ||
| gateway_id_bs58 TEXT NOT NULL UNIQUE PRIMARY KEY REFERENCES registered_gateway (gateway_id_bs58), | ||
| derived_aes256_gcm_siv_key BLOB NOT NULL, | ||
| gateway_details TEXT NOT NULL CHECK (json_valid(gateway_details)), | ||
| expiration_timestamp DATETIME NOT NULL | ||
| ); | ||
|
|
||
| -- keep none, the gateways listener URL does not contain the gateway details information | ||
| -- 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; | ||
|
|
||
| DROP TABLE remote_gateway_details; | ||
| ALTER TABLE remote_gateway_details_temp RENAME TO remote_gateway_details; | ||
|
|
||
| -- delete registrations with no key | ||
| DELETE FROM registered_gateway WHERE gateway_id_bs58 NOT IN ( SELECT gateway_id_bs58 FROM remote_gateway_details); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,15 +156,16 @@ impl StorageManager { | |
| &self, | ||
| remote: &RawRemoteGatewayDetails, | ||
| ) -> Result<(), sqlx::Error> { | ||
| let details = | ||
| serde_json::to_string(&remote.published_data.gateway_details).expect("AHHHHHHHHH"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems something is missing here : ) |
||
| sqlx::query!( | ||
| r#" | ||
| INSERT INTO remote_gateway_details(gateway_id_bs58, derived_aes256_gcm_siv_key, gateway_listener, fallback_listener, expiration_timestamp) | ||
| VALUES (?, ?, ?, ?, ?) | ||
| INSERT INTO remote_gateway_details(gateway_id_bs58, derived_aes256_gcm_siv_key, gateway_details, expiration_timestamp) | ||
| VALUES (?, ?, ?, ?) | ||
| "#, | ||
| remote.gateway_id_bs58, | ||
| remote.derived_aes256_gcm_siv_key, | ||
| remote.published_data.gateway_listener, | ||
| remote.published_data.fallback_listener, | ||
| details, | ||
| remote.published_data.expiration_timestamp | ||
| ) | ||
| .execute(&self.connection_pool) | ||
|
|
@@ -177,12 +178,12 @@ impl StorageManager { | |
| gateway_id_bs58: &str, | ||
| published_data: &RawGatewayPublishedData, | ||
| ) -> Result<(), sqlx::Error> { | ||
| let details = serde_json::to_string(&published_data.gateway_details).expect("AHHHHHHHHH"); | ||
| sqlx::query!( | ||
| r#" | ||
| UPDATE remote_gateway_details SET gateway_listener = ?, fallback_listener = ?, expiration_timestamp = ? WHERE gateway_id_bs58 = ? | ||
| UPDATE remote_gateway_details SET gateway_details = ?, expiration_timestamp = ? WHERE gateway_id_bs58 = ? | ||
| "#, | ||
| published_data.gateway_listener, | ||
| published_data.fallback_listener, | ||
| details, | ||
| published_data.expiration_timestamp, | ||
| gateway_id_bs58 | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,15 +3,14 @@ | |
|
|
||
| use crate::BadGateway; | ||
| use nym_crypto::asymmetric::ed25519; | ||
| use nym_gateway_client::client::GatewayListeners; | ||
| use nym_gateway_requests::shared_key::SharedSymmetricKey; | ||
| use nym_topology::EntryDetails; | ||
| use serde::{Deserialize, Serialize}; | ||
| use std::fmt::{Display, Formatter}; | ||
| use std::str::FromStr; | ||
| use std::sync::Arc; | ||
| use time::Duration; | ||
| use time::OffsetDateTime; | ||
| use url::Url; | ||
| use zeroize::{Zeroize, ZeroizeOnDrop}; | ||
|
|
||
| pub const REMOTE_GATEWAY_TYPE: &str = "remote"; | ||
|
|
@@ -172,14 +171,14 @@ pub struct RegisteredGateway { | |
|
|
||
| #[derive(Debug, Clone)] | ||
| pub struct GatewayPublishedData { | ||
| pub listeners: GatewayListeners, | ||
| pub details: EntryDetails, | ||
| pub expiration_timestamp: OffsetDateTime, | ||
| } | ||
|
|
||
| impl GatewayPublishedData { | ||
| pub fn new(listeners: GatewayListeners) -> GatewayPublishedData { | ||
| pub fn new(details: EntryDetails) -> GatewayPublishedData { | ||
| GatewayPublishedData { | ||
| listeners, | ||
| details, | ||
| expiration_timestamp: OffsetDateTime::now_utc() + GATEWAY_DETAILS_TTL, | ||
| } | ||
| } | ||
|
|
@@ -188,16 +187,16 @@ impl GatewayPublishedData { | |
| #[derive(Debug, Serialize, Deserialize, Clone)] | ||
| #[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))] | ||
| pub struct RawGatewayPublishedData { | ||
| pub gateway_listener: String, | ||
| pub fallback_listener: Option<String>, | ||
| #[cfg_attr(feature = "sqlx", sqlx(json))] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does json actually work with sqlx + sqlite? i.e. have you run it before? I remember I had problems with that combination in the past and json was only supported with postgres. but that was in an older version so it might have changed |
||
| pub gateway_details: EntryDetails, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, for the purposes of the database schema, it'd make more sense to redefine that type, even if it would duplicate all the data. The reason is that |
||
| pub expiration_timestamp: OffsetDateTime, | ||
| } | ||
|
|
||
| impl<'a> From<&'a GatewayPublishedData> for RawGatewayPublishedData { | ||
| fn from(value: &'a GatewayPublishedData) -> Self { | ||
| Self { | ||
| gateway_listener: value.listeners.primary.to_string(), | ||
| fallback_listener: value.listeners.fallback.as_ref().map(|uri| uri.to_string()), | ||
| // fallback_listener: value.listeners.fallback.as_ref().map(|uri| uri.to_string()), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dead code |
||
| gateway_details: value.details.clone(), | ||
| expiration_timestamp: value.expiration_timestamp, | ||
| } | ||
| } | ||
|
|
@@ -207,28 +206,15 @@ impl TryFrom<RawGatewayPublishedData> for GatewayPublishedData { | |
| type Error = BadGateway; | ||
|
|
||
| fn try_from(value: RawGatewayPublishedData) -> Result<Self, Self::Error> { | ||
| let gateway_listener: Url = Url::parse(&value.gateway_listener).map_err(|source| { | ||
| BadGateway::MalformedListenerNoId { | ||
| raw_listener: value.gateway_listener.clone(), | ||
| source, | ||
| } | ||
| })?; | ||
| let fallback_listener = value | ||
| .fallback_listener | ||
| .as_ref() | ||
| .map(|uri| { | ||
| Url::parse(uri).map_err(|source| BadGateway::MalformedListenerNoId { | ||
| raw_listener: uri.to_owned(), | ||
| source, | ||
| }) | ||
| }) | ||
| .transpose()?; | ||
| // let details = serde_json::from_str(&value.gateway_listener).map_err(|source| { | ||
| // BadGateway::MalformedDetailsNoId { | ||
| // raw_details: value.gateway_listener.clone(), | ||
| // source, | ||
| // } | ||
| // })?; | ||
|
|
||
| Ok(GatewayPublishedData { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this now looks to be infallible, so change the |
||
| listeners: GatewayListeners { | ||
| primary: gateway_listener, | ||
| fallback: fallback_listener, | ||
| }, | ||
| details: value.gateway_details, | ||
| expiration_timestamp: value.expiration_timestamp, | ||
| }) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,7 +87,6 @@ where | |
| user_chosen_gateway_id.map(|id| id.to_base58_string()), | ||
| Some(common_args.latency_based_selection), | ||
| common_args.force_tls_gateway, | ||
| false, | ||
| ); | ||
| tracing::debug!("Gateway selection specification: {selection_spec:?}"); | ||
|
|
||
|
|
@@ -168,7 +167,6 @@ where | |
| identity: gateway_details.gateway_id, | ||
| active: common_args.set_active, | ||
| typ: gateway_registration.details.typ().to_string(), | ||
| endpoint: Some(gateway_details.published_data.listeners.primary.clone()), | ||
| fallback_endpoint: gateway_details.published_data.listeners.fallback.clone(), | ||
| endpoint: Some(gateway_details.published_data.details.clone()), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's a nit, but I think it'd make more sense to rename that field. it's no longer just an |
||
| }) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but then we're losing our shared keys