mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-23 03:17:43 +08:00
uses the global PeerHost and don't expose the P2P one
License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
This commit is contained in:
parent
fe8ffde4c2
commit
b720d1f0b5
@ -33,7 +33,7 @@ func ProxyOption() ServeOption {
|
||||
return
|
||||
}
|
||||
|
||||
rt := p2phttp.NewTransport(ipfsNode.P2P.PeerHost, p2phttp.ProtocolOption(parsedRequest.name))
|
||||
rt := p2phttp.NewTransport(ipfsNode.PeerHost, p2phttp.ProtocolOption(parsedRequest.name))
|
||||
proxy := httputil.NewSingleHostReverseProxy(target)
|
||||
proxy.Transport = rt
|
||||
proxy.ServeHTTP(w, request)
|
||||
|
||||
@ -55,7 +55,7 @@ func (l *localListener) dial(ctx context.Context) (net.Stream, error) {
|
||||
cctx, cancel := context.WithTimeout(ctx, time.Second*30) //TODO: configurable?
|
||||
defer cancel()
|
||||
|
||||
return l.p2p.PeerHost.NewStream(cctx, l.peer, l.proto)
|
||||
return l.p2p.peerHost.NewStream(cctx, l.peer, l.proto)
|
||||
}
|
||||
|
||||
func (l *localListener) acceptConns() {
|
||||
|
||||
12
p2p/p2p.go
12
p2p/p2p.go
@ -16,23 +16,23 @@ type P2P struct {
|
||||
Streams *StreamRegistry
|
||||
|
||||
identity peer.ID
|
||||
PeerHost p2phost.Host
|
||||
peerHost p2phost.Host
|
||||
peerstore pstore.Peerstore
|
||||
}
|
||||
|
||||
// NewP2P creates new P2P struct
|
||||
func NewP2P(identity peer.ID, PeerHost p2phost.Host, peerstore pstore.Peerstore) *P2P {
|
||||
func NewP2P(identity peer.ID, peerHost p2phost.Host, peerstore pstore.Peerstore) *P2P {
|
||||
return &P2P{
|
||||
identity: identity,
|
||||
PeerHost: PeerHost,
|
||||
peerHost: peerHost,
|
||||
peerstore: peerstore,
|
||||
|
||||
ListenersLocal: newListenersLocal(),
|
||||
ListenersP2P: newListenersP2P(PeerHost),
|
||||
ListenersP2P: newListenersP2P(peerHost),
|
||||
|
||||
Streams: &StreamRegistry{
|
||||
Streams: map[uint64]*Stream{},
|
||||
ConnManager: PeerHost.ConnManager(),
|
||||
ConnManager: peerHost.ConnManager(),
|
||||
conns: map[peer.ID]int{},
|
||||
},
|
||||
}
|
||||
@ -41,7 +41,7 @@ func NewP2P(identity peer.ID, PeerHost p2phost.Host, peerstore pstore.Peerstore)
|
||||
// CheckProtoExists checks whether a proto handler is registered to
|
||||
// mux handler
|
||||
func (p2p *P2P) CheckProtoExists(proto string) bool {
|
||||
protos := p2p.PeerHost.Mux().Protocols()
|
||||
protos := p2p.peerHost.Mux().Protocols()
|
||||
|
||||
for _, p := range protos {
|
||||
if p != proto {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user