Documentation ¶
Overview ¶
Package ipfsutil contains helpers around IPFS (logging, datastore, networking, core API, ...).
Index ¶
- Constants
- Variables
- func CreateBaseConfig() (*ipfs_cfg.Config, error)
- func CreateMockedRepo(dstore ipfs_ds.Batching) (ipfs_repo.Repo, error)
- func CreateOrLoadMockedRepo(dstore ipfs_ds.Batching) (ipfs_repo.Repo, error)
- func CustomRoutingOption(mode p2p_dht.ModeOpt, net DHTNetworkMode, opts ...p2p_dht.Option) ...
- func EnableConnLogger(ctx context.Context, logger *zap.Logger, h host.Host)
- func FullClose(s network.Stream) error
- func InjectPubSubAPI(api ipfs_interface.CoreAPI, ps ipfs_interface.PubSubAPI) ipfs_interface.CoreAPI
- func LoadPlugins(repoPath string) (*ipfs_loader.PluginLoader, error)
- func LoadRepoFromPath(path string) (ipfs_repo.Repo, error)
- func MockHostOption(mn p2p_mocknet.Mocknet) ipfs_p2p.HostOption
- func MultiaddrIsEqual(a Multiaddrs, b Multiaddrs) bool
- func NewDatastoreKeystore(ds datastore.Datastore) keystore.Keystore
- func NewIPFSMobile(ctx context.Context, repo *ipfs_mobile.RepoMobile, opts *MobileOptions) (*ipfs_mobile.IpfsMobile, error)
- func NewPubSubAPI(ctx context.Context, logger *zap.Logger, ps *p2p_pubsub.PubSub) ipfs_interface.PubSubAPI
- func OptionLocalRecord(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 ParseAndResolveMaddrs(ctx context.Context, logger *zap.Logger, addrs []string) ([]*peer.AddrInfo, error)
- func ResetExistingRepoIdentity(repo ipfs_repo.Repo) (ipfs_repo.Repo, error)
- func ResetRepoIdentity(c *ipfs_cfg.Config) error
- func TestingRDVP(ctx context.Context, t testing.TB, h host.Host) (*rendezvous.RendezvousService, func())
- func TestingRepo(t testing.TB, ctx context.Context, datastore ds.Datastore) ipfs_repo.Repo
- type BandwidthCollector
- type BertyConnManager
- func (c *BertyConnManager) GetPeerScore(p peer.ID) (score int, exist bool)
- func (c *BertyConnManager) RegisterEventBus(bus event.Bus) (err error)
- func (c *BertyConnManager) TagPeer(p peer.ID, tag string, score int)
- func (c *BertyConnManager) UntagPeer(p peer.ID, tag string)
- func (c *BertyConnManager) UpsertTag(p peer.ID, tag string, upsert func(int) int)
- type Config
- type ConnLifecycle
- type ConnMgr
- type CoreAPIMock
- type DHTNetworkMode
- type EventMonitor
- type EventTracer
- type EvtPeerTag
- type EvtPubSubTopic
- type 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 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 MobileOptions
- type Multiaddrs
- type PeeringService
- 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 PubsubMonitor
- type TestingAPIOpts
- type TypeTagAction
Constants ¶
const DefaultCloseTimeout = time.Second * 5
const ( // MaximumReconnectingDelay define the maximum time a peer is able to // reconnect, if reached peer will be remove from the store MaximumReconnectingDelay = time.Second * 30 )
Seed the random number generator.
We don't need good randomness, but we do need randomness.
const UnknownProtocol = "UnknownProtocol"
Variables ¶
var ( ConnLifecycleGracePeriod = time.Second ConnLifecyclePingTimeout = time.Second * 5 ConnPeerOfInterestMinScore = 20 )
var DefaultSwarmListeners = []string{
"/ip4/0.0.0.0/udp/0/quic",
"/ip6/::/udp/0/quic",
}
var ErrExpectedEOF = errors.New("red data when expecting EOF")
Functions ¶
func CreateBaseConfig ¶ added in v1.2.4
func CreateOrLoadMockedRepo ¶ added in v1.2.0
func CustomRoutingOption ¶
func InjectPubSubAPI ¶
func InjectPubSubAPI(api ipfs_interface.CoreAPI, ps ipfs_interface.PubSubAPI) ipfs_interface.CoreAPI
func LoadPlugins ¶ added in v1.2.4
func LoadPlugins(repoPath string) (*ipfs_loader.PluginLoader, error)
func MockHostOption ¶ added in v1.10.2
func MockHostOption(mn p2p_mocknet.Mocknet) ipfs_p2p.HostOption
func MultiaddrIsEqual ¶
func MultiaddrIsEqual(a Multiaddrs, b Multiaddrs) bool
MultiaddrIsEqual return true if both slice are equal
func NewIPFSMobile ¶
func NewIPFSMobile(ctx context.Context, repo *ipfs_mobile.RepoMobile, opts *MobileOptions) (*ipfs_mobile.IpfsMobile, error)
func NewPubSubAPI ¶
func NewPubSubAPI(ctx context.Context, logger *zap.Logger, ps *p2p_pubsub.PubSub) ipfs_interface.PubSubAPI
func OptionLocalRecord ¶
func OptionLocalRecord(node *ipfs_core.IpfsNode, api ipfs_interface.CoreAPI) error
OptionLocalRecord is given to CoreAPIOption.Options when the ipfs node setup
func ParseAndResolveIpfsAddr ¶
func ParseAndResolveMaddrs ¶
func ResetRepoIdentity ¶ added in v1.2.4
func TestingRDVP ¶
func TestingRDVP(ctx context.Context, t testing.TB, h host.Host) (*rendezvous.RendezvousService, func())
Types ¶
type BandwidthCollector ¶
type BandwidthCollector struct {
// contains filtered or unexported fields
}
func NewBandwidthCollector ¶
func NewBandwidthCollector(reporter *metrics.BandwidthCounter) *BandwidthCollector
func (*BandwidthCollector) Collect ¶
func (bc *BandwidthCollector) Collect(cmetric chan<- prometheus.Metric)
func (*BandwidthCollector) Describe ¶
func (bc *BandwidthCollector) Describe(ch chan<- *prometheus.Desc)
type BertyConnManager ¶
type BertyConnManager struct { connmgr.ConnManager // contains filtered or unexported fields }
keep track of peer of interest
func NewBertyConnManager ¶
func NewBertyConnManager(logger *zap.Logger, cm connmgr.ConnManager) *BertyConnManager
func (*BertyConnManager) GetPeerScore ¶
func (c *BertyConnManager) GetPeerScore(p peer.ID) (score int, exist bool)
func (*BertyConnManager) RegisterEventBus ¶
func (c *BertyConnManager) RegisterEventBus(bus event.Bus) (err error)
func (*BertyConnManager) TagPeer ¶
func (c *BertyConnManager) TagPeer(p peer.ID, tag string, score int)
TagPeer tags a peer with a string, associating a weight with the tag.
type ConnLifecycle ¶
type ConnLifecycle struct { connmgr.ConnManager // contains filtered or unexported fields }
func NewConnLifecycle ¶
func NewConnLifecycle(ctx context.Context, logger *zap.Logger, h host.Host, ps *PeeringService, lm *lifecycle.Manager, net *netmanager.NetManager) (*ConnLifecycle, error)
type ConnMgr ¶
type ConnMgr interface { connmgr.ConnManager }
type CoreAPIMock ¶
type CoreAPIMock interface { API() ExtendedCoreAPI PubSub() *pubsub.PubSub Tinder() *tinder.Service 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
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
TestingCoreAPIUsingMockNet returns a fully initialized mocked Core API with the given mocknet
type DHTNetworkMode ¶
type DHTNetworkMode int
const ( DHTNetworkLan DHTNetworkMode = iota DHTNetworkWan DHTNetworkDual )
type EventMonitor ¶
type EventMonitor int
const ( TypeEventMonitorPeerUnknown EventMonitor = iota TypeEventMonitorPeerJoined TypeEventMonitorPeerLeft )
type EventTracer ¶
func NewPubsubMonitor ¶
type EvtPeerTag ¶
type EvtPubSubTopic ¶
type EvtPubSubTopic struct { EventType EventMonitor Topic string PeerID peer.ID }
type ExtendedCoreAPI ¶
type ExtendedCoreAPI interface { ipfs_interface.CoreAPI ipfs_host.Host ConnMgr() ConnMgr }
func InjectPubSubCoreAPIExtendedAdapter ¶
func InjectPubSubCoreAPIExtendedAdapter(exapi ExtendedCoreAPI, ps ipfs_interface.PubSubAPI) ExtendedCoreAPI
func NewExtendedCoreAPI ¶
func NewExtendedCoreAPI(host ipfs_host.Host, api ipfs_interface.CoreAPI) ExtendedCoreAPI
func NewExtendedCoreAPIFromNode ¶
func NewExtendedCoreAPIFromNode(node *ipfs_core.IpfsNode) (ExtendedCoreAPI, error)
type HostCollector ¶
type HostCollector struct {
// contains filtered or unexported fields
}
func NewHostCollector ¶
func NewHostCollector(h host.Host) *HostCollector
func (*HostCollector) ClosedStream ¶
func (cc *HostCollector) ClosedStream(n network.Network, s network.Stream)
func (*HostCollector) Collect ¶
func (cc *HostCollector) Collect(cmetric chan<- prometheus.Metric)
func (*HostCollector) Connected ¶
func (cc *HostCollector) Connected(n network.Network, c network.Conn)
func (*HostCollector) Describe ¶
func (cc *HostCollector) Describe(ch chan<- *prometheus.Desc)
func (*HostCollector) Disconnected ¶
func (cc *HostCollector) Disconnected(n network.Network, c network.Conn)
func (*HostCollector) ListenClose ¶
func (cc *HostCollector) ListenClose(network.Network, ma.Multiaddr)
func (*HostCollector) OpenedStream ¶
func (cc *HostCollector) OpenedStream(n network.Network, s network.Stream)
type LocalRecord ¶
type LocalRecord struct {
// contains filtered or unexported fields
}
func (*LocalRecord) ClosedStream ¶
func (lr *LocalRecord) ClosedStream(network.Network, network.Stream)
called when a stream closed
func (*LocalRecord) Connected ¶
func (lr *LocalRecord) Connected(net network.Network, c network.Conn)
called when a connection opened
func (*LocalRecord) Disconnected ¶
func (lr *LocalRecord) Disconnected(network.Network, network.Conn)
called when a connection closed
func (*LocalRecord) Listen ¶
func (lr *LocalRecord) Listen(network.Network, ma.Multiaddr)
called when network starts listening on an addr
func (*LocalRecord) ListenClose ¶
func (lr *LocalRecord) ListenClose(network.Network, ma.Multiaddr)
called when network stops listening on an addr
func (*LocalRecord) OpenedStream ¶
func (lr *LocalRecord) OpenedStream(network.Network, network.Stream)
called when a stream opened
type MobileOptions ¶
type MobileOptions struct { IpfsConfigPatch Config HostOption ipfs_p2p.HostOption RoutingOption ipfs_p2p.RoutingOption HostConfigFunc ipfs_mobile.HostConfigFunc RoutingConfigFunc ipfs_mobile.RoutingConfigFunc ExtraOpts map[string]bool }
type Multiaddrs ¶
func NewMultiaddrs ¶
func NewMultiaddrs(m []ma.Multiaddr) Multiaddrs
func (Multiaddrs) Len ¶
func (ms Multiaddrs) Len() int
Len is the number of elements in the collection.
func (Multiaddrs) Less ¶
func (ms Multiaddrs) Less(i, j int) bool
Less reports whether the element with index i should sort before the element with index j.
func (Multiaddrs) Swap ¶
func (ms Multiaddrs) Swap(i, j int)
Swap swaps the elements with indexes i and j.
type PeeringService ¶
type PeeringService struct {
// contains filtered or unexported fields
}
PeeringService maintains connections to specified peers, reconnecting on disconnect with a back-off.
func NewPeeringService ¶
func NewPeeringService(logger *zap.Logger, host host.Host, fact backoff.BackoffFactory) *PeeringService
NewPeeringService constructs a new peering service. Peers can be added and removed immediately, but connections won't be formed until `Start` is called.
func (*PeeringService) AddPeer ¶
func (ps *PeeringService) AddPeer(info peer.AddrInfo)
AddPeer adds a peer to the peering service. This function may be safely called at any time: before the service is started, while running, or after it stops.
Add peer may also be called multiple times for the same peer. The new addresses will replace the old.
func (*PeeringService) ListPeers ¶
func (ps *PeeringService) ListPeers() []peer.AddrInfo
ListPeers lists peers in the peering service.
func (*PeeringService) RemovePeer ¶
func (ps *PeeringService) RemovePeer(id peer.ID)
RemovePeer removes a peer from the peering service. This function may be safely called at any time: before the service is started, while running, or after it stops.
func (*PeeringService) Start ¶
func (ps *PeeringService) Start() error
Start starts the peering service, connecting and maintaining connections to all registered peers. It returns an error if the service has already been stopped.
func (*PeeringService) Stop ¶
func (ps *PeeringService) Stop() error
Stop stops the peering service.
type PubSubAPI ¶
type PubSubAPI struct { *p2p_pubsub.PubSub // contains filtered or unexported fields }
func (*PubSubAPI) Peers ¶
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 ¶
func (ps *PubSubAPI) Subscribe(ctx context.Context, topic string, opts ...ipfs_iopts.PubSubSubscribeOption) (ipfs_interface.PubSubSubscription, error)
Subscribe to messages on a given topic
type PubsubMonitor ¶
type PubsubMonitor struct {
// contains filtered or unexported fields
}
func (*PubsubMonitor) Emit ¶
func (pt *PubsubMonitor) Emit(e *EvtPubSubTopic)
func (*PubsubMonitor) EventTracerOption ¶
func (pt *PubsubMonitor) EventTracerOption() ps.Option
func (*PubsubMonitor) Trace ¶
func (pt *PubsubMonitor) Trace(e *ps_pb.TraceEvent)
type TestingAPIOpts ¶
type TestingAPIOpts struct { Logger *zap.Logger Mocknet p2p_mocknet.Mocknet Datastore ds.Batching DiscoveryServer *tinder.MockDriverServer }
type TypeTagAction ¶
type TypeTagAction int
const ( TypeTagActionTag TypeTagAction = iota TypeTagActionUntag TypeTagActionUpsert )