func newMemoryTransport(network *MemoryNetwork, nodeID types.NodeID) *MemoryTransport {
	return &MemoryTransport{
		logger:     network.logger.With("local", nodeID),
		network:    network,
		nodeID:     nodeID,
		bufferSize: network.bufferSize,
		acceptCh:   make(chan *MemoryConnection),
		closeCh:    make(chan struct{}),
	}
}
newMemoryTransport creates a new MemoryTransport. This is for internal use by
MemoryNetwork, use MemoryNetwork.CreateTransport() instead.
package p2p
import (
	"context"
	"errors"
	"fmt"
	"io"
	"net"
	"sync"
	"github.com/tendermint/tendermint/crypto"
	tmsync "github.com/tendermint/tendermint/internal/libs/sync"
	"github.com/tendermint/tendermint/libs/log"
	"github.com/tendermint/tendermint/types"
)
const (
	MemoryProtocol Protocol = "memory"
)
type MemoryNetwork struct {
	logger log.Logger
	mtx        sync.RWMutex
	transports map[types.NodeID]*MemoryTransport
	bufferSize int
}
func NewMemoryNetwork(logger log.Logger, bufferSize int) *MemoryNetwork {
	return &MemoryNetwork{
		bufferSize: bufferSize,
		logger:     logger,
		transports: map[types.NodeID]*MemoryTransport{},
	}
}
func (n *MemoryNetwork) CreateTransport(nodeID types.NodeID) *MemoryTransport {
	t := newMemoryTransport(n, nodeID)
	n.mtx.Lock()
	defer n.mtx.Unlock()
	if _, ok := n.transports[nodeID]; ok {
		panic(fmt.Sprintf("memory transport with node ID %q already exists", nodeID))
	}
	n.transports[nodeID] = t
	return t
}
func (n *MemoryNetwork) GetTransport(id types.NodeID) *MemoryTransport {
	n.mtx.RLock()
	defer n.mtx.RUnlock()
	return n.transports[id]
}
func (n *MemoryNetwork) RemoveTransport(id types.NodeID) {
	n.mtx.Lock()
	t, ok := n.transports[id]
	delete(n.transports, id)
	n.mtx.Unlock()
	if ok {
		if err := t.Close(); err != nil {
			n.logger.Error("failed to close memory transport", "id", id, "err", err)
		}
	}
}
func (n *MemoryNetwork) Size() int {
	return len(n.transports)
}
type MemoryTransport struct {
	logger     log.Logger
	network    *MemoryNetwork
	nodeID     types.NodeID
	bufferSize int
	acceptCh  chan *MemoryConnection
	closeCh   chan struct{}
	closeOnce sync.Once
}