func (n NetworkMock) PublishNewRemoteConnection(nce NewConnectionEvent) {
	for _, f := range n.regNewRemoteConn {
		f(nce)
	}
}
PublishNewRemoteConnection and stuff
package net
import (
	"context"
	"net"
	"sync/atomic"
	"time"
	"github.com/libonomy/libonomy-p2p/log"
	"github.com/libonomy/libonomy-p2p/p2p/p2pcrypto"
	"github.com/libonomy/libonomy-p2p/rand"
)
type ReadWriteCloserMock struct {
}
func (m ReadWriteCloserMock) Read(p []byte) (n int, err error) {
	return 0, nil
}
func (m ReadWriteCloserMock) Write(p []byte) (n int, err error) {
	return 0, nil
}
func (m ReadWriteCloserMock) Close() error {
	return nil
}
func (m ReadWriteCloserMock) RemoteAddr() net.Addr {
	r, err := net.ResolveTCPAddr("tcp", "127.0.0.0")
	if err != nil {
		log.Panic("RemoteAddr panicked: ", err)
	}
	return r
}
func getTestLogger(name string) log.Log {
	return log.New(name, "", "")
}
type NetworkMock struct {
	dialErr          error
	dialDelayMs      int8
	dialCount        int32
	preSessionErr    error
	preSessionCount  int32
	regNewRemoteConn []func(NewConnectionEvent)
	networkID        int8
	closingConn      []func(ConnectionWithErr)
	incomingMessages []chan IncomingMessageEvent
	dialSessionID    []byte
	logger           log.Log
}
func NewNetworkMock() *NetworkMock {
	return &NetworkMock{
		regNewRemoteConn: make([]func(NewConnectionEvent), 0, 3),
		closingConn:      make([]func(ConnectionWithErr), 0, 3),
		logger:           getTestLogger("network mock"),
		incomingMessages: []chan IncomingMessageEvent{make(chan IncomingMessageEvent, 256)},
	}
}
func (n *NetworkMock) SetNextDialSessionID(sID []byte) {
	n.dialSessionID = sID
}
func (n *NetworkMock) SetDialResult(err error) {
	n.dialErr = err
}
func (n *NetworkMock) SetDialDelayMs(delay int8) {
	n.dialDelayMs = delay
}
func (n *NetworkMock) Dial(ctx context.Context, address net.Addr, remotePublicKey p2pcrypto.PublicKey) (Connection, error) {
	atomic.AddInt32(&n.dialCount, 1)
	select {
	case <-time.After(time.Duration(n.dialDelayMs) * time.Millisecond):
		break
	case <-ctx.Done():
		return nil, ctx.Err()
	}
	sID := n.dialSessionID
	if sID == nil {
		sID = make([]byte, 4)
		_, err := rand.Read(sID)
		if err != nil {
			panic("no randomness for networkmock")
		}
	}
	conn := NewConnectionMock(remotePublicKey)
	publicKey, _ := p2pcrypto.NewPubkeyFromBytes(sID)
	conn.SetSession(SessionMock{id: publicKey})
	return conn, n.dialErr
}
func (n *NetworkMock) DialCount() int32 {
	return atomic.LoadInt32(&n.dialCount)
}
func (n *NetworkMock) SubscribeOnNewRemoteConnections(f func(event NewConnectionEvent)) {
	n.regNewRemoteConn = append(n.regNewRemoteConn, f)
}