Skip to content

Commit

Permalink
Add option to configure extra gossip data for datatransfer publisher
Browse files Browse the repository at this point in the history
If the datatransfer publisher is configured with extra gossip data, then
that is included with pubsub messages.  It is used to allow lotus
chain-nodes to authenticate the message for relay.
  • Loading branch information
gammazero authored and masih committed Feb 8, 2022
1 parent 15ae807 commit 75130f4
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.16

require (
github.com/filecoin-project/go-data-transfer v1.14.0
github.com/filecoin-project/go-legs v0.2.7
github.com/filecoin-project/go-legs v0.2.8
github.com/filecoin-project/index-provider v0.2.1
github.com/filecoin-project/storetheindex v0.3.0
github.com/ipfs/go-cid v0.1.0
Expand Down
3 changes: 2 additions & 1 deletion cmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ github.com/filecoin-project/go-ds-versioning v0.0.0-20211206185234-508abd7c2aff/
github.com/filecoin-project/go-ds-versioning v0.1.1 h1:JiyBqaQlwC+UM0WhcBtVEeT3XrX59mQhT8U3p7nu86o=
github.com/filecoin-project/go-ds-versioning v0.1.1/go.mod h1:C9/l9PnB1+mwPa26BBVpCjG/XQCB0yj/q5CK2J8X1I4=
github.com/filecoin-project/go-indexer-core v0.2.8/go.mod h1:IagNfTdFuX4057kla43PjRCn3yBuUiZgIxuA0hTUamY=
github.com/filecoin-project/go-legs v0.2.7 h1:+b1BQv4QKkRNsDUE8Z4sEhLXhfVQ+iGpHhANpYqxJlA=
github.com/filecoin-project/go-legs v0.2.7/go.mod h1:NrdELuDbtAH8/xqRMgyOYms67aliQajExInLS6g8zFM=
github.com/filecoin-project/go-legs v0.2.8 h1:l76g9Yi7YzxNHwe60jPmQiezUUF0TMjqB/NP4+f23vU=
github.com/filecoin-project/go-legs v0.2.8/go.mod h1:NrdELuDbtAH8/xqRMgyOYms67aliQajExInLS6g8zFM=
github.com/filecoin-project/go-state-types v0.1.0 h1:9r2HCSMMCmyMfGyMKxQtv0GKp6VT/m5GgVk8EhYbLJU=
github.com/filecoin-project/go-state-types v0.1.0/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g=
github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe h1:dF8u+LEWeIcTcfUcCf3WFVlc81Fr2JKg8zPzIbBDKDw=
Expand Down
20 changes: 14 additions & 6 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ type Engine struct {
// indexed data, etc.)
ds datastore.Batching

publisherKind config.PublisherKind
publisher legs.Publisher
publisherKind config.PublisherKind
publisher legs.Publisher
extraGossipData []byte

httpPublisherCfg *config.HttpPublisher

Expand Down Expand Up @@ -98,7 +99,13 @@ var _ provider.Interface = (*Engine)(nil)
//
// The engine must be started via Engine.Start before use and discarded via Engine.Shutdown when no longer needed.
// See: Engine.Start, Engine.Shutdown.
func New(ingestCfg config.Ingest, privKey crypto.PrivKey, dt dt.Manager, h host.Host, ds datastore.Batching, retAddrs []string) (*Engine, error) {
func New(ingestCfg config.Ingest, privKey crypto.PrivKey, dt dt.Manager, h host.Host, ds datastore.Batching, retAddrs []string, options ...Option) (*Engine, error) {
var cfg engineConfig
err := cfg.apply(options)
if err != nil {
return nil, err
}

if len(retAddrs) == 0 {
retAddrs = []string{h.Addrs()[0].String()}
log.Infof("Retrieval address not configured, using %s", retAddrs[0])
Expand All @@ -122,6 +129,7 @@ func New(ingestCfg config.Ingest, privKey crypto.PrivKey, dt dt.Manager, h host.
addrs: retAddrs,
httpPublisherCfg: &ingestCfg.HttpPublisher,
publisherKind: ingestCfg.PublisherKind,
extraGossipData: cfg.extraGossipData,
}

e.cachelsys = e.cacheLinkSystem()
Expand All @@ -135,13 +143,13 @@ func New(ingestCfg config.Ingest, privKey crypto.PrivKey, dt dt.Manager, h host.
// config.ProviderServer as retrieval addresses in advertisements.
//
// See: engine.New .
func NewFromConfig(cfg config.Config, dt dt.Manager, host host.Host, ds datastore.Batching) (*Engine, error) {
func NewFromConfig(cfg config.Config, dt dt.Manager, host host.Host, ds datastore.Batching, options ...Option) (*Engine, error) {
log.Info("Instantiating a new index provider engine")
privKey, err := cfg.Identity.DecodePrivateKey("")
if err != nil {
return nil, fmt.Errorf("cannot decode private key: %s", err)
}
return New(cfg.Ingest, privKey, dt, host, ds, cfg.ProviderServer.RetrievalMultiaddrs)
return New(cfg.Ingest, privKey, dt, host, ds, cfg.ProviderServer.RetrievalMultiaddrs, options...)
}

// Start starts the engine by instantiating the internal storage and joins the configured gossipsub
Expand Down Expand Up @@ -175,7 +183,7 @@ func (e *Engine) Start(ctx context.Context) error {
}
e.publisher, err = httpsync.NewPublisher(addr, e.lsys, e.host.ID(), e.privKey)
} else {
e.publisher, err = dtsync.NewPublisherFromExisting(e.dataTransfer, e.host, e.pubSubTopic, e.lsys)
e.publisher, err = dtsync.NewPublisherFromExisting(e.dataTransfer, e.host, e.pubSubTopic, e.lsys, dtsync.WithExtraData(e.extraGossipData))
}
if err != nil {
return fmt.Errorf("cannot initialize publisher: %s", err)
Expand Down
32 changes: 32 additions & 0 deletions engine/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package engine

import "fmt"

// engineConfig contains all options for engineConfiguring Engine.
type engineConfig struct {
extraGossipData []byte
}

type Option func(*engineConfig) error

// apply applies the given options to this engineConfig.
func (c *engineConfig) apply(opts []Option) error {
for i, opt := range opts {
if err := opt(c); err != nil {
return fmt.Errorf("option %d failed: %s", i, err)
}
}
return nil
}

// WithExtraGossipData supplies extra data to include in the pubsub announcement.
func WithExtraGossipData(extraData []byte) Option {
return func(c *engineConfig) error {
if len(extraData) != 0 {
// Make copy for safety.
c.extraGossipData = make([]byte, len(extraData))
copy(c.extraGossipData, extraData)
}
return nil
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.16

require (
github.com/filecoin-project/go-data-transfer v1.14.0
github.com/filecoin-project/go-legs v0.2.7
github.com/filecoin-project/go-legs v0.2.8
github.com/filecoin-project/go-state-types v0.1.0
github.com/filecoin-project/storetheindex v0.3.0
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ github.com/filecoin-project/go-ds-versioning v0.0.0-20211206185234-508abd7c2aff/
github.com/filecoin-project/go-ds-versioning v0.1.1 h1:JiyBqaQlwC+UM0WhcBtVEeT3XrX59mQhT8U3p7nu86o=
github.com/filecoin-project/go-ds-versioning v0.1.1/go.mod h1:C9/l9PnB1+mwPa26BBVpCjG/XQCB0yj/q5CK2J8X1I4=
github.com/filecoin-project/go-indexer-core v0.2.8/go.mod h1:IagNfTdFuX4057kla43PjRCn3yBuUiZgIxuA0hTUamY=
github.com/filecoin-project/go-legs v0.2.7 h1:+b1BQv4QKkRNsDUE8Z4sEhLXhfVQ+iGpHhANpYqxJlA=
github.com/filecoin-project/go-legs v0.2.7/go.mod h1:NrdELuDbtAH8/xqRMgyOYms67aliQajExInLS6g8zFM=
github.com/filecoin-project/go-legs v0.2.8 h1:l76g9Yi7YzxNHwe60jPmQiezUUF0TMjqB/NP4+f23vU=
github.com/filecoin-project/go-legs v0.2.8/go.mod h1:NrdELuDbtAH8/xqRMgyOYms67aliQajExInLS6g8zFM=
github.com/filecoin-project/go-state-types v0.1.0 h1:9r2HCSMMCmyMfGyMKxQtv0GKp6VT/m5GgVk8EhYbLJU=
github.com/filecoin-project/go-state-types v0.1.0/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g=
github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe h1:dF8u+LEWeIcTcfUcCf3WFVlc81Fr2JKg8zPzIbBDKDw=
Expand Down

0 comments on commit 75130f4

Please sign in to comment.