diff options
author | fiaxh <git@lightrise.org> | 2020-11-16 15:55:33 +0100 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2020-11-20 15:21:18 +0100 |
commit | 07917f1d841f449157aa3aaa2507b0547dd274e7 (patch) | |
tree | 315ef3bc243491565d3d5097968dca38d67a7eab /xmpp-vala/src/core/direct_tls_xmpp_stream.vala | |
parent | 881b9eec9dcd8fd8c81b0b9d7bfd2ae714d7722e (diff) | |
download | dino-07917f1d841f449157aa3aaa2507b0547dd274e7.tar.gz dino-07917f1d841f449157aa3aaa2507b0547dd274e7.zip |
Refactor XmppStream, TLS and connection method logic
fixes #534
Diffstat (limited to 'xmpp-vala/src/core/direct_tls_xmpp_stream.vala')
-rw-r--r-- | xmpp-vala/src/core/direct_tls_xmpp_stream.vala | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/xmpp-vala/src/core/direct_tls_xmpp_stream.vala b/xmpp-vala/src/core/direct_tls_xmpp_stream.vala new file mode 100644 index 00000000..1d2f7339 --- /dev/null +++ b/xmpp-vala/src/core/direct_tls_xmpp_stream.vala @@ -0,0 +1,31 @@ +public class Xmpp.DirectTlsXmppStream : TlsXmppStream { + + string host; + uint16 port; + + public DirectTlsXmppStream(Jid remote, string host, uint16 port) { + this.remote_name = remote; + this.host = host; + this.port = port; + } + + public override async void connect() throws IOStreamError { + SocketClient client = new SocketClient(); + try { + debug("Connecting to %s %i (tls)", host, port); + IOStream? io_stream = yield client.connect_to_host_async(host, port); + TlsConnection tls_connection = TlsClientConnection.new(io_stream, new NetworkAddress(remote_name.to_string(), port)); + #if ALPN_SUPPORT + tls_connection.set_advertised_protocols(new string[]{"xmpp-client"}); + #endif + tls_connection.accept_certificate.connect(on_invalid_certificate); + reset_stream(tls_connection); + + yield setup(); + + attach_negotation_modules(); + } catch (Error e) { + throw new IOStreamError.CONNECT("Failed connecting to %s:%i (tls): %s", host, port, e.message); + } + } +}
\ No newline at end of file |