Merge branch 'develop' into feature/ts-sdk-fixes

This commit is contained in:
Lorexia
2023-11-07 17:25:06 +01:00
6 changed files with 82 additions and 14 deletions
+14
View File
@@ -4,6 +4,18 @@ Post 1.0.0 release, the changelog format is based on [Keep a Changelog](https://
## [Unreleased]
## [2023.4-galaxy] (2023-11-07)
- DRY up client cli ([#4077])
- [mixnode] replace rocket with axum ([#4071])
- incorporate the nym node HTTP api into the mixnode ([#4070])
- replaced '--disable-sign-ext' with '--signext-lowering' when running wasm-opt ([#3896])
[#4077]: https://github.com/nymtech/nym/pull/4077
[#4071]: https://github.com/nymtech/nym/pull/4071
[#4070]: https://github.com/nymtech/nym/issues/4070
[#3896]: https://github.com/nymtech/nym/pull/3896
## [2023.3-kinder] (2023-10-31)
- suppress error output ([#4056])
@@ -15,6 +27,7 @@ Post 1.0.0 release, the changelog format is based on [Keep a Changelog](https://
- use saturating sub in case outfox is not enabled ([#3986])
- Fix sorting for mixnodes and gateways ([#3985])
- Gateway client registry and api routes ([#3955])
- Feature/configurable socks5 bind address ([#3992])
[#4056]: https://github.com/nymtech/nym/pull/4056
[#4042]: https://github.com/nymtech/nym/pull/4042
@@ -25,6 +38,7 @@ Post 1.0.0 release, the changelog format is based on [Keep a Changelog](https://
[#3986]: https://github.com/nymtech/nym/pull/3986
[#3985]: https://github.com/nymtech/nym/pull/3985
[#3955]: https://github.com/nymtech/nym/pull/3955
[#3992]: https://github.com/nymtech/nym/pull/3992
## [2023.1-milka] (2023-09-24)
Generated
+1 -1
View File
@@ -6705,7 +6705,7 @@ dependencies = [
[[package]]
name = "nym-mixnode"
version = "1.1.32"
version = "1.1.33"
dependencies = [
"anyhow",
"axum",
+1 -1
View File
@@ -11,7 +11,7 @@ use thiserror::Error;
use tracing::warn;
use url::Url;
pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(3);
pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(10);
pub type PathSegments<'a> = &'a [&'a str];
pub type Params<'a, K, V> = &'a [(K, V)];
+1 -1
View File
@@ -3,7 +3,7 @@
[package]
name = "nym-mixnode"
version = "1.1.32"
version = "1.1.33"
authors = [
"Dave Hrycyszyn <futurechimp@users.noreply.github.com>",
"Jędrzej Stuczyński <andrew@nymtech.net>",
+59 -6
View File
@@ -4,6 +4,7 @@
use serde::{Deserialize, Serialize};
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use anyhow::bail;
#[wasm_bindgen(typescript_custom_section)]
const TS_DEFS: &'static str = r#"
@@ -86,15 +87,23 @@ pub fn decode_payload(message: Vec<u8>) -> Result<IEncodedPayload, JsValue> {
pub(crate) fn parse_payload(message: &[u8]) -> anyhow::Result<(EncodedPayloadMetadata, &[u8])> {
// 1st 8 bytes are the size (as u64 big endian)
let mut size = [0u8; 8];
if message.len() < 8 {
bail!("Message is too short to contain size information")
}
size.clone_from_slice(&message[0..8]);
let size = u64::from_be_bytes(size) as usize;
let metadata_size = u64::from_be_bytes(size) as usize;
// then the metadata
let metadata = String::from_utf8_lossy(&message[8..8 + size]).into_owned();
let metadata: EncodedPayloadMetadata = serde_json::from_str(metadata.as_str())?;
if metadata_size + 8 != message.len() {
return Err(anyhow::anyhow!(
format!("Metadata size: {}, exceeds message with length of: {}", metadata_size, message.len()),
));
}
// finally the payload
let payload = &message[8 + size..];
//then the metadata
let metadata: EncodedPayloadMetadata = serde_json::from_slice(&message[8..8 + metadata_size])?;
//finally the payload
let payload = &message[8 + metadata_size..];
Ok((metadata, payload))
}
@@ -235,4 +244,48 @@ mod tests {
assert_eq!(res.0.headers, None);
assert_eq!(res.1, empty);
}
#[wasm_bindgen_test]
async fn test_parse_payload_too_short() {
let message = vec![0u8; 7];
let result = parse_payload(&message);
assert!(result.is_err());
let error = result.unwrap_err();
assert_eq!(error.to_string(), "Message is too short to contain size information");
}
#[wasm_bindgen_test]
async fn test_parse_payload_size_exceeds_length() {
let mut message = vec![0u8; 8];
message.extend(vec![1u8; 10]);
message[0..8].copy_from_slice(&(20u64.to_be_bytes()));
let result = parse_payload(&message);
assert!(result.is_err());
let error = result.unwrap_err();
assert_eq!(error.to_string(), "Metadata size: 20, exceeds message with length of: 18");
}
#[wasm_bindgen_test]
async fn test_parse_payload_valid() {
let metadata = EncodedPayloadMetadata {
mime_type: "text/plain".to_string(),
headers: Some("test headers".to_string()),
};
let payload_data = vec![2u8, 3u8, 5u8];
let serialized_metadata = serde_json::to_string(&metadata).unwrap();
let metadata_length = serialized_metadata.len() as u64;
let mut message = metadata_length.to_be_bytes().to_vec();
message.extend_from_slice(serialized_metadata.as_bytes());
message.extend_from_slice(&payload_data);
let (parsed_metadata, parsed_payload) = parse_payload(&message).unwrap();
assert_eq!(parsed_metadata.mime_type, metadata.mime_type);
assert!(parsed_metadata.headers.is_some());
assert_eq!(parsed_metadata.headers.unwrap(), "test headers");
assert_eq!(parsed_payload, payload_data.as_slice());
}
}
@@ -223,23 +223,24 @@ func parseHeaders(headers js.Value, reqOpts types.RequestOptions, method string)
func parseBody(request *js.Value) (io.Reader, error) {
jsBody := request.Get(fieldRequestBody)
var bodyReader io.Reader
if !jsBody.IsUndefined() && !jsBody.IsNull() {
if jsBody.InstanceOf(js.Global().Get("ReadableStream")) && jsBody.Get("getReader").Type() == js.TypeFunction {
// Check to see if getReader is a function
log.Debug("stream body - getReader")
bodyReader = external.NewStreamReader(jsBody.Call("getReader"))
} else {
log.Debug("unstremable body - fallback to ArrayBuffer")
// Fall back to using ArrayBuffer
// https://developer.mozilla.org/en-US/docs/Web/API/Body/arrayBuffer
log.Debug("unstreamable body - fallback to ArrayBuffer")
bodyReader = external.NewArrayReader(request.Call("arrayBuffer"))
}
bodyBytes, err := io.ReadAll(bodyReader)
if err != nil {
return nil, err
}
// Leaving historical notes as reference points
// TODO: that seems super awkward. we're constructing a reader only to fully consume it
// and create it all over again so that we the recipient wouldn't complain about content-length
// surely there must be a better way?
return bytes.NewReader(bodyBytes), nil
}