sockety

package module
v0.0.0-...-075136f Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2023 License: MIT Imports: 19 Imported by: 0

README

Sockety - work in progress

Client/server implementation of Sockety protocol.

Documentation

Index

Constants

View Source
const (
	MaxUint4  = 15
	MaxUint8  = 255
	MaxUint12 = 4095
	MaxUint16 = 65_535
	MaxUint24 = 16_777_215
	MaxUint32 = 4_294_967_295
	MaxUint48 = 281_474_976_710_655
)
View Source
const (
	DefaultReadBufferSize = 4_096
)
View Source
const (
	MaxChannels = maxChannelId + 1
)

Variables

View Source
var ErrNotReady = errors.New("stream reader source has not enough bytes")
View Source
var ErrServerClosed = errors.New("server closed")

Functions

This section is empty.

Types

type BufferedReader

type BufferedReader interface {
	Len() offset
	MayHave(size offset) bool
	ReadByte() (byte, error)
	Read(target []byte) (offset, error)
	Preload() error
}

type ChannelID

type ChannelID uint16

type ChannelManager

type ChannelManager interface {
	Current() ChannelID           // not thread-safe
	Is(id ChannelID) bool         // not thread-safe
	SetCurrent(channel ChannelID) // not thread-safe
	GetFree() ChannelID           // not thread-safe
	Reserve() ChannelID
	Release(channel ChannelID)
}

func NewChannelManager

func NewChannelManager(channelsCount uint16) ChannelManager

type Conn

type Conn interface {
	LocalAddr() net.Addr
	RemoteAddr() net.Addr

	Request(p ProducerWithRequest) Request
	Pass(p Producer) error

	Close() error

	ReadDone() <-chan struct{}
	ConnectionClosed() <-chan struct{}
	Done() <-chan struct{}

	Messages() <-chan Message
	Responses() <-chan Response
	FastReplies() <-chan FastReply
}

func Dial

func Dial(network string, address string, options *ConnOptions) (Conn, error)

func DialContext

func DialContext(context context.Context, network string, address string, options *ConnOptions) (Conn, error)

func NewConn

func NewConn(parentCtx context.Context, rw io.ReadWriteCloser, options *ConnOptions) (Conn, error)

type ConnOptions

type ConnOptions struct {
	Channels         uint16        // default: max
	WriteChannels    uint16        // default: max
	BufferedMessages uint16        // default: 0
	ReadBufferSize   uint32        // default: 4096
	Timeout          time.Duration // default: 0 = none
}

type FastReply

type FastReply struct {
	Code Uint12
	Id   uuid.UUID
}

type GoAway

type GoAway interface {
}

type Message

type Message interface {
	Id() uuid.UUID
	Action() string
	DataSize() uint64
	TotalFilesSize() uint64
	FilesCount() uint32
	ExpectsResponse() bool
	Stream() MessageStream
	Data() MessageData
}

type MessageData

type MessageData interface {
	io.Reader
	Received() uint64
	Size() uint64
	Done() bool
}

type MessageDraft

type MessageDraft struct {
	HasStream bool
	Action    string
	Data      []byte
}

func NewMessageDraft

func NewMessageDraft(action string) *MessageDraft

func (*MessageDraft) NoStream

func (m *MessageDraft) NoStream() *MessageDraft

func (*MessageDraft) PassTo

func (m *MessageDraft) PassTo(c Conn) error

func (*MessageDraft) RawData

func (m *MessageDraft) RawData(data []byte) *MessageDraft

func (*MessageDraft) RequestTo

func (m *MessageDraft) RequestTo(c Conn) Request

func (*MessageDraft) Stream

func (m *MessageDraft) Stream() *MessageDraft

type MessageStream

type MessageStream interface {
	io.Reader
	Received() uint64
	Done() bool
}

type Parser

type Parser interface {
	Read() (ParserResult, error)
}

func NewParser

func NewParser(source io.Reader, options ParserOptions) Parser

type ParserChannelOptions

type ParserChannelOptions struct {
}

type ParserChannelResult

type ParserChannelResult interface {
	message | Response
}

type ParserOptions

type ParserOptions struct {
	Channels   uint16
	BufferSize uint32
}

type ParserResult

type ParserResult interface {
	message | Response | FastReply | GoAway
}

type Producer

type Producer interface {
	// contains filtered or unexported methods
}

type ProducerWithRequest

type ProducerWithRequest interface {
	// contains filtered or unexported methods
}

type Request

type Request interface {
	Id() uuid.UUID
	Stream() io.WriteCloser
	Send() error
	Initiated() <-chan struct{}
	Done() <-chan struct{}
}

type Response

type Response interface {
}

type Server

type Server interface {
	Listen(network string, address string) error
	ListenContext(context context.Context, network string, address string) error
	Close() error

	Accept() (Conn, error)
	Next() <-chan Conn
	Done() <-chan struct{}
}

func NewServer

func NewServer(options *ServerOptions) Server

type ServerOptions

type ServerOptions struct {
	HandleError      func(e error) // default: ignore errors TODO?
	Timeout          time.Duration // default: none TODO?
	Channels         uint16        // default: max
	WriteChannels    uint16        // default: max
	ReadBufferSize   uint32        // per connection, default: 4096
	BufferedMessages uint16        // per connection, default: 0

}

type Uint12

type Uint12 uint16

func (Uint12) Valid

func (u Uint12) Valid() bool

type Uint24

type Uint24 uint32

func (Uint24) Valid

func (u Uint24) Valid() bool

type Uint48

type Uint48 uint64

func (Uint48) Valid

func (u Uint48) Valid() bool

type Writer

type Writer interface {
	ObtainChannel() ChannelID
	ReleaseChannel(channel ChannelID)

	WriteRaw(data []byte) error

	WriteStandalone(p packet) error
	Write(p packet) error
	WriteAndObtainChannel(p packet) (ChannelID, error)
	WriteRawAtChannel(channel ChannelID, data []byte) error
	WriteAtChannel(channel ChannelID, p packet) error
	WriteAndReleaseChannel(channel ChannelID, p packet) error
	WriteExternalWithSignatureAtChannel(channel ChannelID, signature uint8, data []byte) error
}

func NewWriter

func NewWriter(target io.Writer, options WriterOptions) Writer

type WriterOptions

type WriterOptions struct {
	Channels uint16
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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