Skip to content

Commit

Permalink
Split out stun types/proto to a separate crate
Browse files Browse the repository at this point in the history
Now depends on stun-types/stun-proto for STUN.
  • Loading branch information
ystreet committed Jun 19, 2024
1 parent c6c8db1 commit 5b54863
Show file tree
Hide file tree
Showing 25 changed files with 139 additions and 5,891 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/rust-fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ jobs:
command: 'install'
args: 'cargo-fuzz'

- name: Run cargo-fuzz
uses: actions-rs/cargo@v1
with:
command: 'fuzz'
args: 'run stun_msg_from_bytes -- -max_total_time=20'

- name: Run cargo-fuzz
uses: actions-rs/cargo@v1
with:
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ edition = "2021"
rust-version = "1.68.2"

[workspace.dependencies]
stun-proto = "0.0.1"
arbitrary = { version = "1", features = ["derive"] }
byteorder = "1"
get_if_addrs = "0.5"
Expand Down
8 changes: 1 addition & 7 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,12 @@ cargo-fuzz = true
arbitrary.workspace = true
libfuzzer-sys = "0.4"
tracing.workspace = true
tracing-subscriber.workspace = true
tracing-subscriber = { workspace = true, features = ["env-filter"] }

[dependencies.librice-proto]
path = "../librice-proto"
features = ["arbitrary"]

[[bin]]
name = "stun_msg_from_bytes"
path = "fuzz_targets/stun_msg_from_bytes.rs"
test = false
doc = false

[[bin]]
name = "parse_candidate"
path = "fuzz_targets/parse_candidate.rs"
Expand Down
36 changes: 0 additions & 36 deletions fuzz/fuzz_targets/stun_msg_from_bytes.rs

This file was deleted.

6 changes: 1 addition & 5 deletions librice-proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ capi = ["libc", "socket2", "tracing-subscriber/env-filter", "get_if_addrs"]
[dependencies]
arbitrary = { workspace = true, optional = true }
byteorder.workspace = true
crc = "3"
get_if_addrs = { workspace = true, optional = true }
hmac = "0.12"
md-5 = "0.10"
nom = "7"
rand.workspace = true
sha-1 = "0.10"
sha2 = "0.10"
tracing.workspace = true
libc = { version = "0.2", optional = true }
socket2 = { version = "0.5", optional = true }
stun-proto.workspace = true
tracing-subscriber = { workspace = true, optional = true }

[dev-dependencies]
Expand Down
15 changes: 4 additions & 11 deletions librice-proto/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use crate::component::ComponentConnectionState;
use crate::candidate::{ParseCandidateError, TransportType};
use crate::conncheck::{CheckListSetPollRet, ConnCheckEvent, ConnCheckListSet, SelectedPair};
use crate::stream::{Stream, StreamMut, StreamState};
use crate::stun::agent::{StunError, Transmit};
use crate::stun::attribute::StunParseError;
use stun_proto::agent::{StunError, Transmit};
use stun_proto::types::message::StunParseError;
//use crate::turn::agent::TurnCredentials;

/// Errors that can be returned as a result of agent operations.
Expand All @@ -49,10 +49,9 @@ pub enum AgentError {
Aborted,
TimedOut,
StunParse,
StunWrite,
/// Parsing the candidate failed.
CandidateParse(ParseCandidateError),
/// An I/O error occurred.
IoError(std::io::Error),
/// Data was received that does not match the protocol specifications.
ProtocolViolation,
}
Expand All @@ -65,12 +64,6 @@ impl Display for AgentError {
}
}

impl From<std::io::Error> for AgentError {
fn from(e: std::io::Error) -> Self {
Self::IoError(e)
}
}

impl From<ParseCandidateError> for AgentError {
fn from(e: ParseCandidateError) -> Self {
Self::CandidateParse(e)
Expand All @@ -88,7 +81,7 @@ impl From<StunError> for AgentError {
StunError::IntegrityCheckFailed => AgentError::IntegrityCheckFailed,
StunError::ProtocolViolation => AgentError::ProtocolViolation,
StunError::ParseError(_) => AgentError::StunParse,
StunError::IoError(e) => AgentError::IoError(e),
StunError::WriteError(_) => AgentError::StunWrite,
StunError::Aborted => AgentError::Aborted,
StunError::AlreadyInProgress => AgentError::AlreadyInProgress,
}
Expand Down
4 changes: 2 additions & 2 deletions librice-proto/src/candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

//! ICE Candidates
pub use crate::stun::TransportType;
pub use parse::ParseCandidateError;
pub use stun_proto::types::TransportType;

use std::error::Error;
use std::net::SocketAddr;
Expand Down Expand Up @@ -442,7 +442,7 @@ mod parse {

use super::{Candidate, CandidateType, ParseCandidateTypeError};
use super::{ParseTcpTypeError, TcpType};
use crate::stun::{ParseTransportTypeError, TransportType};
use stun_proto::types::{ParseTransportTypeError, TransportType};

/// Errors produced when parsing a candidate
#[derive(Debug)]
Expand Down
4 changes: 2 additions & 2 deletions librice-proto/src/capi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use crate::candidate::{Candidate, CandidateType};
pub use crate::component::ComponentConnectionState;
use crate::gathering::GatherPoll;
use crate::stream::Credentials;
use crate::stun::agent::{Data, DataOwned, DataSlice, StunAgent, StunError, Transmit};
use crate::stun::TransportType;
use stun_proto::agent::{Data, DataOwned, DataSlice, StunAgent, StunError, Transmit};
use stun_proto::types::TransportType;

static TRACING: Once = Once::new();

Expand Down
Loading

0 comments on commit 5b54863

Please sign in to comment.