mirror of
https://git.robbyzambito.me/zaprus
synced 2025-12-20 16:24:50 +00:00
Update gatorcat dep and use bytes for broadcast message
The latter is helpful for the lifetime of the message.
This commit is contained in:
@@ -45,8 +45,8 @@
|
||||
.hash = "clap-0.10.0-oBajB434AQBDh-Ei3YtoKIRxZacVPF1iSwp3IX_ZB8f0",
|
||||
},
|
||||
.gatorcat = .{
|
||||
.url = "git+https://github.com/kj4tmp/gatorcat#bb1847f6c95852e7a0ec8c07870a948c171d5f98",
|
||||
.hash = "gatorcat-0.3.2-WcrpTf1mBwDrmPaIhKCfLJO064v8Sjjn7DBq4CKZSgHH",
|
||||
.url = "git+https://github.com/kj4tmp/gatorcat.git#0a97b666677501db4939e3e8245f88a19e015893",
|
||||
.hash = "gatorcat-0.3.4-WcrpTcleBwCta_9TjomuIGb3bdg2Pke_FXI_WkMTEivH",
|
||||
},
|
||||
},
|
||||
.paths = .{
|
||||
|
||||
@@ -19,12 +19,12 @@ pub fn deinit() void {
|
||||
network.deinit();
|
||||
}
|
||||
|
||||
fn broadcastSaprusMessage(msg: *SaprusMessage, udp_port: u16) !void {
|
||||
fn broadcastSaprusMessage(msg_bytes: []align(@alignOf(SaprusMessage)) u8, udp_port: u16) !void {
|
||||
if (false) {
|
||||
var foo: gcat.nic.RawSocket = try .init("enp7s0"); // /proc/net/dev
|
||||
defer foo.deinit();
|
||||
}
|
||||
const msg_bytes = msg.asBytes();
|
||||
const msg: *SaprusMessage = try .bytesAsValue(msg_bytes);
|
||||
try msg.networkFromNativeEndian();
|
||||
defer msg.nativeFromNetworkEndian() catch unreachable;
|
||||
|
||||
@@ -46,6 +46,8 @@ fn broadcastSaprusMessage(msg: *SaprusMessage, udp_port: u16) !void {
|
||||
|
||||
try sock.bind(bind_addr);
|
||||
|
||||
std.debug.print("{x}\n", .{msg_bytes});
|
||||
|
||||
_ = try sock.sendTo(dest_addr, msg_bytes);
|
||||
}
|
||||
|
||||
@@ -61,7 +63,7 @@ pub fn sendRelay(payload: []const u8, dest: [4]u8) !void {
|
||||
relay.dest = dest;
|
||||
_ = base64Enc.encode(relay.getPayload(), payload);
|
||||
|
||||
try broadcastSaprusMessage(msg, 8888);
|
||||
try broadcastSaprusMessage(msg_bytes, 8888);
|
||||
}
|
||||
|
||||
fn randomPort() u16 {
|
||||
@@ -80,14 +82,14 @@ pub fn sendInitialConnection(payload: []const u8, initial_port: u16) !*SaprusMes
|
||||
.connection,
|
||||
base64Enc.calcSize(payload.len),
|
||||
)];
|
||||
const msg: *SaprusMessage = .init(.relay, msg_bytes);
|
||||
const msg: *SaprusMessage = .init(.connection, msg_bytes);
|
||||
|
||||
const connection = (try msg.getSaprusTypePayload()).connection;
|
||||
connection.src_port = initial_port;
|
||||
connection.dest_port = dest_port;
|
||||
_ = base64Enc.encode(connection.getPayload(), payload);
|
||||
|
||||
try broadcastSaprusMessage(msg, 8888);
|
||||
try broadcastSaprusMessage(msg_bytes, 8888);
|
||||
|
||||
return msg;
|
||||
}
|
||||
@@ -120,7 +122,7 @@ pub fn connect(payload: []const u8) !?SaprusConnection {
|
||||
initial_conn_res = try .networkBytesAsValue(response_buf[0..len]);
|
||||
|
||||
// Complete handshake after awaiting response
|
||||
try broadcastSaprusMessage(msg, randomPort());
|
||||
try broadcastSaprusMessage(msg.asBytes(), randomPort());
|
||||
|
||||
if (false) {
|
||||
return initial_conn_res.?;
|
||||
|
||||
Reference in New Issue
Block a user