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

     1  package tunnel
     2  
     3  import (
     4  	"context"
     5  	"io"
     6  	"net"
     7  )
     8  
     9  type Conn interface {
    10  	net.Conn
    11  	Metadata() *Metadata
    12  }
    13  
    14  type PacketConn interface {
    15  	net.PacketConn
    16  	WriteWithMetadata([]byte, *Metadata) (int, error)
    17  	ReadWithMetadata([]byte) (int, *Metadata, error)
    18  }
    19  
    20  type ConnListener interface {
    21  	AcceptConn(Tunnel) (Conn, error)
    22  }
    23  
    24  type PacketListener interface {
    25  	AcceptPacket(Tunnel) (PacketConn, error)
    26  }
    27  
    28  type ConnDialer interface {
    29  	DialConn(*Address, Tunnel) (net.Conn, error)
    30  }
    31  
    32  type PacketDialer interface {
    33  	DialPacket(Tunnel) (PacketConn, error)
    34  }
    35  
    36  type Dialer interface {
    37  	ConnDialer
    38  }
    39  
    40  type Client interface {
    41  	Dialer
    42  	io.Closer
    43  }
    44  
    45  type Server interface {
    46  	ConnListener
    47  	PacketListener
    48  	io.Closer
    49  }
    50  
    51  type Tunnel interface {
    52  	Name() string
    53  	// NewClient(context.Context, Client) (Client, error)
    54  	NewServer(context.Context, Server) (Server, error)
    55  }