valeriansaliou / vigil

🚦 Microservices Status Page. Monitors a distributed infrastructure and sends alerts (Slack, SMS, etc.).

Home Page:https://crates.io/crates/vigil-server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

XMPP notifier uses deprecated APIs

kauron opened this issue · comments

It seems that src/notifier/xmpp.rs is outdated w.r.t. the time and libstrophe libraries.

With my limited Rust knowledge, I created a patch, but there are still errors that escape my comprehension. Can anyone help me complete this fix?

Patch
@@ -5,8 +5,7 @@
 // License: Mozilla Public License v2.0 (MPL v2.0)
 
 use std::sync::RwLock;
-use std::time::Duration;
-use time;
+use std::time::{SystemTime, UNIX_EPOCH, Duration};
 
 use libstrophe::{Connection, ConnectionEvent, Context, Stanza, StreamError};
 
@@ -46,13 +45,16 @@
                              _error: i32,
                              _stream_error: Option<StreamError>| {
                 match event {
-                    ConnectionEvent::XMPP_CONN_CONNECT => {
+                    ConnectionEvent::Connect => {
                         debug!("connected to XMPP account: {}", &xmpp.from);
 
                         // Send status message
                         let mut message_stanza = Stanza::new_message(
                             Some("chat"),
-                            Some(&format!("vigil-{}", time::now().to_timespec().sec)),
+                            Some(&format!("vigil-{}", SystemTime::now()
+                                          .duration_since(UNIX_EPOCH)
+                                          .expect("Time went backwards")
+                                          .as_secs())),
                             Some(&xmpp.to),
                         );
 
@@ -69,7 +71,7 @@
                         // Disconnect immediately
                         connection.disconnect();
                     }
-                    ConnectionEvent::XMPP_CONN_DISCONNECT | ConnectionEvent::XMPP_CONN_FAIL => {
+                    ConnectionEvent::Disconnect(..) => {
                         debug!(
                             "disconnected from XMPP account: {} ({:?})",
                             &xmpp.from, event
Error
  • Vigil version: 1.22.5
  • Apply patch and run: cargo build --frozen --release --all-features
  • Rust version: 1.59.0
  • Error:
error[E0593]: closure is expected to take 3 arguments, but it takes 5 arguments
   --> src/notifier/xmpp.rs:99:83
    |
42  |               let fn_handle = |context: &Context,
    |  _____________________________-
43  | |                              connection: &mut Connection,
44  | |                              event: ConnectionEvent,
45  | |                              _error: i32,
46  | |                              _stream_error: Option<StreamError>| {
    | |________________________________________________________________- takes 5 arguments
...
99  |               if let Ok(connection_context) = connection.connect_client(None, None, &fn_handle) {
    |                                                          --------------             ^^^^^^^^^^ expected closure that takes 3 arguments
    |                                                          |
    |                                                          required by a bound introduced by this call
    |
    = note: required because of the requirements on the impl of `for<'r, 's, 't0, 't1> FnMut<(&'r libstrophe::Context<'_, '_>, &'s mut Connection<'_, '_>, ConnectionEvent<'t0, 't1>)>` for `&[closure@src/notifier/xmpp.rs:42:29: 84:14]`
note: required by a bound in `Connection::<'cb, 'cx>::connect_client`
   --> $HOME/.cargo/registry/src/github.com-1285ae84e5963aae/libstrophe-0.16.1/src/connection.rs:336:8
    |
336 |             CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>, ConnectionEvent) + Send + 'cb,
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Connection::<'cb, 'cx>::connect_client`

For more information about this error, try `rustc --explain E0593`.
error: could not compile `vigil-server` due to previous error

Hello there! Do you mean that the current libstrophe v0.16.x has different APIs than those implemented in Vigil, therefore leading to failing compilation?

Yes, exactly. There are some changes that I don't understand due to lack of knowledge of Rust, so I couldn't fix them all.

Working for me using libstrophe 0.12.2 from Homebrew on macOS, w/ the following environment variable set during the build of Vigil:

export RUSTFLAGS="-L /opt/homebrew/Cellar/libstrophe/0.12.2/lib/"
cargo run --all-features

Should work w/o passing the library path on Linux systems w/ libstrophe installed.