114d92f93f
* changed NymConfigTemplate trait to call 'template' by reference * network requester lib * introduced generic parameter to 'MixTrafficController' to allow non-remote gateways * allowing for custom gateway sender * types cleanup * minor gateway cmds refactor + initial NR work * wip * running a NR inside gateway note: this NR isnt tied to the gateway yet * rebase fixes * propagating same shutdown handle * wip * starting NR with appropriate local transceiver * fixed premature shutdown * wiring up PacketRouter * both ends wired together * actually working so much cleanup to do now * started removing dead code * wip * temp: hardcode gateway * further cleanup * fixed build of other binaries * setup-network-requester subcmd * overriding NR config in gateway init/run * wip making it wasm-compatible [again] * refactored 'GatewaySetup' * clippy and friends * removed debug code * rust 1.72 lints * ensuring local gateway is available + some comments * correctly putting network requester data in the same underlying details struct * improved gateway errors * changed 'network_requester_config' deserialization * missing clap annotation for 'enabled' flag in 'setup-network-requester' command * saving config file after 'setup-network-requester' * removed dead code * review comments * make embedded NR wait for gateway to come online (for at most 70min) * fixed shutdown on successful gateway wait * updated NR config override
62 lines
1.9 KiB
Rust
62 lines
1.9 KiB
Rust
// Copyright 2021-2023 - Nym Technologies SA <contact@nymtech.net>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
use crate::error::GatewayClientError;
|
|
use log::warn;
|
|
use nym_gateway_requests::BinaryResponse;
|
|
use tungstenite::{protocol::Message, Error as WsError};
|
|
|
|
pub use client::{GatewayClient, GatewayConfig};
|
|
pub use nym_gateway_requests::registration::handshake::SharedKeys;
|
|
pub use packet_router::{
|
|
AcknowledgementReceiver, AcknowledgementSender, MixnetMessageReceiver, MixnetMessageSender,
|
|
PacketRouter,
|
|
};
|
|
pub use traits::GatewayPacketRouter;
|
|
|
|
pub mod client;
|
|
pub mod error;
|
|
pub mod packet_router;
|
|
pub mod socket_state;
|
|
pub mod traits;
|
|
|
|
/// Helper method for reading from websocket stream. Helps to flatten the structure.
|
|
pub(crate) fn cleanup_socket_message(
|
|
msg: Option<Result<Message, WsError>>,
|
|
) -> Result<Message, GatewayClientError> {
|
|
match msg {
|
|
Some(msg) => msg.map_err(GatewayClientError::NetworkError),
|
|
None => Err(GatewayClientError::ConnectionAbruptlyClosed),
|
|
}
|
|
}
|
|
|
|
pub(crate) fn cleanup_socket_messages(
|
|
msgs: Option<Vec<Result<Message, WsError>>>,
|
|
) -> Result<Vec<Message>, GatewayClientError> {
|
|
match msgs {
|
|
Some(msgs) => msgs
|
|
.into_iter()
|
|
.map(|msg| msg.map_err(GatewayClientError::NetworkError))
|
|
.collect(),
|
|
None => Err(GatewayClientError::ConnectionAbruptlyClosed),
|
|
}
|
|
}
|
|
|
|
pub(crate) fn try_decrypt_binary_message(
|
|
bin_msg: Vec<u8>,
|
|
shared_keys: &SharedKeys,
|
|
) -> Option<Vec<u8>> {
|
|
match BinaryResponse::try_from_encrypted_tagged_bytes(bin_msg, shared_keys) {
|
|
Ok(bin_response) => match bin_response {
|
|
BinaryResponse::PushedMixMessage(plaintext) => Some(plaintext),
|
|
},
|
|
Err(err) => {
|
|
warn!(
|
|
"message received from the gateway was malformed! - {:?}",
|
|
err
|
|
);
|
|
None
|
|
}
|
|
}
|
|
}
|