stream

package
v0.0.0-...-543ca17 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stream

type Stream struct {
	dndm.Base
	// contains filtered or unexported fields
}

Stream converts regular ReaderWriter into a Remote

func New

func New(ctx context.Context, localPeer, remotePeer dndm.Peer, rw io.ReadWriter, handlers map[types.Type]network.MessageHandler) *Stream

New creates a Remote using provided ReaderWriter.

func NewIO

func NewIO(ctx context.Context, localPeer, remotePeer dndm.Peer, r io.Reader, w io.Writer, handlers map[types.Type]network.MessageHandler) *Stream

NewIO creates a Remote using io.Reader and io.Writer.

func (*Stream) AddRoute

func (w *Stream) AddRoute(routes ...dndm.Route)

func (*Stream) Close

func (w *Stream) Close() error

func (*Stream) DelRoute

func (w *Stream) DelRoute(routes ...dndm.Route)

func (*Stream) Local

func (w *Stream) Local() dndm.Peer

func (*Stream) OnClose

func (w *Stream) OnClose(f func()) network.Conn

func (*Stream) Read

func (w *Stream) Read(ctx context.Context) (*types.Header, proto.Message, error)

func (*Stream) Remote

func (w *Stream) Remote() dndm.Peer

func (*Stream) UpdateRemotePeer

func (w *Stream) UpdateRemotePeer(p dndm.Peer) error

func (*Stream) Write

func (w *Stream) Write(ctx context.Context, route dndm.Route, msg proto.Message) error

type StreamContext

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

StreamContext is a wrapper over ReadWriter that will read and decode messages from Reader as well as encode and write them to the Writer. It allows using regular Reader/Writer interfaces with a context, however, it must be noted that the read/write loop will be leaked if Read/Write blocks.

- Read will read a message and decode it. Then call any registered handler for that message. Then it returns the message for further processing. - Read will also modify received header ReceivedAt with the timestamp of local reception of the packet before decoding it - Write will encode the message - Write will set header Timestamp to the time when the header is constructed, so it will include the overhead of marshaling the message

func NewWithContext

func NewWithContext(ctx context.Context, localPeer, remotePeer dndm.Peer, rw io.ReadWriter, handlers map[types.Type]network.MessageHandler) *StreamContext

NewWithContext will use ReadWriter and allow for context cancellation in Read and Write methods.

func (*StreamContext) Close

func (w *StreamContext) Close() error

func (*StreamContext) Read

func (*StreamContext) Reader

func (c *StreamContext) Reader(ctx context.Context) io.Reader

func (*StreamContext) Write

func (w *StreamContext) Write(ctx context.Context, route dndm.Route, msg proto.Message) error

Jump to

Keyboard shortcuts

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