kubo/p2p/p2p.go
Chris 90021c16d6 [http_proxy_over_p2p]
This implements an http-proxy over p2p-streams.

License: MIT
Signed-off-by: Chris Boddy <chris@boddy.im>
2018-11-28 23:17:26 -08:00

54 lines
1.3 KiB
Go

package p2p
import (
pstore "gx/ipfs/QmQAGG1zxfePqj2t7bLxyN8AFccZ889DDR9Gn8kVLDrGZo/go-libp2p-peerstore"
p2phost "gx/ipfs/QmahxMNoNuSsgQefo9rkpcfRFmQrMN6Q99aztKXf63K7YJ/go-libp2p-host"
peer "gx/ipfs/QmcqU6QUDSXprb1518vYDGczrTJTyGwLG9eUa5iNX4xUtS/go-libp2p-peer"
logging "gx/ipfs/QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C/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
}