Skip to content

Commit a857688

Browse files
committed
backend: share udp socket between ManagementSockets
1 parent 89c62e9 commit a857688

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

backend/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub struct BridgeState {
8181
pub charger_remote_conn_map: Mutex<HashMap<RemoteConnMeta, SocketAddr>>,
8282
pub undiscovered_chargers: Arc<Mutex<HashMap<IpNetwork, HashSet<DiscoveryCharger>>>>,
8383
pub lost_connections: Mutex<HashMap<uuid::Uuid, Vec<(i32, Session)>>>,
84-
pub socket: UdpSocket,
84+
pub socket: Arc<UdpSocket>,
8585
}
8686

8787
pub struct AppState {
@@ -345,7 +345,7 @@ pub(crate) mod tests {
345345
web_client_map: Mutex::new(HashMap::new()),
346346
undiscovered_chargers: Arc::new(Mutex::new(HashMap::new())),
347347
lost_connections: Mutex::new(HashMap::new()),
348-
socket: UdpSocket::bind(("0", 0)).unwrap(),
348+
socket: Arc::new(UdpSocket::bind(("0", 0)).unwrap()),
349349
};
350350

351351
let cache: web::Data<std::sync::Mutex<LruCache<String, Vec<u8>>>> = web::Data::new(

backend/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ async fn main() -> std::io::Result<()> {
166166
charger_remote_conn_map: Mutex::new(HashMap::new()),
167167
undiscovered_chargers: Arc::new(Mutex::new(HashMap::new())),
168168
lost_connections: Mutex::new(HashMap::new()),
169-
socket: UdpSocket::bind("0.0.0.0:51820").unwrap(),
169+
socket: Arc::new(UdpSocket::bind("0.0.0.0:51820").unwrap()),
170170
});
171171

172172
let state_cpy = state.clone();

backend/src/udp_server/multiplex.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ async fn create_tunn(
149149
));
150150
};
151151

152-
let udp_socket = state.socket.try_clone()?;
152+
let udp_socket = Arc::clone(&state.socket);
153153
let socket = ManagementSocket::new(
154154
self_ip,
155155
peer_ip,
156156
addr,
157157
tunn,
158158
rate_limiter,
159-
Arc::new(udp_socket),
159+
udp_socket,
160160
charger.id,
161161
);
162162
return Ok((charger.id, socket));

0 commit comments

Comments
 (0)