Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clippys and rust analyzer warnings. #10

Merged
merged 3 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions src/association/association_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ fn create_association(config: TransportConfig) -> Association {

#[test]
fn test_create_forward_tsn_forward_one_abandoned() -> Result<()> {
let mut a = Association::default();
let mut a = Association {
cumulative_tsn_ack_point: 9,
advanced_peer_tsn_ack_point: 10,
..Default::default()
};

a.cumulative_tsn_ack_point = 9;
a.advanced_peer_tsn_ack_point = 10;
a.inflight_queue.push_no_check(ChunkPayloadData {
beginning_fragment: true,
ending_fragment: true,
Expand All @@ -44,10 +46,12 @@ fn test_create_forward_tsn_forward_one_abandoned() -> Result<()> {

#[test]
fn test_create_forward_tsn_forward_two_abandoned_with_the_same_si() -> Result<()> {
let mut a = Association::default();
let mut a = Association {
cumulative_tsn_ack_point: 9,
advanced_peer_tsn_ack_point: 12,
..Default::default()
};

a.cumulative_tsn_ack_point = 9;
a.advanced_peer_tsn_ack_point = 12;
a.inflight_queue.push_no_check(ChunkPayloadData {
beginning_fragment: true,
ending_fragment: true,
Expand Down Expand Up @@ -99,7 +103,7 @@ fn test_create_forward_tsn_forward_two_abandoned_with_the_same_si() -> Result<()
assert_eq!(1, s.sequence, "ssn should be 1");
si2ok = true;
}
_ => assert!(false, "unexpected stream indentifier"),
_ => panic!("unexpected stream indentifier"),
}
}
assert!(si1ok, "si=1 should be present");
Expand All @@ -110,9 +114,11 @@ fn test_create_forward_tsn_forward_two_abandoned_with_the_same_si() -> Result<()

#[test]
fn test_handle_forward_tsn_forward_3unreceived_chunks() -> Result<()> {
let mut a = Association::default();
let mut a = Association {
use_forward_tsn: true,
..Default::default()
};

a.use_forward_tsn = true;
let prev_tsn = a.peer_last_tsn;

let fwdtsn = ChunkForwardTsn {
Expand Down Expand Up @@ -144,9 +150,11 @@ fn test_handle_forward_tsn_forward_3unreceived_chunks() -> Result<()> {

#[test]
fn test_handle_forward_tsn_forward_1for1_missing() -> Result<()> {
let mut a = Association::default();
let mut a = Association {
use_forward_tsn: true,
..Default::default()
};

a.use_forward_tsn = true;
let prev_tsn = a.peer_last_tsn;

// this chunk is blocked by the missing chunk at tsn=1
Expand Down Expand Up @@ -192,7 +200,10 @@ fn test_handle_forward_tsn_forward_1for1_missing() -> Result<()> {

#[test]
fn test_handle_forward_tsn_forward_1for2_missing() -> Result<()> {
let mut a = Association::default();
let mut a = Association {
use_forward_tsn: true,
..Default::default()
};

a.use_forward_tsn = true;
let prev_tsn = a.peer_last_tsn;
Expand Down Expand Up @@ -238,9 +249,11 @@ fn test_handle_forward_tsn_forward_1for2_missing() -> Result<()> {

#[test]
fn test_handle_forward_tsn_dup_forward_tsn_chunk_should_generate_sack() -> Result<()> {
let mut a = Association::default();
let mut a = Association {
use_forward_tsn: true,
..Default::default()
};

a.use_forward_tsn = true;
let prev_tsn = a.peer_last_tsn;

let fwdtsn = ChunkForwardTsn {
Expand Down Expand Up @@ -270,8 +283,7 @@ fn test_assoc_create_new_stream() -> Result<()> {
if let Some(s) = a.create_stream(i as u16, true, PayloadProtocolIdentifier::Unknown) {
s.stream_identifier
} else {
assert!(false, "{} should success", i);
0
panic!("{} should success", i);
};
let result = a.streams.get(&stream_identifier);
assert!(result.is_some(), "should be in a.streams map");
Expand Down Expand Up @@ -406,7 +418,7 @@ fn test_assoc_max_message_size_default() -> Result<()> {
"should be not Error::ErrOutboundPacketTooLarge"
);
} else {
assert!(false, "should be error");
panic!("should be error");
}

if let Err(err) = s.write_sctp(&p.slice(..65537), ppi) {
Expand All @@ -416,7 +428,7 @@ fn test_assoc_max_message_size_default() -> Result<()> {
"should be Error::ErrOutboundPacketTooLarge"
);
} else {
assert!(false, "should be error");
panic!("should be error");
}
}

Expand All @@ -443,7 +455,7 @@ fn test_assoc_max_message_size_explicit() -> Result<()> {
"should be not Error::ErrOutboundPacketTooLarge"
);
} else {
assert!(false, "should be error");
panic!("should be error");
}

if let Err(err) = s.write_sctp(&p.slice(..30001), ppi) {
Expand All @@ -453,7 +465,7 @@ fn test_assoc_max_message_size_explicit() -> Result<()> {
"should be Error::ErrOutboundPacketTooLarge"
);
} else {
assert!(false, "should be error");
panic!("should be error");
}
}

Expand Down
1 change: 0 additions & 1 deletion src/association/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1889,7 +1889,6 @@ impl Association {
reconfig_response_sequence_number: p.reconfig_request_sequence_number,
sender_last_tsn: tsn,
stream_identifiers: sis_to_reset,
..Default::default()
})),
..Default::default()
};
Expand Down
28 changes: 7 additions & 21 deletions src/association/state.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::fmt;

/// association state enums
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Default)]
pub(crate) enum AssociationState {
#[default]
Closed = 0,
CookieWait = 1,
CookieEchoed = 2,
Expand All @@ -13,12 +14,6 @@ pub(crate) enum AssociationState {
ShutdownSent = 7,
}

impl Default for AssociationState {
fn default() -> Self {
AssociationState::Closed
}
}

impl From<u8> for AssociationState {
fn from(v: u8) -> AssociationState {
match v {
Expand Down Expand Up @@ -63,17 +58,13 @@ impl AssociationState {
}

/// ack mode (for testing)
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Default)]
pub(crate) enum AckMode {
#[default]
Normal,
NoDelay,
AlwaysDelay,
}
impl Default for AckMode {
fn default() -> Self {
AckMode::Normal
}
}

impl fmt::Display for AckMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand All @@ -87,19 +78,14 @@ impl fmt::Display for AckMode {
}

/// ack transmission state
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Default)]
pub(crate) enum AckState {
Idle, // ack timer is off
#[default]
Idle, // ack timer is off
Immediate, // will send ack immediately
Delay, // ack timer is on (ack is being delayed)
}

impl Default for AckState {
fn default() -> Self {
AckState::Idle
}
}

impl fmt::Display for AckState {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match *self {
Expand Down
18 changes: 4 additions & 14 deletions src/association/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,17 @@ pub enum StreamEvent {
}

/// Reliability type for stream
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Default)]
pub enum ReliabilityType {
/// ReliabilityTypeReliable is used for reliable transmission
#[default]
Reliable = 0,
/// ReliabilityTypeRexmit is used for partial reliability by retransmission count
Rexmit = 1,
/// ReliabilityTypeTimed is used for partial reliability by retransmission duration
Timed = 2,
}

impl Default for ReliabilityType {
fn default() -> Self {
ReliabilityType::Reliable
}
}

impl fmt::Display for ReliabilityType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match *self {
Expand Down Expand Up @@ -319,8 +314,9 @@ impl<'a> Stream<'a> {
}
}

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
pub enum RecvSendState {
#[default]
Closed = 0,
Readable = 1,
Writable = 2,
Expand All @@ -338,12 +334,6 @@ impl From<u8> for RecvSendState {
}
}

impl Default for RecvSendState {
fn default() -> Self {
RecvSendState::Closed
}
}

/// StreamState represents the state of an SCTP stream
#[derive(Default, Debug)]
pub struct StreamState {
Expand Down
3 changes: 0 additions & 3 deletions src/chunk/chunk_abort.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::{chunk_header::*, chunk_type::*, *};

use bytes::{Bytes, BytesMut};
use std::fmt;

///Abort represents an SCTP Chunk of type ABORT
///
///The ABORT chunk is sent to the peer of an association to close the
Expand Down
3 changes: 0 additions & 3 deletions src/chunk/chunk_cookie_ack.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::{chunk_header::*, chunk_type::*, *};

use bytes::{Bytes, BytesMut};
use std::fmt;

/// chunkCookieAck represents an SCTP Chunk of type chunkCookieAck
///
/// 0 1 2 3
Expand Down
3 changes: 0 additions & 3 deletions src/chunk/chunk_cookie_echo.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::{chunk_header::*, chunk_type::*, *};

use bytes::{Bytes, BytesMut};
use std::fmt;

/// CookieEcho represents an SCTP Chunk of type CookieEcho
///
/// 0 1 2 3
Expand Down
3 changes: 0 additions & 3 deletions src/chunk/chunk_error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::{chunk_header::*, chunk_type::*, *};

use bytes::{Bytes, BytesMut};
use std::fmt;

///Operation Error (ERROR) (9)
///
///An endpoint sends this chunk to its peer endpoint to notify it of
Expand Down
3 changes: 0 additions & 3 deletions src/chunk/chunk_forward_tsn.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::{chunk_header::*, chunk_type::*, *};

use bytes::{Buf, BufMut, Bytes, BytesMut};
use std::fmt;

///This chunk shall be used by the data sender to inform the data
///receiver to adjust its cumulative received TSN point forward because
///some missing TSNs are associated with data chunks that SHOULD NOT be
Expand Down
3 changes: 0 additions & 3 deletions src/chunk/chunk_header.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::{chunk_type::*, *};

use bytes::{Buf, BufMut, Bytes, BytesMut};
use std::fmt;

///chunkHeader represents a SCTP Chunk header, defined in https://tools.ietf.org/html/rfc4960#section-3.2
///The figure below illustrates the field format for the chunks to be
///transmitted in the SCTP packet. Each chunk is formatted with a Chunk
Expand Down
3 changes: 0 additions & 3 deletions src/chunk/chunk_heartbeat.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use super::{chunk_header::*, chunk_type::*, *};
use crate::param::{param_header::*, param_type::*, *};

use bytes::{Bytes, BytesMut};
use std::fmt;

///chunkHeartbeat represents an SCTP Chunk of type HEARTBEAT
///
///An endpoint should send this chunk to its peer endpoint to probe the
Expand Down
3 changes: 0 additions & 3 deletions src/chunk/chunk_heartbeat_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ use crate::param::param_type::ParamType;
use crate::param::{param_header::*, *};
use crate::util::get_padding_size;

use bytes::{Bytes, BytesMut};
use std::fmt;

///chunkHeartbeatAck represents an SCTP Chunk of type HEARTBEAT ACK
///
///An endpoint should send this chunk to its peer endpoint as a response
Expand Down
3 changes: 0 additions & 3 deletions src/chunk/chunk_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ use crate::param::param_supported_extensions::ParamSupportedExtensions;
use crate::param::{param_header::*, *};
use crate::util::get_padding_size;

use bytes::{Buf, BufMut, Bytes, BytesMut};
use std::fmt;

///chunkInitCommon represents an SCTP Chunk body of type INIT and INIT ACK
///
/// 0 1 2 3
Expand Down
10 changes: 2 additions & 8 deletions src/chunk/chunk_payload_data.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use super::{chunk_header::*, chunk_type::*, *};

use bytes::{Buf, BufMut, Bytes, BytesMut};
use std::fmt;
use std::time::Instant;

pub(crate) const PAYLOAD_DATA_ENDING_FRAGMENT_BITMASK: u8 = 1;
Expand All @@ -15,21 +13,17 @@ pub(crate) const PAYLOAD_DATA_HEADER_SIZE: usize = 12;
// <https://www.iana.org/assignments/sctp-parameters/sctp-parameters.xhtml#sctp-parameters-25>
#[derive(Debug, Copy, Clone, PartialEq)]
#[repr(C)]
#[derive(Default)]
pub enum PayloadProtocolIdentifier {
Dcep = 50,
String = 51,
Binary = 53,
StringEmpty = 56,
BinaryEmpty = 57,
#[default]
Unknown,
}

impl Default for PayloadProtocolIdentifier {
fn default() -> Self {
PayloadProtocolIdentifier::Unknown
}
}

impl fmt::Display for PayloadProtocolIdentifier {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match *self {
Expand Down
3 changes: 0 additions & 3 deletions src/chunk/chunk_reconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ use super::{chunk_header::*, chunk_type::*, *};
use crate::param::{param_header::*, *};
use crate::util::get_padding_size;

use bytes::{Bytes, BytesMut};
use std::fmt;

///https://tools.ietf.org/html/rfc6525#section-3.1
///chunkReconfig represents an SCTP Chunk used to reconfigure streams.
///
Expand Down
3 changes: 0 additions & 3 deletions src/chunk/chunk_selective_ack.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use super::{chunk_header::*, chunk_type::*, *};

use bytes::{Buf, BufMut, Bytes, BytesMut};
use std::fmt;

///chunkSelectiveAck represents an SCTP Chunk of type SACK
///
///This chunk is sent to the peer endpoint to acknowledge received DATA
Expand Down
Loading
Loading