ipfsutil

package
v2.439.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2022 License: Apache-2.0, MIT Imports: 67 Imported by: 0

Documentation

Overview

Package ipfsutil contains helpers around IPFS (logging, datastore, networking, core API, ...).

Index

Constants

View Source
const DefaultCloseTimeout = time.Second * 5
View Source
const (
	MDNSServiceName = p2p_mdns.ServiceName
)
View Source
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.

View Source
const UnknownProtocol = "UnknownProtocol"

Variables

View Source
var (
	ConnLifecycleGracePeriod   = time.Second
	ConnLifecyclePingTimeout   = time.Second * 5
	ConnPeerOfInterestMinScore = 20
)
View Source
var DefaultSwarmListeners = []string{
	"/ip4/0.0.0.0/tcp/0",
	"/ip6/::/tcp/0",
}
View Source
var DiscoveryTimeout = time.Second * 30
View Source
var ErrExpectedEOF = errors.New("red data when expecting EOF")

Functions

func CreateMockedRepo added in v2.57.1

func CreateMockedRepo(dstore ipfs_ds.Batching) (ipfs_repo.Repo, error)

func CustomRoutingOption added in v2.257.0

func CustomRoutingOption(mode p2p_dht.ModeOpt, opts ...p2p_dht.Option) func(
	ctx context.Context,
	host p2p_host.Host,
	dstore ds.Batching,
	validator p2p_record.Validator,
	bootstrapPeers ...p2p_peer.AddrInfo,
) (p2p_routing.Routing, error)

func DiscoveryHandler added in v2.346.0

func DiscoveryHandler(ctx context.Context, l *zap.Logger, h host.Host) p2p_mdns.Notifee

func EnableConnLogger added in v2.97.0

func EnableConnLogger(ctx context.Context, logger *zap.Logger, h host.Host)

func FullClose added in v2.212.4

func FullClose(s network.Stream) error

func GetMulticastInterfaces added in v2.354.3

func GetMulticastInterfaces() ([]net.Interface, error)

func InjectPubSubAPI added in v2.109.0

func LoadRepoFromPath added in v2.57.1

func LoadRepoFromPath(path string, key []byte, salt []byte) (ipfs_repo.Repo, error)

func MultiaddrIsEqual added in v2.210.1

func MultiaddrIsEqual(a Multiaddrs, b Multiaddrs) bool

MultiaddrIsEqual return true if both slice are equal

func NewDatastoreKeystore

func NewDatastoreKeystore(ds datastore.Datastore) keystore.Keystore

func NewIPFSMobile added in v2.257.0

func NewIPFSMobile(ctx context.Context, repo *ipfs_mobile.RepoMobile, opts *MobileOptions) (*ipfs_mobile.IpfsMobile, error)

func NewMdnsService added in v2.346.0

func NewMdnsService(logger *zap.Logger, host host.Host, serviceName string, notifee p2p_mdns.Notifee) p2p_mdns.Service

func NewPubSubAPI added in v2.109.0

func NewPubSubAPI(ctx context.Context, logger *zap.Logger, ps *p2p_pubsub.PubSub) ipfs_interface.PubSubAPI

func OptionLocalRecord added in v2.94.0

func OptionLocalRecord(node *ipfs_core.IpfsNode, api ipfs_interface.CoreAPI) error

OptionLocalRecord is given to CoreAPIOption.Options when the ipfs node setup

func ParseAddr added in v2.138.0

func ParseAddr(addr string) (ma.Multiaddr, error)

func ParseAddrs added in v2.138.0

func ParseAddrs(addrs ...string) ([]ma.Multiaddr, error)

func ParseAndResolveIpfsAddr added in v2.53.1

func ParseAndResolveIpfsAddr(ctx context.Context, addr string) (*peer.AddrInfo, error)

func ParseAndResolveMaddrs added in v2.278.0

func ParseAndResolveMaddrs(ctx context.Context, logger *zap.Logger, addrs []string) ([]*peer.AddrInfo, error)

func ResetExistingRepoIdentity added in v2.322.0

func ResetExistingRepoIdentity(repo ipfs_repo.Repo, path string, key []byte, salt []byte) (ipfs_repo.Repo, error)

func SetNetDriver added in v2.346.0

func SetNetDriver(n Net)

func TestingRDVP added in v2.50.0

func TestingRDVP(ctx context.Context, t testing.TB, h host.Host) (*rendezvous.RendezvousService, func())

func TestingRepo added in v2.31.1

func TestingRepo(t testing.TB, ctx context.Context, datastore ds.Datastore) ipfs_repo.Repo

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 BertyConnManager added in v2.414.0

type BertyConnManager struct {
	connmgr.ConnManager
	// contains filtered or unexported fields
}

keep track of peer of interest

func NewBertyConnManager added in v2.414.0

func NewBertyConnManager(logger *zap.Logger, cm connmgr.ConnManager) *BertyConnManager

func (*BertyConnManager) GetPeerScore added in v2.414.0

func (c *BertyConnManager) GetPeerScore(p peer.ID) (score int, exist bool)

func (*BertyConnManager) RegisterEventBus added in v2.414.0

func (c *BertyConnManager) RegisterEventBus(bus event.Bus) (err error)

func (*BertyConnManager) TagPeer added in v2.414.0

func (c *BertyConnManager) TagPeer(p peer.ID, tag string, score int)

TagPeer tags a peer with a string, associating a weight with the tag.

func (*BertyConnManager) UntagPeer added in v2.414.0

func (c *BertyConnManager) UntagPeer(p peer.ID, tag string)

Untag removes the tagged value from the peer.

func (*BertyConnManager) UpsertTag added in v2.414.0

func (c *BertyConnManager) UpsertTag(p peer.ID, tag string, upsert func(int) int)

The connection manager calls the upsert function supplying the current value of the tag (or zero if inexistent). The return value is used as the new value of the tag.

type Config added in v2.257.0

type Config func(cfg *ipfs_config.Config) ([]p2p.Option, error)

type ConnLifecycle added in v2.414.0

type ConnLifecycle struct {
	connmgr.ConnManager
	// contains filtered or unexported fields
}

func NewConnLifecycle added in v2.414.0

func NewConnLifecycle(ctx context.Context, logger *zap.Logger, h host.Host, ps *PeeringService, lm *lifecycle.Manager) (*ConnLifecycle, error)

type ConnMgr added in v2.70.0

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, 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 EventMonitor added in v2.210.1

type EventMonitor int
const (
	TypeEventMonitorPeerUnknown EventMonitor = iota
	TypeEventMonitorPeerJoined
	TypeEventMonitorPeerLeft
)

type EventTracer added in v2.210.1

type EventTracer interface {
	EventTracerOption() ps.Option
}

func NewPubsubMonitor added in v2.210.1

func NewPubsubMonitor(l *zap.Logger, h host.Host) (EventTracer, error)

type EvtPeerTag added in v2.414.0

type EvtPeerTag struct {
	Kind TypeTagAction

	Peer  peer.ID
	Tag   string
	Diff  int
	Total int
}

type EvtPubSubTopic added in v2.210.1

type EvtPubSubTopic struct {
	EventType EventMonitor
	Topic     string
	PeerID    peer.ID
}

type ExtendedCoreAPI added in v2.59.0

type ExtendedCoreAPI interface {
	ipfs_interface.CoreAPI
	ipfs_host.Host

	ConnMgr() ConnMgr
}

func InjectPubSubCoreAPIExtendedAdapter added in v2.302.0

func InjectPubSubCoreAPIExtendedAdapter(exapi ExtendedCoreAPI, ps ipfs_interface.PubSubAPI) ExtendedCoreAPI

func NewExtendedCoreAPI added in v2.59.0

func NewExtendedCoreAPI(host ipfs_host.Host, api ipfs_interface.CoreAPI) ExtendedCoreAPI

func NewExtendedCoreAPIFromNode added in v2.257.0

func NewExtendedCoreAPIFromNode(node *ipfs_core.IpfsNode) (ExtendedCoreAPI, error)

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 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 MobileOptions added in v2.257.0

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 added in v2.210.1

type Multiaddrs []ma.Multiaddr

func NewMultiaddrs added in v2.210.1

func NewMultiaddrs(m []ma.Multiaddr) Multiaddrs

func (Multiaddrs) Len added in v2.210.1

func (ms Multiaddrs) Len() int

Len is the number of elements in the collection.

func (Multiaddrs) Less added in v2.210.1

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 added in v2.210.1

func (ms Multiaddrs) Swap(i, j int)

Swap swaps the elements with indexes i and j.

type Net added in v2.346.0

type Net interface {
	NetAddrs
	NetInterface
}

type NetAddrs added in v2.346.0

type NetAddrs interface {
	InterfaceAddrs() ([]net.Addr, error)
}

type NetInterface added in v2.346.0

type NetInterface interface {
	Interfaces() ([]net.Interface, error)
}

type PeeringService added in v2.414.0

type PeeringService struct {
	// contains filtered or unexported fields
}

PeeringService maintains connections to specified peers, reconnecting on disconnect with a back-off.

func NewPeeringService added in v2.414.0

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 added in v2.414.0

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 added in v2.414.0

func (ps *PeeringService) ListPeers() []peer.AddrInfo

ListPeers lists peers in the peering service.

func (*PeeringService) RemovePeer added in v2.414.0

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 added in v2.414.0

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 added in v2.414.0

func (ps *PeeringService) Stop() error

Stop stops the peering service.

type PubSubAPI added in v2.109.0

type PubSubAPI struct {
	*p2p_pubsub.PubSub
	// contains filtered or unexported fields
}

func (*PubSubAPI) Ls added in v2.109.0

func (ps *PubSubAPI) Ls(ctx context.Context) ([]string, error)

Ls lists subscribed topics by name

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) Publish added in v2.109.0

func (ps *PubSubAPI) Publish(ctx context.Context, topic string, msg []byte) error

Publish a message to a given pubsub topic

func (*PubSubAPI) Subscribe added in v2.109.0

Subscribe to messages on a given topic

type PubsubMonitor added in v2.210.1

type PubsubMonitor struct {
	// contains filtered or unexported fields
}

func (*PubsubMonitor) Emit added in v2.210.1

func (pt *PubsubMonitor) Emit(e *EvtPubSubTopic)

func (*PubsubMonitor) EventTracerOption added in v2.210.1

func (pt *PubsubMonitor) EventTracerOption() ps.Option

func (*PubsubMonitor) Trace added in v2.210.1

func (pt *PubsubMonitor) Trace(e *ps_pb.TraceEvent)

type TestingAPIOpts added in v2.50.0

type TestingAPIOpts struct {
	Logger    *zap.Logger
	Mocknet   p2p_mocknet.Mocknet
	RDVPeer   p2p_peer.AddrInfo
	Datastore ds.Batching
}

type TypeTagAction added in v2.414.0

type TypeTagAction int
const (
	TypeTagActionTag TypeTagAction = iota
	TypeTagActionUntag
	TypeTagActionUpsert
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL