Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vm): extend peer.identify with vm connection info #2364

Merged
merged 8 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,4 @@ jobs:
uses: fluencelabs/aqua/.github/workflows/tests.yml@main
with:
nox-image: "${{ needs.nox-snapshot.outputs.nox-image }}"
ref: update-peer-identify
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
22 changes: 13 additions & 9 deletions nox/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use libp2p::{
use libp2p_connection_limits::ConnectionLimits;
use libp2p_metrics::{Metrics, Recorder};
use prometheus_client::registry::Registry;
use std::path::PathBuf;
use std::process::exit;
use std::sync::Arc;
use std::{io, net::SocketAddr};
Expand All @@ -54,7 +53,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 @@ -393,20 +392,25 @@ impl<RT: AquaRuntime> Node<RT> {
)
.await;

let allowed_binaries = config
let allowed_effectors = config
.allowed_effectors
.values()
.flat_map(|v| v.values().cloned().collect::<Vec<PathBuf>>())
.collect::<std::collections::HashSet<_>>()
.into_iter()
.keys()
.map(|key| key.to_string())
.collect::<_>();
let node_info = NodeInfo {
external_addresses: config.external_addresses(),
node_version: env!("CARGO_PKG_VERSION"),
air_version: air_interpreter_wasm::VERSION,
spell_version: spell_version.clone(),
// TODO: remove
allowed_binaries,
allowed_effectors,
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
44 changes: 42 additions & 2 deletions particle-builtins/src/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,53 @@
*/
use libp2p::core::Multiaddr;
use serde::Serialize;
use std::path::PathBuf;

#[derive(Serialize, Clone, Debug)]
pub struct NodeInfo {
pub external_addresses: Vec<Multiaddr>,
pub node_version: &'static str,
pub air_version: &'static str,
pub spell_version: String,
pub allowed_binaries: Vec<PathBuf>,
pub allowed_effectors: Vec<String>,
// 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
Loading