create Mutual Witness Protocol specs and implementation. #1

Merged
mdt merged 26 commits from mwp into main 2026-02-11 17:38:08 +00:00
82 changed files with 11230 additions and 418 deletions
Showing only changes of commit ae1061f4a5 - Show all commits

View File

@@ -1106,7 +1106,6 @@ pub const FileSharingManager = struct {
/// Dynamically adjusts max_concurrent_downloads based on network health /// Dynamically adjusts max_concurrent_downloads based on network health
adaptive_controller: ?AdaptiveConcurrencyController, adaptive_controller: ?AdaptiveConcurrencyController,
/// TIMING: Counter for periodic timing logs /// TIMING: Counter for periodic timing logs
timing_log_counter: u32 = 0,
// ======================================================================== // ========================================================================
// HIGH-5 FIX: LOCK ORDERING DOCUMENTATION // HIGH-5 FIX: LOCK ORDERING DOCUMENTATION
@@ -2565,7 +2564,7 @@ pub const FileSharingManager = struct {
// Debug logging for adaptive controller state // Debug logging for adaptive controller state
if (total_stuck > 0 or total_in_flight > 50) { if (total_stuck > 0 or total_in_flight > 50) {
const stats = ctrl.getStats(); const stats = ctrl.getStats();
std.log.info("ADAPTIVE: in_flight={}, stuck={}, timeouts_recorded={}, success={d:.1}%, timeout={d:.1}%, concurrency={}", .{ std.log.debug("ADAPTIVE: in_flight={}, stuck={}, timeouts_recorded={}, success={d:.1}%, timeout={d:.1}%, concurrency={}", .{
total_in_flight, total_in_flight,
total_stuck, total_stuck,
weighted_timeouts, weighted_timeouts,
@@ -2606,12 +2605,10 @@ pub const FileSharingManager = struct {
// Clean up completed/failed sessions // Clean up completed/failed sessions
self.cleanupCompletedSessions(); self.cleanupCompletedSessions();
// TIMING: Log timing breakdown (only when significant time spent) // TIMING: Log timing breakdown only when significant (>10ms)
const total_time = std.time.nanoTimestamp() - timer_start; const total_time = std.time.nanoTimestamp() - timer_start;
const total_ms = @as(f64, @floatFromInt(total_time)) / 1_000_000.0; const total_ms = @as(f64, @floatFromInt(total_time)) / 1_000_000.0;
// Log every 100th call or when > 1ms to reduce spam while getting data if (total_ms > 10.0) {
self.timing_log_counter +%= 1;
if (total_ms > 1.0 or self.timing_log_counter % 100 == 0) {
const p1_ms = @as(f64, @floatFromInt(phase1_time)) / 1_000_000.0; const p1_ms = @as(f64, @floatFromInt(phase1_time)) / 1_000_000.0;
const p2_ms = @as(f64, @floatFromInt(phase2_time)) / 1_000_000.0; const p2_ms = @as(f64, @floatFromInt(phase2_time)) / 1_000_000.0;
const p3_ms = @as(f64, @floatFromInt(phase3_time)) / 1_000_000.0; const p3_ms = @as(f64, @floatFromInt(phase3_time)) / 1_000_000.0;
@@ -5250,7 +5247,7 @@ test "file sharing session creation" {
test "file sharing manager basic operations" { test "file sharing manager basic operations" {
const allocator = testing.allocator; const allocator = testing.allocator;
const config = FileSharingConfig.default(); const config = FileSharingConfig.default();
var manager = try FileSharingManager.init(config, allocator); var manager = try FileSharingManager.initForTesting(config, allocator);
defer manager.deinit(); defer manager.deinit();
// Test initial stats // Test initial stats
@@ -5268,7 +5265,7 @@ test "file sharing manager basic operations" {
test "file sharing manager processing" { test "file sharing manager processing" {
const allocator = testing.allocator; const allocator = testing.allocator;
const config = FileSharingConfig.default(); const config = FileSharingConfig.default();
var manager = try FileSharingManager.init(config, allocator); var manager = try FileSharingManager.initForTesting(config, allocator);
defer manager.deinit(); defer manager.deinit();
// Process empty manager (should not crash) // Process empty manager (should not crash)
@@ -5527,7 +5524,7 @@ test "handlePieceData rejects bad hash and blacklists peer" {
test "blacklisted peer cannot send pieces" { test "blacklisted peer cannot send pieces" {
const allocator = testing.allocator; const allocator = testing.allocator;
const config = FileSharingConfig.default(); const config = FileSharingConfig.default();
var manager = try FileSharingManager.init(config, allocator); var manager = try FileSharingManager.initForTesting(config, allocator);
defer manager.deinit(); defer manager.deinit();
const peer_id: [32]u8 = [_]u8{77} ** 32; const peer_id: [32]u8 = [_]u8{77} ** 32;