Skip to content

Commit 0ff7dea

Browse files
committed
Suggest a socket read buffer of 4KiB to limit message count
...and switch the same in `lightning-net-tokio`
1 parent 018f090 commit 0ff7dea

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lightning-net-tokio/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ impl Connection {
176176
let (event_waker, event_receiver) = mpsc::channel(1);
177177
tokio::spawn(Self::poll_event_process(peer_manager.clone(), event_receiver));
178178

179-
// 8KB is nice and big but also should never cause any issues with stack overflowing.
180-
let mut buf = [0; 8192];
179+
// 4KiB is nice and big without handling too many messages all at once, giving other peers
180+
// a chance to do some work.
181+
let mut buf = [0; 4096];
181182

182183
let mut our_descriptor = SocketDescriptor::new(us.clone());
183184
// An enum describing why we did/are disconnecting:

lightning/src/ln/peer_handler.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,9 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
10051005
/// [`send_data`] call on this descriptor has `resume_read` set (preventing DoS issues in the
10061006
/// send buffer).
10071007
///
1008+
/// In order to avoid processing too many messages at once per peer, `data` should be on the
1009+
/// order of 4KiB.
1010+
///
10081011
/// [`send_data`]: SocketDescriptor::send_data
10091012
/// [`process_events`]: PeerManager::process_events
10101013
pub fn read_event(&self, peer_descriptor: &mut Descriptor, data: &[u8]) -> Result<bool, PeerHandleError> {

0 commit comments

Comments
 (0)