mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-05 04:47:40 +03:00
33 lines
863 B
Go
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.AddrPort) (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.AddrPort) (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{}
|