Documentation
¶
Overview ¶
Package proto provides control protocol definitions for Wormhole.
This file contains helper functions for creating protocol messages. The actual protobuf-generated code would be in control.pb.go. For now, we use a simplified JSON-based implementation.
Index ¶
- type AuthRequest
- type AuthResponse
- type CloseRequest
- type CloseResponse
- type ControlMessage
- func DecodeControlMessage(data []byte) (*ControlMessage, error)
- func NewAuthRequest(token, version, subdomain string) *ControlMessage
- func NewAuthResponse(success bool, err string, subdomain, publicURL, sessionID string) *ControlMessage
- func NewCloseRequest(tunnelID, reason string) *ControlMessage
- func NewCloseResponse(success bool) *ControlMessage
- func NewP2PCandidates(tunnelID string, candidates []string) *ControlMessage
- func NewP2POfferRequest(tunnelID, natType, publicAddr, localAddr, publicKey string) *ControlMessage
- func NewP2POfferResponse(success bool, err, peerAddr, peerNATType, peerPublicKey string) *ControlMessage
- func NewP2PResult(tunnelID string, success bool, peerAddr, err string) *ControlMessage
- func NewPingRequest(pingID uint64) *ControlMessage
- func NewPingResponse(pingID uint64) *ControlMessage
- func NewRegisterRequest(localPort uint32, protocol Protocol, subdomain, hostname, pathPrefix string) *ControlMessage
- func NewRegisterResponse(success bool, err, tunnelID, publicURL string, tcpPort uint32) *ControlMessage
- func NewStreamRequest(tunnelID, requestID, remoteAddr string, protocol Protocol) *ControlMessage
- func NewStreamResponse(requestID string, accepted bool, err string) *ControlMessage
- type HTTPMetadata
- type MessageType
- type P2PCandidates
- type P2POfferRequest
- type P2POfferResponse
- type P2PResult
- type PingRequest
- type PingResponse
- type Protocol
- type RegisterRequest
- type RegisterResponse
- type StatsRequest
- type StatsResponse
- type StreamRequest
- type StreamResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthRequest ¶
type AuthRequest struct {
Token string `json:"token"`
Version string `json:"version"`
Subdomain string `json:"subdomain,omitempty"`
Capabilities []string `json:"capabilities,omitempty"`
}
AuthRequest is sent by client to authenticate with the server.
type AuthResponse ¶
type AuthResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty"`
Subdomain string `json:"subdomain,omitempty"`
PublicURL string `json:"public_url,omitempty"`
TCPPort uint32 `json:"tcp_port,omitempty"`
Capabilities []string `json:"capabilities,omitempty"`
SessionID string `json:"session_id,omitempty"`
}
AuthResponse is sent by server after authentication.
type CloseRequest ¶
type CloseRequest struct {
TunnelID string `json:"tunnel_id"`
Reason string `json:"reason,omitempty"`
}
CloseRequest is sent to close a tunnel.
type CloseResponse ¶
type CloseResponse struct {
Success bool `json:"success"`
}
CloseResponse acknowledges a close request.
type ControlMessage ¶
type ControlMessage struct {
Type MessageType `json:"type"`
Sequence uint64 `json:"sequence"`
// Payload (only one should be set)
AuthRequest *AuthRequest `json:"auth_request,omitempty"`
AuthResponse *AuthResponse `json:"auth_response,omitempty"`
RegisterRequest *RegisterRequest `json:"register_request,omitempty"`
RegisterResponse *RegisterResponse `json:"register_response,omitempty"`
PingRequest *PingRequest `json:"ping_request,omitempty"`
PingResponse *PingResponse `json:"ping_response,omitempty"`
StreamRequest *StreamRequest `json:"stream_request,omitempty"`
StreamResponse *StreamResponse `json:"stream_response,omitempty"`
StatsRequest *StatsRequest `json:"stats_request,omitempty"`
StatsResponse *StatsResponse `json:"stats_response,omitempty"`
CloseRequest *CloseRequest `json:"close_request,omitempty"`
CloseResponse *CloseResponse `json:"close_response,omitempty"`
P2POfferRequest *P2POfferRequest `json:"p2p_offer_request,omitempty"`
P2POfferResponse *P2POfferResponse `json:"p2p_offer_response,omitempty"`
P2PCandidates *P2PCandidates `json:"p2p_candidates,omitempty"`
P2PResult *P2PResult `json:"p2p_result,omitempty"`
}
ControlMessage is a wrapper for all control messages.
func DecodeControlMessage ¶
func DecodeControlMessage(data []byte) (*ControlMessage, error)
DecodeControlMessage deserializes a control message from bytes.
func NewAuthRequest ¶
func NewAuthRequest(token, version, subdomain string) *ControlMessage
NewAuthRequest creates a new auth request message.
func NewAuthResponse ¶
func NewAuthResponse(success bool, err string, subdomain, publicURL, sessionID string) *ControlMessage
NewAuthResponse creates a new auth response message.
func NewCloseRequest ¶
func NewCloseRequest(tunnelID, reason string) *ControlMessage
NewCloseRequest creates a new close request message.
func NewCloseResponse ¶
func NewCloseResponse(success bool) *ControlMessage
NewCloseResponse creates a new close response message.
func NewP2PCandidates ¶
func NewP2PCandidates(tunnelID string, candidates []string) *ControlMessage
NewP2PCandidates creates a P2P candidates message.
func NewP2POfferRequest ¶
func NewP2POfferRequest(tunnelID, natType, publicAddr, localAddr, publicKey string) *ControlMessage
NewP2POfferRequest creates a P2P offer request message.
func NewP2POfferResponse ¶
func NewP2POfferResponse(success bool, err, peerAddr, peerNATType, peerPublicKey string) *ControlMessage
NewP2POfferResponse creates a P2P offer response message.
func NewP2PResult ¶
func NewP2PResult(tunnelID string, success bool, peerAddr, err string) *ControlMessage
NewP2PResult creates a P2P result message.
func NewPingRequest ¶
func NewPingRequest(pingID uint64) *ControlMessage
NewPingRequest creates a new ping request message.
func NewPingResponse ¶
func NewPingResponse(pingID uint64) *ControlMessage
NewPingResponse creates a new ping response message.
func NewRegisterRequest ¶
func NewRegisterRequest(localPort uint32, protocol Protocol, subdomain, hostname, pathPrefix string) *ControlMessage
NewRegisterRequest creates a new register request message.
func NewRegisterResponse ¶
func NewRegisterResponse(success bool, err, tunnelID, publicURL string, tcpPort uint32) *ControlMessage
NewRegisterResponse creates a new register response message.
func NewStreamRequest ¶
func NewStreamRequest(tunnelID, requestID, remoteAddr string, protocol Protocol) *ControlMessage
NewStreamRequest creates a new stream request message.
func NewStreamResponse ¶
func NewStreamResponse(requestID string, accepted bool, err string) *ControlMessage
NewStreamResponse creates a new stream response message.
func (*ControlMessage) Encode ¶
func (m *ControlMessage) Encode() ([]byte, error)
Encode serializes a control message to bytes.
type HTTPMetadata ¶
type HTTPMetadata struct {
Method string `json:"method"`
URI string `json:"uri"`
Host string `json:"host"`
ContentType string `json:"content_type,omitempty"`
ContentLength int64 `json:"content_length,omitempty"`
}
HTTPMetadata contains HTTP-specific information.
type MessageType ¶
type MessageType int32
MessageType identifies the type of control message.
const ( MessageTypeUnknown MessageType = 0 MessageTypeAuthRequest MessageType = 1 MessageTypeAuthResponse MessageType = 2 MessageTypeRegisterRequest MessageType = 3 MessageTypeRegisterResponse MessageType = 4 MessageTypePingRequest MessageType = 5 MessageTypePingResponse MessageType = 6 MessageTypeStreamRequest MessageType = 7 MessageTypeStreamResponse MessageType = 8 MessageTypeStatsRequest MessageType = 9 MessageTypeStatsResponse MessageType = 10 MessageTypeCloseRequest MessageType = 11 MessageTypeCloseResponse MessageType = 12 MessageTypeP2POfferRequest MessageType = 13 MessageTypeP2POfferResponse MessageType = 14 MessageTypeP2PCandidates MessageType = 15 MessageTypeP2PResult MessageType = 16 )
type P2PCandidates ¶
type P2PCandidates struct {
// TunnelID identifies the tunnel.
TunnelID string `json:"tunnel_id"`
// Candidates is a list of candidate endpoints.
Candidates []string `json:"candidates"`
}
P2PCandidates carries additional candidate endpoints for hole punching.
type P2POfferRequest ¶
type P2POfferRequest struct {
// TunnelID identifies the tunnel wanting P2P.
TunnelID string `json:"tunnel_id"`
// NATType is the sender's detected NAT type.
NATType string `json:"nat_type"`
// PublicAddr is the sender's public endpoint as discovered by STUN.
PublicAddr string `json:"public_addr"`
// LocalAddr is the sender's local endpoint.
LocalAddr string `json:"local_addr,omitempty"`
// PublicKey is the sender's ECDH X25519 public key (base64-encoded).
PublicKey string `json:"public_key,omitempty"`
}
P2POfferRequest is sent by a client to initiate a P2P connection.
type P2POfferResponse ¶
type P2POfferResponse struct {
// Success indicates whether a peer was found.
Success bool `json:"success"`
// Error contains a reason if the offer was rejected.
Error string `json:"error,omitempty"`
// PeerAddr is the peer's public endpoint.
PeerAddr string `json:"peer_addr,omitempty"`
// PeerNATType is the peer's NAT type.
PeerNATType string `json:"peer_nat_type,omitempty"`
// PeerPublicKey is the peer's ECDH X25519 public key (base64-encoded).
PeerPublicKey string `json:"peer_public_key,omitempty"`
}
P2POfferResponse is the server's response to a P2P offer.
type P2PResult ¶
type P2PResult struct {
// TunnelID identifies the tunnel.
TunnelID string `json:"tunnel_id"`
// Success indicates whether P2P was established.
Success bool `json:"success"`
// PeerAddr is the confirmed peer address (if successful).
PeerAddr string `json:"peer_addr,omitempty"`
// Error contains a reason if P2P failed.
Error string `json:"error,omitempty"`
}
P2PResult reports the outcome of a P2P connection attempt.
type PingRequest ¶
PingRequest is used for keep-alive.
type PingResponse ¶
PingResponse is the response to a ping.
type RegisterRequest ¶
type RegisterRequest struct {
LocalPort uint32 `json:"local_port"`
Protocol Protocol `json:"protocol"`
Subdomain string `json:"subdomain,omitempty"`
Hostname string `json:"hostname,omitempty"`
PathPrefix string `json:"path_prefix,omitempty"`
}
RegisterRequest is sent by client to register a tunnel.
type RegisterResponse ¶
type RegisterResponse struct {
Success bool `json:"success"`
Error string `json:"error,omitempty"`
TunnelID string `json:"tunnel_id,omitempty"`
PublicURL string `json:"public_url,omitempty"`
TCPPort uint32 `json:"tcp_port,omitempty"`
}
RegisterResponse is sent by server after tunnel registration.
type StatsRequest ¶
type StatsRequest struct {
SessionID string `json:"session_id,omitempty"`
}
StatsRequest requests statistics from the server.
type StatsResponse ¶
type StatsResponse struct {
ActiveTunnels uint32 `json:"active_tunnels"`
ActiveConnections uint32 `json:"active_connections"`
BytesSent uint64 `json:"bytes_sent"`
BytesReceived uint64 `json:"bytes_received"`
RequestsHandled uint64 `json:"requests_handled"`
UptimeSeconds uint64 `json:"uptime_seconds"`
}
StatsResponse contains statistics.
type StreamRequest ¶
type StreamRequest struct {
TunnelID string `json:"tunnel_id"`
RequestID string `json:"request_id"`
RemoteAddr string `json:"remote_addr"`
Protocol Protocol `json:"protocol"`
HTTPMetadata *HTTPMetadata `json:"http_metadata,omitempty"`
}
StreamRequest is sent to initiate a new stream.
type StreamResponse ¶
type StreamResponse struct {
RequestID string `json:"request_id"`
Accepted bool `json:"accepted"`
Error string `json:"error,omitempty"`
}
StreamResponse is the response to a stream request.