Skip to content

Commit

Permalink
dialers,ipn: impl Handle()
Browse files Browse the repository at this point in the history
  • Loading branch information
ignoramous committed Oct 19, 2024
1 parent b9055f2 commit de0b86c
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 5 deletions.
5 changes: 5 additions & 0 deletions intra/ipn/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions intra/ipn/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions intra/ipn/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions intra/ipn/ground.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions intra/ipn/http1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions intra/ipn/piph2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 10 additions & 5 deletions intra/ipn/pipws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions intra/ipn/socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions intra/ipn/wgproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions intra/protect/xdial.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

1 comment on commit de0b86c

@ignoramous
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.