Don't set timeouts on registration connection attempts

This commit is contained in:
fiaxh 2019-06-01 18:48:58 +02:00
parent 8aab18c1ec
commit 8120203d62
3 changed files with 23 additions and 8 deletions

View File

@ -75,42 +75,53 @@ public class Register : StreamInteractionModule, Object{
Idle.add((owned)callback);
}
});
Timeout.add_seconds(5, () => {
stream.connect.begin(jid.domainpart, (_, res) => {
try {
stream.connect.end(res);
} catch (Error e) {
debug("Error connecting to stream: %s", e.message);
}
if (callback != null) {
Idle.add((owned)callback);
}
return false;
});
stream.connect.begin(jid.domainpart);
yield;
try {
stream.disconnect();
} catch (Error e) {}
return ret;
}
public static async Xep.InBandRegistration.Form get_registration_form(Jid jid) {
public static async Xep.InBandRegistration.Form? get_registration_form(Jid jid) {
XmppStream stream = new XmppStream();
stream.add_module(new Tls.Module());
stream.add_module(new Iq.Module());
stream.add_module(new Xep.SrvRecordsTls.Module());
stream.add_module(new Xep.InBandRegistration.Module());
stream.connect.begin(jid.bare_jid.to_string());
Xep.InBandRegistration.Form? form = null;
SourceFunc callback = get_registration_form.callback;
stream.stream_negotiated.connect(() => {
if (callback != null) {
Idle.add((owned)callback);
}
});
Timeout.add_seconds(5, () => {
stream.connect.begin(jid.domainpart, (_, res) => {
try {
stream.connect.end(res);
} catch (Error e) {
debug("Error connecting to stream: %s", e.message);
}
if (callback != null) {
Idle.add((owned)callback);
}
return false;
});
yield;
if (stream.negotiation_complete) {
form = yield stream.get_module(Xep.InBandRegistration.Module.IDENTITY).get_from_server(stream, jid);

View File

@ -60,6 +60,7 @@ public class XmppStream {
stream = yield best_provider.connect(this);
}
if (stream == null) {
debug("Connecting to %s, xmpp-client, tcp (fallback)", this.remote_name.to_string());
stream = yield (new SocketClient()).connect_async(new NetworkService("xmpp-client", "tcp", this.remote_name.to_string()));
}
if (stream == null) {
@ -67,9 +68,10 @@ public class XmppStream {
}
reset_stream((!)stream);
} catch (Error e) {
debug("[%p] Could not connect to server", this);
debug("[%p] Could not connect to server: %s", this, e.message);
throw new IOStreamError.CONNECT(e.message);
}
debug("Connected to %s", remote_name);
yield loop();
}
@ -379,6 +381,7 @@ public class StartTlsConnectionProvider : ConnectionProvider {
public async override IOStream? connect(XmppStream stream) {
try {
SocketClient client = new SocketClient();
debug("Connecting to %s %i (starttls)", srv_target.get_hostname(), srv_target.get_port());
return yield client.connect_to_host_async(srv_target.get_hostname(), srv_target.get_port());
} catch (Error e) {
return null;

View File

@ -36,6 +36,7 @@ public class TlsConnectionProvider : ConnectionProvider {
public async override IOStream? connect(XmppStream stream) {
SocketClient client = new SocketClient();
try {
debug("Connecting to %s %i (tls)", srv_target.get_hostname(), srv_target.get_port());
IOStream? io_stream = yield client.connect_to_host_async(srv_target.get_hostname(), srv_target.get_port());
TlsConnection tls_connection = TlsClientConnection.new(io_stream, new NetworkAddress(stream.remote_name.to_string(), srv_target.get_port()));
tls_connection.accept_certificate.connect(stream.get_module(Tls.Module.IDENTITY).on_invalid_certificate);