aboutsummaryrefslogtreecommitdiff
path: root/src/Client.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client.zig')
-rw-r--r--src/Client.zig15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/Client.zig b/src/Client.zig
index 1709cab..2344f83 100644
--- a/src/Client.zig
+++ b/src/Client.zig
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License along with
// Zaprus. If not, see <https://www.gnu.org/licenses/>.
+//! A client is used to handle interactions with the network.
+
const base64_enc = std.base64.standard.Encoder;
const base64_dec = std.base64.standard.Decoder;
@@ -37,6 +39,8 @@ pub fn deinit(self: *Client) void {
self.* = undefined;
}
+/// Sends a fire and forget message over the network.
+/// This function asserts that `payload` fits within a single packet.
pub fn sendRelay(self: *Client, io: Io, payload: []const u8, dest: [4]u8) !void {
const io_source: std.Random.IoSource = .{ .io = io };
const rand = io_source.interface();
@@ -76,7 +80,8 @@ pub fn sendRelay(self: *Client, io: Io, payload: []const u8, dest: [4]u8) !void
try self.socket.send(full_msg);
}
-pub fn connect(self: Client, io: Io, payload: []const u8) !SaprusConnection {
+/// Attempts to establish a new connection with the sentinel.
+pub fn connect(self: Client, io: Io, payload: []const u8) (error{ BpfAttachFailed, Timeout } || SaprusMessage.ParseError)!SaprusConnection {
const io_source: std.Random.IoSource = .{ .io = io };
const rand = io_source.interface();
@@ -157,13 +162,17 @@ pub fn connect(self: Client, io: Io, payload: []const u8) !SaprusConnection {
try self.socket.send(full_msg);
- return .init(self.socket, headers, connection);
+ return .{
+ .socket = self.socket,
+ .headers = headers,
+ .connection = connection,
+ };
}
const RawSocket = @import("./RawSocket.zig");
const SaprusMessage = @import("message.zig").Message;
-const saprusParse = @import("message.zig").parse;
+const saprusParse = SaprusMessage.parse;
const SaprusConnection = @import("Connection.zig");
const EthIpUdp = @import("./EthIpUdp.zig").EthIpUdp;