Documentation ¶
Index ¶
- type Stream
- func (w *Stream) AddRoute(routes ...dndm.Route)
- func (w *Stream) Close() error
- func (w *Stream) DelRoute(routes ...dndm.Route)
- func (w *Stream) Local() dndm.Peer
- func (w *Stream) OnClose(f func()) network.Conn
- func (w *Stream) Read(ctx context.Context) (*types.Header, proto.Message, error)
- func (w *Stream) Remote() dndm.Peer
- func (w *Stream) UpdateRemotePeer(p dndm.Peer) error
- func (w *Stream) Write(ctx context.Context, route dndm.Route, msg proto.Message) error
- type StreamContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Stream ¶
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.
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