proto

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Magic bytes: "JAY\0"
	Magic uint32 = 0x4A415900

	// Protocol version
	Version byte = 0x01

	// HeaderSize is the fixed size of a request/response frame header.
	// Layout: [1B op/status] [4B stream_id] [4B meta_len] [8B data_len]
	HeaderSize = 17

	// HandshakeSize is the fixed part of the handshake.
	// Layout: [4B magic] [1B version] [1B flags] [2B auth_len]
	HandshakeSize = 8

	// HandshakeResponseSize is the server's handshake response.
	// Layout: [4B magic] [1B version] [1B status] [2B reserved]
	HandshakeResponseSize = 8

	// MaxMetaSize limits metadata payload to 1MB (prevents memory exhaustion).
	MaxMetaSize = 1 << 20

	// MaxDrainSize is how much data we'll drain on auth failure before closing.
	MaxDrainSize = 10 << 20 // 10MB
)
View Source
const (
	OpCreateBucket byte = 0x01
	OpDeleteBucket byte = 0x02
	OpHeadBucket   byte = 0x03
	OpListBuckets  byte = 0x04

	OpPutObject    byte = 0x10
	OpGetObject    byte = 0x11
	OpHeadObject   byte = 0x12
	OpDeleteObject byte = 0x13
	OpListObjects  byte = 0x14

	OpCreateMultipartUpload byte = 0x20
	OpUploadPart            byte = 0x21
	OpCompleteMultipart     byte = 0x22
	OpAbortMultipart        byte = 0x23
	OpListParts             byte = 0x24

	OpPing byte = 0xFF
)

Op codes for request frames.

View Source
const (
	StatusOK         byte = 0x00
	StatusNotFound   byte = 0x01
	StatusConflict   byte = 0x02
	StatusBadRequest byte = 0x03
	StatusForbidden  byte = 0x04
	StatusInternal   byte = 0x05
)

Status codes for response frames.

View Source
const (
	HandshakeOK              byte = 0x00
	HandshakeAuthFailed      byte = 0x01
	HandshakeVersionMismatch byte = 0x02
)

Handshake status codes.

Variables

This section is empty.

Functions

func DecodeBucket

func DecodeBucket(data []byte) (string, error)

DecodeBucket decodes a bucket name.

func DecodeBucketInfo

func DecodeBucketInfo(data []byte) (bucketID, name, createdAt, visibility string, err error)

DecodeBucketInfo decodes bucket metadata.

func DecodeBucketKey

func DecodeBucketKey(data []byte) (bucket, key string, err error)

DecodeBucketKey decodes a bucket+key pair.

func DecodeBucketKeyUpload

func DecodeBucketKeyUpload(data []byte) (bucket, key, uploadID string, err error)

DecodeBucketKeyUpload decodes a bucket+key+uploadID triple.

func DecodeBucketList

func DecodeBucketList(data []byte) (names []string, createdAts []string, err error)

DecodeBucketList decodes a list of buckets.

func DecodeCompleteMultipartRequest

func DecodeCompleteMultipartRequest(data []byte) (bucket, key, uploadID string, partNumbers []int, err error)

DecodeCompleteMultipartRequest decodes a CompleteMultipartUpload request.

func DecodeCompleteMultipartResponse

func DecodeCompleteMultipartResponse(data []byte) (etag, checksum string, size int64, err error)

DecodeCompleteMultipartResponse decodes a CompleteMultipartUpload response.

func DecodeCreateMultipartRequest

func DecodeCreateMultipartRequest(data []byte) (bucket, key, contentType string, err error)

DecodeCreateMultipartRequest decodes a CreateMultipartUpload request.

func DecodeError

func DecodeError(data []byte) (message, code string, err error)

DecodeError decodes an error response.

func DecodeListObjectsRequest

func DecodeListObjectsRequest(data []byte) (bucket, prefix, delimiter, startAfter string, maxKeys int, err error)

DecodeListObjectsRequest decodes a ListObjects request.

func DecodeObjectInfo

func DecodeObjectInfo(data []byte) (contentType string, size int64, etag, checksum, lastModified string, metadata map[string]string, err error)

DecodeObjectInfo decodes object metadata.

func DecodePutObjectRequest

func DecodePutObjectRequest(data []byte) (bucket, key, contentType string, metadata map[string]string, err error)

DecodePutObjectRequest decodes a PutObject request.

func DecodePutResponse

func DecodePutResponse(data []byte) (etag, checksum string, err error)

DecodePutResponse decodes a PutObject/UploadPart response.

func DecodeUploadPartRequest

func DecodeUploadPartRequest(data []byte) (bucket, key, uploadID string, partNumber int, err error)

DecodeUploadPartRequest decodes an UploadPart request.

func EncodeBucket

func EncodeBucket(bucket string) []byte

EncodeBucket encodes a bucket name.

func EncodeBucketInfo

func EncodeBucketInfo(bucketID, name, createdAt, visibility string) []byte

EncodeBucketInfo encodes bucket metadata.

func EncodeBucketKey

func EncodeBucketKey(bucket, key string) []byte

EncodeBucketKey encodes a bucket+key pair (used by Get, Head, Delete).

func EncodeBucketKeyUpload

func EncodeBucketKeyUpload(bucket, key, uploadID string) []byte

EncodeBucketKeyUpload encodes a bucket+key+uploadID triple (for abort/list parts).

func EncodeBucketList

func EncodeBucketList(names []string, createdAts []string) []byte

EncodeBucketList encodes a list of buckets.

func EncodeCompleteMultipartRequest

func EncodeCompleteMultipartRequest(bucket, key, uploadID string, partNumbers []int) []byte

EncodeCompleteMultipartRequest encodes a CompleteMultipartUpload request.

func EncodeCompleteMultipartResponse

func EncodeCompleteMultipartResponse(etag, checksum string, size int64) []byte

EncodeCompleteMultipartResponse encodes a CompleteMultipartUpload response.

func EncodeCreateMultipartRequest

func EncodeCreateMultipartRequest(bucket, key, contentType string) []byte

EncodeCreateMultipartRequest encodes a CreateMultipartUpload request.

func EncodeError

func EncodeError(message, code string) []byte

EncodeError encodes an error response.

func EncodeListObjectsRequest

func EncodeListObjectsRequest(bucket, prefix, delimiter, startAfter string, maxKeys int) []byte

EncodeListObjectsRequest encodes a ListObjects request.

func EncodeListObjectsResponse

func EncodeListObjectsResponse(objects []ListObjectEntry, commonPrefixes []string, isTruncated bool, nextStartAfter string) []byte

EncodeListObjectsResponse encodes a ListObjects response.

func EncodeListPartsResponse

func EncodeListPartsResponse(parts []PartInfoEntry) []byte

EncodeListPartsResponse encodes a ListParts response.

func EncodeObjectInfo

func EncodeObjectInfo(contentType string, size int64, etag, checksum, lastModified string, metadata map[string]string) []byte

EncodeObjectInfo encodes object metadata for Get/Head responses.

func EncodePutObjectRequest

func EncodePutObjectRequest(bucket, key, contentType string, metadata map[string]string) []byte

EncodePutObjectRequest encodes a PutObject request.

func EncodePutResponse

func EncodePutResponse(etag, checksum string) []byte

EncodePutResponse encodes a PutObject/UploadPart response.

func EncodeUploadPartRequest

func EncodeUploadPartRequest(bucket, key, uploadID string, partNumber int) []byte

EncodeUploadPartRequest encodes an UploadPart request.

func ReadHandshake

func ReadHandshake(r io.Reader) (credentials string, err error)

ReadHandshake reads and validates the client handshake from r. Returns the credentials string (token_id:secret).

func ReadHandshakeResponse

func ReadHandshakeResponse(r io.Reader) (status byte, err error)

ReadHandshakeResponse reads the server's handshake response.

func ReadHeader

func ReadHeader(r io.Reader) (opOrStatus byte, streamID uint32, metaLen uint32, dataLen int64, err error)

ReadHeader reads the 17-byte frame header from r.

func WriteFrame

func WriteFrame(w io.Writer, opOrStatus byte, streamID uint32, meta []byte, data io.Reader, dataLen int64) error

WriteFrame writes a complete frame (header + metadata + data). If data is nil, dataLen must be 0.

func WriteFrameCombined

func WriteFrameCombined(w io.Writer, opOrStatus byte, streamID uint32, meta []byte) error

WriteFrameCombined writes header + meta in a single write when possible. This is an optimization over WriteFrame for responses without data.

func WriteHandshake

func WriteHandshake(w io.Writer, credentials string) error

WriteHandshake writes the client handshake to w.

func WriteHandshakeResponse

func WriteHandshakeResponse(w io.Writer, status byte) error

WriteHandshakeResponse writes the server handshake response.

func WriteHeader

func WriteHeader(w io.Writer, opOrStatus byte, streamID uint32, metaLen uint32, dataLen int64) error

WriteHeader writes the 17-byte frame header to w.

Types

type Decoder

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

Decoder reads binary-encoded fields from a byte slice.

func NewDecoder

func NewDecoder(buf []byte) *Decoder

func (*Decoder) Bool

func (d *Decoder) Bool() bool

func (*Decoder) Err

func (d *Decoder) Err() error

func (*Decoder) Int32

func (d *Decoder) Int32() int32

func (*Decoder) Int64

func (d *Decoder) Int64() int64

func (*Decoder) Ints

func (d *Decoder) Ints() []int

func (*Decoder) String

func (d *Decoder) String() string

func (*Decoder) StringMap

func (d *Decoder) StringMap() map[string]string

func (*Decoder) Strings

func (d *Decoder) Strings() []string

type Encoder

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

Encoder appends binary-encoded fields to a byte slice.

func NewEncoder

func NewEncoder(buf []byte) *Encoder

func (*Encoder) Bool

func (e *Encoder) Bool(v bool)

func (*Encoder) Bytes

func (e *Encoder) Bytes() []byte

func (*Encoder) Int32

func (e *Encoder) Int32(v int32)

func (*Encoder) Int64

func (e *Encoder) Int64(v int64)

func (*Encoder) Ints

func (e *Encoder) Ints(ii []int)

func (*Encoder) String

func (e *Encoder) String(s string)

func (*Encoder) StringMap

func (e *Encoder) StringMap(m map[string]string)

func (*Encoder) Strings

func (e *Encoder) Strings(ss []string)

type ListObjectEntry

type ListObjectEntry struct {
	Key            string
	Size           int64
	ETag           string
	ChecksumSHA256 string
	LastModified   string
	ContentType    string
}

ListObjectEntry is used for encoding list object entries.

func DecodeListObjectsResponse

func DecodeListObjectsResponse(data []byte) (objects []ListObjectEntry, commonPrefixes []string, isTruncated bool, nextStartAfter string, err error)

DecodeListObjectsResponse decodes a ListObjects response.

type PartInfoEntry

type PartInfoEntry struct {
	PartNumber     int
	Size           int64
	ETag           string
	ChecksumSHA256 string
}

PartInfoEntry for list parts response.

func DecodeListPartsResponse

func DecodeListPartsResponse(data []byte) ([]PartInfoEntry, error)

DecodeListPartsResponse decodes a ListParts response.

type Server

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

Server is the native TCP protocol server.

Rate limiting uses a token-bucket algorithm with per-token buckets. rateLimit is requests per second; rateBurst is the bucket capacity. rateLimit <= 0 disables the limiter entirely.

func NewServer

func NewServer(db *meta.DB, st *store.Store, au *auth.Auth, log *slog.Logger, metrics *maintenance.Metrics, rateLimit, rateBurst int) *Server

NewServer creates a new native protocol server.

rateLimit is requests per second per connection key; rateBurst is the token-bucket capacity. rateLimit <= 0 disables the limiter entirely. Pre-existing callers pass (100, 200) from config; those defaults are preserved by internal/ratelimit.New when Burst <= 0.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) (func() error, error)

ListenAndServe starts the TCP server on the given address. Returns a shutdown function.

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown gracefully stops the server.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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