feat: refactor core+network+protocol: use platform abstractions,
transport vtable
This commit is contained in:
@@ -12,8 +12,11 @@ const posix = std.posix;
|
||||
const mem = std.mem;
|
||||
const fmt = std.fmt;
|
||||
const builtin = @import("builtin");
|
||||
const Mutex = @import("sync").Mutex;
|
||||
const AtomicValue = @import("sync").AtomicValue;
|
||||
|
||||
const Error = @import("error.zig").Error;
|
||||
const platform_time = @import("platform").time;
|
||||
|
||||
/// Address family types
|
||||
pub const AddressFamily = enum(u8) {
|
||||
@@ -825,7 +828,7 @@ pub const MAX_DNS_CACHE_MEMORY: usize = 10 * 1024 * 1024;
|
||||
/// DNS rate limiting per host
|
||||
pub const DnsRateLimit = struct {
|
||||
last_lookup: std.AutoHashMap(u64, i64),
|
||||
mutex: std.Thread.Mutex,
|
||||
mutex: Mutex,
|
||||
allocator: mem.Allocator,
|
||||
min_interval_ms: i64,
|
||||
|
||||
@@ -852,7 +855,7 @@ pub const DnsRateLimit = struct {
|
||||
self.mutex.lock();
|
||||
defer self.mutex.unlock();
|
||||
|
||||
const now = std.time.milliTimestamp();
|
||||
const now = platform_time.milliTimestamp();
|
||||
|
||||
if (self.last_lookup.get(hash)) |last_time| {
|
||||
// Check if enough time has passed since last lookup
|
||||
@@ -877,13 +880,13 @@ pub const AddressResolver = struct {
|
||||
/// SECURITY: Rate limiter to prevent DNS amplification attacks
|
||||
rate_limiter: DnsRateLimit,
|
||||
/// SECURITY: Track total cache memory usage
|
||||
cache_memory_used: std.atomic.Value(usize),
|
||||
cache_memory_used: AtomicValue(usize),
|
||||
|
||||
pub fn init(allocator: mem.Allocator) AddressResolver {
|
||||
return .{
|
||||
.allocator = allocator,
|
||||
.rate_limiter = DnsRateLimit.init(allocator, 1000), // 1 second minimum between lookups
|
||||
.cache_memory_used = std.atomic.Value(usize).init(0),
|
||||
.cache_memory_used = AtomicValue(usize).init(0),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user