Documentation ¶
Overview ¶
Package ipfsutil contains helpers around IPFS (logging, datastore, networking, core API, ...).
Index ¶
- Constants
- Variables
- func CreateBuildConfig(repo ipfs_repo.Repo, opts *CoreAPIConfig) (*ipfs_node.BuildCfg, error)
- func CreateMockedRepo(dstore ipfs_ds.Batching) (ipfs_repo.Repo, error)
- func EnableConnLogger(ctx context.Context, logger *zap.Logger, h host.Host)
- func InjectPubSubAPI(api ipfs_interface.CoreAPI, ps ipfs_interface.PubSubAPI) ipfs_interface.CoreAPI
- func LoadRepoFromPath(path string) (ipfs_repo.Repo, error)
- func NewDatastoreKeystore(ds datastore.Datastore) keystore.Keystore
- func NewNamespacedDatastore(child ds.Datastore, prefix ds.Key) ds.Batching
- func NewPubSubAPI(ctx context.Context, logger *zap.Logger, disc p2p_disc.Discovery, ...) ipfs_interface.PubSubAPI
- func OptionLocalRecord(ctx context.Context, node *ipfs_core.IpfsNode, api ipfs_interface.CoreAPI) error
- func OptionMDNSDiscovery(ctx context.Context, node *ipfs_core.IpfsNode, api ipfs_interface.CoreAPI) error
- func ParseAddr(addr string) (ma.Multiaddr, error)
- func ParseAddrs(addrs ...string) ([]ma.Multiaddr, error)
- func ParseAndResolveIpfsAddr(ctx context.Context, addr string) (*peer.AddrInfo, error)
- func ParseAndResolveRdvpMaddrs(ctx context.Context, log *zap.Logger, addrs []string) ([]*peer.AddrInfo, error)
- func ServeHTTPApi(logger *zap.Logger, node *core.IpfsNode, rootDirectory string) error
- func ServeHTTPWebui(listenerAddr string, logger *zap.Logger) func()
- func TestingRDVP(ctx context.Context, t testing.TB, h host.Host) (*rendezvous.RendezvousService, func())
- func TestingRepo(t testing.TB, datastore ds.Datastore) ipfs_repo.Repo
- type BandwidthCollector
- type ConnMgr
- type CoreAPIConfig
- type CoreAPIMock
- type CoreAPIOption
- type DiscoveryNotifee
- type ExtendedCoreAPI
- func InjectPubSubCoreAPIExtendedAdaptater(exapi ExtendedCoreAPI, ps ipfs_interface.PubSubAPI) ExtendedCoreAPI
- func NewConfigurableCoreAPI(ctx context.Context, bcfg *ipfs_node.BuildCfg, opts ...CoreAPIOption) (ExtendedCoreAPI, *ipfs_core.IpfsNode, error)
- func NewCoreAPI(ctx context.Context, cfg *CoreAPIConfig) (ExtendedCoreAPI, *ipfs_core.IpfsNode, error)
- func NewCoreAPIFromDatastore(ctx context.Context, ds ds.Batching, cfg *CoreAPIConfig) (ExtendedCoreAPI, *ipfs_core.IpfsNode, error)
- func NewCoreAPIFromRepo(ctx context.Context, repo ipfs_repo.Repo, cfg *CoreAPIConfig) (ExtendedCoreAPI, *ipfs_core.IpfsNode, error)
- func NewExtendedCoreAPI(host ipfs_host.Host, api ipfs_interface.CoreAPI) ExtendedCoreAPI
- type HostCollector
- func (cc *HostCollector) ClosedStream(n network.Network, s network.Stream)
- func (cc *HostCollector) Collect(cmetric chan<- prometheus.Metric)
- func (cc *HostCollector) Connected(n network.Network, c network.Conn)
- func (cc *HostCollector) Describe(ch chan<- *prometheus.Desc)
- func (cc *HostCollector) Disconnected(n network.Network, c network.Conn)
- func (cc *HostCollector) Listen(network.Network, ma.Multiaddr)
- func (cc *HostCollector) ListenClose(network.Network, ma.Multiaddr)
- func (cc *HostCollector) OpenedStream(n network.Network, s network.Stream)
- type IpfsConfigPatcher
- type LocalRecord
- func (lr *LocalRecord) ClosedStream(network.Network, network.Stream)
- func (lr *LocalRecord) Connected(net network.Network, c network.Conn)
- func (lr *LocalRecord) Disconnected(network.Network, network.Conn)
- func (lr *LocalRecord) Listen(network.Network, ma.Multiaddr)
- func (lr *LocalRecord) ListenClose(network.Network, ma.Multiaddr)
- func (lr *LocalRecord) OpenedStream(network.Network, network.Stream)
- type PubSubAPI
- func (ps *PubSubAPI) Ls(ctx context.Context) ([]string, error)
- func (ps *PubSubAPI) Peers(ctx context.Context, opts ...ipfs_iopts.PubSubPeersOption) ([]p2p_peer.ID, error)
- func (ps *PubSubAPI) Publish(ctx context.Context, topic string, msg []byte) error
- func (ps *PubSubAPI) Subscribe(ctx context.Context, topic string, opts ...ipfs_iopts.PubSubSubscribeOption) (ipfs_interface.PubSubSubscription, error)
- type TestingAPIOpts
Constants ¶
const UnknownProtocol = "UnknownProtocol"
Variables ¶
var DefaultSwarmListeners = []string{
"/ip4/0.0.0.0/tcp/0",
"/ip6/::/tcp/0",
"/ip4/0.0.0.0/udp/0/quic",
"/ip6/::/udp/0/quic",
}
Functions ¶
func CreateBuildConfig ¶ added in v2.53.1
func CreateMockedRepo ¶ added in v2.57.1
func EnableConnLogger ¶ added in v2.97.0
func InjectPubSubAPI ¶ added in v2.109.0
func InjectPubSubAPI(api ipfs_interface.CoreAPI, ps ipfs_interface.PubSubAPI) ipfs_interface.CoreAPI
func NewNamespacedDatastore ¶
func NewPubSubAPI ¶ added in v2.109.0
func NewPubSubAPI(ctx context.Context, logger *zap.Logger, disc p2p_disc.Discovery, ps *p2p_pubsub.PubSub) ipfs_interface.PubSubAPI
func OptionLocalRecord ¶ added in v2.94.0
func OptionLocalRecord(ctx context.Context, node *ipfs_core.IpfsNode, api ipfs_interface.CoreAPI) error
OptionLocalRecord is given to CoreAPIOption.Options when the ipfs node setup
func OptionMDNSDiscovery ¶
func ParseAndResolveIpfsAddr ¶ added in v2.53.1
func ParseAndResolveRdvpMaddrs ¶ added in v2.149.0
func ServeHTTPApi ¶ added in v2.70.0
ServeHTTPApi collects options, creates listener, prints status message and starts serving requests
func ServeHTTPWebui ¶ added in v2.70.0
func TestingRDVP ¶ added in v2.50.0
func TestingRDVP(ctx context.Context, t testing.TB, h host.Host) (*rendezvous.RendezvousService, func())
Types ¶
type BandwidthCollector ¶ added in v2.182.0
type BandwidthCollector struct {
// contains filtered or unexported fields
}
func NewBandwidthCollector ¶ added in v2.182.0
func NewBandwidthCollector(reporter *metrics.BandwidthCounter) *BandwidthCollector
func (*BandwidthCollector) Collect ¶ added in v2.182.0
func (bc *BandwidthCollector) Collect(cmetric chan<- prometheus.Metric)
func (*BandwidthCollector) Describe ¶ added in v2.182.0
func (bc *BandwidthCollector) Describe(ch chan<- *prometheus.Desc)
type CoreAPIConfig ¶ added in v2.53.1
type CoreAPIConfig struct { BootstrapAddrs []string SwarmAddrs []string APIAddrs []string Announce []string NoAnnounce []string APIConfig config.API DisableCorePubSub bool HostConfig func(host.Host, p2p_routing.Routing) error ExtraLibp2pOption p2p.Option DHTOption []p2p_dht.Option IpfsConfigPatch IpfsConfigPatcher Routing ipfs_libp2p.RoutingOption Host ipfs_libp2p.HostOption Options []CoreAPIOption }
type CoreAPIMock ¶
type CoreAPIMock interface { API() ExtendedCoreAPI PubSub() *pubsub.PubSub Tinder() tinder.Driver MockNetwork() p2p_mocknet.Mocknet MockNode() *ipfs_core.IpfsNode Close() }
CoreAPIMock implements ipfs.CoreAPI and adds some debugging helpers
func TestingCoreAPI ¶
func TestingCoreAPI(ctx context.Context, t testing.TB) (CoreAPIMock, func())
TestingCoreAPI returns a fully initialized mocked Core API. If you want to do some tests involving multiple peers you should use `TestingCoreAPIUsingMockNet` with the same mocknet instead.
func TestingCoreAPIUsingMockNet ¶
func TestingCoreAPIUsingMockNet(ctx context.Context, t testing.TB, opts *TestingAPIOpts) (CoreAPIMock, func())
TestingCoreAPIUsingMockNet returns a fully initialized mocked Core API with the given mocknet
type CoreAPIOption ¶ added in v2.53.1
type DiscoveryNotifee ¶
type DiscoveryNotifee struct {
// contains filtered or unexported fields
}
func (*DiscoveryNotifee) HandlePeerFound ¶
func (n *DiscoveryNotifee) HandlePeerFound(pi peer.AddrInfo)
type ExtendedCoreAPI ¶ added in v2.59.0
type ExtendedCoreAPI interface { ipfs_interface.CoreAPI NewStream(ctx context.Context, p peer.ID, pids ...protocol.ID) (network.Stream, error) SetStreamHandler(pid protocol.ID, handler network.StreamHandler) RemoveStreamHandler(pid protocol.ID) ConnMgr() ConnMgr }
func InjectPubSubCoreAPIExtendedAdaptater ¶ added in v2.109.0
func InjectPubSubCoreAPIExtendedAdaptater(exapi ExtendedCoreAPI, ps ipfs_interface.PubSubAPI) ExtendedCoreAPI
func NewConfigurableCoreAPI ¶
func NewConfigurableCoreAPI(ctx context.Context, bcfg *ipfs_node.BuildCfg, opts ...CoreAPIOption) (ExtendedCoreAPI, *ipfs_core.IpfsNode, error)
NewConfigurableCoreAPI returns an IPFS CoreAPI from a provided ipfs_node.BuildCfg
func NewCoreAPI ¶ added in v2.53.1
func NewCoreAPI(ctx context.Context, cfg *CoreAPIConfig) (ExtendedCoreAPI, *ipfs_core.IpfsNode, error)
func NewCoreAPIFromDatastore ¶ added in v2.57.1
func NewCoreAPIFromDatastore(ctx context.Context, ds ds.Batching, cfg *CoreAPIConfig) (ExtendedCoreAPI, *ipfs_core.IpfsNode, error)
func NewCoreAPIFromRepo ¶ added in v2.57.1
func NewCoreAPIFromRepo(ctx context.Context, repo ipfs_repo.Repo, cfg *CoreAPIConfig) (ExtendedCoreAPI, *ipfs_core.IpfsNode, error)
func NewExtendedCoreAPI ¶ added in v2.59.0
func NewExtendedCoreAPI(host ipfs_host.Host, api ipfs_interface.CoreAPI) ExtendedCoreAPI
type HostCollector ¶ added in v2.182.0
type HostCollector struct {
// contains filtered or unexported fields
}
func NewHostCollector ¶ added in v2.182.0
func NewHostCollector(h host.Host) *HostCollector
func (*HostCollector) ClosedStream ¶ added in v2.182.0
func (cc *HostCollector) ClosedStream(n network.Network, s network.Stream)
func (*HostCollector) Collect ¶ added in v2.182.0
func (cc *HostCollector) Collect(cmetric chan<- prometheus.Metric)
func (*HostCollector) Connected ¶ added in v2.182.0
func (cc *HostCollector) Connected(n network.Network, c network.Conn)
func (*HostCollector) Describe ¶ added in v2.182.0
func (cc *HostCollector) Describe(ch chan<- *prometheus.Desc)
func (*HostCollector) Disconnected ¶ added in v2.182.0
func (cc *HostCollector) Disconnected(n network.Network, c network.Conn)
func (*HostCollector) Listen ¶ added in v2.182.0
func (cc *HostCollector) Listen(network.Network, ma.Multiaddr)
func (*HostCollector) ListenClose ¶ added in v2.182.0
func (cc *HostCollector) ListenClose(network.Network, ma.Multiaddr)
func (*HostCollector) OpenedStream ¶ added in v2.182.0
func (cc *HostCollector) OpenedStream(n network.Network, s network.Stream)
type IpfsConfigPatcher ¶ added in v2.174.0
func ChainIpfsConfigPatch ¶ added in v2.174.0
func ChainIpfsConfigPatch(ps ...IpfsConfigPatcher) IpfsConfigPatcher
ChainIpfsConfigPatch will execute multiple IpfsConfigPatcher from the first to the last. They can be safely be nilled and will just be ignored.
type LocalRecord ¶ added in v2.94.0
type LocalRecord struct {
// contains filtered or unexported fields
}
func (*LocalRecord) ClosedStream ¶ added in v2.94.0
func (lr *LocalRecord) ClosedStream(network.Network, network.Stream)
called when a stream closed
func (*LocalRecord) Connected ¶ added in v2.94.0
func (lr *LocalRecord) Connected(net network.Network, c network.Conn)
called when a connection opened
func (*LocalRecord) Disconnected ¶ added in v2.94.0
func (lr *LocalRecord) Disconnected(network.Network, network.Conn)
called when a connection closed
func (*LocalRecord) Listen ¶ added in v2.94.0
func (lr *LocalRecord) Listen(network.Network, ma.Multiaddr)
called when network starts listening on an addr
func (*LocalRecord) ListenClose ¶ added in v2.94.0
func (lr *LocalRecord) ListenClose(network.Network, ma.Multiaddr)
called when network stops listening on an addr
func (*LocalRecord) OpenedStream ¶ added in v2.94.0
func (lr *LocalRecord) OpenedStream(network.Network, network.Stream)
called when a stream opened
type PubSubAPI ¶ added in v2.109.0
type PubSubAPI struct { *p2p_pubsub.PubSub // contains filtered or unexported fields }
func (*PubSubAPI) Peers ¶ added in v2.109.0
func (ps *PubSubAPI) Peers(ctx context.Context, opts ...ipfs_iopts.PubSubPeersOption) ([]p2p_peer.ID, error)
Peers list peers we are currently pubsubbing with
func (*PubSubAPI) Subscribe ¶ added in v2.109.0
func (ps *PubSubAPI) Subscribe(ctx context.Context, topic string, opts ...ipfs_iopts.PubSubSubscribeOption) (ipfs_interface.PubSubSubscription, error)
Subscribe to messages on a given topic