From 5cd67b0b515663a584b73ea854e0e8aa741457f6 Mon Sep 17 00:00:00 2001 From: Hailey Somerville Date: Tue, 22 Aug 2023 15:36:23 +1000 Subject: [PATCH] rename MultiSocket to Socket --- src/receive.rs | 4 ++-- src/socket.rs | 18 ++++++++++-------- src/stats/mod.rs | 4 ++-- src/stream.rs | 4 ++-- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/receive.rs b/src/receive.rs index 7281171..a5b93c3 100644 --- a/src/receive.rs +++ b/src/receive.rs @@ -10,7 +10,7 @@ use structopt::StructOpt; use crate::protocol::{AudioPacket, self, TimePacket, TimestampMicros, Packet, SessionId, ReceiverId, TimePhase, StatsReplyPacket, StatsReplyFlags}; use crate::resample::Resampler; -use crate::socket::{MultiSocket, SocketOpt}; +use crate::socket::{Socket, SocketOpt}; use crate::stats::node::NodeStats; use crate::stats::receiver::{ReceiverStats, StreamStatus}; use crate::time::{Timestamp, SampleDuration, TimestampDelta, ClockDelta}; @@ -529,7 +529,7 @@ pub fn run(opt: ReceiveOpt) -> Result<(), RunError> { None ).map_err(RunError::BuildStream)?; - let socket = MultiSocket::open(opt.socket) + let socket = Socket::open(opt.socket) .map_err(RunError::Listen)?; crate::thread::set_name("bark/network"); diff --git a/src/socket.rs b/src/socket.rs index ea260fd..0b49c11 100644 --- a/src/socket.rs +++ b/src/socket.rs @@ -3,7 +3,7 @@ use std::net::{Ipv4Addr, UdpSocket, SocketAddr, SocketAddrV4}; use std::os::fd::AsRawFd; use nix::poll::{PollFd, PollFlags}; -use socket2::{Socket, Domain, Type}; +use socket2::{Domain, Type}; use structopt::StructOpt; // expedited forwarding - IP header field indicating that switches should @@ -26,7 +26,7 @@ pub struct SocketOpt { pub multicast: SocketAddrV4, } -pub struct MultiSocket { +pub struct Socket { multicast: SocketAddrV4, // used to send unicast + multicast packets, as well as receive unicast replies @@ -37,15 +37,17 @@ pub struct MultiSocket { rx: UdpSocket, } -impl MultiSocket { - pub fn open(opt: SocketOpt) -> Result { +pub struct PeerId(SocketAddrV4); + +impl Socket { + pub fn open(opt: SocketOpt) -> Result { let group = *opt.multicast.ip(); let port = opt.multicast.port(); let tx = open_multicast(group, SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 0))?; let rx = open_multicast(group, SocketAddrV4::new(group, port))?; - Ok(MultiSocket { + Ok(Socket { multicast: SocketAddrV4::new(group, port), tx: tx.into(), rx: rx.into(), @@ -79,7 +81,7 @@ impl MultiSocket { } } -fn open_multicast(group: Ipv4Addr, bind: SocketAddrV4) -> Result { +fn open_multicast(group: Ipv4Addr, bind: SocketAddrV4) -> Result { let socket = bind_socket(bind)?; // join multicast group @@ -93,8 +95,8 @@ fn open_multicast(group: Ipv4Addr, bind: SocketAddrV4) -> Result Result { - let socket = Socket::new(Domain::IPV4, Type::DGRAM, None) +fn bind_socket(bind: SocketAddrV4) -> Result { + let socket = socket2::Socket::new(Domain::IPV4, Type::DGRAM, None) .map_err(ListenError::Socket)?; socket.set_reuse_address(true).map_err(ListenError::SetReuseAddr)?; diff --git a/src/stats/mod.rs b/src/stats/mod.rs index 6301c9f..ba502d3 100644 --- a/src/stats/mod.rs +++ b/src/stats/mod.rs @@ -14,7 +14,7 @@ use structopt::StructOpt; use termcolor::BufferedStandardStream; use crate::protocol::{StatsRequestPacket, self, StatsReplyPacket, StatsReplyFlags}; -use crate::socket::{MultiSocket, SocketOpt}; +use crate::socket::{Socket, SocketOpt}; use crate::RunError; use self::render::Padding; @@ -26,7 +26,7 @@ pub struct StatsOpt { } pub fn run(opt: StatsOpt) -> Result<(), RunError> { - let socket = MultiSocket::open(opt.socket) + let socket = Socket::open(opt.socket) .map_err(RunError::Listen)?; let socket = Arc::new(socket); diff --git a/src/stream.rs b/src/stream.rs index a2c273c..75174c4 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -7,7 +7,7 @@ use cpal::InputCallbackInfo; use structopt::StructOpt; use crate::protocol::{self, Packet, TimestampMicros, AudioPacket, PacketBuffer, TimePacket, MAX_PACKET_SIZE, TimePacketPadding, SessionId, ReceiverId, TimePhase, StatsReplyPacket, StatsReplyFlags}; -use crate::socket::{MultiSocket, SocketOpt}; +use crate::socket::{Socket, SocketOpt}; use crate::stats::node::NodeStats; use crate::stats::receiver::ReceiverStats; use crate::time::{SampleDuration, Timestamp}; @@ -45,7 +45,7 @@ pub fn run(opt: StreamOpt) -> Result<(), RunError> { let config = util::config_for_device(&device)?; - let socket = MultiSocket::open(opt.socket) + let socket = Socket::open(opt.socket) .map_err(RunError::Listen)?; let socket = Arc::new(socket);