mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
Some checks are pending
CodeQL / codeql (push) Waiting to run
Docker Build / docker-build (push) Waiting to run
Gateway Conformance / gateway-conformance (push) Waiting to run
Gateway Conformance / gateway-conformance-libp2p-experiment (push) Waiting to run
Go Build / go-build (push) Waiting to run
Go Check / go-check (push) Waiting to run
Go Lint / go-lint (push) Waiting to run
Go Test / go-test (push) Waiting to run
Interop / interop-prep (push) Waiting to run
Interop / helia-interop (push) Blocked by required conditions
Interop / ipfs-webui (push) Blocked by required conditions
Sharness / sharness-test (push) Waiting to run
Spell Check / spellcheck (push) Waiting to run
* chore: update to go-log/v2 go-log v2 has been out for quite a while now and it is time to deprecate v1. Replace all use of go-log with go-log/v2 Makes /api/v0/log/tail useful over HTTP Updates dependencies that have moved to go-lov/v2 Removes support for ContextWithLoggable as this is not needed for tracing-like functionality - Replaces: PR #8765 - Closes issue #8753 - Closes issue #9245 - Closes issue #10809 Other fixes: * update go-ipfs-cmds * update http logs test * fix test * Read/send one line of log data at a time * Update -log-level docs
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package p2p
|
|
|
|
import (
|
|
logging "github.com/ipfs/go-log/v2"
|
|
p2phost "github.com/libp2p/go-libp2p/core/host"
|
|
"github.com/libp2p/go-libp2p/core/peer"
|
|
pstore "github.com/libp2p/go-libp2p/core/peerstore"
|
|
"github.com/libp2p/go-libp2p/core/protocol"
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
// New creates new P2P struct.
|
|
func New(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 protocol.ID) bool {
|
|
protos := p2p.peerHost.Mux().Protocols()
|
|
|
|
for _, p := range protos {
|
|
if p != proto {
|
|
continue
|
|
}
|
|
return true
|
|
}
|
|
return false
|
|
}
|