add bootstrap node, MWP peer discovery, and DNS resolution
This commit is contained in:
@@ -1475,17 +1475,30 @@ fn parseHostPort(s: []const u8) ?struct { host: [4]u8, port: u16 } {
|
||||
const port_str = s[colon_idx + 1 ..];
|
||||
const port = std.fmt.parseInt(u16, port_str, 10) catch return null;
|
||||
|
||||
// Try IPv4 dotted notation first
|
||||
var parts: [4]u8 = undefined;
|
||||
var iter = std.mem.splitScalar(u8, host_str, '.');
|
||||
var idx: usize = 0;
|
||||
var is_ip = true;
|
||||
while (iter.next()) |part| {
|
||||
if (idx >= 4) return null;
|
||||
parts[idx] = std.fmt.parseInt(u8, part, 10) catch return null;
|
||||
if (idx >= 4) { is_ip = false; break; }
|
||||
parts[idx] = std.fmt.parseInt(u8, part, 10) catch { is_ip = false; break; };
|
||||
idx += 1;
|
||||
}
|
||||
if (idx != 4) return null;
|
||||
if (is_ip and idx == 4) return .{ .host = parts, .port = port };
|
||||
|
||||
return .{ .host = parts, .port = port };
|
||||
// Fall back to DNS resolution
|
||||
var gpa_alloc = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
defer _ = gpa_alloc.deinit();
|
||||
const list = std.net.getAddressList(gpa_alloc.allocator(), host_str, port) catch return null;
|
||||
defer list.deinit();
|
||||
for (list.addrs) |addr| {
|
||||
if (addr.any.family == std.posix.AF.INET) {
|
||||
const bytes = @as(*const [4]u8, @ptrCast(&addr.in.sa.addr));
|
||||
return .{ .host = bytes.*, .port = port };
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
fn hasActiveSendTo(transfers: *const TransferMap, peer_id: PeerId) bool {
|
||||
|
||||
Reference in New Issue
Block a user