mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-05-25 21:51:47 +03:00
Add MTProxy, MASQUE, VPN, Link parser. Update AmneziaWG. Remove Tunneling
This commit is contained in:
43
protocol/mtproxy/network.go
Normal file
43
protocol/mtproxy/network.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package mtproxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/dolonet/mtg-multi/essentials"
|
||||
)
|
||||
|
||||
type NetworkAdapter struct {
|
||||
ctx context.Context
|
||||
dialer essentials.Dialer
|
||||
}
|
||||
|
||||
func NewNetworkAdapter(ctx context.Context, dialer essentials.Dialer) *NetworkAdapter {
|
||||
return &NetworkAdapter{ctx, dialer}
|
||||
}
|
||||
|
||||
func (a *NetworkAdapter) Dial(network, address string) (essentials.Conn, error) {
|
||||
return a.DialContext(a.ctx, network, address)
|
||||
}
|
||||
|
||||
func (a *NetworkAdapter) DialContext(ctx context.Context, network, address string) (essentials.Conn, error) {
|
||||
conn, err := a.dialer.DialContext(ctx, network, address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return essentials.WrapNetConn(conn), nil
|
||||
}
|
||||
|
||||
func (a *NetworkAdapter) MakeHTTPClient(func(ctx context.Context, network, address string) (essentials.Conn, error)) *http.Client {
|
||||
return &http.Client{
|
||||
Timeout: 10,
|
||||
Transport: &http.Transport{DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
return a.DialContext(ctx, network, addr)
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
func (a *NetworkAdapter) NativeDialer() essentials.Dialer {
|
||||
return a.dialer
|
||||
}
|
||||
Reference in New Issue
Block a user