rchannel

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TODO: meaning of flags should be based on conn Type
	WaitRecvBuf   uint32 = 1 << iota // The recevier should wait receive buffer
	IsResponse    uint32 = 1 << iota // This is a response message for ConnPeerToPeer
	RequestFailed uint32 = 1 << iota // This is a response meesage for failed request
)
View Source
const NoFlag uint32 = 0

Variables

View Source
var (
	GetBuf = defaultPool.GetBuf
	PutBuf = defaultPool.PutBuf
)
View Source
var ErrInvalidConnectionType = errors.New("invalid connection type")

Functions

func Stream

func Stream(conn net.Conn, remote plan.NetAddr, accept acceptFunc, handle MsgHandleFunc) (int, error)

Types

type BufferPool

type BufferPool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

type ByteSlicePool

type ByteSlicePool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ByteSlicePool reuse byte slices: chunk size -> pool.

func (*ByteSlicePool) GetBuf

func (p *ByteSlicePool) GetBuf(size uint32) []byte

GetBuf gets a chunk from reuse pool or creates a new one if reuse failed.

func (*ByteSlicePool) PutBuf

func (p *ByteSlicePool) PutBuf(buf []byte)

PutBuf puts a chunk to reuse pool if it can be reused.

type CollectiveEndpoint added in v0.2.0

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

func NewCollectiveEndpoint added in v0.2.0

func NewCollectiveEndpoint() *CollectiveEndpoint

func (*CollectiveEndpoint) Handle added in v0.2.0

func (e *CollectiveEndpoint) Handle(conn net.Conn, remote plan.NetAddr, t ConnType) error

Handle implements ConnHandler.Handle interface

func (*CollectiveEndpoint) Recv added in v0.2.0

func (e *CollectiveEndpoint) Recv(a plan.Addr) Message

func (*CollectiveEndpoint) RecvInto added in v0.2.0

func (e *CollectiveEndpoint) RecvInto(a plan.Addr, m Message) error

type ConnHandler

type ConnHandler interface {
	Handle(conn net.Conn, remote plan.NetAddr, t ConnType) error
}

type ConnType

type ConnType uint16
const (
	ConnPing       ConnType = iota // 0
	ConnControl    ConnType = iota
	ConnCollective ConnType = iota
	ConnPeerToPeer ConnType = iota
)

func (ConnType) String

func (t ConnType) String() string

type Connection

type Connection interface {
	io.Closer
	Send(msgName string, m Message, flags uint32) error
	Read(msgName string, m Message) error
}

Connection is a simplex logical connection from one peer to another

func NewPingConnection

func NewPingConnection(remote, local plan.NetAddr) (Connection, error)

type ConnectionPool

type ConnectionPool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

type Endpoint

type Endpoint interface {
	Self() plan.PeerID
	ConnHandler
}

type Message

type Message struct {
	Length uint32
	Data   []byte
	// contains filtered or unexported fields
}

Message is the data transferred via channel

func Accept

func Accept(conn net.Conn, _remote plan.NetAddr) (string, *Message, error)

Accept accepts one message from connection

func (*Message) ReadFrom

func (m *Message) ReadFrom(r io.Reader) error

ReadFrom reads the message from a reader into new buffer. The message length is obtained from the reader and should be trusted.

func (*Message) ReadInto

func (m *Message) ReadInto(r io.Reader) error

ReadInto reads the message from a reader into existing buffer. The message length obtained from the reader should be checked.

func (Message) String

func (m Message) String() string

func (Message) WriteTo

func (m Message) WriteTo(w io.Writer) error

type MsgHandleFunc

type MsgHandleFunc func(name string, msg *Message, conn net.Conn, remote plan.NetAddr)

type PeerToPeerEndpoint added in v0.2.0

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

func NewPeerToPeerEndpoint added in v0.2.0

func NewPeerToPeerEndpoint(router *Router) *PeerToPeerEndpoint

func (*PeerToPeerEndpoint) Handle added in v0.2.0

func (e *PeerToPeerEndpoint) Handle(conn net.Conn, remote plan.NetAddr, t ConnType) error

Handle implements ConnHandler.Handle interface

func (*PeerToPeerEndpoint) Request added in v0.2.0

func (e *PeerToPeerEndpoint) Request(a plan.Addr, version string, m Message) (bool, error)

func (*PeerToPeerEndpoint) Save added in v0.2.0

func (e *PeerToPeerEndpoint) Save(name string, buf *kb.Vector) error

func (*PeerToPeerEndpoint) SaveVersion added in v0.2.0

func (e *PeerToPeerEndpoint) SaveVersion(version, name string, buf *kb.Vector) error

type Router

type Router struct {
	Collective *CollectiveEndpoint // FIXME: move it out of Router
	P2P        *PeerToPeerEndpoint
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter(self plan.PeerID) *Router

func (*Router) Handle

func (r *Router) Handle(conn net.Conn, remote plan.NetAddr, t ConnType) error

Handle implements ConnHandler.Handle interface

func (*Router) ResetConnections

func (r *Router) ResetConnections(keeps plan.PeerList)

func (*Router) Self

func (r *Router) Self() plan.PeerID

func (*Router) Send

func (r *Router) Send(a plan.Addr, buf []byte, t ConnType, flags uint32) error

Send sends data in buf to given Addr

type Server

type Server interface {
	Start() error
	Close()
}

Server receives messages from remove endpoints

func NewServer

func NewServer(endpoint Endpoint) Server

NewServer creates a new Server

Jump to

Keyboard shortcuts

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