Some checks failed
Windows project source guards / test (push) Has been cancelled
Owner request 2026-11-26 ("so everything works with Hysteria, AWG and the rest"). The helpers that dial with
their own UDP socket talk to a loopback `direct` UDP inbound of sing-box (override address = the real server) whose
rule leads into the WARP hop: the AmneziaWG helper in both modes (peer 127.0.0.1:relay, new `unbound` mode without the
physical-interface binding, IPv4 tunnel with an inner MTU of 1250, started after the front), the main Hysteria2
helper in the proxy mode (server name kept in the TLS SNI). Slot helpers stay TUN-only. Verified on win10 with the
real components: the real AmneziaWG server brings a real page through the hop in the proxy mode and under the TUN;
Go tests of the helper pass as a Windows exe. Hysteria2 through the relay is unit-tested on real nodes but not live:
the test person's Hysteria2 servers do not answer from the VM with or without the hop.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net"
|
|
"net/netip"
|
|
"strings"
|
|
"time"
|
|
|
|
"golang.org/x/net/dns/dnsmessage"
|
|
)
|
|
|
|
// Only peer hostnames use physical-network bootstrap. SOCKS destinations
|
|
// exclusively use the separate sing-box DNS delegation, with no fallback here.
|
|
func bootstrapPeers(c *config) error {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 8*time.Second)
|
|
defer cancel()
|
|
dialer := &net.Dialer{Control: physicalSocketControl(c.InterfaceIndex)}
|
|
for index := range c.Endpoint.Peers {
|
|
peer := &c.Endpoint.Peers[index]
|
|
if _, err := netip.ParseAddr(peer.Address); err == nil {
|
|
continue
|
|
}
|
|
if c.Unbound {
|
|
return fmt.Errorf("peer[%d] must be an address when the socket is not bound to the physical interface", index)
|
|
}
|
|
if len(c.BootstrapDNS) == 0 {
|
|
return fmt.Errorf("peer[%d] bootstrap: physical network has no DNS server", index)
|
|
}
|
|
var last error
|
|
resolved := false
|
|
for _, raw := range c.BootstrapDNS {
|
|
ip, err := netip.ParseAddr(raw)
|
|
if err != nil || ip.IsUnspecified() || ip.IsMulticast() {
|
|
return fmt.Errorf("invalid physical bootstrap DNS address")
|
|
}
|
|
for _, kind := range []dnsmessage.Type{dnsmessage.TypeA, dnsmessage.TypeAAAA} {
|
|
queryCtx, queryCancel := context.WithTimeout(ctx, 2*time.Second)
|
|
ips, err := lookupDNS(queryCtx, netip.AddrPortFrom(ip, 53).String(), strings.TrimSuffix(peer.Address, ".")+".", kind, dialer)
|
|
queryCancel()
|
|
last = err
|
|
for _, result := range ips {
|
|
if result.IsUnspecified() || result.IsMulticast() {
|
|
continue
|
|
}
|
|
peer.Address = result.Unmap().String()
|
|
resolved = true
|
|
break
|
|
}
|
|
if resolved || ctx.Err() != nil {
|
|
break
|
|
}
|
|
}
|
|
if resolved || ctx.Err() != nil {
|
|
break
|
|
}
|
|
}
|
|
if !resolved {
|
|
return fmt.Errorf("peer[%d] bootstrap DNS failed: %v", index, last)
|
|
}
|
|
}
|
|
return nil
|
|
}
|