protocol

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: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetadataHTTPMethod       = "HttpMethod"
	MetadataHTTPHost         = "HttpHost"
	MetadataHTTPHeader       = "HttpHeader"
	MetadataHTTPHeaderPrefix = MetadataHTTPHeader + ":"
	MetadataHTTPStatus       = "HttpStatus"
)
View Source
const (
	DefaultDatagramVersion = "v2"
	DatagramVersionV3      = "v3"
)
View Source
const (
	H2HeaderUpgrade        = "Cf-Cloudflared-Proxy-Connection-Upgrade"
	H2HeaderTCPSrc         = "Cf-Cloudflared-Proxy-Src"
	H2HeaderResponseMeta   = "Cf-Cloudflared-Response-Meta"
	H2HeaderResponseUser   = "Cf-Cloudflared-Response-Headers"
	H2UpgradeControlStream = "control-stream"
	H2UpgradeWebsocket     = "websocket"
	H2UpgradeConfiguration = "update-configuration"
	H2ResponseMetaOrigin   = `{"src":"origin"}`
)
View Source
const MetadataFlowConnectRateLimited = "FlowConnectRateLimited"
View Source
const ProtocolVersion = "01"

Variables

View Source
var (
	DataStreamSignature = [6]byte{0x0A, 0x36, 0xCD, 0x12, 0xA1, 0x3E}
	RPCStreamSignature  = [6]byte{0x52, 0xBB, 0x82, 0x5C, 0xDB, 0x65}
)
View Source
var HeaderEncoding = base64.RawStdEncoding

Functions

func HasFlowConnectRateLimited

func HasFlowConnectRateLimited(metadata []Metadata) bool

func IsControlResponseHeader

func IsControlResponseHeader(name string) bool

func IsWebsocketClientHeader

func IsWebsocketClientHeader(name string) bool

func SerializeHeaders

func SerializeHeaders(header http.Header) string

func WriteConnectResponse

func WriteConnectResponse(w io.Writer, responseError error, metadata ...Metadata) error

func WriteRPCStreamSignature

func WriteRPCStreamSignature(w io.Writer) error

Types

type ConnectRequest

type ConnectRequest struct {
	Dest     string         `capnp:"dest"`
	Type     ConnectionType `capnp:"type"`
	Metadata []Metadata     `capnp:"metadata"`
}

func ReadConnectRequest

func ReadConnectRequest(r io.Reader) (*ConnectRequest, error)

func (*ConnectRequest) FromCapnp

func (r *ConnectRequest) FromCapnp(msg *capnp.Message) error

func (*ConnectRequest) MetadataMap

func (r *ConnectRequest) MetadataMap() map[string]string

type ConnectResponse

type ConnectResponse struct {
	Error    string     `capnp:"error"`
	Metadata []Metadata `capnp:"metadata"`
}

func (*ConnectResponse) ToCapnp

func (r *ConnectResponse) ToCapnp() (*capnp.Message, error)

type ConnectResponseWriter

type ConnectResponseWriter interface {
	WriteResponse(responseError error, metadata []Metadata) error
}

type ConnectionType

type ConnectionType uint16
const (
	ConnectionTypeHTTP ConnectionType = iota
	ConnectionTypeWebsocket
	ConnectionTypeTCP
)

func (ConnectionType) String

func (c ConnectionType) String() string

type Credentials

type Credentials struct {
	AccountTag   string    `json:"AccountTag"`
	TunnelSecret []byte    `json:"TunnelSecret"`
	TunnelID     uuid.UUID `json:"TunnelID"`
	Endpoint     string    `json:"Endpoint,omitempty"`
}

func (*Credentials) Auth

func (c *Credentials) Auth() TunnelAuth

type DatagramSender

type DatagramSender interface {
	SendDatagram(data []byte) error
}

type DatagramV2Type

type DatagramV2Type byte
const (
	DatagramV2TypeUDP         DatagramV2Type = 0
	DatagramV2TypeIP          DatagramV2Type = 1
	DatagramV2TypeIPWithTrace DatagramV2Type = 2
	DatagramV2TypeTracingSpan DatagramV2Type = 3

	TypeIDLength = 1
)

type DatagramV3Type

type DatagramV3Type byte
const (
	DatagramV3TypeRegistration         DatagramV3Type = 0
	DatagramV3TypePayload              DatagramV3Type = 1
	DatagramV3TypeICMP                 DatagramV3Type = 2
	DatagramV3TypeRegistrationResponse DatagramV3Type = 3

	MaxV3UDPPayloadLen = 1280
)

type Metadata

type Metadata struct {
	Key string `capnp:"key"`
	Val string `capnp:"val"`
}

func FlowConnectRateLimitedMetadata

func FlowConnectRateLimitedMetadata() []Metadata

type RegistrationClientInfo

type RegistrationClientInfo struct {
	ClientID []byte   `capnp:"clientId"`
	Features []string `capnp:"features"`
	Version  string   `capnp:"version"`
	Arch     string   `capnp:"arch"`
}

type RegistrationConnectionOptions

type RegistrationConnectionOptions struct {
	Client              RegistrationClientInfo `capnp:"client"`
	OriginLocalIP       net.IP                 `capnp:"originLocalIp"`
	ReplaceExisting     bool                   `capnp:"replaceExisting"`
	CompressionQuality  uint8                  `capnp:"compressionQuality"`
	NumPreviousAttempts uint8                  `capnp:"numPreviousAttempts"`
}

type RegistrationResult

type RegistrationResult struct {
	ConnectionID            uuid.UUID
	Location                string
	TunnelIsRemotelyManaged bool
}

type RegistrationTunnelAuth

type RegistrationTunnelAuth struct {
	AccountTag   string `capnp:"accountTag"`
	TunnelSecret []byte `capnp:"tunnelSecret"`
}

type RequestID

type RequestID [16]byte

type RetryableError

type RetryableError struct {
	Err   error
	Delay time.Duration
}

func (*RetryableError) Error

func (e *RetryableError) Error() string

func (*RetryableError) Unwrap

func (e *RetryableError) Unwrap() error

type StreamType

type StreamType int
const (
	StreamTypeData StreamType = iota
	StreamTypeRPC
)

func ReadStreamSignature

func ReadStreamSignature(r io.Reader) (StreamType, error)

type TunnelAuth

type TunnelAuth struct {
	AccountTag   string
	TunnelSecret []byte
}

type TunnelToken

type TunnelToken struct {
	AccountTag   string    `json:"a"`
	TunnelSecret []byte    `json:"s"`
	TunnelID     uuid.UUID `json:"t"`
	Endpoint     string    `json:"e,omitempty"`
}

func (TunnelToken) ToCredentials

func (t TunnelToken) ToCredentials() Credentials

Jump to

Keyboard shortcuts

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