Skip to content

Commit e29fca5

Browse files
kmd-fljustprosh
andauthored
feat(vm): extend peer.identify with vm connection info (#2364)
* extend peer.identify with vm connection info --------- Co-authored-by: Aleksey Proshutinskiy <[email protected]>
1 parent 127fac5 commit e29fca5

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed

crates/server-config/src/node_config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,10 @@ pub struct VmNetworkConfig {
637637
pub public_ip: Ipv4Addr,
638638
#[serde(default = "default_vm_ip")]
639639
pub vm_ip: Ipv4Addr,
640+
// SSH port on the host machine to connect to the VM from outside
640641
#[serde(default = "default_host_ssh_port")]
641642
pub host_ssh_port: u16,
643+
// SSH port inside the VM
642644
#[serde(default = "default_vm_ssh_port")]
643645
pub vm_ssh_port: u16,
644646
#[serde(default = "default_port_range_config")]

nox/src/node.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use core_distributor::CoreDistributor;
5454
use fluence_libp2p::build_transport;
5555
use health::HealthCheckRegistry;
5656
use particle_builtins::{
57-
Builtins, BuiltinsConfig, CustomService, NodeInfo, ParticleAppServicesConfig,
57+
Builtins, BuiltinsConfig, CustomService, NodeInfo, ParticleAppServicesConfig, PortInfo, VmInfo,
5858
};
5959
use particle_execution::ParticleFunctionStatic;
6060
use particle_protocol::ExtendedParticle;
@@ -405,8 +405,15 @@ impl<RT: AquaRuntime> Node<RT> {
405405
node_version: env!("CARGO_PKG_VERSION"),
406406
air_version: air_interpreter_wasm::VERSION,
407407
spell_version: spell_version.clone(),
408-
// TODO: remove
409408
allowed_binaries,
409+
vm_info: config.node_config.vm.as_ref().map(|vm| VmInfo {
410+
ip: vm.network.public_ip.to_string(),
411+
default_ssh_port: vm.network.host_ssh_port,
412+
forwarded_ports: vec![PortInfo::Range(
413+
vm.network.port_range.start,
414+
vm.network.port_range.end,
415+
)],
416+
}),
410417
};
411418
if let Some(m) = metrics_registry.as_mut() {
412419
peer_metrics::add_info_metrics(

particle-builtins/src/identify.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,45 @@ pub struct NodeInfo {
2727
pub air_version: &'static str,
2828
pub spell_version: String,
2929
pub allowed_binaries: Vec<PathBuf>,
30+
// Note: this is Vec for Aqua's representation of an option
31+
#[serde(serialize_with = "serialize_aqua_option")]
32+
pub vm_info: Option<VmInfo>,
33+
}
34+
35+
fn serialize_aqua_option<S>(value: &Option<VmInfo>, serializer: S) -> Result<S::Ok, S::Error>
36+
where
37+
S: serde::Serializer,
38+
{
39+
match value {
40+
Some(vm_info) => serializer.collect_seq(&[vm_info]),
41+
None => serializer.serialize_none(),
42+
}
43+
}
44+
45+
#[derive(Serialize, Clone, Debug)]
46+
pub struct VmInfo {
47+
// Public IP via which we can connect to the VM
48+
pub ip: String,
49+
// List of ports that are forwarded to the VM
50+
pub forwarded_ports: Vec<PortInfo>,
51+
// Default SSH port to which to connect
52+
pub default_ssh_port: u16,
53+
}
54+
55+
#[derive(Clone, Debug)]
56+
pub enum PortInfo {
57+
Port(u16),
58+
Range(u16, u16),
59+
}
60+
61+
impl Serialize for PortInfo {
62+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
63+
where
64+
S: serde::Serializer,
65+
{
66+
match self {
67+
PortInfo::Port(port) => serializer.serialize_u16(*port),
68+
PortInfo::Range(start, end) => serializer.serialize_str(&format!("{}-{}", start, end)),
69+
}
70+
}
3071
}

particle-builtins/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
)]
3434

3535
pub use builtins::{Builtins, BuiltinsConfig, CustomService};
36-
pub use identify::NodeInfo;
36+
pub use identify::{NodeInfo, PortInfo, VmInfo};
3737
pub use outcome::{ok, wrap, wrap_unit};
3838
pub use particle_services::ParticleAppServicesConfig;
3939
mod builtins;

0 commit comments

Comments
 (0)