From cb88f3c3b34e68ee3babeb837c42b58c2e1a0b9d Mon Sep 17 00:00:00 2001 From: Kitteh Date: Sat, 5 Jun 2021 09:32:04 +0100 Subject: [PATCH] Make TLS work. --- src/client.zig | 3 ++- src/main.zig | 31 +++++++++++++++++++------------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/client.zig b/src/client.zig index bf6596d..1acc0f0 100644 --- a/src/client.zig +++ b/src/client.zig @@ -50,6 +50,7 @@ pub const Client = struct { .cert_verifier = .none, .ciphersuites = tls.ciphersuites.all, }, "quassel.owo.monster"); + tlsConnected = true; } } @@ -137,8 +138,8 @@ pub const Client = struct { try s.writeFrame(data); var varient = try s.readFrame(); - tlsAllowed = varient.QVariantMap.get("SupportSsl").?.Byte == 1; prettyPrintQVariant(varient, 0); + tlsAllowed = varient.QVariantMap.get("SupportSsl").?.Byte == 1; freeQVariant(varient, s.allocator); } diff --git a/src/main.zig b/src/main.zig index 382de03..0db049d 100644 --- a/src/main.zig +++ b/src/main.zig @@ -18,18 +18,25 @@ pub fn main() !void { std.debug.print("host={s} port={d}\n", .{ host, portInt }); - var sock = try std.net.tcpConnectToHost(allocator, host, portInt); - var client = initClient(allocator, &sock); - try client.handshake(); - try client.quassel_init_packet(); - try client.quassel_login(username, password); while (true) { - client.read_quassel_packet() catch |err| { - if (err == error.DecodeError) { - std.debug.print("Decode Error.\n", .{}); - } else { - return err; - } - }; + var sock = try std.net.tcpConnectToHost(allocator, host, portInt); + var client = initClient(allocator, &sock); + try client.handshake(); + try client.quassel_init_packet(); + try client.quassel_login(username, password); + + while (true) { + client.read_quassel_packet() catch |err| { + if (err == error.DecodeError) { + std.debug.print("Decode Error.\n", .{}); + } else if (err == error.EndOfStream) { + std.debug.print("EOS.\n", .{}); + std.time.sleep(1000 * std.time.ns_per_ms); + continue; + } else { + return err; + } + }; + } } }