Comments (4)
I do like the idea of this being documented but I do wonder if we should make sizes configurable, either as a const or adding fields to Codec
for the size
from rust-libp2p.
I do like the idea of this being documented but I do wonder if we should make sizes configurable, either as a const or adding fields to
Codec
for the size
I like the idea too, it would require more work but it might be usefull
from rust-libp2p.
I like the idea too, it would require more work but it might be usefull
Though outside the scope of this issue, I would imagine it being something along the lines of the following (give or take):
diff --git a/protocols/request-response/src/cbor.rs b/protocols/request-response/src/cbor.rs
index 44d82be2..aaad251c 100644
--- a/protocols/request-response/src/cbor.rs
+++ b/protocols/request-response/src/cbor.rs
@@ -56,21 +56,30 @@ mod codec {
/// Max response size in bytes
const RESPONSE_SIZE_MAXIMUM: u64 = 10 * 1024 * 1024;
+ #[derive(Clone)]
pub struct Codec<Req, Resp> {
+ max_request_size: u64,
+ max_response_size: u64,
phantom: PhantomData<(Req, Resp)>,
}
impl<Req, Resp> Default for Codec<Req, Resp> {
fn default() -> Self {
Codec {
+ max_response_size: RESPONSE_SIZE_MAXIMUM,
+ max_request_size: REQUEST_SIZE_MAXIMUM,
phantom: PhantomData,
}
}
}
- impl<Req, Resp> Clone for Codec<Req, Resp> {
- fn clone(&self) -> Self {
- Self::default()
+ impl<Req, Resp> Codec<Req, Resp> {
+ pub fn new(max_request: u64, max_response: u64) -> Self {
+ Self {
+ max_request_size: max_request,
+ max_response_size: max_response,
+ phantom: PhantomData
+ }
}
}
@@ -90,7 +99,7 @@ mod codec {
{
let mut vec = Vec::new();
- io.take(REQUEST_SIZE_MAXIMUM).read_to_end(&mut vec).await?;
+ io.take(self.max_request_size).read_to_end(&mut vec).await?;
cbor4ii::serde::from_slice(vec.as_slice()).map_err(decode_into_io_error)
}
@@ -101,7 +110,7 @@ mod codec {
{
let mut vec = Vec::new();
- io.take(RESPONSE_SIZE_MAXIMUM).read_to_end(&mut vec).await?;
+ io.take(self.max_response_size).read_to_end(&mut vec).await?;
cbor4ii::serde::from_slice(vec.as_slice()).map_err(decode_into_io_error)
}
diff --git a/protocols/request-response/src/json.rs b/protocols/request-response/src/json.rs
index 85e78e7d..09c1f45f 100644
--- a/protocols/request-response/src/json.rs
+++ b/protocols/request-response/src/json.rs
@@ -54,21 +54,30 @@ mod codec {
/// Max response size in bytes
const RESPONSE_SIZE_MAXIMUM: u64 = 10 * 1024 * 1024;
+ #[derive(Clone)]
pub struct Codec<Req, Resp> {
+ max_request_size: u64,
+ max_response_size: u64,
phantom: PhantomData<(Req, Resp)>,
}
impl<Req, Resp> Default for Codec<Req, Resp> {
fn default() -> Self {
Codec {
+ max_response_size: RESPONSE_SIZE_MAXIMUM,
+ max_request_size: REQUEST_SIZE_MAXIMUM,
phantom: PhantomData,
}
}
}
- impl<Req, Resp> Clone for Codec<Req, Resp> {
- fn clone(&self) -> Self {
- Self::default()
+ impl<Req, Resp> Codec<Req, Resp> {
+ pub fn new(max_request: u64, max_response: u64) -> Self {
+ Self {
+ max_request_size: max_request,
+ max_response_size: max_response,
+ phantom: PhantomData
+ }
}
}
@@ -88,7 +97,7 @@ mod codec {
{
let mut vec = Vec::new();
- io.take(REQUEST_SIZE_MAXIMUM).read_to_end(&mut vec).await?;
+ io.take(self.max_request_size).read_to_end(&mut vec).await?;
Ok(serde_json::from_slice(vec.as_slice())?)
}
@@ -99,7 +108,7 @@ mod codec {
{
let mut vec = Vec::new();
- io.take(RESPONSE_SIZE_MAXIMUM).read_to_end(&mut vec).await?;
+ io.take(self.max_response_size).read_to_end(&mut vec).await?;
Ok(serde_json::from_slice(vec.as_slice())?)
}
from rust-libp2p.
Thank you @dariusc93, it seems perfect ! With the documentation it should be good
from rust-libp2p.
Related Issues (20)
- InvalidCertificate(Other(OtherError(UnsupportedCriticalExtension))) error with `[email protected]` HOT 7
- websocket-websys: Use-after-free of onclose and onerror event handlers HOT 4
- TLS server cert key error in libp2p-core 0.41.3 HOT 2
- After upgrading to macOS 15 (macOS Sequoia) beta3, using quic will cause p2p startup failure HOT 4
- Why rust-libp2p kademlia protocol's K_VALUE is consistent HOT 2
- thread 'main' panicked at libp2p-relay-0.17.2/src/priv_client/transport.rs:237 HOT 3
- upnp: Gateway does not support UPnP (but it does) HOT 4
- websocket wasm cannot dial /tls/ws addresses HOT 2
- `/dnsaddr` can not be properly used with secure WebSocket transport HOT 1
- Support `/dnsaddr` in web environments (wasm-bindgen) HOT 1
- UPnP port mappings should be deleted on graceful shutdown HOT 1
- NetworkBehaviour driver error after update to V0.54 HOT 4
- `libp2p` with the `quic` feature enabled results in duplicated versions of `libp2p-core` in the dependency graph HOT 1
- refactor: ping tutorial using tokio HOT 2
- webrtc-websys: __Nonexhaustive does not exist
- Semver violation in `libp2p-metrics v0.14.2` HOT 1
- feat: gossipsub pre-validation checks on incoming message HOT 1
- AutoNAT V1 panic: `Peer is connected` HOT 3
- Error (Xcode): Undefined symbol:
- Build libp2p on RISC-V CPU architecture
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-libp2p.