func (m *MuxBroker) Run() {
	for {
		stream, err := m.session.AcceptStream()
		if err != nil {
			break
		}
		var id uint32
		if err := binary.Read(stream, binary.LittleEndian, &id); err != nil {
			stream.Close()
			continue
		}
		p := m.getStream(id)
		select {
		case p.ch <- stream:
		default:
		}
		go m.timeoutWait(id, p)
	}
}
Run starts the brokering and should be executed in a goroutine, since it
blocks forever, or until the session closes.

Uses of MuxBroker never need to call this. It is called internally by
the plugin host/client.
package plugin
import (
	"encoding/binary"
	"fmt"
	"log"
	"net"
	"sync"
	"sync/atomic"
	"time"
	"github.com/hashicorp/yamux"
)
type MuxBroker struct {
	nextId  uint32
	session *yamux.Session
	streams map[uint32]*muxBrokerPending
	sync.Mutex
}
type muxBrokerPending struct {
	ch     chan net.Conn
	doneCh chan struct{}
}
func newMuxBroker(s *yamux.Session) *MuxBroker {
	return &MuxBroker{
		session: s,
		streams: make(map[uint32]*muxBrokerPending),
	}
}
func (m *MuxBroker) Accept(id uint32) (net.Conn, error) {
	var c net.Conn
	p := m.getStream(id)
	select {
	case c = <-p.ch:
		close(p.doneCh)
	case <-time.After(5 * time.Second):
		m.Lock()
		defer m.Unlock()
		delete(m.streams, id)
		return nil, fmt.Errorf("timeout waiting for accept")
	}
	if err := binary.Write(c, binary.LittleEndian, id); err != nil {
		c.Close()
		return nil, err
	}
	return c, nil
}
func (m *MuxBroker) AcceptAndServe(id uint32, v interface{}) {
	conn, err := m.Accept(id)
	if err != nil {
		log.Printf("[ERR] plugin: plugin acceptAndServe error: %s", err)
		return
	}
	serve(conn, "Plugin", v)
}
func (m *MuxBroker) Close() error {
	return m.session.Close()
}
func (m *MuxBroker) Dial(id uint32) (net.Conn, error) {
	stream, err := m.session.OpenStream()
	if err != nil {
		return nil, err
	}
	if err := binary.Write(stream, binary.LittleEndian, id); err != nil {
		stream.Close()
		return nil, err
	}
	var ack uint32
	if err := binary.Read(stream, binary.LittleEndian, &ack); err != nil {
		stream.Close()
		return nil, err
	}
	if ack != id {
		stream.Close()
		return nil, fmt.Errorf("bad ack: %d (expected %d)", ack, id)
	}
	return stream, nil
}
func (m *MuxBroker) NextId() uint32 {
	return atomic.AddUint32(&m.nextId, 1)
}