package p2p import ( pstore "gx/ipfs/QmZR2XWVVBCtbgBWnQhWk2xcQfaR3W8faQPriAiaaj7rsr/go-libp2p-peerstore" p2phost "gx/ipfs/Qmb8T6YBBsjYsVGfrihQLfCJveczZnneSBqBKkYEBWDjge/go-libp2p-host" logging "gx/ipfs/QmcVVHfdyv15GVPk7NrxdWjh2hLVccXnoD8j2tyQShiXJb/go-log" peer "gx/ipfs/QmdVrMn1LhB4ybb8hMVaMLXnA8XRSewMnK6YqXKXoTcRvN/go-libp2p-peer" ) var log = logging.Logger("p2p-mount") // P2P structure holds information on currently running streams/listeners type P2P struct { Listeners *ListenerRegistry Streams *StreamRegistry identity peer.ID peerHost p2phost.Host peerstore pstore.Peerstore } // NewP2P creates new P2P struct func NewP2P(identity peer.ID, peerHost p2phost.Host, peerstore pstore.Peerstore) *P2P { return &P2P{ identity: identity, peerHost: peerHost, peerstore: peerstore, Listeners: newListenerRegistry(identity, peerHost), Streams: &StreamRegistry{ Streams: map[uint64]*Stream{}, }, } } // CheckProtoExists checks whether a proto handler is registered to // mux handler func (p2p *P2P) CheckProtoExists(proto string) bool { protos := p2p.peerHost.Mux().Protocols() for _, p := range protos { if p != proto { continue } return true } return false }