From de0b86ce5c1c1309e429fdccff7fe9b3924b7eff Mon Sep 17 00:00:00 2001 From: Murtaza Aliakbar Date: Sun, 20 Oct 2024 02:37:08 +0530 Subject: [PATCH] dialers,ipn: impl Handle() --- intra/ipn/auto.go | 5 +++++ intra/ipn/base.go | 5 +++++ intra/ipn/exit.go | 5 +++++ intra/ipn/ground.go | 6 ++++++ intra/ipn/http1.go | 5 +++++ intra/ipn/piph2.go | 5 +++++ intra/ipn/pipws.go | 15 ++++++++++----- intra/ipn/socks5.go | 5 +++++ intra/ipn/wgproxy.go | 5 +++++ intra/protect/xdial.go | 6 ++++++ 10 files changed, 57 insertions(+), 5 deletions(-) diff --git a/intra/ipn/auto.go b/intra/ipn/auto.go index 2cb0160a..1f793fe4 100644 --- a/intra/ipn/auto.go +++ b/intra/ipn/auto.go @@ -55,6 +55,11 @@ func NewAutoProxy(ctx context.Context, pxr Proxies) *auto { return h } +// Handle implements Proxy. +func (h *auto) Handle() uintptr { + return core.Loc(h) +} + // Dial implements Proxy. func (h *auto) Dial(network, addr string) (protect.Conn, error) { if h.status.Load() == END { diff --git a/intra/ipn/base.go b/intra/ipn/base.go index 2a7f99be..ab0e2816 100644 --- a/intra/ipn/base.go +++ b/intra/ipn/base.go @@ -37,6 +37,11 @@ func NewBaseProxy(c protect.Controller) *base { return h } +// Handle implements Proxy. +func (h *base) Handle() uintptr { + return core.Loc(h) +} + // Dial implements the Proxy interface. func (h *base) Dial(network, addr string) (c protect.Conn, err error) { if h.status.Load() == END { diff --git a/intra/ipn/exit.go b/intra/ipn/exit.go index 68df9bbe..9681949e 100644 --- a/intra/ipn/exit.go +++ b/intra/ipn/exit.go @@ -35,6 +35,11 @@ func NewExitProxy(c protect.Controller) *exit { return h } +// Handle implements Proxy. +func (h *exit) Handle() uintptr { + return core.Loc(h) +} + // Dial implements Proxy. func (h *exit) Dial(network, addr string) (protect.Conn, error) { if h.status.Load() == END { diff --git a/intra/ipn/ground.go b/intra/ipn/ground.go index 2307113f..e1aec1a2 100644 --- a/intra/ipn/ground.go +++ b/intra/ipn/ground.go @@ -8,6 +8,7 @@ package ipn import ( x "github.com/celzero/firestack/intra/backend" + "github.com/celzero/firestack/intra/core" "github.com/celzero/firestack/intra/protect" ) @@ -30,6 +31,11 @@ func NewGroundProxy() *ground { return h } +// Handle implements Proxy. +func (h *ground) Handle() uintptr { + return core.Loc(h) +} + // Dial implements Proxy. func (h *ground) Dial(network, addr string) (protect.Conn, error) { return nil, errNoProxyResponse diff --git a/intra/ipn/http1.go b/intra/ipn/http1.go index 891b9c11..9067e19e 100644 --- a/intra/ipn/http1.go +++ b/intra/ipn/http1.go @@ -75,6 +75,11 @@ func NewHTTPProxy(id string, c protect.Controller, po *settings.ProxyOptions) (* return h, nil } +// Handle implements Proxy. +func (h *http1) Handle() uintptr { + return core.Loc(h) +} + // Dial implements Proxy. func (h *http1) Dial(network, addr string) (c protect.Conn, err error) { if h.status.Load() == END { diff --git a/intra/ipn/piph2.go b/intra/ipn/piph2.go index becd3328..690b9efb 100644 --- a/intra/ipn/piph2.go +++ b/intra/ipn/piph2.go @@ -280,6 +280,11 @@ func (t *piph2) claim(msg string) []string { return []string{t.token, byte2hex(msgmac)} } +// Handle implements Proxy. +func (h *piph2) Handle() uintptr { + return core.Loc(h) +} + // Dial implements Proxy. func (t *piph2) Dial(network, addr string) (protect.Conn, error) { if t.status.Load() == END { diff --git a/intra/ipn/pipws.go b/intra/ipn/pipws.go index 04dde77b..349e2db5 100644 --- a/intra/ipn/pipws.go +++ b/intra/ipn/pipws.go @@ -267,6 +267,11 @@ func (t *pipws) claim(msg string) []string { return []string{t.token, byte2hex(msgmac)} } +// Handle implements Proxy. +func (t *pipws) Handle() uintptr { + return core.Loc(t) +} + // Dial connects to addr via wsconn over this ws proxy func (t *pipws) Dial(network, addr string) (protect.Conn, error) { if t.status.Load() == END { @@ -319,16 +324,16 @@ func (t *pipws) Dial(network, addr string) (protect.Conn, error) { return c, nil } -func (h *pipws) Dialer() protect.RDialer { - return h +func (t *pipws) Dialer() protect.RDialer { + return t } -func (h *pipws) DNS() string { +func (*pipws) DNS() string { return nodns } -func (h *pipws) ech() []byte { - name := h.hostname +func (t *pipws) ech() []byte { + name := t.hostname if len(name) <= 0 { return nil } else if v, err := dialers.ECH(name); err != nil { diff --git a/intra/ipn/socks5.go b/intra/ipn/socks5.go index 85f35469..1acdeedf 100644 --- a/intra/ipn/socks5.go +++ b/intra/ipn/socks5.go @@ -142,6 +142,11 @@ func NewSocks5Proxy(id string, ctl protect.Controller, po *settings.ProxyOptions return h, nil } +// Handle implements Proxy. +func (h *socks5) Handle() uintptr { + return core.Loc(h) +} + // Dial implements Proxy. func (h *socks5) Dial(network, addr string) (c protect.Conn, err error) { if h.status == END { diff --git a/intra/ipn/wgproxy.go b/intra/ipn/wgproxy.go index b4851b36..eaaa3481 100644 --- a/intra/ipn/wgproxy.go +++ b/intra/ipn/wgproxy.go @@ -122,6 +122,11 @@ type WgProxy interface { IpcSet(txt string) error } +// Handle implements Proxy. +func (h *wgproxy) Handle() uintptr { + return core.Loc(h) +} + // Dial implements WgProxy func (h *wgproxy) Dial(network, address string) (c protect.Conn, err error) { // ProxyDial resolves address if needed; then dials into all resolved ips. diff --git a/intra/protect/xdial.go b/intra/protect/xdial.go index 17042920..1178f253 100644 --- a/intra/protect/xdial.go +++ b/intra/protect/xdial.go @@ -28,6 +28,8 @@ type Listener = net.Listener type DialFn func(network, addr string) (net.Conn, error) type RDialer interface { + // Handle uniquely identifies the concrete type backing this dialer. + Handle() uintptr // Dial creates a connection to the given address, // the resulting net.Conn must be a *net.TCPConn if // network is "tcp" or "tcp4" or "tcp6" and must be @@ -74,6 +76,10 @@ var ( errAccept = errors.New("cannot accept network") ) +func (d *RDial) Handle() uintptr { + return core.Loc(d) +} + func (d *RDial) dial(network, addr string) (net.Conn, error) { usedialer := d.dialer != nil usedelegate := d.delegate != nil && core.IsNotNil(d.delegate)