Documentation
¶
Overview ¶
Package stream provides low-level TCP socket stream management and message framing for the CEDAR protocol.
This package implements the binary framing protocol that wraps messages before sending them over TCP sockets, based on HTCondor's reli_sock.cpp implementation.
Index ¶
- Constants
- type Stream
- func (s *Stream) Close() error
- func (s *Stream) EndMessage(ctx context.Context) error
- func (s *Stream) EndMessageRead() error
- func (s *Stream) GetConnection() net.Conn
- func (s *Stream) GetEncryption() bool
- func (s *Stream) GetFile(ctx context.Context, filename string) (int64, error)
- func (s *Stream) GetPeerAddr() string
- func (s *Stream) GetSecret(ctx context.Context) (string, error)
- func (s *Stream) GetTimeout() time.Duration
- func (s *Stream) IsAuthenticated() bool
- func (s *Stream) IsConnected() bool
- func (s *Stream) IsEncrypted() bool
- func (s *Stream) PutFile(ctx context.Context, filename string) (int64, error)
- func (s *Stream) PutSecret(ctx context.Context, secret string) error
- func (s *Stream) ReadFrame(ctx context.Context) ([]byte, bool, error)
- func (s *Stream) ReadMessageBytes(ctx context.Context, data []byte) (int, error)
- func (s *Stream) ReceiveCompleteMessage(ctx context.Context) ([]byte, error)
- func (s *Stream) ReceiveFrame(ctx context.Context) ([]byte, error)
- func (s *Stream) ReceiveFrameWithEnd(ctx context.Context) ([]byte, byte, error)
- func (s *Stream) SendMessage(ctx context.Context, data []byte) error
- func (s *Stream) SendPartialMessage(ctx context.Context, data []byte) error
- func (s *Stream) SetAuthenticated(authenticated bool)
- func (s *Stream) SetConnection(conn net.Conn)
- func (s *Stream) SetCryptoMode(enabled bool) bool
- func (s *Stream) SetEncrypted(encrypted bool)
- func (s *Stream) SetPeerAddr(addr string)
- func (s *Stream) SetSymmetricKey(key []byte) error
- func (s *Stream) SetTimeout(duration time.Duration) error
- func (s *Stream) StartMessage()
- func (s *Stream) StartMessageRead(ctx context.Context) error
- func (s *Stream) WriteFrame(ctx context.Context, data []byte, isEOM bool) error
- func (s *Stream) WriteMessage(ctx context.Context, data []byte) error
Constants ¶
const ( // Header sizes from HTCondor reli_sock.cpp NormalHeaderSize = 5 MaxHeaderSize = NormalHeaderSize // TODO: Add MAC_SIZE when implementing MD // Maximum message size from HTCondor (1MB) MaxMessageSize = 1024 * 1024 // Frame size threshold - send frame when message reaches this size DefaultFrameThreshold = 4096 // 4KB default threshold // End flag values EndFlagPartial = 0 // More frames follow EndFlagComplete = 1 // Last frame in message )
CEDAR protocol constants based on HTCondor's reli_sock.cpp
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream represents a CEDAR protocol stream over a TCP connection
func (*Stream) EndMessage ¶
EndMessage indicates end of message and sends any remaining buffered data
func (*Stream) EndMessageRead ¶
EndMessageRead indicates that message reading is complete Returns error if not all bytes have been consumed
func (*Stream) GetConnection ¶
GetConnection returns the underlying connection for TLS upgrade
func (*Stream) GetEncryption ¶
GetEncryption returns true if encryption is currently enabled Based on HTCondor's Stream::get_encryption() from stream.cpp
func (*Stream) GetFile ¶
GetFile receives a file from the stream Based on HTCondor's ReliSock::get_file() from reli_sock.cpp Returns the number of bytes received
func (*Stream) GetPeerAddr ¶
GetPeerAddr returns the remote address of the connection in HTCondor sinful string format
func (*Stream) GetSecret ¶
GetSecret receives a secret string with automatic encryption Based on HTCondor's Stream::get_secret() from stream.cpp Temporarily enables encryption if possible, then restores previous state
func (*Stream) GetTimeout ¶
GetTimeout returns the current socket timeout duration
func (*Stream) IsAuthenticated ¶
IsAuthenticated returns true if the stream has completed authentication
func (*Stream) IsConnected ¶
IsConnected returns true if the underlying connection is still open
func (*Stream) IsEncrypted ¶
IsEncrypted returns true if the stream is using encryption
func (*Stream) PutFile ¶
PutFile sends a file over the stream Based on HTCondor's ReliSock::put_file() from reli_sock.cpp Returns the number of bytes sent
func (*Stream) PutSecret ¶
PutSecret sends a secret string with automatic encryption Based on HTCondor's Stream::put_secret() from stream.cpp Temporarily enables encryption if possible, then restores previous state
func (*Stream) ReadFrame ¶
ReadFrame reads a single frame from the stream and returns the data and EOM flag
func (*Stream) ReadMessageBytes ¶
ReadMessageBytes reads up to n bytes from the current message Returns error if trying to read more bytes than available in current message
func (*Stream) ReceiveCompleteMessage ¶
ReceiveCompleteMessage receives a complete message, reading multiple frames if necessary This is the main method for reading complete messages that may span multiple frames
func (*Stream) ReceiveFrame ¶
ReceiveFrame receives and deframes a message from the stream Uses HTCondor CEDAR protocol format: [1 byte: end flag] [4 bytes: message length in network order] [message data]
func (*Stream) ReceiveFrameWithEnd ¶
ReceiveFrameWithEnd receives a message and returns both data and end flag
func (*Stream) SendMessage ¶
SendMessage sends a framed message over the stream Uses HTCondor CEDAR protocol format: [1 byte: end flag] [4 bytes: message length in network order] [message data]
func (*Stream) SendPartialMessage ¶
SendPartialMessage sends a message frame (end flag = 0)
func (*Stream) SetAuthenticated ¶
SetAuthenticated sets the authentication status of the stream
func (*Stream) SetConnection ¶
SetConnection replaces the underlying connection (e.g., with TLS connection)
func (*Stream) SetCryptoMode ¶
SetCryptoMode enables or disables encryption on the stream Based on HTCondor's Stream::set_crypto_mode() from stream.cpp Returns false if encryption cannot be enabled (e.g., no key exchanged)
func (*Stream) SetEncrypted ¶
SetEncrypted sets the encryption status of the stream
func (*Stream) SetPeerAddr ¶
SetPeerAddr sets the remote address (useful when the address should be in a specific format)
func (*Stream) SetSymmetricKey ¶
SetSymmetricKey configures AES-GCM encryption with the provided key
func (*Stream) SetTimeout ¶
SetTimeout sets the socket timeout duration Based on HTCondor's Stream::timeout() from stream.cpp A timeout of 0 means no timeout (blocking indefinitely)
func (*Stream) StartMessage ¶
func (s *Stream) StartMessage()
StartMessage resets EOM state to allow writing a new message
func (*Stream) StartMessageRead ¶
StartMessageRead begins reading a complete message (potentially across multiple frames)
func (*Stream) WriteFrame ¶
WriteFrame writes a single frame to the stream with the EOM flag