Improve ping timeouts, add debug output for XmlErrors and ping timeouts
This commit is contained in:
parent
cdd4c0b854
commit
fc1a9a5712
|
@ -232,6 +232,7 @@ public class ConnectionManager : Object {
|
||||||
|
|
||||||
private void check_reconnect(Account account) {
|
private void check_reconnect(Account account) {
|
||||||
bool acked = false;
|
bool acked = false;
|
||||||
|
DateTime? last_activity_was = connections[account].last_activity != null ? connections[account].last_activity : null;
|
||||||
|
|
||||||
XmppStream stream = connections[account].stream;
|
XmppStream stream = connections[account].stream;
|
||||||
stream.get_module(Xep.Ping.Module.IDENTITY).send_ping(stream, account.bare_jid.domain_jid, () => {
|
stream.get_module(Xep.Ping.Module.IDENTITY).send_ping(stream, account.bare_jid.domain_jid, () => {
|
||||||
|
@ -240,10 +241,13 @@ public class ConnectionManager : Object {
|
||||||
change_connection_state(account, ConnectionState.CONNECTED);
|
change_connection_state(account, ConnectionState.CONNECTED);
|
||||||
});
|
});
|
||||||
|
|
||||||
Timeout.add_seconds(5, () => {
|
Timeout.add_seconds(10, () => {
|
||||||
if (connections[account].stream != stream) return false;
|
if (connections[account].stream != stream) return false;
|
||||||
if (acked) return false;
|
if (acked) return false;
|
||||||
|
if (connections[account].last_activity != last_activity_was) return false;
|
||||||
|
|
||||||
|
// Reconnect. Nothing gets through the stream.
|
||||||
|
print(@"[$(account.bare_jid)] Ping timeouted. Reconnecting\n");
|
||||||
change_connection_state(account, ConnectionState.DISCONNECTED);
|
change_connection_state(account, ConnectionState.DISCONNECTED);
|
||||||
try {
|
try {
|
||||||
connections[account].stream.disconnect();
|
connections[account].stream.disconnect();
|
||||||
|
|
|
@ -144,7 +144,7 @@ public class FileManager : StreamInteractionModule, Object {
|
||||||
if (!is_sender_trustworthy(file_transfer, conversation)) return;
|
if (!is_sender_trustworthy(file_transfer, conversation)) return;
|
||||||
|
|
||||||
if (file_transfer.size == -1) {
|
if (file_transfer.size == -1) {
|
||||||
file_provider.get_meta_info(file_transfer);
|
yield file_provider.get_meta_info(file_transfer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_transfer.size >= 0 && file_transfer.size < 5000000) {
|
if (file_transfer.size >= 0 && file_transfer.size < 5000000) {
|
||||||
|
|
|
@ -223,38 +223,45 @@ public class StanzaReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async StanzaNode read_stanza_node() throws XmlError {
|
public async StanzaNode read_stanza_node() throws XmlError {
|
||||||
ns_state = ns_state.push();
|
try {
|
||||||
var res = yield read_node_start();
|
ns_state = ns_state.push();
|
||||||
if (res.has_nodes) {
|
var res = yield read_node_start();
|
||||||
bool finishNodeSeen = false;
|
if (res.has_nodes) {
|
||||||
do {
|
bool finish_node_seen = false;
|
||||||
yield skip_until_non_ws();
|
do {
|
||||||
if ((yield peek_single()) == '<') {
|
yield skip_until_non_ws();
|
||||||
skip_single();
|
if ((yield peek_single()) == '<') {
|
||||||
if ((yield peek_single()) == '/') {
|
|
||||||
skip_single();
|
skip_single();
|
||||||
string desc = yield read_until_char('>');
|
if ((yield peek_single()) == '/') {
|
||||||
skip_single();
|
skip_single();
|
||||||
if (desc.contains(":")) {
|
string desc = yield read_until_char('>');
|
||||||
var split = desc.split(":");
|
skip_single();
|
||||||
if (split[0] != ns_state.find_name((!)res.ns_uri)) throw new XmlError.BAD_XML("");
|
if (desc.contains(":")) {
|
||||||
if (split[1] != res.name) throw new XmlError.BAD_XML("");
|
var split = desc.split(":");
|
||||||
|
if (split[0] != ns_state.find_name((!)res.ns_uri)) throw new XmlError.BAD_XML("");
|
||||||
|
if (split[1] != res.name) throw new XmlError.BAD_XML("");
|
||||||
|
} else {
|
||||||
|
if (ns_state.current_ns_uri != res.ns_uri) throw new XmlError.BAD_XML("");
|
||||||
|
if (desc != res.name) throw new XmlError.BAD_XML("");
|
||||||
|
}
|
||||||
|
finish_node_seen = true;
|
||||||
} else {
|
} else {
|
||||||
if (ns_state.current_ns_uri != res.ns_uri) throw new XmlError.BAD_XML("");
|
res.sub_nodes.add(yield read_stanza_node());
|
||||||
if (desc != res.name) throw new XmlError.BAD_XML("");
|
|
||||||
}
|
}
|
||||||
finishNodeSeen = true;
|
|
||||||
} else {
|
} else {
|
||||||
res.sub_nodes.add(yield read_stanza_node());
|
res.sub_nodes.add(yield read_text_node());
|
||||||
}
|
}
|
||||||
} else {
|
} while (!finish_node_seen);
|
||||||
res.sub_nodes.add(yield read_text_node());
|
if (res.sub_nodes.size == 0) res.has_nodes = false;
|
||||||
}
|
}
|
||||||
} while (!finishNodeSeen);
|
ns_state = ns_state.pop();
|
||||||
if (res.sub_nodes.size == 0) res.has_nodes = false;
|
return res;
|
||||||
|
} catch (XmlError e) {
|
||||||
|
uint8[] buffer_cpy = buffer.copy();
|
||||||
|
buffer_cpy += '\0';
|
||||||
|
warning("XmlError at: %s".printf((string)buffer_cpy) + "\n");
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
ns_state = ns_state.pop();
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async StanzaNode read_node() throws XmlError {
|
public async StanzaNode read_node() throws XmlError {
|
||||||
|
|
Loading…
Reference in a new issue