DTLS: Use own thread for connection establishment
This commit is contained in:
parent
b07c4187ef
commit
b1c1751cc4
|
@ -112,6 +112,19 @@ public class Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Xmpp.Xep.Jingle.ContentEncryption? setup_dtls_connection() {
|
public async Xmpp.Xep.Jingle.ContentEncryption? setup_dtls_connection() {
|
||||||
|
MainContext context = MainContext.current_source().get_context();
|
||||||
|
var thread = new Thread<Xmpp.Xep.Jingle.ContentEncryption>("dtls-connection", () => {
|
||||||
|
var res = setup_dtls_connection_thread();
|
||||||
|
Source source = new IdleSource();
|
||||||
|
source.set_callback(setup_dtls_connection.callback);
|
||||||
|
source.attach(context);
|
||||||
|
return res;
|
||||||
|
});
|
||||||
|
yield;
|
||||||
|
return thread.join();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Xmpp.Xep.Jingle.ContentEncryption? setup_dtls_connection_thread() {
|
||||||
buffer_mutex.lock();
|
buffer_mutex.lock();
|
||||||
if (stop) {
|
if (stop) {
|
||||||
restart = true;
|
restart = true;
|
||||||
|
@ -146,7 +159,6 @@ public class Handler {
|
||||||
session.set_push_function(push_function);
|
session.set_push_function(push_function);
|
||||||
session.set_verify_function(verify_function);
|
session.set_verify_function(verify_function);
|
||||||
|
|
||||||
Thread<int> thread = new Thread<int> (null, () => {
|
|
||||||
DateTime maximum_time = new DateTime.now_utc().add_seconds(20);
|
DateTime maximum_time = new DateTime.now_utc().add_seconds(20);
|
||||||
do {
|
do {
|
||||||
err = session.handshake();
|
err = session.handshake();
|
||||||
|
@ -163,11 +175,7 @@ public class Handler {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (err < 0 && !((ErrorCode)err).is_fatal());
|
} while (err < 0 && !((ErrorCode)err).is_fatal());
|
||||||
Idle.add(setup_dtls_connection.callback);
|
|
||||||
return err;
|
|
||||||
});
|
|
||||||
yield;
|
|
||||||
err = thread.join();
|
|
||||||
buffer_mutex.lock();
|
buffer_mutex.lock();
|
||||||
if (stop) {
|
if (stop) {
|
||||||
stop = false;
|
stop = false;
|
||||||
|
@ -176,7 +184,7 @@ public class Handler {
|
||||||
buffer_mutex.unlock();
|
buffer_mutex.unlock();
|
||||||
if (restart) {
|
if (restart) {
|
||||||
debug("Restarting DTLS handshake");
|
debug("Restarting DTLS handshake");
|
||||||
return yield setup_dtls_connection();
|
return setup_dtls_connection_thread();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue