Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add streaming API #5

Merged
merged 29 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a864ccb
add draft for streaming API
lun-4 Jan 30, 2023
eedfc7c
add WIP impl for Parser interface
lun-4 Feb 1, 2023
16607c5
make it compile
lun-4 Feb 2, 2023
8fc65b7
remove errdefer because of ownership issues to be fixed
lun-4 Feb 2, 2023
344faed
fix names
lun-4 Feb 2, 2023
ea107d8
parser: add logging
lun-4 Feb 2, 2023
5c599b8
test: add allocator
lun-4 Feb 2, 2023
03c54df
fix more things
lun-4 Feb 2, 2023
bae07c3
fix stack use-after-free
lun-4 Feb 3, 2023
d0534d0
fix pointer reading
lun-4 Feb 3, 2023
dbd6ef1
add ResourceClass.readFrom
lun-4 Feb 3, 2023
7adeb78
fix name parsing on pointers
lun-4 Feb 3, 2023
5504e80
helpers: fix parseFullPacket
lun-4 Feb 3, 2023
9ec3581
fixes for latest zig
lun-4 Feb 8, 2023
55cba9e
fix memory leak
lun-4 Feb 8, 2023
e19b999
use ResourceClaass.readFrom in Resource.readFrom
lun-4 Feb 8, 2023
b568fcd
install both executables
lun-4 Feb 8, 2023
576f9df
fix receiveTrustedAddresses
lun-4 Feb 8, 2023
2205206
fix ownership issues with getAddressList
lun-4 Feb 8, 2023
9353e71
add debug logging env var to tinyhost
lun-4 Feb 8, 2023
929be80
do not parse empty labels in FullName.fromString
lun-4 Feb 8, 2023
3238713
add header ID check
lun-4 Feb 9, 2023
d95cb9e
add pointer resolution through NamePool
lun-4 Feb 9, 2023
0a32b93
pass allocator to receiveFullPacket
lun-4 Feb 9, 2023
950d2ff
free raw name labels after transmute
lun-4 Feb 9, 2023
79a6127
add support for resource data using NamePool
lun-4 Feb 9, 2023
c96086f
add DEBUG env var to main executable
lun-4 Feb 9, 2023
75209a4
propagate RawName's packet_index when transmuting to FullName
lun-4 Feb 9, 2023
aba3883
add Name.format
lun-4 Feb 9, 2023
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
44 changes: 26 additions & 18 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Builder = std.build.Builder;
const std = @import("std");
pub fn build(b: *Builder) void {
const native_opt = b.option(bool, "native", "if many cpu, turn this on");
const native_opt = b.option(bool, "native", "if other people exist, turn this off");
const option_libc = (b.option(bool, "libc", "build with libc?")) orelse false;
const is_native = native_opt orelse true;

Expand All @@ -17,21 +17,32 @@ pub fn build(b: *Builder) void {
});
}

const mode = b.standardReleaseOptions();
const optimize = b.standardOptimizeOption(.{});

// this exports both a library and a binary

const exe = b.addExecutable("zigdig", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
const exe = b.addExecutable(.{
.name = "zigdig",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
if (option_libc) exe.linkLibC();
exe.install();

const exe_tinyhost = b.addExecutable(.{
.name = "zigdig-tiny",
.root_source_file = .{ .path = "src/main_tinyhost.zig" },
.target = target,
.optimize = optimize,
});
if (option_libc) exe.linkLibC();
exe_tinyhost.install();

const lib = b.addStaticLibrary("zigdig", "src/lib.zig");
lib.setTarget(target);
lib.setBuildMode(mode);

var lib_tests = b.addTest("src/main.zig");
lib_tests.setBuildMode(mode);
var lib_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.optimize = optimize,
});

const test_step = b.step("test", "Run library tests");
test_step.dependOn(&lib_tests.step);
Expand All @@ -40,12 +51,9 @@ pub fn build(b: *Builder) void {
const run_step = b.step("run", "Run example binary");
run_step.dependOn(&run_cmd.step);

b.default_step.dependOn(&lib.step);
b.default_step.dependOn(&exe.step);

lib.addPackagePath("dns", "src/lib.zig");
exe.addPackagePath("dns", "src/lib.zig");

b.installArtifact(lib);
b.addModule(.{
.name = "dns",
.source_file = .{ .path = "src/lib.zig" },
});
b.installArtifact(exe);
}
11 changes: 11 additions & 0 deletions src/enums.zig
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ pub const ResourceClass = enum(u16) {
HS = 4,
WILDCARD = 255,

pub fn readFrom(reader: anytype) !@This() {
const resource_class_int = try reader.readIntBig(u16);
return std.meta.intToEnum(@This(), resource_class_int) catch |err| {
logger.err(
"unknown resource class {d}, got {s}",
.{ resource_class_int, @errorName(err) },
);
return err;
};
}

pub fn writeTo(self: @This(), writer: anytype) !usize {
try writer.writeIntBig(u16, @enumToInt(self));
return 16 / 8;
Expand Down
Loading