peer

package
v0.10.6 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handle

func Handle(ctx context.Context, peer Peer, parent Parent, remote Remote, duplicateChecker DuplicateChecker) error

Handle sends and receives messages no matter outgoing or incoming connection. Handle consumes provided peer parameter and closes it when the function ends.

Types

type Connected

type Connected struct {
	Peer Peer
}

type Direction

type Direction int
const Incoming Direction = 1
const Outgoing Direction = 2

func (Direction) String

func (a Direction) String() string

type DuplicateChecker added in v0.8.1

type DuplicateChecker interface {
	Add([]byte) (isNew bool)
}

type ID added in v0.10.0

type ID interface {
	fmt.Stringer
}

type InfoMessage

type InfoMessage struct {
	Peer  Peer
	Value InfoMessageValue
}

type InfoMessageValue added in v0.10.4

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

type InternalErr added in v0.10.4

type InternalErr struct {
	Err error
}

type Parent

type Parent struct {
	MessageCh       chan ProtoMessage
	InfoCh          chan InfoMessage
	SkipMessageList *messages.SkipMessageList
}

func NewParent

func NewParent() Parent

type Peer

type Peer interface {
	Direction() Direction
	Close() error
	SendMessage(proto.Message)
	ID() ID
	Connection() conn.Connection
	Handshake() proto.Handshake
	RemoteAddr() proto.TCPAddr
}

type PeerImpl

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

func NewPeerImpl

func NewPeerImpl(handshake proto.Handshake, conn conn.Connection, direction Direction, remote Remote, cancel context.CancelFunc) (*PeerImpl, error)

func (*PeerImpl) Close

func (a *PeerImpl) Close() error

func (*PeerImpl) Connection

func (a *PeerImpl) Connection() conn.Connection

func (*PeerImpl) Direction

func (a *PeerImpl) Direction() Direction

func (*PeerImpl) Handshake

func (a *PeerImpl) Handshake() proto.Handshake

func (*PeerImpl) ID

func (a *PeerImpl) ID() ID

func (*PeerImpl) RemoteAddr

func (a *PeerImpl) RemoteAddr() proto.TCPAddr

func (*PeerImpl) SendMessage

func (a *PeerImpl) SendMessage(m proto.Message)

SendMessage marshals provided message and sends it to its internal Remote.ToCh channel. It sends the error to internal Remote.ErrCh if Remote.ToCh is full. That notifies Handle to propagate this error to FMS through Parent.InfoCh.

type ProtoMessage

type ProtoMessage struct {
	ID      Peer
	Message proto.Message
}

type Remote

type Remote struct {
	ToCh   chan []byte
	FromCh chan *bytebufferpool.ByteBuffer
	ErrCh  chan error
}

func NewRemote

func NewRemote() Remote

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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