Skip to content

Commit

Permalink
Update dependencies (#421)
Browse files Browse the repository at this point in the history
- Update dependencies (go-libipni, go-libp2p, go-graphsync, etc.)
- Use boxo instead of kubo for bootstrapping
- Do not save backup bootstrap peers in datastore
- Additional error checks
- Minor log formatting
  • Loading branch information
gammazero committed Nov 9, 2023
1 parent 893a2a2 commit b5a3c45
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 144 deletions.
53 changes: 1 addition & 52 deletions cmd/provider/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
Expand All @@ -11,13 +10,11 @@ import (
datatransfer "github.com/filecoin-project/go-data-transfer/v2/impl"
dtnetwork "github.com/filecoin-project/go-data-transfer/v2/network"
gstransport "github.com/filecoin-project/go-data-transfer/v2/transport/graphsync"
"github.com/ipfs/go-datastore"
"github.com/ipfs/boxo/bootstrap"
leveldb "github.com/ipfs/go-ds-leveldb"
gsimpl "github.com/ipfs/go-graphsync/impl"
gsnet "github.com/ipfs/go-graphsync/network"
logging "github.com/ipfs/go-log/v2"
kuboconfig "github.com/ipfs/kubo/config"
"github.com/ipfs/kubo/core/bootstrap"
"github.com/ipld/go-car/v2"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/ipni/index-provider/cardatatransfer"
Expand All @@ -28,7 +25,6 @@ import (
droutingserver "github.com/ipni/index-provider/server/delegatedrouting/server"
"github.com/ipni/index-provider/supplier"
"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/mitchellh/go-homedir"
"github.com/multiformats/go-multiaddr"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -73,8 +69,6 @@ var daemonFlags = []cli.Flag{
},
}

var tempBootstrapPeersKey = datastore.NewKey("/local/temp_bootstrap_peers")

func daemonCommand(cctx *cli.Context) error {
err := logging.SetLogLevel("*", cctx.String("log-level"))
if err != nil {
Expand Down Expand Up @@ -224,51 +218,6 @@ func daemonCommand(cctx *cli.Context) error {
bootCfg := bootstrap.BootstrapConfigWithPeers(addrs)
bootCfg.MinPeerThreshold = cfg.Bootstrap.MinimumPeers

if ds == nil {
bootCfg.LoadBackupBootstrapPeers = func(_ context.Context) []peer.AddrInfo { return nil }
bootCfg.SaveBackupBootstrapPeers = func(_ context.Context, _ []peer.AddrInfo) {}
} else {
bootCfg.LoadBackupBootstrapPeers = func(ctx context.Context) []peer.AddrInfo {
data, err := ds.Get(ctx, tempBootstrapPeersKey)
if err != nil {
if !errors.Is(err, datastore.ErrNotFound) {
log.Errorw("failed to read temp bootstrap peers", "err", err)
}
return nil
}
if len(data) == 0 {
return nil
}
var addrs []string
if err = json.Unmarshal(data, &addrs); err != nil {
log.Errorw("failed to unmarshal temp bootstrap peers", "err", err)
return nil
}
peerList, err := kuboconfig.ParseBootstrapPeers(addrs)
if err != nil {
log.Errorw("failed to parse temp bootstrap peers", "err", err)
return nil
}
return peerList
}

bootCfg.SaveBackupBootstrapPeers = func(ctx context.Context, peerList []peer.AddrInfo) {
data, err := json.Marshal(kuboconfig.BootstrapPeerStrings(peerList))
if err != nil {
log.Errorw("failed to marshal temp bootstrap peers", "err", err)
return
}
if err = ds.Put(ctx, tempBootstrapPeersKey, data); err != nil {
log.Errorw("failed to write temp bootstrap peers", "err", err)
return
}
if err = ds.Sync(ctx, tempBootstrapPeersKey); err != nil {
log.Errorw("failed to sync datastore", "err", err)
return
}
}
}

bootstrapper, err := bootstrap.Bootstrap(peerID, h, nil, bootCfg)
if err != nil {
return fmt.Errorf("bootstrap failed: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/provider/internal/config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func CreateIdentity(out io.Writer) (Identity, error) {
if err != nil {
return ident, err
}
ident.PeerID = id.Pretty()
ident.PeerID = id.String()
fmt.Fprintf(out, "peer identity: %s\n", ident.PeerID)
return ident, nil
}
6 changes: 5 additions & 1 deletion delegatedrouting/chunker.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ type cidsChunk struct {

func defaultNonceGen() []byte {
nonce := make([]byte, 8)
rand.Read(nonce)
_, err := rand.Read(nonce)
if err != nil {
// Do not allow non-random nonce to be created.
panic(err.Error())
}
return nonce
}

Expand Down
7 changes: 1 addition & 6 deletions delegatedrouting/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (listener *Listener) PutIPNS(ctx context.Context, name ipns.Name, record *i
return errors.New("unsupported put ipns request")
}

func (listener *Listener) FindPeers(ctx context.Context, pid peer.ID, limit int) (iter.ResultIter[types.Record], error) {
func (listener *Listener) FindPeers(ctx context.Context, pid peer.ID, limit int) (iter.ResultIter[*types.PeerRecord], error) {
log.Warn("Received unsupported FindPeers request")
return nil, errors.New("unsupported find peers request")
}
Expand All @@ -293,11 +293,6 @@ func (listener *Listener) FindProviders(ctx context.Context, key cid.Cid, limit
return nil, errors.New("unsupported find providers request")
}

func (listener *Listener) Provide(ctx context.Context, req *server.WriteProvideRequest) (iter.ResultIter[types.Record], error) {
log.Warn("Received unsupported Provide request")
return nil, errors.New("unsupported provide request")
}

func (listener *Listener) ProvideBitswap(ctx context.Context, req *server.BitswapWriteProvideRequest) (time.Duration, error) {

Check failure on line 296 in delegatedrouting/listener.go

View workflow job for this annotation

GitHub Actions / go-check / All

server.BitswapWriteProvideRequest is deprecated: protocol-agnostic provide is being worked on in [IPIP-378]: (SA1019)
cids := req.Keys
pid := req.ID
Expand Down
3 changes: 2 additions & 1 deletion delegatedrouting/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,8 @@ func TestMissingCidTimestampsBackfilledOnIntialisation(t *testing.T) {

s.Close()

drouting.WrappedDatastore(listener1).Delete(ctx, datastore.NewKey("tc/"+testCid1.String()))
err = drouting.WrappedDatastore(listener1).Delete(ctx, datastore.NewKey("tc/"+testCid1.String()))
require.NoError(t, err)

listener2, err := drouting.New(ctx, mockEng, ttl, chunkSize, snapshotSize, "", nil, ds, testNonceGen)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (e *Engine) Start(ctx context.Context) error {

e.publisher, err = e.newPublisher()
if err != nil {
log.Errorw("Failed to instantiate publisher", "err", err, "kind", e.pubKind)
log.Errorw("Failed to create publisher", "err", err)
return err
}

Expand Down Expand Up @@ -206,7 +206,7 @@ func (e *Engine) newPublisher() (dagsync.Publisher, error) {
}
return dtPub, nil
}
return nil, fmt.Errorf("unknown publisher kind: %s", e.pubKind)
return nil, fmt.Errorf("unknown publisher kind %s, expecting one of %v", e.pubKind, []PublisherKind{HttpPublisher, Libp2pPublisher, Libp2pHttpPublisher, DataTransferPublisher})
}

func (e *Engine) createSenders() ([]announce.Sender, error) {
Expand Down
4 changes: 3 additions & 1 deletion engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ func TestEngine_PublishLocal(t *testing.T) {
require.NoError(t, err)
err = subject.Start(ctx)
require.NoError(t, err)
defer subject.Shutdown()
t.Cleanup(func() {
require.NoError(t, subject.Shutdown())
})

chunkLnk, err := subject.Chunker().Chunk(ctx, provider.SliceMultihashIterator(mhs))
require.NoError(t, err)
Expand Down
53 changes: 27 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
github.com/golang/mock v1.6.0
github.com/hashicorp/go-multierror v1.1.1
github.com/ipfs/boxo v0.13.1
github.com/ipfs/boxo v0.15.0
github.com/ipfs/go-cid v0.4.1
github.com/ipfs/go-datastore v0.6.0
github.com/ipfs/go-ds-leveldb v0.5.0
github.com/ipfs/go-graphsync v0.15.1
github.com/ipfs/go-graphsync v0.16.0
github.com/ipfs/go-ipfs-blockstore v1.3.0
github.com/ipfs/go-log/v2 v2.5.1
github.com/ipfs/kubo v0.22.0
github.com/ipld/go-car/v2 v2.13.1
github.com/ipld/go-codec-dagpb v1.6.0
github.com/ipld/go-ipld-adl-hamt v0.0.0-20220616142416-9004dbd839e0
github.com/ipld/go-ipld-prime v0.21.0
github.com/ipni/go-libipni v0.5.4
github.com/libp2p/go-libp2p v0.31.0
github.com/libp2p/go-libp2p-pubsub v0.9.3
github.com/ipni/go-libipni v0.5.5
github.com/libp2p/go-libp2p v0.32.0
github.com/libp2p/go-libp2p-pubsub v0.10.0
github.com/mitchellh/go-homedir v1.1.0
github.com/multiformats/go-multiaddr v0.11.0
github.com/multiformats/go-multiaddr v0.12.0
github.com/multiformats/go-multicodec v0.9.0
github.com/multiformats/go-multihash v0.2.3
github.com/prometheus/client_golang v1.16.0
Expand All @@ -40,29 +39,32 @@ require (
github.com/filecoin-project/go-amt-ipld/v4 v4.0.0 // indirect
github.com/filecoin-project/go-hamt-ipld/v3 v3.1.0 // indirect
github.com/filecoin-project/go-state-types v0.9.9 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gammazero/channelqueue v0.2.1 // indirect
github.com/gammazero/deque v0.2.1 // indirect
github.com/google/pprof v0.0.0-20230821062121-407c9e7a662f // indirect
github.com/google/pprof v0.0.0-20231023181126-ff6d637d2a7b // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.5 // indirect
github.com/ipfs/go-bitfield v1.1.0 // indirect
github.com/ipfs/go-ipfs-files v0.3.0 // indirect
github.com/ipfs/go-libipfs v0.7.0 // indirect
github.com/libp2p/go-libp2p-record v0.2.0 // indirect
github.com/libp2p/go-libp2p-routing-helpers v0.7.1 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/onsi/ginkgo/v2 v2.11.0 // indirect
github.com/onsi/ginkgo/v2 v2.13.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-20 v0.3.3 // indirect
github.com/quic-go/quic-go v0.38.1 // indirect
github.com/quic-go/webtransport-go v0.5.3 // indirect
github.com/quic-go/qtls-go1-20 v0.3.4 // indirect
github.com/quic-go/quic-go v0.39.3 // indirect
github.com/quic-go/webtransport-go v0.6.0 // indirect
github.com/samber/lo v1.36.0 // indirect
github.com/whyrusleeping/cbor-gen v0.0.0-20230818171029-f91ae536ca25 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/dig v1.17.0 // indirect
go.uber.org/fx v1.20.0 // indirect
go.uber.org/dig v1.17.1 // indirect
go.uber.org/fx v1.20.1 // indirect
go.uber.org/mock v0.3.0 // indirect
go4.org v0.0.0-20230225012048-214862532bf5 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
)
Expand Down Expand Up @@ -102,7 +104,7 @@ require (
github.com/hannahhoward/go-pubsub v0.0.0-20200423002714-8d62886cc36e // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/huin/goupnp v1.2.0 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/ipfs/bbloom v0.0.4 // indirect
github.com/ipfs/go-block-format v0.2.0 // indirect
github.com/ipfs/go-blockservice v0.5.1 // indirect
Expand All @@ -111,7 +113,6 @@ require (
github.com/ipfs/go-ipfs-util v0.0.3 // indirect
github.com/ipfs/go-ipld-cbor v0.1.0 // indirect
github.com/ipfs/go-ipld-format v0.6.0 // indirect
github.com/ipfs/go-ipld-legacy v0.2.1 // indirect
github.com/ipfs/go-log v1.0.5 // indirect
github.com/ipfs/go-metrics-interface v0.0.1 // indirect
github.com/ipfs/go-peertaskqueue v0.8.1 // indirect
Expand All @@ -120,7 +121,7 @@ require (
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/compress v1.17.2 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/koron/go-ssdp v0.0.4 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
Expand All @@ -133,9 +134,9 @@ require (
github.com/libp2p/go-reuseport v0.4.0 // indirect
github.com/libp2p/go-yamux/v4 v4.0.1 // indirect
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/miekg/dns v1.1.55 // indirect
github.com/miekg/dns v1.1.56 // indirect
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect
github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect
Expand All @@ -146,7 +147,7 @@ require (
github.com/multiformats/go-multiaddr-dns v0.3.1 // indirect
github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect
github.com/multiformats/go-multibase v0.2.0 // indirect
github.com/multiformats/go-multistream v0.4.1 // indirect
github.com/multiformats/go-multistream v0.5.0 // indirect
github.com/opencontainers/runtime-spec v1.1.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
Expand All @@ -168,14 +169,14 @@ require (
go.opentelemetry.io/otel/trace v1.16.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.25.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect
golang.org/x/tools v0.14.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
Expand Down
Loading

0 comments on commit b5a3c45

Please sign in to comment.