Skip to content

Commit

Permalink
feat: version check for pruntime
Browse files Browse the repository at this point in the history
  • Loading branch information
krhougs committed Oct 31, 2022
1 parent fbe3844 commit 0148434
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ trust-dns-resolver = { version = "0.22.0", features = ["dns-over-https-rustls"]
rust-fsm = "0.6.0"
urlparse = "0.7.3"
tower-http = { version = "0.3.4", features = ["cors"] }
semver = "1.0.14"

[workspace]
22 changes: 20 additions & 2 deletions src/bin/service_worker/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::WorkerRuntimeStatus::*;
use crate::{
ShouldLockBroker, ShouldSetBrokerFailed, ShouldUpdateStatus, CONFIG, PRUNTIME_CLIENT,
REQ_CLIENT, RT_CTX, WR,
ShouldLockBroker, ShouldSetBrokerFailed, ShouldUpdateStatus, CONFIG, REQ_CLIENT, RT_CTX, WR,
};
use anyhow::{anyhow, Context, Result};
use log::{debug, error, info};
use mdns_sd::{Error, ServiceDaemon};
use phactory_api::prpc::{NetworkConfig, NetworkConfigResponse, PhactoryInfo};
use phactory_api::pruntime_client::PRuntimeClient;
use reqwest::header::CONTENT_TYPE;
use semver::{Version, VersionReq};
use service_network::config::LOCAL_WORKER_KEEPALIVE_INTERVAL;
use service_network::mgmt_types::{LocalWorkerIdentity, MyIdentity, R_V0_LOCAL_WORKER_KEEPALIVE};
use service_network::peer::local_worker::{BrokerPeerUpdateSender, WrappedBrokerPeer};
Expand All @@ -22,6 +22,8 @@ use tokio::sync::RwLock;
use tokio::time::{sleep, Duration};
use urlparse::urlparse;

const PRUNTIME_VERSION_REQ: &str = ">=2.0.0";

#[derive(Debug, Clone)]
pub enum WorkerRuntimeChannelMessage {
ShouldUpdateInfo(PhactoryInfo),
Expand Down Expand Up @@ -119,6 +121,22 @@ impl WorkerRuntime {
.hostname
.unwrap();

let version_req = VersionReq::parse(PRUNTIME_VERSION_REQ).unwrap();
let version = Version::parse(&ir.version).unwrap();
if !(version_req.matches(&version)) {
error!(
"pRuntime version unsupported! Requires {}, found {}.",
PRUNTIME_VERSION_REQ, &ir.version
);
let _ = rt_tx
.clone()
.send(WorkerRuntimeChannelMessage::ShouldSetPRuntimeFailed(
"pRuntime version unsupported!".to_string(),
))
.await;
return;
}

let initialized = &ir.initialized;
let initialized = *initialized;
if !initialized {
Expand Down

0 comments on commit 0148434

Please sign in to comment.