datagram

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2026 License: GPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	V3RegistrationFlagLen = 1
	V3RegistrationPortLen = 2
	V3RegistrationIdleLen = 2
	V3RequestIDLength     = 16
	V3IPv4AddrLen         = 4
	V3IPv6AddrLen         = 16

	V3PayloadHeaderLen = 1 + V3RequestIDLength

	V3FlagIPv6 byte = 0x01

	V3ResponseDestinationUnreachable byte = 0x01

	V3ResponseErrorWithMsg byte = 0xFF
)
View Source
const SessionIDLength = 16

Variables

View Source
var (
	ErrUnsupportedDatagramV3UDPRegistration   = E.New("datagram v3 does not support RegisterUdpSession RPC")
	ErrUnsupportedDatagramV3UDPUnregistration = E.New("datagram v3 does not support UnregisterUdpSession RPC")
)
View Source
var NewV2SessionRPCClient = func(ctx context.Context, sender protocol.DatagramSender) (V2SessionRPCClient, error) {
	opener, ok := sender.(RPCStreamOpener)
	if !ok {
		return nil, E.New("sender does not support rpc streams")
	}
	stream, err := opener.OpenRPCStream(ctx)
	if err != nil {
		return nil, err
	}
	transport := control.SafeTransport(stream)
	conn := control.NewRPCClientConn(transport)
	return &capnpV2SessionRPCClient{
		client:    tunnelrpc.SessionManager{Client: conn.Bootstrap(ctx)},
		rpcConn:   conn,
		transport: transport,
	}, nil
}

Functions

func ServeRPCStream

func ServeRPCStream(ctx context.Context, stream io.ReadWriteCloser, applyConfig control.ConfigApplier, muxer *DatagramV2Muxer, log logger.ContextLogger)

func ServeV3RPCStream

func ServeV3RPCStream(ctx context.Context, stream io.ReadWriteCloser, applyConfig control.ConfigApplier, log logger.ContextLogger)

Types

type CloudflaredServer

type CloudflaredServer struct {
	// contains filtered or unexported fields
}

func (*CloudflaredServer) RegisterUdpSession

func (*CloudflaredServer) UnregisterUdpSession

func (*CloudflaredServer) UpdateConfiguration

type CloudflaredV3Server

type CloudflaredV3Server struct {
	// contains filtered or unexported fields
}

func (*CloudflaredV3Server) RegisterUdpSession

func (*CloudflaredV3Server) UnregisterUdpSession

func (*CloudflaredV3Server) UpdateConfiguration

type DatagramV2Muxer

type DatagramV2Muxer struct {
	// contains filtered or unexported fields
}

func NewDatagramV2Muxer

func NewDatagramV2Muxer(muxerContext MuxerContext, sender protocol.DatagramSender, log logger.ContextLogger) *DatagramV2Muxer

func (*DatagramV2Muxer) Close

func (m *DatagramV2Muxer) Close()

func (*DatagramV2Muxer) HandleDatagram

func (m *DatagramV2Muxer) HandleDatagram(ctx context.Context, data []byte)

func (*DatagramV2Muxer) RegisterSession

func (m *DatagramV2Muxer) RegisterSession(
	ctx context.Context,
	sessionID uuid.UUID,
	destinationIP net.IP,
	destinationPort uint16,
	closeAfterIdle time.Duration,
) error

func (*DatagramV2Muxer) UnregisterSession

func (m *DatagramV2Muxer) UnregisterSession(sessionID uuid.UUID, message string)

type DatagramV3Muxer

type DatagramV3Muxer struct {
	// contains filtered or unexported fields
}

func NewDatagramV3Muxer

func NewDatagramV3Muxer(muxerContext MuxerContext, sender protocol.DatagramSender, log logger.ContextLogger, manager *DatagramV3SessionManager) *DatagramV3Muxer

func (*DatagramV3Muxer) Close

func (m *DatagramV3Muxer) Close()

func (*DatagramV3Muxer) HandleDatagram

func (m *DatagramV3Muxer) HandleDatagram(ctx context.Context, data []byte)

type DatagramV3SessionManager

type DatagramV3SessionManager struct {
	// contains filtered or unexported fields
}

func NewDatagramV3SessionManager

func NewDatagramV3SessionManager() *DatagramV3SessionManager

func (*DatagramV3SessionManager) Get

func (*DatagramV3SessionManager) Register

func (m *DatagramV3SessionManager) Register(
	muxerContext MuxerContext,
	ctx context.Context,
	requestID protocol.RequestID,
	destination netip.AddrPort,
	closeAfterIdle time.Duration,
	sender protocol.DatagramSender,
) (*V3Session, v3RegistrationState, error)

type FlowLimiter

type FlowLimiter struct {
	// contains filtered or unexported fields
}

func (*FlowLimiter) Acquire

func (l *FlowLimiter) Acquire(limit uint64) bool

func (*FlowLimiter) Release

func (l *FlowLimiter) Release(limit uint64)

type MuxerContext

type MuxerContext struct {
	Context        context.Context
	Logger         logger.ContextLogger
	MaxActiveFlows func() uint64
	FlowLimiter    *FlowLimiter
	DialPacket     func(ctx context.Context, destination M.Socksaddr) (N.PacketConn, error)
	ICMPHandler    icmp.RouteHandler
}

type RPCStreamOpener

type RPCStreamOpener interface {
	OpenRPCStream(ctx context.Context) (io.ReadWriteCloser, error)
}

type UDPSession

type UDPSession struct {
	// contains filtered or unexported fields
}

func NewUDPSession

func NewUDPSession(id uuid.UUID, destination netip.AddrPort, closeAfterIdle time.Duration, origin N.PacketConn, muxer *DatagramV2Muxer) *UDPSession

func (*UDPSession) Close

func (s *UDPSession) Close() error

func (*UDPSession) LocalAddr

func (s *UDPSession) LocalAddr() net.Addr

func (*UDPSession) ReadPacket

func (s *UDPSession) ReadPacket(buffer *buf.Buffer) (M.Socksaddr, error)

func (*UDPSession) SetDeadline

func (s *UDPSession) SetDeadline(_ time.Time) error

func (*UDPSession) SetReadDeadline

func (s *UDPSession) SetReadDeadline(_ time.Time) error

func (*UDPSession) SetWriteDeadline

func (s *UDPSession) SetWriteDeadline(_ time.Time) error

func (*UDPSession) WritePacket

func (s *UDPSession) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error

type V2SessionRPCClient

type V2SessionRPCClient interface {
	UnregisterSession(ctx context.Context, sessionID uuid.UUID, message string) error
	Close() error
}

type V3Session

type V3Session struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL