aboutsummaryrefslogtreecommitdiff
path: root/plugins/ice/src/dtls_srtp.vala
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/ice/src/dtls_srtp.vala')
-rw-r--r--plugins/ice/src/dtls_srtp.vala86
1 files changed, 42 insertions, 44 deletions
diff --git a/plugins/ice/src/dtls_srtp.vala b/plugins/ice/src/dtls_srtp.vala
index ca398e69..c5b2eb75 100644
--- a/plugins/ice/src/dtls_srtp.vala
+++ b/plugins/ice/src/dtls_srtp.vala
@@ -37,40 +37,30 @@ public class Handler {
this.own_fingerprint = creds.own_fingerprint;
}
- public uint8[]? process_incoming_data(uint component_id, uint8[] data) {
+ public uint8[]? process_incoming_data(uint component_id, uint8[] data) throws Crypto.Error {
if (srtp_session.has_decrypt) {
- try {
- if (component_id == 1) {
- if (data.length >= 2 && data[1] >= 192 && data[1] < 224) {
- return srtp_session.decrypt_rtcp(data);
- }
- return srtp_session.decrypt_rtp(data);
+ if (component_id == 1) {
+ if (data.length >= 2 && data[1] >= 192 && data[1] < 224) {
+ return srtp_session.decrypt_rtcp(data);
}
- if (component_id == 2) return srtp_session.decrypt_rtcp(data);
- } catch (Error e) {
- warning("%s (%d)", e.message, e.code);
- return null;
+ return srtp_session.decrypt_rtp(data);
}
+ if (component_id == 2) return srtp_session.decrypt_rtcp(data);
} else if (component_id == 1) {
on_data_rec(data);
}
return null;
}
- public uint8[]? process_outgoing_data(uint component_id, uint8[] data) {
+ public uint8[]? process_outgoing_data(uint component_id, uint8[] data) throws Crypto.Error {
if (srtp_session.has_encrypt) {
- try {
- if (component_id == 1) {
- if (data.length >= 2 && data[1] >= 192 && data[1] < 224) {
- return srtp_session.encrypt_rtcp(data);
- }
- return srtp_session.encrypt_rtp(data);
+ if (component_id == 1) {
+ if (data.length >= 2 && data[1] >= 192 && data[1] < 224) {
+ return srtp_session.encrypt_rtcp(data);
}
- if (component_id == 2) return srtp_session.encrypt_rtcp(data);
- } catch (Error e) {
- warning("%s (%d)", e.message, e.code);
- return null;
+ return srtp_session.encrypt_rtp(data);
}
+ if (component_id == 2) return srtp_session.encrypt_rtcp(data);
}
return null;
}
@@ -122,6 +112,19 @@ public class Handler {
}
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();
if (stop) {
restart = true;
@@ -156,28 +159,23 @@ public class Handler {
session.set_push_function(push_function);
session.set_verify_function(verify_function);
- Thread<int> thread = new Thread<int> (null, () => {
- DateTime maximum_time = new DateTime.now_utc().add_seconds(20);
- do {
- err = session.handshake();
+ DateTime maximum_time = new DateTime.now_utc().add_seconds(20);
+ do {
+ err = session.handshake();
+
+ DateTime current_time = new DateTime.now_utc();
+ if (maximum_time.compare(current_time) < 0) {
+ warning("DTLS handshake timeouted");
+ err = ErrorCode.APPLICATION_ERROR_MIN + 1;
+ break;
+ }
+ if (stop) {
+ debug("DTLS handshake stopped");
+ err = ErrorCode.APPLICATION_ERROR_MIN + 2;
+ break;
+ }
+ } while (err < 0 && !((ErrorCode)err).is_fatal());
- DateTime current_time = new DateTime.now_utc();
- if (maximum_time.compare(current_time) < 0) {
- warning("DTLS handshake timeouted");
- err = ErrorCode.APPLICATION_ERROR_MIN + 1;
- break;
- }
- if (stop) {
- debug("DTLS handshake stopped");
- err = ErrorCode.APPLICATION_ERROR_MIN + 2;
- break;
- }
- } while (err < 0 && !((ErrorCode)err).is_fatal());
- Idle.add(setup_dtls_connection.callback);
- return err;
- });
- yield;
- err = thread.join();
buffer_mutex.lock();
if (stop) {
stop = false;
@@ -186,7 +184,7 @@ public class Handler {
buffer_mutex.unlock();
if (restart) {
debug("Restarting DTLS handshake");
- return yield setup_dtls_connection();
+ return setup_dtls_connection_thread();
}
return null;
}