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

Add a 'Connections' property #110

Merged
merged 6 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ else
endif
@start-sdk pack

install:
ifeq (,$(wildcard ~/.embassy/config.yaml))
@echo; echo "You must define \"host: http://server-name.local\" in ~/.embassy/config.yaml config file first"; echo
install: $(PKG_ID).s9pk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is wrong - it will force universal package build on each install making arm and x86 targets useless

ifeq (,$(wildcard ./start9/config.yaml))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are searching for the start-sdk config file that resides (by default) in users home directory and has host defined for easy installation

@echo; echo "You must define \"host: http://embassy-server-name.local\" in ./start9/config.yaml config file first"; echo
kn0wmad marked this conversation as resolved.
Show resolved Hide resolved
else
start-cli package install $(PKG_ID).s9pk
endif
Expand Down
32 changes: 32 additions & 0 deletions manager/src/main.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dr-bonez take a look at it please

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed main.rs looks good to my eye. Good catch on the Makefile

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ pub struct ChainInfo {
softforks: LinearMap<String, SoftFork>,
}

#[derive(Clone, Debug, serde::Deserialize)]
pub struct NetworkInfo {
connections: usize,
connections_in: usize,
connections_out: usize,
}

#[derive(Clone, Debug, serde::Deserialize)]
#[serde(tag = "type")]
pub enum SoftFork {
Expand Down Expand Up @@ -372,6 +379,31 @@ fn sidecar(config: &Mapping, addr: &str) -> Result<(), Box<dyn Error>> {
std::str::from_utf8(&info_res.stderr).unwrap_or("UNKNOWN ERROR")
);
}
let info_res = std::process::Command::new("bitcoin-cli")
.arg("-conf=/root/.bitcoin/bitcoin.conf")
.arg("getnetworkinfo")
.output()?;
if info_res.status.success() {
let info: NetworkInfo = serde_json::from_slice(&info_res.stdout)?;
stats.insert(
Cow::from("Connections"),
Stat {
value_type: "string",
value: format!("{} ({} in / {} out)", info.connections, info.connections_in, info.connections_out),
description: Some(Cow::from("The number of peers connected (inbound and outbound)")),
copyable: false,
qr: false,
masked: false,
},
);
} else if info_res.status.code() == Some(28) {
return Ok(());
} else {
eprintln!(
"Error updating network info: {}",
std::str::from_utf8(&info_res.stderr).unwrap_or("UNKNOWN ERROR")
);
}
serde_yaml::to_writer(
std::fs::File::create("/root/.bitcoin/start9/.stats.yaml.tmp")?,
&Stats {
Expand Down