Compare commits
2 Commits
webrtc-tra
...
82c3cd8c6e
| Author | SHA1 | Date | |
|---|---|---|---|
| 82c3cd8c6e | |||
| c762f94166 |
27
build.zig
27
build.zig
@@ -47,6 +47,7 @@ pub fn build(b: *std.Build) void {
|
||||
.root_source_file = b.path("src/files.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.link_libc = true,
|
||||
});
|
||||
files_module.addImport("core", core_module);
|
||||
files_module.addImport("protocol", protocol_module);
|
||||
@@ -95,6 +96,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "example-server",
|
||||
.root_module = server_module,
|
||||
});
|
||||
example_server.linkLibC();
|
||||
b.installArtifact(example_server);
|
||||
|
||||
const run_server = b.addRunArtifact(example_server);
|
||||
@@ -116,6 +118,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "example-client",
|
||||
.root_module = client_module,
|
||||
});
|
||||
example_client.linkLibC();
|
||||
b.installArtifact(example_client);
|
||||
|
||||
const run_client = b.addRunArtifact(example_client);
|
||||
@@ -137,6 +140,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "encrypted-server",
|
||||
.root_module = encrypted_server_module,
|
||||
});
|
||||
encrypted_server.linkLibC();
|
||||
b.installArtifact(encrypted_server);
|
||||
|
||||
const run_encrypted_server = b.addRunArtifact(encrypted_server);
|
||||
@@ -158,6 +162,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "encrypted-client",
|
||||
.root_module = encrypted_client_module,
|
||||
});
|
||||
encrypted_client.linkLibC();
|
||||
b.installArtifact(encrypted_client);
|
||||
|
||||
const run_encrypted_client = b.addRunArtifact(encrypted_client);
|
||||
@@ -181,6 +186,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "example-p2p",
|
||||
.root_module = p2p_example_module,
|
||||
});
|
||||
example_p2p.linkLibC();
|
||||
b.installArtifact(example_p2p);
|
||||
|
||||
const run_p2p = b.addRunArtifact(example_p2p);
|
||||
@@ -200,6 +206,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "network-test",
|
||||
.root_module = network_test_module,
|
||||
});
|
||||
network_test.linkLibC();
|
||||
b.installArtifact(network_test);
|
||||
|
||||
const run_network_test = b.addRunArtifact(network_test);
|
||||
@@ -223,6 +230,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "integration-test",
|
||||
.root_module = integration_test_module,
|
||||
});
|
||||
integration_test.linkLibC();
|
||||
b.installArtifact(integration_test);
|
||||
|
||||
const run_integration_test = b.addRunArtifact(integration_test);
|
||||
@@ -246,6 +254,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "real-test",
|
||||
.root_module = real_test_module,
|
||||
});
|
||||
real_test.linkLibC();
|
||||
b.installArtifact(real_test);
|
||||
|
||||
const run_real_test = b.addRunArtifact(real_test);
|
||||
@@ -266,6 +275,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "protocol-example",
|
||||
.root_module = protocol_example_module,
|
||||
});
|
||||
protocol_example.linkLibC();
|
||||
b.installArtifact(protocol_example);
|
||||
|
||||
const run_protocol_example = b.addRunArtifact(protocol_example);
|
||||
@@ -287,6 +297,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "file-server",
|
||||
.root_module = file_server_module,
|
||||
});
|
||||
file_server.linkLibC();
|
||||
b.installArtifact(file_server);
|
||||
|
||||
const run_file_server = b.addRunArtifact(file_server);
|
||||
@@ -308,6 +319,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "file-transfer-test",
|
||||
.root_module = file_transfer_test_module,
|
||||
});
|
||||
file_transfer_test.linkLibC();
|
||||
b.installArtifact(file_transfer_test);
|
||||
|
||||
const run_file_transfer_test = b.addRunArtifact(file_transfer_test);
|
||||
@@ -329,6 +341,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "multi-peer-test",
|
||||
.root_module = multi_peer_test_module,
|
||||
});
|
||||
multi_peer_test.linkLibC();
|
||||
b.installArtifact(multi_peer_test);
|
||||
|
||||
const run_multi_peer_test = b.addRunArtifact(multi_peer_test);
|
||||
@@ -350,6 +363,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "multi-file-swarm-test",
|
||||
.root_module = multi_file_swarm_module,
|
||||
});
|
||||
multi_file_swarm_test.linkLibC();
|
||||
b.installArtifact(multi_file_swarm_test);
|
||||
|
||||
const run_multi_file_swarm = b.addRunArtifact(multi_file_swarm_test);
|
||||
@@ -371,6 +385,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "swarm-chaos-test",
|
||||
.root_module = swarm_chaos_module,
|
||||
});
|
||||
swarm_chaos_test.linkLibC();
|
||||
b.installArtifact(swarm_chaos_test);
|
||||
|
||||
const run_swarm_chaos = b.addRunArtifact(swarm_chaos_test);
|
||||
@@ -391,6 +406,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "dht-test",
|
||||
.root_module = dht_test_module,
|
||||
});
|
||||
dht_test.linkLibC();
|
||||
b.installArtifact(dht_test);
|
||||
|
||||
const run_dht_test = b.addRunArtifact(dht_test);
|
||||
@@ -411,6 +427,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "basic-file-share",
|
||||
.root_module = basic_file_share_module,
|
||||
});
|
||||
basic_file_share.linkLibC();
|
||||
b.installArtifact(basic_file_share);
|
||||
|
||||
const run_basic_file_share = b.addRunArtifact(basic_file_share);
|
||||
@@ -432,6 +449,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "file-downloader",
|
||||
.root_module = file_downloader_module,
|
||||
});
|
||||
file_downloader.linkLibC();
|
||||
b.installArtifact(file_downloader);
|
||||
|
||||
const run_file_downloader = b.addRunArtifact(file_downloader);
|
||||
@@ -454,6 +472,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "network-discovery",
|
||||
.root_module = network_discovery_module,
|
||||
});
|
||||
network_discovery.linkLibC();
|
||||
b.installArtifact(network_discovery);
|
||||
|
||||
const run_network_discovery = b.addRunArtifact(network_discovery);
|
||||
@@ -477,6 +496,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "complete-app",
|
||||
.root_module = complete_app_module,
|
||||
});
|
||||
complete_app.linkLibC();
|
||||
b.installArtifact(complete_app);
|
||||
|
||||
const run_complete_app = b.addRunArtifact(complete_app);
|
||||
@@ -496,6 +516,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "benchmark",
|
||||
.root_module = benchmark_module,
|
||||
});
|
||||
benchmark.linkLibC();
|
||||
b.installArtifact(benchmark);
|
||||
|
||||
const run_benchmark = b.addRunArtifact(benchmark);
|
||||
@@ -528,6 +549,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "llm-agent",
|
||||
.root_module = llm_agent_module,
|
||||
});
|
||||
llm_agent.linkLibC();
|
||||
b.installArtifact(llm_agent);
|
||||
|
||||
const run_llm_agent = b.addRunArtifact(llm_agent);
|
||||
@@ -550,6 +572,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "client-agent",
|
||||
.root_module = client_agent_module,
|
||||
});
|
||||
client_agent.linkLibC();
|
||||
b.installArtifact(client_agent);
|
||||
|
||||
const run_client_agent = b.addRunArtifact(client_agent);
|
||||
@@ -572,6 +595,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "a2a-agent",
|
||||
.root_module = a2a_agent_module,
|
||||
});
|
||||
a2a_agent.linkLibC();
|
||||
b.installArtifact(a2a_agent);
|
||||
|
||||
const run_a2a_agent = b.addRunArtifact(a2a_agent);
|
||||
@@ -594,6 +618,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "a2a-conversation",
|
||||
.root_module = a2a_conversation_module,
|
||||
});
|
||||
a2a_conversation.linkLibC();
|
||||
b.installArtifact(a2a_conversation);
|
||||
|
||||
const run_a2a_conversation = b.addRunArtifact(a2a_conversation);
|
||||
@@ -615,6 +640,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "resume-test",
|
||||
.root_module = resume_test_module,
|
||||
});
|
||||
resume_test.linkLibC();
|
||||
b.installArtifact(resume_test);
|
||||
|
||||
const run_resume_test = b.addRunArtifact(resume_test);
|
||||
@@ -635,6 +661,7 @@ pub fn build(b: *std.Build) void {
|
||||
.name = "interrupted-transfer-test",
|
||||
.root_module = interrupted_test_module,
|
||||
});
|
||||
interrupted_test.linkLibC();
|
||||
b.installArtifact(interrupted_test);
|
||||
|
||||
const run_interrupted_test = b.addRunArtifact(interrupted_test);
|
||||
|
||||
@@ -17,7 +17,7 @@ pub const RateLimiter = struct {
|
||||
/// Token refill rate (tokens per second)
|
||||
refill_rate: u64,
|
||||
/// Last refill timestamp (nanoseconds)
|
||||
last_refill: std.atomic.Value(i128),
|
||||
last_refill: std.atomic.Value(i64),
|
||||
/// Mutex for non-atomic operations
|
||||
mutex: std.Thread.Mutex = .{},
|
||||
|
||||
@@ -26,7 +26,7 @@ pub const RateLimiter = struct {
|
||||
.tokens = std.atomic.Value(u64).init(config.burst_size),
|
||||
.max_tokens = config.burst_size,
|
||||
.refill_rate = config.tokens_per_second,
|
||||
.last_refill = std.atomic.Value(i128).init(time.nanoTimestamp()),
|
||||
.last_refill = std.atomic.Value(i64).init(@intCast(time.nanoTimestamp())),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -79,14 +79,15 @@ pub const RateLimiter = struct {
|
||||
|
||||
/// Refill tokens based on elapsed time
|
||||
fn refill(self: *RateLimiter) void {
|
||||
const now = time.nanoTimestamp();
|
||||
const now: i64 = @intCast(time.nanoTimestamp());
|
||||
const last = self.last_refill.load(.acquire);
|
||||
const elapsed_ns = now - last;
|
||||
|
||||
if (elapsed_ns <= 0) return;
|
||||
|
||||
// Calculate tokens to add (using nanoseconds for precision)
|
||||
const elapsed_seconds = @as(u64, @intCast(@divFloor(elapsed_ns, time.ns_per_s)));
|
||||
const elapsed_ns_u64: u64 = @intCast(elapsed_ns);
|
||||
const elapsed_seconds = elapsed_ns_u64 / time.ns_per_s;
|
||||
if (elapsed_seconds == 0) return;
|
||||
|
||||
const new_tokens = elapsed_seconds * self.refill_rate;
|
||||
|
||||
Reference in New Issue
Block a user