ipld-eth-server/vendor/github.com/ipfs/go-ipfs/p2p/p2p.go
2019-12-02 13:24:46 -06:00

54 lines
1.3 KiB
Go

package p2p
import (
peer "gx/ipfs/QmYVXrKrKHDC9FobgmcmshCDyWwdrfwfanNQN4oxJ9Fk3h/go-libp2p-peer"
p2phost "gx/ipfs/QmYrWiWM4qtrnCeT3R14jY3ZZyirDNJgwK57q4qFYePgbd/go-libp2p-host"
pstore "gx/ipfs/QmaCTz9RkrU13bm9kMB54f7atgqM4qkjDZpRwRoJiWXEqs/go-libp2p-peerstore"
logging "gx/ipfs/QmbkT7eMTyXfpeyB3ZMxxcxg7XH8t6uXp49jqzz4HB7BGF/go-log"
)
var log = logging.Logger("p2p-mount")
// P2P structure holds information on currently running streams/Listeners
type P2P struct {
ListenersLocal *Listeners
ListenersP2P *Listeners
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,
ListenersLocal: newListenersLocal(),
ListenersP2P: newListenersP2P(peerHost),
Streams: &StreamRegistry{
Streams: map[uint64]*Stream{},
ConnManager: peerHost.ConnManager(),
conns: map[peer.ID]int{},
},
}
}
// 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
}