Don't try to send oversized packets (#10042)
* Don't construct oversized packets * Add test for payload limit * [eth-sync] Fix wrongly computed data sizes * Replace `MAX_RECEIPTS_TO_SEND` with overall softlimit
This commit is contained in:
committed by
Afri Schoedon
parent
b180be7526
commit
e435407080
@@ -41,6 +41,10 @@ const ENCRYPTED_HEADER_LEN: usize = 32;
|
||||
const RECEIVE_PAYLOAD: Duration = Duration::from_secs(30);
|
||||
pub const MAX_PAYLOAD_SIZE: usize = (1 << 24) - 1;
|
||||
|
||||
/// Network responses should try not to go over this limit.
|
||||
/// This should be lower than MAX_PAYLOAD_SIZE
|
||||
pub const PAYLOAD_SOFT_LIMIT: usize = (1 << 22) - 1;
|
||||
|
||||
pub trait GenericSocket : Read + Write {
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ use ip_utils::{map_external_address, select_public_address};
|
||||
use parity_path::restrict_permissions_owner;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use network::{ConnectionFilter, ConnectionDirection};
|
||||
use connection::PAYLOAD_SOFT_LIMIT;
|
||||
|
||||
type Slab<T> = ::slab::Slab<T, usize>;
|
||||
|
||||
@@ -200,6 +201,10 @@ impl<'s> NetworkContextTrait for NetworkContext<'s> {
|
||||
.map(|node| self.reserved_peers.contains(&node))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn payload_soft_limit(&self) -> usize {
|
||||
PAYLOAD_SOFT_LIMIT
|
||||
}
|
||||
}
|
||||
|
||||
/// Shared host information
|
||||
|
||||
@@ -288,6 +288,9 @@ pub trait NetworkContext {
|
||||
|
||||
/// Returns whether the given peer ID is a reserved peer.
|
||||
fn is_reserved_peer(&self, peer: PeerId) -> bool;
|
||||
|
||||
/// Returns the size the payload shouldn't exceed
|
||||
fn payload_soft_limit(&self) -> usize;
|
||||
}
|
||||
|
||||
impl<'a, T> NetworkContext for &'a T where T: ?Sized + NetworkContext {
|
||||
@@ -338,6 +341,10 @@ impl<'a, T> NetworkContext for &'a T where T: ?Sized + NetworkContext {
|
||||
fn is_reserved_peer(&self, peer: PeerId) -> bool {
|
||||
(**self).is_reserved_peer(peer)
|
||||
}
|
||||
|
||||
fn payload_soft_limit(&self) -> usize {
|
||||
(**self).payload_soft_limit()
|
||||
}
|
||||
}
|
||||
|
||||
/// Network IO protocol handler. This needs to be implemented for each new subprotocol.
|
||||
|
||||
Reference in New Issue
Block a user