sing/common/network/dialer.go
2022-05-04 19:34:55 +08:00

33 lines
863 B
Go

package network
import (
"context"
"net"
M "github.com/sagernet/sing/common/metadata"
)
type ContextDialer interface {
DialContext(ctx context.Context, network string, address M.Socksaddr) (net.Conn, error)
}
var SystemDialer ContextDialer = &DefaultDialer{}
type DefaultDialer struct {
net.Dialer
}
func (d *DefaultDialer) ListenUDP(network string, laddr *net.UDPAddr) (*net.UDPConn, error) {
return net.ListenUDP(network, laddr)
}
func (d *DefaultDialer) DialContext(ctx context.Context, network string, address M.Socksaddr) (net.Conn, error) {
return d.Dialer.DialContext(ctx, network, address.String())
}
type Listener interface {
Listen(ctx context.Context, network, address string) (net.Listener, error)
ListenPacket(ctx context.Context, network, address string) (net.PacketConn, error)
}
var SystemListener Listener = &net.ListenConfig{}