Documentation ¶
Index ¶
- func ReadLengthPrefix(r io.Reader) (string, error)
- func WriteHeader(w io.Writer, id ID) error
- type ID
- type Mux
- func (m *Mux) Handle(s inet.Stream)
- func (m *Mux) HandleSync(s inet.Stream)
- func (m *Mux) Protocols() []ID
- func (m *Mux) ReadHeader(s io.Reader) (ID, inet.StreamHandler, error)
- func (m *Mux) RemoveHandler(p ID)
- func (m *Mux) SetDefaultHandler(h inet.StreamHandler)
- func (m *Mux) SetHandler(p ID, h inet.StreamHandler)
- func (m *Mux) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadLengthPrefix ¶
ReadLengthPrefix reads the name from Reader with a length-byte-prefix.
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.
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 ¶
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 ¶
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) ReadHeader ¶
ReadHeader reads the stream and returns the next Handler function according to the muxer encoding.
func (*Mux) RemoveHandler ¶
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.