Skip to content

Commit

Permalink
update local_rr.zig
Browse files Browse the repository at this point in the history
  • Loading branch information
zfl9 committed Jul 20, 2024
1 parent 56f2d29 commit 5b1490c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ group-upstream 192.168.1.1
- “退出”是指进程收到了`SIGTERM/SIGINT`信号,即`kill <PID>``CTRL+C`发送的信号。
- 发送`SIGUSR1`信号将触发缓存写回,若未指定 db 文件,则路径为`/tmp/[email protected]`
- 为了降低性能开销,load/dump 没有做数据校验,请勿修改 db 文件,请勿跨平台共享 db 文件。
- 有时你可能需要清空 db 文件来丢弃旧缓存(关闭进程,清空文件,重新启动进程),例如:
- 更改了`cache-ignore`、域名列表(内容更改、优先级更改等)。
- 需要重新触发 ip add 操作(域名在有缓存的情况下不会触发 add)。

### verdict-cache

Expand Down
6 changes: 4 additions & 2 deletions src/cache.zig
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub fn add(msg: []const u8, qnamelen: c_int, p_ttl: *i32) bool {

/// load from db file
pub fn load() void {
assert(g.cache_size > 0);
assert(enabled());

const src = @src();
const path = g.cache_db orelse return;
Expand All @@ -216,14 +216,16 @@ pub fn load() void {
while (CacheMsg.load(&data)) |cache_msg| {
map.add(cache_msg);
_list.link_to_tail(&cache_msg.list_node);

if (map._nitems >= g.cache_size) break;
}

log.info(src, "%zu entries from %s", .{ map._nitems, path });
}

/// dump to db file
pub fn dump(event: enum { on_exit, on_manual }) void {
if (g.cache_size == 0)
if (!enabled())
return;

const src = @src();
Expand Down
5 changes: 5 additions & 0 deletions src/local_rr.zig
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ const RR_AAAA = packed struct {
data: [c.IPV6_LEN]u8,
};

comptime {
assert(@sizeOf(RR_A) == 2 * 3 + 4 + 2 + c.IPV4_LEN);
assert(@sizeOf(RR_AAAA) == 2 * 3 + 4 + 2 + c.IPV6_LEN);
}

/// for opt.zig
pub fn read_hosts(path: []const u8) ?void {
const src = @src();
Expand Down

0 comments on commit 5b1490c

Please sign in to comment.