func simulatorMetadata() P2PMetadata {
	ip, err := net.ResolveTCPAddr("tcp", "127.0.0.1:1234")
	if err != nil {
		panic("simulator error")
	}
	return P2PMetadata{ip}
}
simulator doesn't go through the regular p2p pipes so the metadata won't be available.
it's okay since this data doesn't matter to the simulator
package service
import (
	"errors"
	"io"
	"net"
	"sync"
	"time"
	"github.com/libonomy/libonomy-p2p/log"
	"github.com/libonomy/libonomy-p2p/p2p/node"
	"github.com/libonomy/libonomy-p2p/p2p/p2pcrypto"
	"github.com/libonomy/libonomy-p2p/priorityq"
	"github.com/libonomy/libonomy-p2p/rand"
)
type Simulator struct {
	io.Closer
	mutex                 sync.RWMutex
	protocolDirectHandler map[p2pcrypto.PublicKey]map[string]chan DirectMessage  
	protocolGossipHandler map[p2pcrypto.PublicKey]map[string]chan GossipMessage  
	nodes                 map[p2pcrypto.PublicKey]*Node
	subLock      sync.Mutex
	newPeersSubs []chan p2pcrypto.PublicKey
	delPeersSubs []chan p2pcrypto.PublicKey
}
var _ Service = new(Node)
type Node struct {
	sim *Simulator
	*node.Info
	sndDelay      uint32
	rcvDelay      uint32
	randBehaviour bool
}
func NewSimulator() *Simulator {
	s := &Simulator{
		protocolDirectHandler: make(map[p2pcrypto.PublicKey]map[string]chan DirectMessage),
		protocolGossipHandler: make(map[p2pcrypto.PublicKey]map[string]chan GossipMessage),
		nodes:                 make(map[p2pcrypto.PublicKey]*Node),
	}
	return s
}
func (s *Simulator) SubscribeToPeerEvents(myid p2pcrypto.Key) (chan p2pcrypto.PublicKey, chan p2pcrypto.PublicKey) {
	s.mutex.RLock()
	var keys []p2pcrypto.PublicKey
	for _, nd := range s.nodes {
		if nd.PublicKey() == myid {
			continue
		}
		keys = append(keys, nd.PublicKey())
	}
	s.mutex.RUnlock()
	newp := make(chan p2pcrypto.PublicKey, len(keys)+1)
	delp := make(chan p2pcrypto.PublicKey, len(keys)+1)
	s.subLock.Lock()
	s.newPeersSubs = append(s.newPeersSubs, newp)
	s.delPeersSubs = append(s.delPeersSubs, delp)
	s.subLock.Unlock()
	for _, x := range keys {
		newp <- x
	}
	return newp, delp
}
func (s *Simulator) publishNewPeer(peer p2pcrypto.PublicKey) {
	s.subLock.Lock()
	for _, ch := range s.newPeersSubs {
		log.Info("publish on chan with len %v, cap %v", len(ch), cap(ch))
		ch <- peer
	}
	s.subLock.Unlock()
}
func (s *Simulator) publishDelPeer(peer p2pcrypto.PublicKey) {
	s.subLock.Lock()
	for _, ch := range s.delPeersSubs {
		ch <- peer
	}
	s.subLock.Unlock()
}
func (s *Simulator) createdNode(n *Node) {
	s.mutex.Lock()
	s.protocolDirectHandler[n.PublicKey()] = make(map[string]chan DirectMessage)
	s.protocolGossipHandler[n.PublicKey()] = make(map[string]chan GossipMessage)
	s.nodes[n.PublicKey()] = n
	s.mutex.Unlock()
	s.publishNewPeer(n.PublicKey())
}
func (s *Simulator) NewFaulty(isRandBehaviour bool, maxBroadcastDelaySec uint32, maxReceiveDelaySec uint32) *Node {
	n := s.NewNode()
	n.randBehaviour = isRandBehaviour
	n.sndDelay = maxBroadcastDelaySec
	n.rcvDelay = maxReceiveDelaySec
	return n
}
func (s *Simulator) NewNode() *Node {
	n := node.GenerateRandomNodeData()
	sn := &Node{
		sim:  s,
		Info: n,
	}
	s.createdNode(sn)
	return sn
}
func (s *Simulator) NewNodeFrom(n *node.Info) *Node {
	sn := &Node{
		sim:  s,
		Info: n,
	}
	s.createdNode(sn)
	return sn
}
type simDirectMessage struct {
	metadata P2PMetadata
	msg      Data
	sender   p2pcrypto.PublicKey
}
func (sm simDirectMessage) Metadata() P2PMetadata {
	return sm.metadata
}
func (sm simDirectMessage) Data() Data {
	return sm.msg
}
func (sm simDirectMessage) Bytes() []byte {
	return sm.msg.Bytes()
}
func (sm simDirectMessage) Sender() p2pcrypto.PublicKey {
	return sm.sender
}
type simGossipMessage struct {
	sender                  p2pcrypto.PublicKey
	msg                     Data
	validationCompletedChan chan MessageValidation
}
func (sm simGossipMessage) Data() Data {
	return sm.msg
}
func (sm simGossipMessage) Sender() p2pcrypto.PublicKey {
	return sm.sender
}
func (sm simGossipMessage) Bytes() []byte {
	return sm.msg.Bytes()
}
func (sm simGossipMessage) ValidationCompletedChan() chan MessageValidation {
	return sm.validationCompletedChan
}
func (sm simGossipMessage) ReportValidation(protocol string) {
	if sm.validationCompletedChan != nil {
		sm.validationCompletedChan <- NewMessageValidation(sm.sender, sm.Bytes(), protocol)
	}
}
func (sn *Node) Start() error {
	return nil
}