github.com/xxf098/lite-proxy@v0.15.1-0.20230422081941-12c69f323218/outbound/base.go (about)

     1  package outbound
     2  
     3  import (
     4  	"context"
     5  	"net"
     6  
     7  	"github.com/xxf098/lite-proxy/common"
     8  	C "github.com/xxf098/lite-proxy/constant"
     9  )
    10  
    11  type Base struct {
    12  	name string
    13  	addr string
    14  	udp  bool
    15  }
    16  
    17  type BasicOption struct {
    18  	Interface   string `proxy:"interface-name,omitempty" group:"interface-name,omitempty"`
    19  	RoutingMark int    `proxy:"routing-mark,omitempty" group:"routing-mark,omitempty"`
    20  }
    21  
    22  type ContextDialer interface {
    23  	DialContext(ctx context.Context, m *C.Metadata) (c net.Conn, err error)
    24  }
    25  
    26  type Dialer interface {
    27  	ContextDialer
    28  	DialUDP(m *C.Metadata) (net.PacketConn, error)
    29  }
    30  
    31  type Creator func(link string) (Dialer, error)
    32  
    33  var creators = make(map[string]Creator)
    34  
    35  func RegisterDialerCreator(name string, c Creator) {
    36  	creators[name] = c
    37  }
    38  
    39  func GetDialerCreator(name string) (Creator, error) {
    40  	if c, ok := creators[name]; ok {
    41  		return c, nil
    42  	}
    43  	return nil, common.NewError("unknown context dialer name " + string(name))
    44  }