Categorygithub.com/filecoin-project/go-legs
modulepackage
0.4.17
Repository: https://github.com/filecoin-project/go-legs.git
Documentation: pkg.go.dev

# README

legs 🦵

Legs is an interface for go-data-transfer, providing a 1:1 mechanism for maintaining a synchronized IPLD dag of data between a publisher and a subscriber's current state for that publisher.

Usage

Typically an application will be either a provider or a subscriber, but may be both.

Publisher

Create a legs publisher. Update its root to cause it to publish.

pub, err :=  NewPublisher(host, dsstore, lsys, "/legs/topic")
if err != nil {
	panic(err)
}
...
// Publish updated root.
err = publisher.UpdateRoot(ctx, lnk.(cidlink.Link).Cid)
if err != nil {
	panic(err)
}

Subscriber

The Subscriber handles subscribing to a topic, reading messages from the topic and tracking the state of each publisher.

Create a Subscriber:

sub, err := legs.NewSubscriber(dstHost, dstStore, dstLnkS, "/legs/topic", nil)
if err != nil {
	panic(err)
}

Optionally, request notification of updates:

watcher, cancelWatcher := sub.OnSyncFinished()
defer cancelWatcher()
go watch(watcher)

func watch(notifications <-chan legs.SyncFinished) {
    for {
        syncFinished := <-notifications
        // newHead is now available in the local dataStore
    }
}

To shutdown a Subscriber, call its Close() method.

A Subscriber can be created with a function that determines if the Subscriber accepts or rejects messages from a publisher. Use the AllowPeer option to specify the function.

sub, err := legs.NewSubscriber(dstHost, dstStore, dstLnkS, "/legs/topic", nil, legs.AllowPeer(allowPeer))

The Subscriber keeps track of the latest head for each publisher that it has synced. This avoids exchanging the whole DAG from scratch in every update and instead downloads only the part that has not been synced. This value is not persisted as part of the library. If you want to start a Subscriber which has already partially synced with a provider you can use the SetLatestSync method:

sub, err := legs.NewSubscriber(dstHost, dstStore, dstLnkS, "/legs/topic", nil)
if err != nil {
    panic(err)
}
// Set up partially synced publishers
if err = sub.SetLatestSync(peerID1, lastSync1) ; err != nil {
    panic(err)
}
if err = sub.SetLatestSync(peerID2, lastSync2) ; err != nil {
    panic(err)
}
if err = sub.SetLatestSync(peerID3, lastSync3) ; err != nil {
    panic(err)
}

License

Legs is dual-licensed under Apache 2.0 and MIT terms:

Apache License, Version 2.0, (LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
Package mautil provider multiaddr utility functions.
No description provided by the author
No description provided by the author

# Functions

AddrTTL sets the peerstore address time-to-live for addresses discovered from pubsub messages.
AllowPeer sets the function that determines whether to allow or reject messages from a peer.
No description provided by the author
BlockHook adds a hook that is run when a block is received via Subscriber.Sync along with a SegmentSyncActions to control the sync flow if segmented sync is enabled.
DtManager provides an existing datatransfer manager.
ExploreRecursiveWithStop builds a selector that recursively syncs a DAG until the link stopLnk is seen.
ExploreRecursiveWithStopNode builds a selector that recursively syncs a DAG until the link stopLnk is seen.
FilterIPs removes any private, loopback, or unspecified IP multiaddrs from addresses supplied in announce messages.
HttpClient provides Subscriber with an existing http client.
IdleHandlerTTL configures the time after which idle handlers are removed.
LegSelector is a convenient function that returns the selector used by leg subscribers LegSelector is a "recurse all" selector that provides conditions to stop the traversal at a specific link (stopAt).
NewSubscriber creates a new Subscriber that process pubsub messages.
RateLimiter configures a function that is called for each sync to get the rate limiter for a specific peer.
ResendAnnounce determines whether to resend the direct announce mesages (those that are not received via pubsub) over pubsub.
ScopedBlockHook is the equivalent of BlockHook option but only applied to a single sync.
ScopedRateLimiter set a rate limiter to use for a singel sync.
ScopedSegmentDepthLimit is the equivalent of SegmentDepthLimit option but only applied to a single sync.
SegmentDepthLimit sets the maximum recursion depth limit for a segmented sync.
SyncRecursionLimit sets the recursion limit of the background syncing process.
Topic provides an existing pubsub topic.
UseLatestSyncHandler sets the latest sync handler to use.

# Structs

No description provided by the author
Subscriber creates a single pubsub subscriber that receives messages from a gossip pubsub topic, and creates a stateful message handler for each message source peer.
SyncFinished notifies an OnSyncFinished reader that a specified peer completed a sync.

# Interfaces

LatestSyncHandler defines how to store the latest synced cid for a given peer and how to fetch it.
Publisher is an interface for updating the published dag.
No description provided by the author
Syncer is the interface used to sync with a data source.

# Type aliases

AllowPeerFunc is the signature of a function given to Subscriber that determines whether to allow or reject messages originating from a peer passed into the function.
BlockHookFunc is the signature of a function that is called when a received.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author