aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-05-21 23:42:27 -0400
committerJesse Luehrs <doy@tozt.net>2020-05-21 23:42:27 -0400
commit318413b119c5f0e988079bb7bede1a4a86583a7a (patch)
treeeb68345d61f86321986188fbd2382fff6cb7e166
parent41123157c6d356006af12425863f003a4dc87f3d (diff)
downloadrbw-318413b119c5f0e988079bb7bede1a4a86583a7a.tar.gz
rbw-318413b119c5f0e988079bb7bede1a4a86583a7a.zip
use the crate version for the protocol version
-rw-r--r--src/bin/rbw-agent/actions.rs2
-rw-r--r--src/bin/rbw/commands.rs17
-rw-r--r--src/protocol.rs12
3 files changed, 21 insertions, 10 deletions
diff --git a/src/bin/rbw-agent/actions.rs b/src/bin/rbw-agent/actions.rs
index e1124e0..d2b38dc 100644
--- a/src/bin/rbw-agent/actions.rs
+++ b/src/bin/rbw-agent/actions.rs
@@ -299,7 +299,7 @@ pub async fn encrypt(
pub async fn version(sock: &mut crate::sock::Sock) -> anyhow::Result<()> {
sock.send(&rbw::protocol::Response::Version {
- version: rbw::protocol::VERSION,
+ version: rbw::protocol::version(),
})
.await
.context("failed to send response")?;
diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs
index 2934de3..ff6f51e 100644
--- a/src/bin/rbw/commands.rs
+++ b/src/bin/rbw/commands.rs
@@ -784,22 +784,23 @@ pub fn stop_agent() -> anyhow::Result<()> {
fn ensure_agent() -> anyhow::Result<()> {
ensure_agent_once()?;
- let version = version_or_quit()?;
- if version != rbw::protocol::VERSION {
+ let client_version = rbw::protocol::version();
+ let agent_version = version_or_quit()?;
+ if agent_version != client_version {
log::debug!(
"client protocol version is {} but agent protocol version is {}",
- rbw::protocol::VERSION,
- version
+ client_version,
+ agent_version
);
crate::actions::quit()?;
ensure_agent_once()?;
- let version = version_or_quit()?;
- if version != rbw::protocol::VERSION {
+ let agent_version = version_or_quit()?;
+ if agent_version != client_version {
crate::actions::quit()?;
return Err(anyhow::anyhow!(
"incompatible protocol versions: client ({}), agent ({})",
- rbw::protocol::VERSION,
- version
+ client_version,
+ agent_version
));
}
}
diff --git a/src/protocol.rs b/src/protocol.rs
index cf0c278..68506b2 100644
--- a/src/protocol.rs
+++ b/src/protocol.rs
@@ -1,4 +1,14 @@
-pub const VERSION: u32 = 3;
+// eventually it would be nice to make this a const function so that we could
+// just get the version from a variable directly, but this is fine for now
+pub fn version() -> u32 {
+ let major = env!("CARGO_PKG_VERSION_MAJOR");
+ let minor = env!("CARGO_PKG_VERSION_MINOR");
+ let patch = env!("CARGO_PKG_VERSION_PATCH");
+
+ major.parse::<u32>().unwrap() * 1_000_000
+ + minor.parse::<u32>().unwrap() * 1_000
+ + patch.parse::<u32>().unwrap()
+}
#[derive(serde::Serialize, serde::Deserialize, Debug)]
pub struct Request {