mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-05-14 14:08:04 +08:00
36 lines
859 B
Go
36 lines
859 B
Go
|
package sing
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"net"
|
||
|
|
||
|
C "github.com/metacubex/mihomo/constant"
|
||
|
"github.com/metacubex/mihomo/listener/inner"
|
||
|
|
||
|
M "github.com/sagernet/sing/common/metadata"
|
||
|
N "github.com/sagernet/sing/common/network"
|
||
|
)
|
||
|
|
||
|
type Dialer struct {
|
||
|
t C.Tunnel
|
||
|
proxy string
|
||
|
}
|
||
|
|
||
|
func (d Dialer) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
|
||
|
if network != "tcp" && network != "tcp4" && network != "tcp6" {
|
||
|
return nil, fmt.Errorf("unsupported network %s", network)
|
||
|
}
|
||
|
return inner.HandleTcp(d.t, destination.String(), d.proxy)
|
||
|
}
|
||
|
|
||
|
func (d Dialer) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
|
||
|
return nil, fmt.Errorf("unsupported ListenPacket")
|
||
|
}
|
||
|
|
||
|
var _ N.Dialer = (*Dialer)(nil)
|
||
|
|
||
|
func NewDialer(t C.Tunnel, proxy string) (d *Dialer) {
|
||
|
return &Dialer{t, proxy}
|
||
|
}
|