mirror of
https://git.robbyzambito.me/zaprus
synced 2026-05-06 14:20:37 +00:00
Clean API and add docs
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user