-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Publish Pando-compatible metadata over GraphSync
Implement a publisher specific to Pando metadata that uses the CID of `RecordUpdate` as byte value of Pando metadata and exposes a GraphSync server that can resolve both Pando metadata, and the `RecordUpdate` CIDs. Decouple `statedb` from publication by changing the state interface to return the CID of `RecordUpdate`. This removes all libp2p and legs code from the `state` package. Instead, the publication is done on the controller itself upon `POST`s to `/complete/<workedby>` as a non-critical operation. This makes a better structured code in the context of Separation of Concerns. Relates to: - #342
- Loading branch information
Showing
13 changed files
with
621 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package publisher | ||
|
||
import ( | ||
"github.com/ipfs/go-ipfs/core/bootstrap" | ||
"github.com/libp2p/go-libp2p" | ||
"github.com/libp2p/go-libp2p-core/host" | ||
"github.com/libp2p/go-libp2p-core/peer" | ||
) | ||
|
||
type ( | ||
// Option represents a configurable parameter in a publisher. | ||
Option func(*options) error | ||
|
||
options struct { | ||
h host.Host | ||
btstrpCfg *bootstrap.BootstrapConfig | ||
topic string | ||
} | ||
) | ||
|
||
func apply(o ...Option) (*options, error) { | ||
opts := &options{ | ||
topic: "/pando/v0.0.1", | ||
} | ||
for _, apply := range o { | ||
if err := apply(opts); err != nil { | ||
return nil, err | ||
} | ||
} | ||
if opts.h == nil { | ||
var err error | ||
opts.h, err = libp2p.New() | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
return opts, nil | ||
} | ||
|
||
// WithBootstrapPeers optionally sets the list of peers to which to remain connected. | ||
// If unset, no bootstrapping will be performed. | ||
// | ||
// See: bootstrap.DefaultBootstrapConfig | ||
func WithBootstrapPeers(b ...peer.AddrInfo) Option { | ||
return func(o *options) error { | ||
addrCount := len(b) | ||
if addrCount > 0 { | ||
o.btstrpCfg = &bootstrap.BootstrapConfig{ | ||
MinPeerThreshold: addrCount, | ||
Period: bootstrap.DefaultBootstrapConfig.Period, | ||
ConnectionTimeout: bootstrap.DefaultBootstrapConfig.ConnectionTimeout, | ||
BootstrapPeers: func() []peer.AddrInfo { return b }, | ||
} | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
// WithHost sets the host on which the publisher is exposed. | ||
// If unset, a default libp2p host is created with random identity and listen addrtesses. | ||
// | ||
// See: libp2p.New. | ||
func WithHost(h host.Host) Option { | ||
return func(o *options) error { | ||
o.h = h | ||
return nil | ||
} | ||
} | ||
|
||
// WithTopic sets the gossipsub topic to which announcements are made. | ||
// Defaults to `/pando/v0.0.1` if unset. | ||
func WithTopic(topic string) Option { | ||
return func(o *options) error { | ||
o.topic = topic | ||
return nil | ||
} | ||
} |
Oops, something went wrong.