mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-06-05 10:47:32 +03:00
Add MTProxy, MASQUE, VPN, Link parser. Update AmneziaWG. Remove Tunneling
This commit is contained in:
38
protocol/mtproxy/dialer.go
Normal file
38
protocol/mtproxy/dialer.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package mtproxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
)
|
||||
|
||||
type Dialer struct {
|
||||
handler adapter.ConnectionHandlerFuncEx
|
||||
}
|
||||
|
||||
func NewDialer(handler adapter.ConnectionHandlerFuncEx) *Dialer {
|
||||
return &Dialer{handler}
|
||||
}
|
||||
|
||||
func (d *Dialer) Dial(network, address string) (net.Conn, error) {
|
||||
return d.DialContext(context.Background(), network, address)
|
||||
}
|
||||
|
||||
func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
inConn, outConn := net.Pipe()
|
||||
var metadata adapter.InboundContext
|
||||
if streamContext, ok := ctx.(streamContext); ok {
|
||||
metadata.Source = M.SocksaddrFromNet(streamContext.ClientAddr())
|
||||
metadata.User = streamContext.SecretName()
|
||||
}
|
||||
metadata.Destination = M.ParseSocksaddr(address)
|
||||
d.handler(ctx, inConn, metadata, func(error) {})
|
||||
return outConn, nil
|
||||
}
|
||||
|
||||
type streamContext interface {
|
||||
ClientAddr() net.Addr
|
||||
SecretName() string
|
||||
}
|
||||
Reference in New Issue
Block a user