Show info about xmpp errors

[?]
Dec 31, 2018, 12:57 PM
4LRBIGVT4GOFDT7EUBBRG7776IC6WVJYTB6NVMIBVWAFGISYGIUAC

Dependencies

  • [2] HOAZX2PB Reorganize roster processing. Output roster
  • [3] 3GEU7TC7 Welcome to 2018!
  • [4] PFC7OJQF Query roster
  • [5] TDOR5XQU Accept destination
  • [6] AGIW6YR3 Use shared future for signal everywhere
  • [7] PBRUH4BJ Rename optional XmppConnection to MaybeXmppConnection
  • [8] EOHEZXX3 Move request processing to structure
  • [9] FV6BJ5K6 Send self-presence and store account info in Rc so it willbe used in some future in parallel
  • [10] H7R7Y3FQ Use new processing code to wait online
  • [11] NDDQQP2P Update deps
  • [12] 5OBTKGDL Update deps
  • [13] HU3NZX5Z Process self-presence via new processing code
  • [14] BTOZT4JP Use failure
  • [15] IK3YDPTY Update deps
  • [16] QYY3KRGL Use failure instead Box<dyn Error>
  • [17] XGP44R5H Rework stopping xmpp connection
  • [18] X6L47BHQ Use different structure for established xmpp connection
  • [19] OGMBXBKP Move online to XmppConnection
  • [20] ZI4GJ72V Add message to xmpp command
  • [21] VS6AHRWI Move XMPP to separate dir
  • [22] FVVPKFTL Initial commit
  • [23] QWE26TMV update deps

Change contents

  • edit in src/xmpp/stanzas.rs at line 2
    [3.57][3.0:26]()
    use xmpp_parsers::iq::Iq;
  • edit in src/xmpp/stanzas.rs at line 3
    [3.141][3.27:61]()
    use xmpp_parsers::roster::Roster;
  • edit in src/xmpp/stanzas.rs at line 12
    [3.419][3.62:272]()
    pub fn make_get_roster(id: &str) -> Element {
    let mut get_roster = Iq::from_get(Roster {
    ver: None,
    items: vec![],
    });
    get_roster.id = Some(id.to_string());
    get_roster.into()
    }
  • edit in src/xmpp/mod.rs at line 9
    [3.434][2.0:47]()
    const ID_GET_ROSTER: &str = "id_get_roster0";
  • replacement in src/xmpp/mod.rs at line 38
    [3.554][3.479:781]()
    /// don't connect if stop_future resolved
    fn connect<F>(
    self,
    stop_future: F,
    ) -> impl Future<Item = XmppConnection, Error = failure::Error>
    where
    F: future::Future + Clone + 'static,
    <F as hyper::rt::Future>::Error: Into<failure::Error> + Send,
    {
    [3.554]
    [3.653]
    /// Error shoud be !
    fn connect<E: 'static>(self) -> impl Future<Item = XmppConnection, Error = E> {
  • replacement in src/xmpp/mod.rs at line 45
    [3.910][3.910:962]()
    as Box<Future<Item = _, Error = _>>
    [3.910]
    [3.944]
    as Box<Future<Item = _, Error = E>>
  • replacement in src/xmpp/mod.rs at line 47
    [3.961][3.963:1618]()
    Box::new(
    stop_future
    .clone()
    .select2(
    future::loop_fn(account, move |account| {
    info!("xmpp initialization...");
    let res_client = Client::new(&account.jid, &account.password);
    match res_client {
    Err(_e) => Box::new(future::ok(future::Loop::Continue(account)))
    as Box<Future<Item = _, Error = _>>,
    Ok(client) => {
    info!("xmpp initialized");
    [3.961]
    [3.1476]
    Box::new(future::loop_fn(account, |account| {
    info!("xmpp initialization...");
    let mut res_client = Client::new(&account.jid, &account.password);
    while let Err(e) = res_client {
    error!("Cann't init xmpp client: {}", e);
    res_client = Client::new(&account.jid, &account.password);
    }
    let client = res_client.expect("Cann't init xmpp client");
    info!("xmpp initialized");
  • replacement in src/xmpp/mod.rs at line 57
    [3.1477][3.1619:1695](),[3.1695][3.273:349](),[3.349][3.1695:2243](),[3.1695][3.1695:2243](),[3.2243][3.350:533](),[3.533][3.2334:2926](),[3.2334][3.2334:2926](),[3.2437][3.426:466](),[3.1167][3.426:466](),[3.2926][3.426:466](),[3.426][3.426:466](),[3.466][3.2927:3372]()
    let stop_future2 = stop_future.clone();
    let stop_future3 = stop_future.clone();
    // future to wait for online
    Box::new(
    XmppConnection {
    inner: client,
    account,
    }
    .processing(XmppConnection::online, stop_future.clone())
    .map(|(conn, _)| conn)
    .map_err(|(acc, _)| acc)
    .and_then(|conn| conn.initial_roster(stop_future2))
    .and_then(|conn| conn.self_presence(stop_future3))
    .then(
    |r| match r {
    Ok(conn) => future::ok(future::Loop::Break(conn)),
    Err(acc) => future::ok(future::Loop::Continue(acc)),
    },
    ),
    )
    }
    }
    })
    .map_err(|_: ()| ()),
    )
    .then(|r| match r {
    Ok(Either::A((_x, _b))) => future::err(format_err!("Stop XMMP connection")),
    Ok(Either::B((x, _a))) => future::ok(x),
    Err(Either::A((e, _b))) => future::err(e.into()),
    Err(Either::B((_, _a))) => {
    future::err(format_err!("Cann't initiate XMPP connection"))
    }
    }),
    )
    [3.1477]
    [3.1858]
    // future to wait for online
    XmppConnection {
    inner: client,
    account,
    }
    .online()
    .and_then(XmppConnection::self_presence)
    .then(|r| match r {
    Ok(conn) => future::ok(future::Loop::Break(conn)),
    Err(acc) => future::ok(future::Loop::Continue(acc)),
    })
    }))
  • replacement in src/xmpp/mod.rs at line 75
    [3.3427][3.3427:3535]()
    fn xmpp_processing(&mut self, event: &Event) {
    info!("Incoming xmpp event: {:?}", event);
    }
    [3.3427]
    [3.3535]
    fn xmpp_processing(&mut self, event: &Event) {}
  • replacement in src/xmpp/mod.rs at line 85
    [3.3776][3.3776:3958]()
    Item = (Self, Result<Either<F, T>, failure::Error>),
    Error = (
    std::rc::Rc<config::Account>,
    Result<Either<F, T>, failure::Error>,
    ),
    [3.3776]
    [3.3958]
    Item = (Self, Result<Either<F, T>, E>),
    Error = (std::rc::Rc<config::Account>, Result<Either<F, T>, E>),
  • replacement in src/xmpp/mod.rs at line 90
    [3.4014][3.4014:4047](),[3.4047][3.534:602]()
    E: Into<failure::Error>,
    S: FnMut(&mut Self, Event) -> Result<bool, failure::Error>,
    [3.4014]
    [3.4116]
    S: FnMut(&mut Self, &Event) -> bool,
  • replacement in src/xmpp/mod.rs at line 104
    [3.4701][3.603:672](),[3.672][3.4771:5203](),[3.4771][3.4771:5203]()
    match stop_condition(&mut xmpp, event) {
    Ok(true) => {
    future::ok(future::Loop::Break((xmpp, Ok(Either::A(b)))))
    }
    Ok(false) => {
    future::ok(future::Loop::Continue((xmpp, b, stop_condition)))
    }
    Err(e) => future::err((xmpp.account, Err(e))),
    [3.4701]
    [3.5203]
    if stop_condition(&mut xmpp, &event) {
    future::ok(future::Loop::Break((xmpp, Ok(Either::A(b)))))
    } else {
    future::ok(future::Loop::Continue((xmpp, b, stop_condition)))
  • replacement in src/xmpp/mod.rs at line 123
    [3.5802][3.5802:5891]()
    Err(Either::A((_e, b))) => future::err((account, Ok(Either::A(b)))),
    [3.5802]
    [3.5891]
    Err(Either::A((e, b))) => {
    warn!("XMPP error: {}", e.0);
    future::err((account, Ok(Either::A(b))))
    }
  • replacement in src/xmpp/mod.rs at line 131
    [3.6129][3.6129:6176]()
    Err(e.into()),
    [3.6129]
    [3.6176]
    Err(e),
  • replacement in src/xmpp/mod.rs at line 134
    [3.6241][3.6241:6307]()
    future::err((account, Err(e.into())))
    [3.6241]
    [3.5513]
    future::err((account, Err(e)))
  • replacement in src/xmpp/mod.rs at line 144
    [3.6432][3.673:746](),[3.746][3.6506:6926](),[3.6506][3.6506:6926](),[3.6926][3.747:748](),[3.748][2.48:1664]()
    fn online(&mut self, event: Event) -> Result<bool, failure::Error> {
    match event {
    Event::Online => {
    info!("Online!");
    Ok(true)
    }
    Event::Stanza(s) => {
    warn!("Stanza before online: {:?}", s);
    Ok(false)
    }
    _ => {
    error!("Disconnected while online");
    Err(format_err!("Disconnected while online"))
    }
    }
    }
    fn process_initial_roster(&mut self, event: Event) -> Result<bool, failure::Error> {
    if let Event::Stanza(s) = event {
    use try_from::TryInto;
    match s.try_into() as Result<xmpp_parsers::iq::Iq, _> {
    Ok(iq) => {
    if let Some(id) = iq.id {
    if id == ID_GET_ROSTER {
    match iq.payload {
    xmpp_parsers::iq::IqType::Error(_e) => {
    Err(format_err!("Get error instead of roster"))
    }
    xmpp_parsers::iq::IqType::Result(Some(result)) => {
    match result.try_into()
    as Result<xmpp_parsers::roster::Roster, _>
    {
    Ok(roster) => {
    info!("Got roster:");
    for i in roster.items {
    info!(" >>> {:?}", i);
    }
    Ok(true)
    }
    Err(e) => Err(format_err!("Cann't parse roster: {}", e)),
    }
    }
    _ => Err(format_err!("Unknown result of roster")),
    }
    } else {
    Ok(false)
    [3.6432]
    [2.1664]
    fn online(self) -> impl Future<Item = XmppConnection, Error = std::rc::Rc<config::Account>> {
    Box::new(future::loop_fn(
    (self.inner, self.account),
    |(client, account)| {
    client.into_future().then(|r| match r {
    Ok((event, client)) => match event {
    Some(Event::Online) => {
    info!("Online");
    future::ok(future::Loop::Break(XmppConnection {
    account,
    inner: client,
    }))
    }
    Some(Event::Stanza(s)) => {
    info!("xmpp stanza: {:?}", s);
    future::ok(future::Loop::Continue((client, account)))
    }
    _ => {
    warn!("Disconnected");
    future::err(account)
  • replacement in src/xmpp/mod.rs at line 165
    [2.1690][2.1690:1784]()
    } else {
    Err(format_err!("Iq stanza without id"))
    [2.1690]
    [2.1784]
    },
    Err((e, _)) => {
    error!("xmpp receive error: {}", e);
    future::err(account)
  • replacement in src/xmpp/mod.rs at line 170
    [2.1806][2.1806:1975](),[2.1975][3.748:1095](),[3.748][3.748:1095](),[3.1162][3.6926:6927](),[3.6926][3.6926:6927](),[3.6927][2.1976:2042](),[2.2042][3.1230:1697](),[3.1230][3.1230:1697](),[3.1697][2.2043:2124](),[2.2124][3.3184:3687](),[3.3184][3.3184:3687]()
    }
    Err(_e) => Ok(false),
    }
    } else {
    Err(format_err!("Wrong event while waiting roster"))
    }
    }
    fn initial_roster<F, E>(
    self,
    stop_future: F,
    ) -> impl Future<Item = Self, Error = std::rc::Rc<config::Account>>
    where
    F: Future<Error = E>,
    E: Into<failure::Error>,
    {
    let XmppConnection {
    account,
    inner: client,
    } = self;
    use tokio::prelude::Sink;
    let get_roster = stanzas::make_get_roster(ID_GET_ROSTER);
    let account2 = account.clone();
    info!("Quering roster... {:?}", get_roster);
    client
    .send(get_roster)
    .map_err(move |e| {
    error!("Error on querying roster: {}", e);
    (account2, Err(failure::SyncFailure::new(e).into()))
    })
    .and_then(move |client| {
    XmppConnection {
    inner: client,
    account,
    }
    .processing(XmppConnection::process_initial_roster, stop_future)
    })
    .then(|r| match r {
    Err((account, e)) => {
    error!(
    "Cann't wait roster: {}",
    e.err().map_or_else(
    || std::borrow::Cow::Borrowed("None"),
    |e| e.to_string().into()
    )
    );
    future::err(account)
    }
    Ok((conn, _)) => future::ok(conn),
    })
    [2.1806]
    [3.3687]
    })
    },
    ))
  • replacement in src/xmpp/mod.rs at line 175
    [3.3694][3.6927:7144](),[3.6927][3.6927:7144](),[3.7144][3.3695:3790]()
    fn self_presence<F, E>(
    self,
    stop_future: F,
    ) -> impl Future<Item = Self, Error = std::rc::Rc<config::Account>>
    where
    F: Future<Error = E>,
    E: Into<failure::Error>,
    {
    let XmppConnection {
    account,
    inner: client,
    } = self;
    [3.3694]
    [3.7173]
    fn self_presence(self) -> impl Future<Item = Self, Error = std::rc::Rc<config::Account>> {
    let XmppConnection { account, inner } = self;
    let client = inner;
  • edit in src/xmpp/mod.rs at line 181
    [3.7265]
    [3.7303]
    info!("Sending presence...");
  • replacement in src/xmpp/mod.rs at line 183
    [3.7343][3.3791:3845](),[3.3845][3.7343:8375](),[3.7343][3.7343:8375](),[3.8375][3.5234:5260](),[3.5234][3.5234:5260](),[3.5260][3.8376:8497](),[3.8497][3.3846:3886](),[3.3886][3.8536:8718](),[3.8536][3.8536:8718]()
    info!("Sending presence... {:?}", presence);
    client
    .send(presence)
    .map_err(|e| {
    error!("Error on send self-presence: {}", e);
    (account2, Err(failure::SyncFailure::new(e).into()))
    })
    .and_then(move |client| {
    XmppConnection {
    inner: client,
    account,
    }
    .processing(
    move |conn, event| {
    if let Event::Stanza(s) = event {
    if s.name() == "presence"
    && s.attr("from").map_or(false, |f| f == conn.account.jid)
    && s.attr("to").map_or(false, |f| f == conn.account.jid)
    {
    Ok(true)
    } else {
    Ok(false)
    }
    } else {
    Err(format_err!("Wrong event while waiting self-presence"))
    }
    },
    stop_future,
    )
    })
    .then(|r| match r {
    Err((account, _e)) => {
    error!("Cann't wait self-presence");
    future::err(account)
    }
    Ok((conn, _)) => future::ok(conn),
    })
    [3.7343]
    [3.3783]
    Box::new(
    client
    .send(presence)
    .map_err(|e| {
    error!("Error on send self-presence: {}", e);
    "Cann't send self-presence".to_owned()
    })
    .and_then(move |client| {
    future::loop_fn((account2.clone(), client), |(account, client)| {
    client
    .into_future()
    .map_err(|(e, _)| {
    error!("Error on reading self-presence: {}", e);
    "Cann't read self-presence".to_owned()
    })
    .and_then(|(event, client)| match event {
    Some(event) => {
    if let tokio_xmpp::Event::Stanza(e) = event {
    info!("Get stanza: {:?}", e);
    if e.name() == "presence"
    && e.attr("from").map_or(false, |f| f == account.jid)
    && e.attr("to").map_or(false, |f| f == account.jid)
    {
    info!("Self presence");
    future::ok(future::Loop::Break(client))
    } else {
    future::ok(future::Loop::Continue((account, client)))
    }
    } else {
    future::err("Got wrong event".to_owned())
    }
    }
    None => future::err("Got closed stream".to_owned()),
    })
    })
    .map_err(|e| format!("waiting self-presence: {}", e))
    })
    .then(|r| match r {
    Err(e) => {
    error!("Self-presence waiting error: {}", e);
    future::err(account)
    }
    Ok(inner) => future::ok(XmppConnection { account, inner }),
    }),
    )
  • replacement in src/xmpp/mod.rs at line 256
    [3.4311][3.8860:8987]()
    F: future::Future + Clone + 'static,
    <F as hyper::rt::Future>::Error: std::fmt::Display + Into<failure::Error> + Send,
    [3.4311]
    [3.465]
    F: future::Future<Item = ()> + 'static,
  • edit in src/xmpp/mod.rs at line 259
    [3.4357]
    [3.8988]
    let signal = signal.map_err(|_| format_err!("Wrong shutdown signal"));
  • replacement in src/xmpp/mod.rs at line 269
    [3.4692][3.9039:9107]()
    conn.connect(signal.clone())
    .and_then(|conn| {
    [3.4692]
    [3.4761]
    signal
    .select2(conn.connect().and_then(|conn| {
  • replacement in src/xmpp/mod.rs at line 278
    [3.675][3.9108:9189]()
    .map(|(cmd, cmd_recv)| (cmd, cmd_recv, conn))
    })
    [3.675]
    [3.731]
    .map(|f| (f, conn))
    }))
  • replacement in src/xmpp/mod.rs at line 282
    [3.5146][3.9190:9763]()
    Ok((cmd, cmd_recv, conn)) => {
    if let Some(_cmd) = cmd {
    info!("Got cmd");
    // got cmd, continue
    future::ok(future::Loop::Continue(XmppState::new(
    cmd_recv,
    signal,
    conn.into(),
    )))
    } else {
    future::ok(future::Loop::Break((None, conn.into())))
    }
    [3.5146]
    [3.7045]
    Ok(Either::A((_x, b))) => {
    info!("Got signal");
    // got signal, breaks
    Box::new(b.map(|b| future::Loop::Break((Some((b.0).1), b.1.into()))))
    as Box<Future<Item = _, Error = _>>
    }
    Ok(Either::B((x, a))) => {
    info!("Got cmd");
    // got cmd, continue
    Box::new(future::ok(future::Loop::Continue(XmppState::new(
    (x.0).1,
    a,
    x.1.into(),
    )))) as Box<Future<Item = _, Error = _>>
    }
    Err(Either::A((e, b))) => {
    // got signal error, breaks
    error!("Signal error: {}", e);
    Box::new(b.map(|b| future::Loop::Break((Some((b.0).1), b.1.into()))))
    as Box<Future<Item = _, Error = _>>
  • replacement in src/xmpp/mod.rs at line 303
    [3.7067][3.9764:9796]()
    Err(e) => {
    [3.7067]
    [3.6240]
    Err(Either::B((e, _a))) => {
  • replacement in src/xmpp/mod.rs at line 306
    [3.6342][3.3887:3926]()
    future::err(e)
    [3.6342]
    [3.6572]
    Box::new(future::err(format_err!("Cmd error")))
    as Box<Future<Item = _, Error = _>>
  • replacement in src/xmpp/mod.rs at line 322
    [3.1354][3.9935:9972]()
    Box::new(future::ok(()))
    [3.1354]
    [3.1422]
    Box::new(future::err(format_err!("cmd receiver gone")))
  • replacement in src/main.rs at line 63
    [3.4954][3.10033:10140]()
    .map_err(|e| {
    error!("Cann't get CTRL+C signal: {}", e.0);
    e.0
    })
    [3.4954]
    [3.5020]
    .map_err(|e| error!("Cann't get CTRL+C signal: {}", e.0))
  • replacement in src/main.rs at line 97
    [3.6389][3.10922:11010]()
    let result = ctrt.block_on(xmpp_process(ctrl_c.clone(), recv, config.account));
    [3.6389]
    [3.6536]
    let result = ctrt.block_on(xmpp_process(
    ctrl_c.clone().map(|_| ()),
    recv,
    config.account,
    ));
  • edit in Cargo.toml at line 23
    [3.7111][3.3927:3976]()
    try_from = "=0.2.2" # dependency of xmpp-parsers
  • edit in Cargo.lock at line 1110
    [3.44807][3.3977:4052]()
    "try_from 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",