Show info about xmpp errors
[?]
Dec 31, 2018, 12:57 PM
4LRBIGVT4GOFDT7EUBBRG7776IC6WVJYTB6NVMIBVWAFGISYGIUACDependencies
- [2]
HOAZX2PBReorganize roster processing. Output roster - [3]
3GEU7TC7Welcome to 2018! - [4]
PFC7OJQFQuery roster - [5]
TDOR5XQUAccept destination - [6]
AGIW6YR3Use shared future for signal everywhere - [7]
PBRUH4BJRename optional XmppConnection to MaybeXmppConnection - [8]
EOHEZXX3Move request processing to structure - [9]
FV6BJ5K6Send self-presence and store account info in Rc so it willbe used in some future in parallel - [10]
H7R7Y3FQUse new processing code to wait online - [11]
NDDQQP2PUpdate deps - [12]
5OBTKGDLUpdate deps - [13]
HU3NZX5ZProcess self-presence via new processing code - [14]
BTOZT4JPUse failure - [15]
IK3YDPTYUpdate deps - [16]
QYY3KRGLUse failure instead Box<dyn Error> - [17]
XGP44R5HRework stopping xmpp connection - [18]
X6L47BHQUse different structure for established xmpp connection - [19]
OGMBXBKPMove online to XmppConnection - [20]
ZI4GJ72VAdd message to xmpp command - [21]
VS6AHRWIMove XMPP to separate dir - [22]
FVVPKFTLInitial commit - [23]
QWE26TMVupdate deps
Change contents
- edit in src/xmpp/stanzas.rs at line 2
use xmpp_parsers::iq::Iq; - edit in src/xmpp/stanzas.rs at line 3
use xmpp_parsers::roster::Roster; - edit in src/xmpp/stanzas.rs at line 12
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
const ID_GET_ROSTER: &str = "id_get_roster0"; - replacement in src/xmpp/mod.rs at line 38
/// don't connect if stop_future resolvedfn connect<F>(self,stop_future: F,) -> impl Future<Item = XmppConnection, Error = failure::Error>whereF: future::Future + Clone + 'static,<F as hyper::rt::Future>::Error: Into<failure::Error> + Send,{/// Error shoud be !fn connect<E: 'static>(self) -> impl Future<Item = XmppConnection, Error = E> { - replacement in src/xmpp/mod.rs at line 45
as Box<Future<Item = _, Error = _>>as Box<Future<Item = _, Error = E>> - replacement in src/xmpp/mod.rs at line 47
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");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 onlineBox::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"))}}),)// future to wait for onlineXmppConnection {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
fn xmpp_processing(&mut self, event: &Event) {info!("Incoming xmpp event: {:?}", event);}fn xmpp_processing(&mut self, event: &Event) {} - replacement in src/xmpp/mod.rs at line 85
Item = (Self, Result<Either<F, T>, failure::Error>),Error = (std::rc::Rc<config::Account>,Result<Either<F, T>, failure::Error>,),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
E: Into<failure::Error>,S: FnMut(&mut Self, Event) -> Result<bool, failure::Error>,S: FnMut(&mut Self, &Event) -> bool, - replacement in src/xmpp/mod.rs at line 104
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))),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
Err(Either::A((_e, b))) => future::err((account, Ok(Either::A(b)))),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
Err(e.into()),Err(e), - replacement in src/xmpp/mod.rs at line 134
future::err((account, Err(e.into())))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)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
} else {Err(format_err!("Iq stanza without id"))},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>>whereF: 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),})})},)) - replacement in src/xmpp/mod.rs at line 175
fn self_presence<F, E>(self,stop_future: F,) -> impl Future<Item = Self, Error = std::rc::Rc<config::Account>>whereF: Future<Error = E>,E: Into<failure::Error>,{let XmppConnection {account,inner: client,} = self;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
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),})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
F: future::Future + Clone + 'static,<F as hyper::rt::Future>::Error: std::fmt::Display + Into<failure::Error> + Send,F: future::Future<Item = ()> + 'static, - edit in src/xmpp/mod.rs at line 259
let signal = signal.map_err(|_| format_err!("Wrong shutdown signal")); - replacement in src/xmpp/mod.rs at line 269
conn.connect(signal.clone()).and_then(|conn| {signal.select2(conn.connect().and_then(|conn| { - replacement in src/xmpp/mod.rs at line 278
.map(|(cmd, cmd_recv)| (cmd, cmd_recv, conn))}).map(|f| (f, conn))})) - replacement in src/xmpp/mod.rs at line 282
Ok((cmd, cmd_recv, conn)) => {if let Some(_cmd) = cmd {info!("Got cmd");// got cmd, continuefuture::ok(future::Loop::Continue(XmppState::new(cmd_recv,signal,conn.into(),)))} else {future::ok(future::Loop::Break((None, conn.into())))}Ok(Either::A((_x, b))) => {info!("Got signal");// got signal, breaksBox::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, continueBox::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, breakserror!("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
Err(e) => {Err(Either::B((e, _a))) => { - replacement in src/xmpp/mod.rs at line 306
future::err(e)Box::new(future::err(format_err!("Cmd error")))as Box<Future<Item = _, Error = _>> - replacement in src/xmpp/mod.rs at line 322
Box::new(future::ok(()))Box::new(future::err(format_err!("cmd receiver gone"))) - replacement in src/main.rs at line 63
.map_err(|e| {error!("Cann't get CTRL+C signal: {}", e.0);e.0}).map_err(|e| error!("Cann't get CTRL+C signal: {}", e.0)) - replacement in src/main.rs at line 97
let result = ctrt.block_on(xmpp_process(ctrl_c.clone(), recv, config.account));let result = ctrt.block_on(xmpp_process(ctrl_c.clone().map(|_| ()),recv,config.account,)); - edit in Cargo.toml at line 23
try_from = "=0.2.2" # dependency of xmpp-parsers - edit in Cargo.lock at line 1110
"try_from 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",