rename MultiSocket to Socket

This commit is contained in:
Hailey Somerville 2023-08-22 15:36:23 +10:00
parent 35c92973d6
commit 5cd67b0b51
4 changed files with 16 additions and 14 deletions

View file

@ -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");

View file

@ -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<MultiSocket, ListenError> {
pub struct PeerId(SocketAddrV4);
impl Socket {
pub fn open(opt: SocketOpt) -> Result<Socket, ListenError> {
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<Socket, ListenError> {
fn open_multicast(group: Ipv4Addr, bind: SocketAddrV4) -> Result<socket2::Socket, ListenError> {
let socket = bind_socket(bind)?;
// join multicast group
@ -93,8 +95,8 @@ fn open_multicast(group: Ipv4Addr, bind: SocketAddrV4) -> Result<Socket, ListenE
Ok(socket.into())
}
fn bind_socket(bind: SocketAddrV4) -> Result<Socket, ListenError> {
let socket = Socket::new(Domain::IPV4, Type::DGRAM, None)
fn bind_socket(bind: SocketAddrV4) -> Result<socket2::Socket, ListenError> {
let socket = socket2::Socket::new(Domain::IPV4, Type::DGRAM, None)
.map_err(ListenError::Socket)?;
socket.set_reuse_address(true).map_err(ListenError::SetReuseAddr)?;

View file

@ -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);

View file

@ -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);