protocol

package
v0.3.11-rc1 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2016 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadLengthPrefix

func ReadLengthPrefix(r io.Reader) (string, error)

ReadLengthPrefix reads the name from Reader with a length-byte-prefix.

func WriteHeader

func WriteHeader(w io.Writer, id ID) error

WriteHeader writes a protocol.ID header to an io.Writer. This is so multiple protocols can be multiplexed on top of the same transport.

We use go-msgio varint encoding:

<varint length><string name>\n

(the varint includes the \n)

Types

type ID

type ID string

ID is an identifier used to write protocol headers in streams.

const (
	TestingID ID = "/p2p/_testing"
)

These are reserved protocol.IDs.

func ReadHeader

func ReadHeader(r io.Reader) (ID, error)

ReadHeader reads a protocol.ID header from an io.Reader. This is so multiple protocols can be multiplexed on top of the same transport. See WriteHeader.

type Mux

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

Mux provides simple stream multixplexing. It helps you precisely when:

  • You have many streams
  • You have function handlers

It contains the handlers for each protocol accepted. It dispatches handlers for streams opened by remote peers.

func NewMux

func NewMux() *Mux

func (*Mux) Handle

func (m *Mux) Handle(s inet.Stream)

Handle reads the next name off the Stream, and calls a handler function This is done in its own goroutine, to avoid blocking the caller.

func (*Mux) HandleSync

func (m *Mux) HandleSync(s inet.Stream)

HandleSync reads the next name off the Stream, and calls a handler function This is done synchronously. The handler function will return before HandleSync returns.

func (*Mux) Protocols

func (m *Mux) Protocols() []ID

Protocols returns the list of protocols this muxer has handlers for

func (*Mux) ReadHeader added in v0.3.2

func (m *Mux) ReadHeader(s io.Reader) (ID, inet.StreamHandler, error)

ReadHeader reads the stream and returns the next Handler function according to the muxer encoding.

func (*Mux) RemoveHandler

func (m *Mux) RemoveHandler(p ID)

RemoveHandler removes the protocol handler on the Network's Muxer. This operation is threadsafe.

func (*Mux) SetDefaultHandler

func (m *Mux) SetDefaultHandler(h inet.StreamHandler)

func (*Mux) SetHandler

func (m *Mux) SetHandler(p ID, h inet.StreamHandler)

SetHandler sets the protocol handler on the Network's Muxer. This operation is threadsafe.

func (*Mux) String

func (m *Mux) String() string

String returns the muxer's printing representation

Directories

Path Synopsis
pb
Package identify_pb is a generated protocol buffer package.
Package identify_pb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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