Skip to content

Commit 9955f49

Browse files
committed
feat(yamux): Add tests
1 parent 6cdc357 commit 9955f49

File tree

3 files changed

+581
-2
lines changed

3 files changed

+581
-2
lines changed

p2p/src/network/yamux/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ pub use self::p2p_network_yamux_state::{
88

99
#[cfg(feature = "p2p-libp2p")]
1010
mod p2p_network_yamux_reducer;
11+
12+
#[cfg(test)]
13+
mod tests;

p2p/src/network/yamux/p2p_network_yamux_state.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ impl P2pNetworkYamuxState {
6666
return None;
6767
}
6868

69+
// Version 0 is the only supported version as per Yamux specification.
70+
// Any other version should be rejected.
6971
let _version = match buf[0] {
7072
0 => 0,
7173
unknown => {
@@ -162,7 +164,7 @@ impl P2pNetworkYamuxState {
162164
self.shift_and_compact_buffer(offset);
163165
}
164166

165-
fn shift_and_compact_buffer(&mut self, offset: usize) {
167+
pub(crate) fn shift_and_compact_buffer(&mut self, offset: usize) {
166168
let new_len = self.buffer.len() - offset;
167169
if self.buffer.capacity() > INITIAL_RECV_BUFFER_CAPACITY * 2
168170
&& new_len < INITIAL_RECV_BUFFER_CAPACITY / 2
@@ -415,7 +417,7 @@ pub enum YamuxFrameInner {
415417
GoAway(#[ignore_malloc_size_of = "doesn't allocate"] Result<(), YamuxSessionError>),
416418
}
417419

418-
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
420+
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Copy)]
419421
pub enum YamuxSessionError {
420422
Protocol,
421423
Internal,

0 commit comments

Comments
 (0)