Skip to content

Commit

Permalink
add node_info struct to feedback status to sdn collector
Browse files Browse the repository at this point in the history
  • Loading branch information
marverlous811 committed Sep 10, 2024
1 parent 9052eae commit 4d982f5
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions crates/relayer/src/proxy_listener/cluster.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use std::{net::SocketAddr, sync::Arc, time::Duration};
use std::{
net::SocketAddr,
sync::Arc,
time::{Duration, Instant},
};

use atm0s_sdn::{
features::{
Expand All @@ -8,14 +12,16 @@ use atm0s_sdn::{
sans_io_runtime::backend::PollingBackend,
secure::StaticKeyAuthorization,
services::visualization,
NodeAddr, NodeId, SdnBuilder, SdnExtIn, SdnExtOut, SdnOwner, ServiceBroadcastLevel,
NodeAddr, NodeId, SdnBuilder, SdnControllerUtils, SdnExtIn, SdnExtOut, SdnOwner,
ServiceBroadcastLevel,
};
use futures::{AsyncRead, AsyncWrite};
use protocol::cluster::{ClusterTunnelRequest, ClusterTunnelResponse};
use quinn::{Endpoint, Incoming};

use alias_async::AliasAsyncEvent;
use rustls::pki_types::{CertificateDer, PrivatePkcs8KeyDer};
use serde::{Deserialize, Serialize};
use vnet::{NetworkPkt, OutEvent};

use super::{ProxyListener, ProxyTunnel};
Expand All @@ -32,7 +38,10 @@ pub use vnet::VirtualNetwork;
pub use vsocket::VirtualUdpSocket;

type UserData = ();
type NodeInfo = ();
#[derive(Clone, Debug, Serialize, Deserialize)]

Check warning on line 41 in crates/relayer/src/proxy_listener/cluster.rs

View check run for this annotation

Codecov / codecov/patch

crates/relayer/src/proxy_listener/cluster.rs#L41

Added line #L41 was not covered by tests
pub struct NodeInfo {
uptime: u32,
}
type SC = visualization::Control<NodeInfo>;
type SE = visualization::Event<NodeInfo>;
type TC = ();
Expand Down Expand Up @@ -68,8 +77,23 @@ pub async fn run_sdn(
}

async_std::task::spawn(async move {
let mut controller = builder.build::<PollingBackend<SdnOwner, 128, 128>>(workers, ());
let node_info = NodeInfo { uptime: 0 };
let started_at = Instant::now();
let mut count = 0;
let mut controller =
builder.build::<PollingBackend<SdnOwner, 128, 128>>(workers, node_info);

Check warning on line 84 in crates/relayer/src/proxy_listener/cluster.rs

View check run for this annotation

Codecov / codecov/patch

crates/relayer/src/proxy_listener/cluster.rs#L80-L84

Added lines #L80 - L84 were not covered by tests
while controller.process().is_some() {
if count % 500 == 0 {
//each 5 seconds
controller.service_control(
visualization::SERVICE_ID.into(),
(),
visualization::Control::UpdateInfo(NodeInfo {
uptime: started_at.elapsed().as_secs() as u32,
}),
);
count = 0;
}

Check warning on line 96 in crates/relayer/src/proxy_listener/cluster.rs

View check run for this annotation

Codecov / codecov/patch

crates/relayer/src/proxy_listener/cluster.rs#L86-L96

Added lines #L86 - L96 were not covered by tests
while let Ok(c) = rx.try_recv() {
// log::info!("Command: {:?}", c);
match c {
Expand Down Expand Up @@ -167,6 +191,7 @@ pub async fn run_sdn(
}
}
async_std::task::sleep(Duration::from_millis(1)).await;
count += 1;

Check warning on line 194 in crates/relayer/src/proxy_listener/cluster.rs

View check run for this annotation

Codecov / codecov/patch

crates/relayer/src/proxy_listener/cluster.rs#L194

Added line #L194 was not covered by tests
}
});

Expand Down

0 comments on commit 4d982f5

Please sign in to comment.