Documentation
¶
Index ¶
- Constants
- func DecodeBucket(data []byte) (string, error)
- func DecodeBucketInfo(data []byte) (bucketID, name, createdAt, visibility string, err error)
- func DecodeBucketKey(data []byte) (bucket, key string, err error)
- func DecodeBucketKeyUpload(data []byte) (bucket, key, uploadID string, err error)
- func DecodeBucketList(data []byte) (names []string, createdAts []string, err error)
- func DecodeCompleteMultipartRequest(data []byte) (bucket, key, uploadID string, partNumbers []int, err error)
- func DecodeCompleteMultipartResponse(data []byte) (etag, checksum string, size int64, err error)
- func DecodeCreateMultipartRequest(data []byte) (bucket, key, contentType string, err error)
- func DecodeError(data []byte) (message, code string, err error)
- func DecodeListObjectsRequest(data []byte) (bucket, prefix, delimiter, startAfter string, maxKeys int, err error)
- func DecodeObjectInfo(data []byte) (contentType string, size int64, etag, checksum, lastModified string, ...)
- func DecodePutObjectRequest(data []byte) (bucket, key, contentType string, metadata map[string]string, err error)
- func DecodePutResponse(data []byte) (etag, checksum string, err error)
- func DecodeUploadPartRequest(data []byte) (bucket, key, uploadID string, partNumber int, err error)
- func EncodeBucket(bucket string) []byte
- func EncodeBucketInfo(bucketID, name, createdAt, visibility string) []byte
- func EncodeBucketKey(bucket, key string) []byte
- func EncodeBucketKeyUpload(bucket, key, uploadID string) []byte
- func EncodeBucketList(names []string, createdAts []string) []byte
- func EncodeCompleteMultipartRequest(bucket, key, uploadID string, partNumbers []int) []byte
- func EncodeCompleteMultipartResponse(etag, checksum string, size int64) []byte
- func EncodeCreateMultipartRequest(bucket, key, contentType string) []byte
- func EncodeError(message, code string) []byte
- func EncodeListObjectsRequest(bucket, prefix, delimiter, startAfter string, maxKeys int) []byte
- func EncodeListObjectsResponse(objects []ListObjectEntry, commonPrefixes []string, isTruncated bool, ...) []byte
- func EncodeListPartsResponse(parts []PartInfoEntry) []byte
- func EncodeObjectInfo(contentType string, size int64, etag, checksum, lastModified string, ...) []byte
- func EncodePutObjectRequest(bucket, key, contentType string, metadata map[string]string) []byte
- func EncodePutResponse(etag, checksum string) []byte
- func EncodeUploadPartRequest(bucket, key, uploadID string, partNumber int) []byte
- func ReadHandshake(r io.Reader) (credentials string, err error)
- func ReadHandshakeResponse(r io.Reader) (status byte, err error)
- func ReadHeader(r io.Reader) (opOrStatus byte, streamID uint32, metaLen uint32, dataLen int64, err error)
- func WriteFrame(w io.Writer, opOrStatus byte, streamID uint32, meta []byte, data io.Reader, ...) error
- func WriteFrameCombined(w io.Writer, opOrStatus byte, streamID uint32, meta []byte) error
- func WriteHandshake(w io.Writer, credentials string) error
- func WriteHandshakeResponse(w io.Writer, status byte) error
- func WriteHeader(w io.Writer, opOrStatus byte, streamID uint32, metaLen uint32, dataLen int64) error
- type Decoder
- type Encoder
- type ListObjectEntry
- type PartInfoEntry
- type Server
Constants ¶
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 )
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.
const ( StatusOK byte = 0x00 StatusNotFound byte = 0x01 StatusConflict byte = 0x02 StatusBadRequest byte = 0x03 StatusForbidden byte = 0x04 StatusInternal byte = 0x05 )
Status codes for response frames.
const ( HandshakeOK byte = 0x00 HandshakeAuthFailed byte = 0x01 HandshakeVersionMismatch byte = 0x02 )
Handshake status codes.
Variables ¶
This section is empty.
Functions ¶
func DecodeBucket ¶
DecodeBucket decodes a bucket name.
func DecodeBucketInfo ¶
DecodeBucketInfo decodes bucket metadata.
func DecodeBucketKey ¶
DecodeBucketKey decodes a bucket+key pair.
func DecodeBucketKeyUpload ¶
DecodeBucketKeyUpload decodes a bucket+key+uploadID triple.
func DecodeBucketList ¶
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 ¶
DecodeCompleteMultipartResponse decodes a CompleteMultipartUpload response.
func DecodeCreateMultipartRequest ¶
DecodeCreateMultipartRequest decodes a CreateMultipartUpload request.
func DecodeError ¶
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 ¶
DecodePutResponse decodes a PutObject/UploadPart response.
func DecodeUploadPartRequest ¶
DecodeUploadPartRequest decodes an UploadPart request.
func EncodeBucketInfo ¶
EncodeBucketInfo encodes bucket metadata.
func EncodeBucketKey ¶
EncodeBucketKey encodes a bucket+key pair (used by Get, Head, Delete).
func EncodeBucketKeyUpload ¶
EncodeBucketKeyUpload encodes a bucket+key+uploadID triple (for abort/list parts).
func EncodeBucketList ¶
EncodeBucketList encodes a list of buckets.
func EncodeCompleteMultipartRequest ¶
EncodeCompleteMultipartRequest encodes a CompleteMultipartUpload request.
func EncodeCompleteMultipartResponse ¶
EncodeCompleteMultipartResponse encodes a CompleteMultipartUpload response.
func EncodeCreateMultipartRequest ¶
EncodeCreateMultipartRequest encodes a CreateMultipartUpload request.
func EncodeError ¶
EncodeError encodes an error response.
func EncodeListObjectsRequest ¶
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 ¶
EncodePutObjectRequest encodes a PutObject request.
func EncodePutResponse ¶
EncodePutResponse encodes a PutObject/UploadPart response.
func EncodeUploadPartRequest ¶
EncodeUploadPartRequest encodes an UploadPart request.
func ReadHandshake ¶
ReadHandshake reads and validates the client handshake from r. Returns the credentials string (token_id:secret).
func ReadHandshakeResponse ¶
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 ¶
WriteFrameCombined writes header + meta in a single write when possible. This is an optimization over WriteFrame for responses without data.
func WriteHandshake ¶
WriteHandshake writes the client handshake to w.
func WriteHandshakeResponse ¶
WriteHandshakeResponse writes the server handshake response.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder reads binary-encoded fields from a byte slice.
func NewDecoder ¶
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder appends binary-encoded fields to a byte slice.
func NewEncoder ¶
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 ¶
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 ¶
ListenAndServe starts the TCP server on the given address. Returns a shutdown function.