Rename XmppState to XmppProcessState
[?]
Dec 31, 2018, 5:57 PM
ALP2YJIUN45LOOJU7GZWYDY7BMLCKR3LJVFPXTTLLZFB4LSYJKMACDependencies
- [2]
5IKA4GO7Rename xmpp client field from "inner" to "client" - [3]
TDOR5XQUAccept destination - [4]
QWE26TMVupdate deps - [5]
EOHEZXX3Move request processing to structure - [6]
VS6AHRWIMove XMPP to separate dir - [7]
XGP44R5HRework stopping xmpp connection - [8]
5OBTKGDLUpdate deps - [9]
FV6BJ5K6Send self-presence and store account info in Rc so it willbe used in some future in parallel - [10]
5A5UVGNMMove receiver closing logic out of xmpp processing - [11]
HU3NZX5ZProcess self-presence via new processing code - [12]
PVCRPP3BSome servers don't send to in initial presence - [13]
PBRUH4BJRename optional XmppConnection to MaybeXmppConnection - [14]
NDDQQP2PUpdate deps - [15]
V5HDBSZMUse jid for receiver address - [16]
PFC7OJQFQuery roster - [17]
ZI4GJ72VAdd message to xmpp command - [18]
O2GM5J4FDon't split xmpp receiving and sending - [19]
HOAZX2PBReorganize roster processing. Output roster - [20]
X6L47BHQUse different structure for established xmpp connection - [21]
AYQZ2UIAUpdate deps - [22]
QYY3KRGLUse failure instead Box<dyn Error> - [23]
AGIW6YR3Use shared future for signal everywhere - [24]
BTOZT4JPUse failure - [25]
IK3YDPTYUpdate deps - [26]
3GEU7TC7Welcome to 2018! - [27]
4LRBIGVTShow info about xmpp errors - [28]
OGMBXBKPMove online to XmppConnection - [*]
FVVPKFTLInitial commit
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 12
client: Option<Client>,inner: Option<Client>, - replacement in src/xmpp/mod.rs at line 17
client: Client,inner: Client, - replacement in src/xmpp/mod.rs at line 24
client: Some(from.client),inner: Some(from.inner), - replacement in src/xmpp/mod.rs at line 33
client: None,inner: None, - replacement in src/xmpp/mod.rs at line 44
F: future::Future + Clone + 'static,F: future::Future + 'static, - replacement in src/xmpp/mod.rs at line 48
let MaybeXmppConnection { account, client } = self;let MaybeXmppConnection { account, inner } = self; - replacement in src/xmpp/mod.rs at line 50
if let Some(client) = client {Box::new(future::ok(XmppConnection { account, client }))if let Some(inner) = inner {Box::new(future::ok(XmppConnection { account, inner })) - edit in src/xmpp/mod.rs at line 56
.clone() - replacement in src/xmpp/mod.rs at line 57
future::loop_fn(account, move |account| {future::loop_fn(account, |account| { - edit in src/xmpp/mod.rs at line 66
let stop_future2 = stop_future.clone();let stop_future3 = stop_future.clone(); - replacement in src/xmpp/mod.rs at line 68
XmppConnection { 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 {XmppConnection {inner: client,account,}.online().and_then(XmppConnection::self_presence).then(|r| match r { - replacement in src/xmpp/mod.rs at line 78
}),},), - replacement in src/xmpp/mod.rs at line 101
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 111
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 116
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 121
let XmppConnection { client, account } = xmpp;client.into_future().select2(stop_future).then(|r| match r {let XmppConnection { inner, account } = xmpp;inner.into_future().select2(stop_future).then(|r| match r { - replacement in src/xmpp/mod.rs at line 125
let mut xmpp = XmppConnection { client, account };let mut xmpp = XmppConnection {inner: client,account,}; - replacement in src/xmpp/mod.rs at line 130
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 140
if let Some(client) = a.into_inner() {if let Some(inner) = a.into_inner() { - replacement in src/xmpp/mod.rs at line 142
XmppConnection { client, account },XmppConnection { inner, account }, - replacement in src/xmpp/mod.rs at line 151
if let Some(client) = a.into_inner() {if let Some(inner) = a.into_inner() { - replacement in src/xmpp/mod.rs at line 153
XmppConnection { client, account },Err(e.into()),XmppConnection { inner, account },Err(e), - replacement in src/xmpp/mod.rs at line 157
future::err((account, Err(e.into())))future::err((account, Err(e))) - replacement in src/xmpp/mod.rs at line 167[2.6737]→[2.6737:7230](∅→∅),[3.2924]→[3.3693:3694](∅→∅),[2.7230]→[3.3693:3694](∅→∅),[3.3693]→[3.3693:3694](∅→∅),[3.3694]→[2.7231:8352](∅→∅),[3.4798]→[3.2496:2542](∅→∅),[2.8352]→[3.2496:2542](∅→∅),[3.2496]→[3.2496:2542](∅→∅),[3.2542]→[2.8353:8406](∅→∅),[3.4885]→[3.2645:2687](∅→∅),[2.8406]→[3.2645:2687](∅→∅),[3.2645]→[3.2645:2687](∅→∅),[3.2687]→[2.8407:8505](∅→∅),[2.8505]→[3.2813:2851](∅→∅),[3.2813]→[3.2813:2851](∅→∅),[3.2851]→[2.8506:8724](∅→∅)
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 188
} 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 193[2.8841]→[2.8841:8911](∅→∅),[2.8911]→[3.5554:5571](∅→∅),[3.5554]→[3.5554:5571](∅→∅),[3.5571]→[2.8912:8977](∅→∅),[2.8977]→[3.5710:5720](∅→∅),[3.5710]→[3.5710:5720](∅→∅),[3.5720]→[2.8978:10350](∅→∅)
}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, 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 { 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 198
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, 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 204
info!("Sending presence..."); - replacement in src/xmpp/mod.rs at line 206
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 { 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 257
struct XmppState<F, S> {struct XmppProcessState<F, S> { - replacement in src/xmpp/mod.rs at line 263[3.3920]→[3.104:133](∅→∅),[3.133]→[2.12169:12252](∅→∅),[3.5851]→[3.4038:4058](∅→∅),[3.211]→[3.4038:4058](∅→∅),[3.4137]→[3.4038:4058](∅→∅),[3.5748]→[3.4038:4058](∅→∅),[3.597]→[3.4038:4058](∅→∅),[3.4900]→[3.4038:4058](∅→∅),[2.12252]→[3.4038:4058](∅→∅),[3.8859]→[3.4038:4058](∅→∅),[3.4038]→[3.4038:4058](∅→∅)
impl<F, S> XmppState<F, S> {fn new(cmd_recv: S, signal: F, conn: MaybeXmppConnection) -> XmppState<F, S> {XmppState {impl<F, S> XmppProcessState<F, S> {fn new(cmd_recv: S, signal: F, conn: MaybeXmppConnection) -> XmppProcessState<F, S> {XmppProcessState { - replacement in src/xmpp/mod.rs at line 285[3.4527]→[3.4527:4617](∅→∅),[3.4527]→[3.4527:4617](∅→∅),[3.4527]→[3.4527:4617](∅→∅),[3.4527]→[3.4527:4617](∅→∅),[3.4527]→[3.4527:4617](∅→∅),[3.4527]→[3.4527:4617](∅→∅),[3.4527]→[3.4527:4617](∅→∅),[3.4527]→[3.4527:4617](∅→∅)
future::loop_fn(XmppState::new(cmd_recv, signal, conn), |s| {let XmppState {future::loop_fn(XmppProcessState::new(cmd_recv, signal, conn), |s| {let XmppProcessState { - replacement in src/xmpp/mod.rs at line 308
future::ok(future::Loop::Continue(XmppState::new(future::ok(future::Loop::Continue(XmppProcessState::new( - replacement in src/xmpp/mod.rs at line 320
future::err(e)future::err(format_err!("Cmd error")) - 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)",