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 (*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) 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.