czar

package
v1.25.4 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Conf = struct {
	// The newly created stream has a higher write priority.
	FastWriteDuration time.Duration
	// The duration a connection needs to be idle before mux begins sending out keep-alive probe.
	IdleProbeDuration time.Duration
	// If no data is read for more than this time, the connection is closed.
	IdleReplyDuration time.Duration
	// Packet size. Since the size of the packet header is 4, this value must be greater than 4. If the value is too
	// small, the transmission efficiency will be reduced, and if it is too large, the concurrency capability of mux
	// will be reduced.
	PacketSize int
}{
	FastWriteDuration: time.Second * 16,
	IdleProbeDuration: time.Second * 32,
	IdleReplyDuration: time.Second * 48,
	PacketSize:        2048,
}

Conf is acting as package level configuration.

Functions

This section is empty.

Types

type Client

type Client struct {
	Cancel chan struct{}
	Cipher []byte
	Mux    chan *Mux
	Server string
}

Client implemented the czar protocol.

func NewClient

func NewClient(server, cipher string) *Client

NewClient returns a new Client. Cipher is a password in string form, with no length limit.

func (*Client) Close

func (c *Client) Close() error

Close the connection. All streams will be closed at the same time.

func (*Client) Dial

func (c *Client) Dial(ctx *daze.Context, network string, address string) (io.ReadWriteCloser, error)

Dial connects to the address on the named network.

func (*Client) Run

func (c *Client) Run()

Run creates an establish connection to czar server.

type Err

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

Err is an object that will only store an error once.

func NewErr

func NewErr() *Err

func (*Err) Get

func (e *Err) Get() error

Get an error from Err.

func (*Err) Put

func (e *Err) Put(err error)

Put an error into Err.

func (*Err) Sig

func (e *Err) Sig() <-chan struct{}

When any error puts, the sig will be sent.

type Mux

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

Mux is used to wrap a reliable ordered connection and to multiplex it into multiple streams.

func NewMux

func NewMux(conn io.ReadWriteCloser) *Mux

NewMux returns a new Mux.

func NewMuxClient

func NewMuxClient(conn io.ReadWriteCloser) *Mux

NewMuxClient returns a new MuxClient.

func NewMuxServer

func NewMuxServer(conn io.ReadWriteCloser) *Mux

NewMuxServer returns a new MuxServer.

func (*Mux) Accept

func (m *Mux) Accept() chan *Stream

Accept is used to block until the next available stream is ready to be accepted.

func (*Mux) Close

func (m *Mux) Close() error

Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.

func (*Mux) Open

func (m *Mux) Open() (*Stream, error)

Open is used to create a new stream as a io.ReadWriteCloser.

func (*Mux) Recv

func (m *Mux) Recv()

Recv continues to receive data until a fatal error is encountered.

type Server

type Server struct {
	Cipher []byte
	Closer io.Closer
	Limits *rate.Limits
	Listen string
}

Server implemented the czar protocol.

func NewServer

func NewServer(listen string, cipher string) *Server

NewServer returns a new Server. Cipher is a password in string form, with no length limit.

func (*Server) Close

func (s *Server) Close() error

Close listener.

func (*Server) Run

func (s *Server) Run() error

Run it.

func (*Server) Serve

func (s *Server) Serve(ctx *daze.Context, cli io.ReadWriteCloser) error

Serve incoming connections. Parameter cli will be closed automatically when the function exits.

type Sip

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

A stream id generator. Stream id can be reused, and the smallest available stream id is guaranteed to be generated each time.

func NewSip

func NewSip() *Sip

NewSip returns a new sip.

func (*Sip) Get

func (s *Sip) Get() (uint8, error)

Get selects an stream id from the pool, removes it from the pool, and returns it to the caller.

func (*Sip) Put

func (s *Sip) Put(x uint8)

Put adds x to the pool.

func (*Sip) Set

func (s *Sip) Set(x uint8)

Set removes x from the pool.

type Stream

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

A Stream managed by the multiplexer.

func NewStream

func NewStream(idx uint8, mux *Mux) *Stream

NewStream returns a new Stream.

func NewWither

func NewWither(idx uint8, mux *Mux) *Stream

NewWither returns a new Stream. Stream has been automatically closed, used as a placeholder.

func (*Stream) Close

func (s *Stream) Close() error

Close implements io.Closer.

func (*Stream) Esolc

func (s *Stream) Esolc() error

Esolc closing a stream passively.

func (*Stream) Read

func (s *Stream) Read(p []byte) (int, error)

Read implements io.Reader.

func (*Stream) Write

func (s *Stream) Write(p []byte) (int, error)

Write implements io.Writer.

Jump to

Keyboard shortcuts

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