addressing comments
This commit is contained in:
@@ -26,8 +26,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn stream_transport_threshold_is_consistent() {
|
||||
assert_eq!(MAX_NON_STREAM_VERSION, v8::VERSION);
|
||||
assert_eq!(SPHINX_STREAM_VERSION_THRESHOLD, v9::VERSION);
|
||||
assert_eq!(MAX_NON_STREAM_VERSION, 8);
|
||||
assert_eq!(SPHINX_STREAM_VERSION_THRESHOLD, 9);
|
||||
assert!(SPHINX_STREAM_VERSION_THRESHOLD > MAX_NON_STREAM_VERSION);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,7 +315,7 @@ async fn connect_exit(
|
||||
let mut ipr_client = IprClientConnect::new(mixnet_client, cancel_token);
|
||||
|
||||
let maybe_ip_pair = ipr_client.connect(exit_router_address).await;
|
||||
let stream_id = ipr_client.active_stream_id();
|
||||
let stream_id = ipr_client.stream_id();
|
||||
let mixnet_client = ipr_client.into_mixnet_client();
|
||||
|
||||
if let Ok(our_ips) = maybe_ip_pair {
|
||||
|
||||
@@ -24,8 +24,12 @@ const IPR_CONNECT_TIMEOUT: Duration = Duration::from_secs(10);
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
enum ConnectionState {
|
||||
Disconnected,
|
||||
Connecting,
|
||||
Connected,
|
||||
Connecting {
|
||||
stream_id: u64,
|
||||
},
|
||||
Connected {
|
||||
stream_id: u64,
|
||||
},
|
||||
#[allow(unused)]
|
||||
Disconnecting,
|
||||
}
|
||||
@@ -36,7 +40,6 @@ pub struct IprClientConnect {
|
||||
mixnet_client: MixnetClient,
|
||||
connected: ConnectionState,
|
||||
cancel_token: CancellationToken,
|
||||
active_stream_id: Option<u64>,
|
||||
}
|
||||
|
||||
impl IprClientConnect {
|
||||
@@ -45,7 +48,6 @@ impl IprClientConnect {
|
||||
mixnet_client,
|
||||
connected: ConnectionState::Disconnected,
|
||||
cancel_token,
|
||||
active_stream_id: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,8 +55,12 @@ impl IprClientConnect {
|
||||
self.mixnet_client
|
||||
}
|
||||
|
||||
pub fn active_stream_id(&self) -> Option<u64> {
|
||||
self.active_stream_id
|
||||
pub fn stream_id(&self) -> Option<u64> {
|
||||
match self.connected {
|
||||
ConnectionState::Connecting { stream_id }
|
||||
| ConnectionState::Connected { stream_id } => Some(stream_id),
|
||||
ConnectionState::Disconnected | ConnectionState::Disconnecting => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn connect(&mut self, ip_packet_router_address: Recipient) -> Result<IpPair> {
|
||||
@@ -63,11 +69,13 @@ impl IprClientConnect {
|
||||
}
|
||||
|
||||
tracing::info!("Connecting to exit gateway");
|
||||
self.connected = ConnectionState::Connecting;
|
||||
match self.connect_inner(ip_packet_router_address).await {
|
||||
Ok(ips) => {
|
||||
debug!("Successfully connected to the ip-packet-router");
|
||||
self.connected = ConnectionState::Connected;
|
||||
let Some(stream_id) = self.stream_id() else {
|
||||
return Err(Error::UnexpectedConnectResponse);
|
||||
};
|
||||
self.connected = ConnectionState::Connected { stream_id };
|
||||
Ok(ips)
|
||||
}
|
||||
Err(err) => {
|
||||
@@ -80,6 +88,9 @@ impl IprClientConnect {
|
||||
|
||||
async fn connect_inner(&mut self, ip_packet_router_address: Recipient) -> Result<IpPair> {
|
||||
let request_id = self.send_connect_request(ip_packet_router_address).await?;
|
||||
self.connected = ConnectionState::Connecting {
|
||||
stream_id: request_id,
|
||||
};
|
||||
|
||||
debug!("Waiting for reply...");
|
||||
self.listen_for_connect_response(request_id).await
|
||||
@@ -95,7 +106,8 @@ impl IprClientConnect {
|
||||
);
|
||||
if let Ok(bytes) = request.to_bytes() {
|
||||
let prefix = bytes.get(0..2).unwrap_or(&bytes);
|
||||
tracing::info!(request_id = request_id, bytes_0_2 = ?prefix, "IPR connect bytes");
|
||||
let prefix_hex = format!("{:02x?}", prefix);
|
||||
tracing::info!(request_id = request_id, prefix = %prefix_hex, "IPR connect bytes prefix");
|
||||
}
|
||||
|
||||
// We use 20 surbs for the connect request because typically the IPR is configured to have
|
||||
@@ -103,9 +115,8 @@ impl IprClientConnect {
|
||||
let surbs = 20;
|
||||
let request_bytes = request.to_bytes()?;
|
||||
let framed_bytes = maybe_wrap_stream_frame(request_id, 0, request_bytes);
|
||||
self.active_stream_id = Some(request_id);
|
||||
self.mixnet_client
|
||||
.send(create_input_message_bytes(
|
||||
.send(create_input_message(
|
||||
ip_packet_router_address,
|
||||
framed_bytes,
|
||||
surbs,
|
||||
@@ -149,7 +160,7 @@ impl IprClientConnect {
|
||||
// Confirm that the version is correct
|
||||
if let Err(err) = check_ipr_message_version(&msg) {
|
||||
let raw: &[u8] = msg.message.as_ref();
|
||||
tracing::info!(
|
||||
tracing::warn!(
|
||||
first_byte = raw.first().copied(),
|
||||
expected = crate::current::VERSION,
|
||||
len = raw.len(),
|
||||
@@ -204,11 +215,7 @@ fn ipr_response_from_reconstructed_message(
|
||||
IpPacketResponse::from_bytes(payload)
|
||||
}
|
||||
|
||||
fn create_input_message_bytes(
|
||||
recipient: Recipient,
|
||||
bytes: Vec<u8>,
|
||||
surbs: u32,
|
||||
) -> Result<InputMessage> {
|
||||
fn create_input_message(recipient: Recipient, bytes: Vec<u8>, surbs: u32) -> Result<InputMessage> {
|
||||
Ok(InputMessage::new_anonymous(
|
||||
recipient,
|
||||
bytes,
|
||||
|
||||
@@ -4,6 +4,7 @@ use nym_lp::packet::frame::{
|
||||
LpFrame, LpFrameHeader, LpFrameKind, SphinxStreamFrameAttributes, SphinxStreamMsgType,
|
||||
};
|
||||
use nym_sdk::mixnet::ReconstructedMessage;
|
||||
use tracing::trace;
|
||||
|
||||
/// Whether the "current" IPR client is operating at a version where the node expects
|
||||
/// non-stream mixnet IPR messages to be LP Stream framed (see `SPHINX_STREAM_VERSION_THRESHOLD`).
|
||||
@@ -16,11 +17,13 @@ pub fn maybe_unwrap_lp_stream_payload(data: &[u8]) -> &[u8] {
|
||||
return data;
|
||||
}
|
||||
let Ok(header) = LpFrameHeader::parse(data) else {
|
||||
trace!("expected LP header but failed to parse; treating as raw payload");
|
||||
return data;
|
||||
};
|
||||
if header.kind == LpFrameKind::SphinxStream {
|
||||
&data[LpFrameHeader::SIZE..]
|
||||
} else {
|
||||
trace!(kind = ?header.kind, "lp header parsed but not a sphinx stream frame; treating as raw payload");
|
||||
data
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,13 +220,7 @@ fn create_ip_packet_response(
|
||||
ClientVersion::V8 => IpPacketResponseV8::new_ip_packet(packets).to_bytes(),
|
||||
ClientVersion::V9 => {
|
||||
let resp = v9::new_ip_packet_response(packets);
|
||||
log::info!("IPR send data resp version byte: {}", resp.version);
|
||||
let bytes = resp.to_bytes()?;
|
||||
log::info!(
|
||||
"IPR send data resp first byte: {:?}",
|
||||
bytes.first().copied()
|
||||
);
|
||||
Ok(bytes)
|
||||
resp.to_bytes()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,6 @@ impl TryFrom<&ReconstructedMessage> for IpPacketRequest {
|
||||
.message
|
||||
.first_chunk::<2>()
|
||||
.ok_or(IpPacketRouterError::EmptyPacket)?;
|
||||
log::info!("IPR recv header bytes: {:02x?}", request_version);
|
||||
|
||||
// With version v8 and onwards, the type of the service provider is included in the
|
||||
// header.
|
||||
@@ -104,7 +103,6 @@ impl TryFrom<&ReconstructedMessage> for IpPacketRequest {
|
||||
}
|
||||
|
||||
let request_version = request_version[0];
|
||||
log::info!("IPR recv version byte: {request_version}");
|
||||
match request_version {
|
||||
6 => {
|
||||
let request_v6 = IpPacketRequestV6::from_reconstructed_message(reconstructed)
|
||||
|
||||
@@ -133,14 +133,7 @@ impl VersionedResponse {
|
||||
ClientVersion::V9 => {
|
||||
let mut resp = IpPacketResponseV8::try_from(self)?;
|
||||
resp.version = nym_ip_packet_requests::v9::VERSION;
|
||||
log::info!("IPR send control resp version byte: {}", resp.version);
|
||||
let bytes = resp.to_bytes();
|
||||
if let Ok(ref bytes) = bytes {
|
||||
log::info!(
|
||||
"IPR send control resp first byte: {:?}",
|
||||
bytes.first().copied()
|
||||
);
|
||||
}
|
||||
bytes
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user