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.
Related Issues (20)
- `Gossipsub`'s substreams keep all connections alive after `idle_connection_timeout`
- mergify continously approving approved pull requests HOT 6
- WebRTC connection doesn't close after timeout HOT 2
- Promote common dependencies to workspace level
- file-sharing works only on local interface HOT 1
- kad: FIND_NODE not conform to specs HOT 9
- Improve request/response documentation HOT 4
- Compilation on docs.rs is failing
- mdns tokio timer panics HOT 2
- Signature verification fails on handshake if 1024 bit RSA key is used HOT 3
- relay: panics due to unimplemented time in wasm HOT 2
- kad: consume `FromSwarm::NewExternalAddrOfPeer` HOT 14
- Reduce `NewExternalAddrCandidate` reports from `identify`
- kad: make `automatic_bootstrap_interval` publicly configurable
- request-response: Inconsistent documentation.
- Active streams affect `yamux::connection::rtt` HOT 10
- rendezvous: Example "discovering with identify" doesn't work HOT 4
- kad: make bucket size configurable HOT 6
- `libp2p_stream` stream deadlocks if using yamux 0.13 HOT 4
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.