@@ -22,6 +22,7 @@ pub use filter::{
22
22
} ;
23
23
pub use recv:: InboundPacket ;
24
24
pub use send:: OutboundPacket ;
25
+
25
26
/// Convenience objects for setting up the recv handler.
26
27
pub struct SocketConfig {
27
28
/// The executor to spawn the tasks.
@@ -30,6 +31,8 @@ pub struct SocketConfig {
30
31
pub socket_addr : SocketAddr ,
31
32
/// Configuration details for the packet filter.
32
33
pub filter_config : FilterConfig ,
34
+ /// Type of socket to create.
35
+ pub ip_mode : IpMode ,
33
36
/// If the filter is enabled this sets the default timeout for bans enacted by the filter.
34
37
pub ban_duration : Option < Duration > ,
35
38
/// The expected responses reference.
@@ -49,7 +52,7 @@ pub struct Socket {
49
52
impl Socket {
50
53
/// This creates and binds a new UDP socket.
51
54
// In general this function can be expanded to handle more advanced socket creation.
52
- pub ( crate ) async fn new_socket (
55
+ async fn new_socket (
53
56
socket_addr : & SocketAddr ,
54
57
ip_mode : IpMode ,
55
58
) -> Result < tokio:: net:: UdpSocket , Error > {
@@ -84,7 +87,9 @@ impl Socket {
84
87
/// Creates a UDP socket, spawns a send/recv task and returns the channels.
85
88
/// If this struct is dropped, the send/recv tasks will shutdown.
86
89
/// This needs to be run inside of a tokio executor.
87
- pub ( crate ) fn new ( socket : tokio:: net:: UdpSocket , config : SocketConfig ) -> Result < Self , Error > {
90
+ pub ( crate ) async fn new ( config : SocketConfig ) -> Result < Self , Error > {
91
+ let socket = Socket :: new_socket ( & config. socket_addr , config. ip_mode ) . await ?;
92
+
88
93
// Arc the udp socket for the send/recv tasks.
89
94
let recv_udp = Arc :: new ( socket) ;
90
95
let send_udp = recv_udp. clone ( ) ;
0 commit comments