stream

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: Apache-2.0 Imports: 12 Imported by: 1

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

View Source
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 NewStream

func NewStream(conn net.Conn) *Stream

NewStream creates a new CEDAR stream from a TCP connection

func (*Stream) Close

func (s *Stream) Close() error

Close closes the underlying connection

func (*Stream) EndMessage

func (s *Stream) EndMessage(ctx context.Context) error

EndMessage indicates end of message and sends any remaining buffered data

func (*Stream) EndMessageRead

func (s *Stream) EndMessageRead() error

EndMessageRead indicates that message reading is complete Returns error if not all bytes have been consumed

func (*Stream) GetConnection

func (s *Stream) GetConnection() net.Conn

GetConnection returns the underlying connection for TLS upgrade

func (*Stream) GetEncryption

func (s *Stream) GetEncryption() bool

GetEncryption returns true if encryption is currently enabled Based on HTCondor's Stream::get_encryption() from stream.cpp

func (*Stream) GetFile

func (s *Stream) GetFile(ctx context.Context, filename string) (int64, error)

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

func (s *Stream) GetPeerAddr() string

GetPeerAddr returns the remote address of the connection in HTCondor sinful string format

func (*Stream) GetSecret

func (s *Stream) GetSecret(ctx context.Context) (string, error)

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

func (s *Stream) GetTimeout() time.Duration

GetTimeout returns the current socket timeout duration

func (*Stream) IsAuthenticated

func (s *Stream) IsAuthenticated() bool

IsAuthenticated returns true if the stream has completed authentication

func (*Stream) IsConnected

func (s *Stream) IsConnected() bool

IsConnected returns true if the underlying connection is still open

func (*Stream) IsEncrypted

func (s *Stream) IsEncrypted() bool

IsEncrypted returns true if the stream is using encryption

func (*Stream) PutFile

func (s *Stream) PutFile(ctx context.Context, filename string) (int64, error)

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

func (s *Stream) PutSecret(ctx context.Context, secret string) error

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

func (s *Stream) ReadFrame(ctx context.Context) ([]byte, bool, error)

ReadFrame reads a single frame from the stream and returns the data and EOM flag

func (*Stream) ReadMessageBytes

func (s *Stream) ReadMessageBytes(ctx context.Context, data []byte) (int, error)

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

func (s *Stream) ReceiveCompleteMessage(ctx context.Context) ([]byte, error)

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

func (s *Stream) ReceiveFrame(ctx context.Context) ([]byte, error)

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

func (s *Stream) ReceiveFrameWithEnd(ctx context.Context) ([]byte, byte, error)

ReceiveFrameWithEnd receives a message and returns both data and end flag

func (*Stream) SendMessage

func (s *Stream) SendMessage(ctx context.Context, data []byte) error

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

func (s *Stream) SendPartialMessage(ctx context.Context, data []byte) error

SendPartialMessage sends a message frame (end flag = 0)

func (*Stream) SetAuthenticated

func (s *Stream) SetAuthenticated(authenticated bool)

SetAuthenticated sets the authentication status of the stream

func (*Stream) SetConnection

func (s *Stream) SetConnection(conn net.Conn)

SetConnection replaces the underlying connection (e.g., with TLS connection)

func (*Stream) SetCryptoMode

func (s *Stream) SetCryptoMode(enabled bool) bool

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

func (s *Stream) SetEncrypted(encrypted bool)

SetEncrypted sets the encryption status of the stream

func (*Stream) SetPeerAddr

func (s *Stream) SetPeerAddr(addr string)

SetPeerAddr sets the remote address (useful when the address should be in a specific format)

func (*Stream) SetSymmetricKey

func (s *Stream) SetSymmetricKey(key []byte) error

SetSymmetricKey configures AES-GCM encryption with the provided key

func (*Stream) SetTimeout

func (s *Stream) SetTimeout(duration time.Duration) error

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

func (s *Stream) StartMessageRead(ctx context.Context) error

StartMessageRead begins reading a complete message (potentially across multiple frames)

func (*Stream) WriteFrame

func (s *Stream) WriteFrame(ctx context.Context, data []byte, isEOM bool) error

WriteFrame writes a single frame to the stream with the EOM flag

func (*Stream) WriteMessage

func (s *Stream) WriteMessage(ctx context.Context, data []byte) error

WriteMessage writes data to the message buffer Data is accumulated until EndMessage() is called or frame threshold is reached

Jump to

Keyboard shortcuts

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