Skip to content

Commit

Permalink
intra: rmv unused tunnel.bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
ignoramous committed Nov 12, 2024
1 parent da94071 commit afd8717
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
14 changes: 6 additions & 8 deletions intra/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ var (
// DefaultDNS is the resolver used by all dialers.
type DefaultDNS interface {
x.DNSTransport
kickstart(px ipn.Proxies, g Bridge) error
kickstart(px ipn.Proxies) error
reinit(typ, ipOrUrl, ips string) error
}

type bootstrap struct {
ctx context.Context
tr dnsx.Transport // the underlying transport
proxies ipn.Proxies // never nil if underlying transport is set
bridge Bridge // never nil if underlying transport is set
typ string // DOH or DNS53
ipports string // never empty for DNS53
url string // never empty for DOH
Expand Down Expand Up @@ -147,24 +146,23 @@ func (b *bootstrap) reinit(trtype, ippOrUrl, ipcsv string) error {

log.I("dns: default: %s reinit %s %s w/ %s", trtype, b.url, b.hostname, b.ipports)

// if proxies and bridges are set, restart to create new transport
if b.proxies != nil && b.bridge != nil {
// if proxies is set, restart to create new transport
if b.proxies != nil {
return b.recreate()
}
return nil
}

func (b *bootstrap) recreate() error {
return b.kickstart(b.proxies, b.bridge)
return b.kickstart(b.proxies)
}

func (b *bootstrap) kickstart(px ipn.Proxies, g Bridge) error {
if px == nil || g == nil {
func (b *bootstrap) kickstart(px ipn.Proxies) error {
if px == nil {
return errCannotStart
}

b.proxies = px
b.bridge = g
var tr dnsx.Transport
var err error
switch b.typ {
Expand Down
9 changes: 9 additions & 0 deletions intra/dialers/ips.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ func For(hostOrIP string) []netip.Addr {
return nil
}

// Addrs returns addresses for hostOrIP from cache. Use Resolve() to bypass cache.
func Addrs(hostOrIP string) []netip.Addr {
ipset := ipm.GetAny(hostOrIP)
if ipset != nil || !ipset.Empty() {
return ipset.Addrs()
}
return nil
}

// Mapper is a hostname to IP (a/aaaa) resolver for the network engine; may be nil.
func Mapper(m ipmap.IPMapper) {
log.I("dialers: ips: mapper ok? %t", m != nil)
Expand Down
3 changes: 1 addition & 2 deletions intra/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,12 @@ func AddODoHTransport(t Tunnel, id, endpoint, resolver, epips string) error {
if rerr != nil || perr != nil {
return errors.Join(rerr, perr)
}
g := t.getBridge()
ctx := t.internalCtx()
split := []string{}
if len(epips) > 0 {
split = strings.Split(epips, ",")
}
if dns, err := doh.NewOdohTransport(ctx, id, endpoint, resolver, split, pxr, g); err != nil {
if dns, err := doh.NewOdohTransport(ctx, id, endpoint, resolver, split, pxr); err != nil {
return err
} else {
return addDNSTransport(r, dns)
Expand Down
11 changes: 1 addition & 10 deletions intra/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ type Tunnel interface {
GetProxies() (x.Proxies, error)
// Get the internal proxies.
internalProxies() (ipn.Proxies, error)
// A bridge to the client code.
getBridge() Bridge
// Sets new default routes for the given engine, where engine is
// one of the constants (Ns4, Ns6, Ns46) defined in package settings.
SetRoute(engine int) error
Expand All @@ -99,7 +97,6 @@ type rtunnel struct {
ctx context.Context
done context.CancelFunc
tunmode *settings.TunMode
bridge Bridge
proxies ipn.Proxies
resolver dnsx.Resolver
services rnet.Services
Expand Down Expand Up @@ -130,7 +127,7 @@ func NewTunnel(fd, mtu int, fakedns string, tunmode *settings.TunMode, dtr Defau
return nil, fmt.Errorf("tun: no proxies? %t or services? %t", proxies == nil, services == nil)
}

if err := dtr.kickstart(proxies, bdg); err != nil {
if err := dtr.kickstart(proxies); err != nil {
log.I("tun: <<< new >>>; kickstart err(%v)", err)
return nil, err
}
Expand Down Expand Up @@ -163,7 +160,6 @@ func NewTunnel(fd, mtu int, fakedns string, tunmode *settings.TunMode, dtr Defau
ctx: ctx,
done: cancel,
tunmode: tunmode,
bridge: bdg,
proxies: proxies,
resolver: resolver,
services: services,
Expand All @@ -173,10 +169,6 @@ func NewTunnel(fd, mtu int, fakedns string, tunmode *settings.TunMode, dtr Defau
return t, nil
}

func (t *rtunnel) getBridge() Bridge {
return t.bridge // may return nil, esp after Disconnect()
}

func (t *rtunnel) Disconnect() {
defer core.Recover(core.Exit11, "intra.Disconnect")

Expand All @@ -187,7 +179,6 @@ func (t *rtunnel) Disconnect() {
t.once.Do(func() {
t.closed.Store(true)
t.done()
t.bridge = nil // "free" ref to the client
log.I("tun: <<< disconnect >>>")
})
}
Expand Down

0 comments on commit afd8717

Please sign in to comment.