Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ on:
- '**.c'
- '**.h'

# Remove guard against Linux Debug when #35 is closed.

jobs:
test:
strategy:
Expand All @@ -28,7 +26,6 @@ jobs:
- uses: mlugg/setup-zig@v2

- name: Debug
if: matrix.os != 'ubuntu-latest'
run: zig build test -Doptimize=Debug

- name: Release
Expand All @@ -48,7 +45,6 @@ jobs:
- uses: mlugg/setup-zig@v2

- name: Debug
if: matrix.os != 'ubuntu-latest'
run: zig build example -Dname=tcp -Doptimize=Debug -Dci=true

- name: Release
Expand All @@ -68,7 +64,6 @@ jobs:
- uses: mlugg/setup-zig@v2

- name: Debug
if: matrix.os != 'ubuntu-latest'
run: zig build c -Doptimize=Debug

- name: Release
Expand All @@ -88,7 +83,6 @@ jobs:
- uses: mlugg/setup-zig@v2

- name: Debug
if: matrix.os != 'ubuntu-latest'
run: zig build wasm -Doptimize=Debug

- name: Release
Expand Down
46 changes: 34 additions & 12 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const Builder = struct {

const write_files = self.b.addWriteFiles();
const bindings = @import("core/bindings.zig");
const data = bindings.data(.c, self.b.allocator) catch |err| {
const data = bindings.data(self.b.allocator, .c) catch |err| {
std.debug.print("Failed to generate header: {any}", .{err});
std.process.exit(1);
};
Expand All @@ -75,13 +75,21 @@ const Builder = struct {

pub fn examples(self: *Self) void {
const step = self.b.step("example", "Run an example");

const name = self.b.option([]const u8, "name", "The module name to run") orelse return;
const example_name = self.b.fmt("example-{s}", .{name});

const example_module = self.b.addModule(
example_name,
.{
.root_source_file = self.b.path(self.b.fmt("examples/{s}.zig", .{name})),
.target = self.target,
.optimize = self.optimize,
},
);

const example = self.b.addExecutable(.{
.name = self.b.fmt("example-{s}", .{name}),
.root_source_file = self.b.path(self.b.fmt("examples/{s}.zig", .{name})),
.target = self.target,
.optimize = self.optimize,
.name = example_name,
.root_module = example_module,
});

self.addImport(example, .core);
Expand Down Expand Up @@ -154,11 +162,18 @@ const Builder = struct {

inline for (.{ .app, .core, .io }) |t| {
const root = if (t == .app) "main" else "lib";
const test_module = self.b.addModule(
@tagName(t),
.{
.root_source_file = self.b.path(@tagName(t) ++ "/" ++ root ++ ".zig"),
.target = self.target,
.optimize = self.optimize,
},
);

const compile = self.b.addTest(.{
.name = @tagName(t),
.root_source_file = self.b.path(@tagName(t) ++ "/" ++ root ++ ".zig"),
.target = self.target,
.optimize = self.optimize,
.root_module = test_module,
});

step.dependOn(&self.b.addRunArtifact(compile).step);
Expand Down Expand Up @@ -195,11 +210,18 @@ const Builder = struct {
};

inline for (test_names) |name| {
const test_module = self.b.addModule(
name,
.{
.root_source_file = self.b.path(root_directory ++ "/" ++ name ++ ".zig"),
.target = self.target,
.optimize = self.optimize,
},
);

const t = self.b.addTest(.{
.name = name,
.root_source_file = self.b.path(root_directory ++ "/" ++ name ++ ".zig"),
.target = self.target,
.optimize = self.optimize,
.root_module = test_module,
});

inline for (packages) |package| {
Expand Down
8 changes: 4 additions & 4 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.{
.name = .reticulum,
.version = "0.2.0",
.minimum_zig_version = "0.14.1",
.version = "0.3.0",
.minimum_zig_version = "0.15.1",
.fingerprint = 0x357e04a91bafe743,
.paths = .{
"build.zig",
Expand All @@ -14,8 +14,8 @@
},
.dependencies = .{
.ohsnap = .{
.url = "git+https://github.com/mnemnion/ohsnap#a140626e388ad3aea2a6a678183f5c0c03887fde",
.hash = "ohsnap-0.3.1-iWxzyu6bAADX1OdmK7FFg94X6RDfDvbt0iwQFH8mSFJE",
.url = "https://github.com/mnemnion/ohsnap/archive/refs/heads/trunk.tar.gz",
.hash = "ohsnap-0.4.1-iWxzyhicAAA90MEnwxA22VshYmsSH3t0dcqM9yib7ose",
},
},
}
2 changes: 1 addition & 1 deletion core/Node.zig
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub fn process(self: *Self) !void {
fn eventsIn(self: *Self, interface: *Interface, now: u64) !void {
while (interface.incoming.pop()) |event_in| {
var event = event_in;
defer event.deinit();
defer event.deinit(self.ally);

try switch (event) {
.announce => |*announce| self.announceTask(interface, announce, now),
Expand Down
38 changes: 21 additions & 17 deletions core/Ratchets.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const System = @import("System.zig");
const Self = @This();

const Entry = struct {
ratchets: std.fifo.LinearFifo(Ratchet, .Dynamic),
ratchets: []Ratchet,
last_rotation_time: u64,
};

Expand All @@ -37,7 +37,7 @@ pub fn add(self: *Self, endpoint: Hash.Short, now: u64) !Ratchet {
const key = try self.ally.dupe(u8, &endpoint);

try self.entries.put(key, .{
.ratchets = self.ally,
.ratchets = self.ally.alloc(Ratchet, max_ratchets),
.last_rotation_time = now,
});

Expand All @@ -46,25 +46,29 @@ pub fn add(self: *Self, endpoint: Hash.Short, now: u64) !Ratchet {
}

pub fn getRatchet(self: *Self, endpoint: Hash.Short, now: u64) !?Ratchet {
if (self.entries.getPtr(&endpoint)) |entry| {
const needs_rotating = now - entry.last_rotation_time >= rotation_period;
_ = self;
_ = endpoint;
_ = now;

if (needs_rotating) {
var seed: [crypto.X25519.seed_length]u8 = undefined;
self.rng.bytes(&seed);
// if (self.entries.getPtr(&endpoint)) |entry| {
// const needs_rotating = now - entry.last_rotation_time >= rotation_period;

const ratchet = try crypto.X25519.KeyPair.generateDeterministic(seed);
// if (needs_rotating) {
// var seed: [crypto.X25519.seed_length]u8 = undefined;
// self.rng.bytes(&seed);

if (entry.ratchets.count >= max_ratchets) {
entry.ratchets.discard(1);
}
// const ratchet = try crypto.X25519.KeyPair.generateDeterministic(seed);

entry.ratchets.writeItem(ratchet.public_key);
entry.last_rotation_time = now;
}
// if (entry.ratchets.count >= max_ratchets) {
// entry.ratchets.discard(1);
// }

return entry.ratchets.peekItem(entry.ratchets.count - 1);
}
// entry.ratchets.writeItem(ratchet.public_key);
// entry.last_rotation_time = now;
// }

// return entry.ratchets.peekItem(entry.ratchets.count - 1);
// }

return null;
}
Expand All @@ -74,7 +78,7 @@ pub fn deinit(self: *Self) void {

while (entries.next()) |entry| {
self.ally.free(entry.key_ptr.*);
entry.value_ptr.ratchets.deinit();
// entry.value_ptr.ratchets.deinit();
}

self.entries.deinit();
Expand Down
Loading