Clean API and add docs

This commit is contained in:
2026-02-01 19:35:14 -05:00
parent 558f40213b
commit 2c9e648c2c
7 changed files with 248 additions and 215 deletions

View File

@@ -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;