Skip to content

Commit

Permalink
ci: fix env vars, bin path
Browse files Browse the repository at this point in the history
  • Loading branch information
flowerinthenight committed Sep 20, 2024
1 parent 8edf26f commit 8c55029
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ $ zig build --summary all

# Run the 1st process. The expected args look like:
#
# ./zgroup name_in_uuid member_ip:port join_ip:port
# ./zgroup groupname member_ip:port join_ip:port
#
# Run the first process without the join args.
$ ./zig-out/bin/zgroup 0xf47ac10b58cc4372a5670e02b2c3d479 0.0.0.0:8080 :
$ ./zig-out/bin/zgroup group1 0.0.0.0:8080 :

# Then you can run multiple instances, specifying the join address.
# Join through the 1st process/node (different terminal):
$ ./zig-out/bin/zgroup 0xf47ac10b58cc4372a5670e02b2c3d479 0.0.0.0:8081 0.0.0.0:8080
$ ./zig-out/bin/zgroup group1 0.0.0.0:8081 0.0.0.0:8080

# Join through the 2nd process/node (different terminal):
$ ./zig-out/bin/zgroup 0xf47ac10b58cc4372a5670e02b2c3d479 0.0.0.0:8082 0.0.0.0:8081
$ ./zig-out/bin/zgroup group1 0.0.0.0:8082 0.0.0.0:8081

# Join through the 1st process/node (different terminal):
$ ./zig-out/bin/zgroup 0xf47ac10b58cc4372a5670e02b2c3d479 0.0.0.0:8083 0.0.0.0:8080
$ ./zig-out/bin/zgroup group1 0.0.0.0:8083 0.0.0.0:8080

# and so on...
```
Expand Down
10 changes: 10 additions & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,13 @@ test "dupe" {
dbg("{s},{d}\n", .{ dup1, dup1.len });
dbg("{s},{d}\n", .{ dup2, dup2.len });
}

test "name" {
// const fname = "callname_extra";
const fname = "group1";
const name = if (fname.len > 8) fname[0..8] else fname;
const v = std.mem.readVarInt(u64, name, .little);
dbg("{x}\n", .{v});
const rev = std.mem.asBytes(&v);
dbg("{s}, {d}\n", .{ rev, rev.len });
}
17 changes: 7 additions & 10 deletions src/zgroup.zig
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn Fleet() type {

// Our generic UDP comms/protocol payload.
const Message = packed struct {
name: u128 = 0,
name: u64 = 0,
// Section for ping, ping_req, ack, nack.
cmd: Command = .noop,
src_ip: u32 = 0,
Expand Down Expand Up @@ -98,10 +98,7 @@ pub fn Fleet() type {
/// Config for init().
pub const Config = struct {
/// We use the name as group identifier when groups are running over the
/// same network. At the moment, we use the UUID format as we can cast
/// it to `u128` for easy network sending than, say, a `[]u8`. Use init()
/// to initialize.
/// Example: "0xf47ac10b58cc4372a5670e02b2c3d479"
/// same network. Max of 8 chars (u64 in payload).
name: []const u8,

/// Member IP address for UDP, eg. "0.0.0.0". Use init() to initialize.
Expand Down Expand Up @@ -130,7 +127,7 @@ pub fn Fleet() type {
log.debug("init: {s}:{d}", .{ config.ip, config.port });
return Self{
.allocator = allocator,
.name = config.name,
.name = if (config.name.len > 8) config.name[0..8] else config.name,
.ip = config.ip,
.port = config.port,
.protocol_time = config.protocol_time,
Expand Down Expand Up @@ -201,8 +198,8 @@ pub fn Fleet() type {

switch (msg.cmd) {
.ack => {
const sname = try std.fmt.parseUnsigned(u128, self.name, 0);
if (sname == msg.name) {
const nn = std.mem.readVarInt(u64, self.name, .little);
if (nn == msg.name) {
const key = try std.fmt.allocPrint(arena, "{s}:{d}", .{
dst_ip,
dst_port,
Expand Down Expand Up @@ -249,7 +246,7 @@ pub fn Fleet() type {
fn listen(self: *Self) !void {
log.info("Starting UDP server on :{d}...", .{self.port});

const name = try std.fmt.parseUnsigned(u128, self.name, 0);
const name = std.mem.readVarInt(u64, self.name, .little);
const buf = try self.allocator.alloc(u8, @sizeOf(Message));
defer self.allocator.free(buf); // release buffer

Expand Down Expand Up @@ -1040,7 +1037,7 @@ pub fn Fleet() type {

// Set default values for the message.
fn presetMessage(self: *Self, msg: *Message) !void {
msg.name = try std.fmt.parseUnsigned(u128, self.name, 0);
msg.name = std.mem.readVarInt(u64, self.name, .little);
msg.cmd = .noop;
msg.src_state = .alive;
msg.dst_cmd = .noop;
Expand Down

0 comments on commit 8c55029

Please sign in to comment.