Skip to content

Commit 81c0466

Browse files
committed
feat(rust): keep the same port for incoming services
1 parent 2fd0902 commit 81c0466

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

implementations/rust/ockam/ockam_app_lib/src/incoming_services/commands.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ impl AppState {
4444
Ok(port) => {
4545
if let Some(service) = guard.find_mut_by_id(service.id()) {
4646
if let Some(port) = port {
47-
service.set_port(port)
47+
service.set_port(port);
4848
}
49+
service.set_connected(true);
4950
}
5051
}
5152
Err(err) => {
5253
warn!(%err, "Failed to refresh TCP inlet for accepted invitation");
5354
if let Some(service) = guard.find_mut_by_id(service.id()) {
54-
service.remove_port()
55+
service.set_connected(false);
5556
}
5657
}
5758
}

implementations/rust/ockam/ockam_app_lib/src/incoming_services/state.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ pub struct IncomingService {
175175
// this field contains the current port number
176176
// it also reflects if the inlet is connected with the destination node
177177
port: Option<Port>,
178+
// true when connected to the destination node
179+
connected: bool,
178180
// whether the service should be enabled or not, this is the driver for the inlet
179181
// and may not reflect the current status
180182
enabled: bool,
@@ -216,6 +218,7 @@ impl IncomingService {
216218
shared_node_identifier,
217219
original_name,
218220
enrollment_ticket,
221+
connected: false,
219222
removed: false,
220223
}
221224
}
@@ -240,6 +243,11 @@ impl IncomingService {
240243
self.port
241244
}
242245

246+
/// Returns true if the inlet is connected to the destination node
247+
pub fn is_connected(&self) -> bool {
248+
self.connected
249+
}
250+
243251
/// The address of the inlet, if service is connected to the destination node
244252
pub fn address(&self) -> Option<SocketAddr> {
245253
self.port
@@ -259,16 +267,15 @@ impl IncomingService {
259267
self.port = Some(port);
260268
}
261269

262-
pub fn remove_port(&mut self) {
263-
self.port = None;
270+
pub fn set_connected(&mut self, connected: bool) {
271+
self.connected = connected;
264272
}
265273

266274
pub fn enable(&mut self) {
267275
self.enabled = true;
268276
}
269277
pub fn disable(&mut self) {
270278
self.enabled = false;
271-
self.port = None;
272279
}
273280

274281
/// True when the service is marked as removed

implementations/rust/ockam/ockam_app_lib/src/state/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ impl AppState {
622622
address: service.address().map(|addr| addr.ip().to_string()),
623623
port: service.port(),
624624
scheme: None,
625-
available: service.port().is_some(),
625+
available: service.is_connected(),
626626
enabled: service.enabled(),
627627
})
628628
.collect();

0 commit comments

Comments
 (0)