Skip to content

Commit

Permalink
feat(vm): extend peer.identify with vm connection info (#2364)
Browse files Browse the repository at this point in the history
* extend peer.identify with vm connection info

---------

Co-authored-by: Aleksey Proshutinskiy <justprosh@users.noreply.github.com>
  • Loading branch information
kmd-fl and justprosh authored Sep 13, 2024
1 parent 127fac5 commit e29fca5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
2 changes: 2 additions & 0 deletions crates/server-config/src/node_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,10 @@ pub struct VmNetworkConfig {
pub public_ip: Ipv4Addr,
#[serde(default = "default_vm_ip")]
pub vm_ip: Ipv4Addr,
// SSH port on the host machine to connect to the VM from outside
#[serde(default = "default_host_ssh_port")]
pub host_ssh_port: u16,
// SSH port inside the VM
#[serde(default = "default_vm_ssh_port")]
pub vm_ssh_port: u16,
#[serde(default = "default_port_range_config")]
Expand Down
11 changes: 9 additions & 2 deletions nox/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use core_distributor::CoreDistributor;
use fluence_libp2p::build_transport;
use health::HealthCheckRegistry;
use particle_builtins::{
Builtins, BuiltinsConfig, CustomService, NodeInfo, ParticleAppServicesConfig,
Builtins, BuiltinsConfig, CustomService, NodeInfo, ParticleAppServicesConfig, PortInfo, VmInfo,
};
use particle_execution::ParticleFunctionStatic;
use particle_protocol::ExtendedParticle;
Expand Down Expand Up @@ -405,8 +405,15 @@ impl<RT: AquaRuntime> Node<RT> {
node_version: env!("CARGO_PKG_VERSION"),
air_version: air_interpreter_wasm::VERSION,
spell_version: spell_version.clone(),
// TODO: remove
allowed_binaries,
vm_info: config.node_config.vm.as_ref().map(|vm| VmInfo {
ip: vm.network.public_ip.to_string(),
default_ssh_port: vm.network.host_ssh_port,
forwarded_ports: vec![PortInfo::Range(
vm.network.port_range.start,
vm.network.port_range.end,
)],
}),
};
if let Some(m) = metrics_registry.as_mut() {
peer_metrics::add_info_metrics(
Expand Down
41 changes: 41 additions & 0 deletions particle-builtins/src/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,45 @@ pub struct NodeInfo {
pub air_version: &'static str,
pub spell_version: String,
pub allowed_binaries: Vec<PathBuf>,
// Note: this is Vec for Aqua's representation of an option
#[serde(serialize_with = "serialize_aqua_option")]
pub vm_info: Option<VmInfo>,
}

fn serialize_aqua_option<S>(value: &Option<VmInfo>, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
match value {
Some(vm_info) => serializer.collect_seq(&[vm_info]),
None => serializer.serialize_none(),
}
}

#[derive(Serialize, Clone, Debug)]
pub struct VmInfo {
// Public IP via which we can connect to the VM
pub ip: String,
// List of ports that are forwarded to the VM
pub forwarded_ports: Vec<PortInfo>,
// Default SSH port to which to connect
pub default_ssh_port: u16,
}

#[derive(Clone, Debug)]
pub enum PortInfo {
Port(u16),
Range(u16, u16),
}

impl Serialize for PortInfo {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
match self {
PortInfo::Port(port) => serializer.serialize_u16(*port),
PortInfo::Range(start, end) => serializer.serialize_str(&format!("{}-{}", start, end)),
}
}
}
2 changes: 1 addition & 1 deletion particle-builtins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
)]

pub use builtins::{Builtins, BuiltinsConfig, CustomService};
pub use identify::NodeInfo;
pub use identify::{NodeInfo, PortInfo, VmInfo};
pub use outcome::{ok, wrap, wrap_unit};
pub use particle_services::ParticleAppServicesConfig;
mod builtins;
Expand Down

0 comments on commit e29fca5

Please sign in to comment.