Skip to content

Commit

Permalink
refactor: reuse vole for checking bitswap
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Apr 4, 2024
1 parent b83765f commit fc535a3
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 176 deletions.
167 changes: 0 additions & 167 deletions bitswap.go

This file was deleted.

31 changes: 22 additions & 9 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sync"
"time"

vole "github.com/ipfs-shipyard/vole/lib"
"github.com/ipfs/boxo/ipns"
"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p"
Expand Down Expand Up @@ -104,19 +105,28 @@ func (d *daemon) runCheck(writer http.ResponseWriter, uristr string) error {
return err
}

mastr := u.Query().Get("multiaddr")
cidstr := u.Query().Get("cid")
maStr := u.Query().Get("multiaddr")
cidStr := u.Query().Get("cid")

if mastr == "" || cidstr == "" {
return errors.New("missing argument")
if maStr == "" {
return errors.New("missing 'multiaddr' argument")
}

ai, err := peer.AddrInfoFromString(mastr)
if cidStr == "" {
return errors.New("missing 'cid' argument")
}

ma, err := multiaddr.NewMultiaddr(maStr)
if err != nil {
return err
}

c, err := cid.Decode(cidstr)
ai, err := peer.AddrInfoFromP2pAddr(ma)
if err != nil {
return err
}

c, err := cid.Decode(cidStr)
if err != nil {
return err
}
Expand Down Expand Up @@ -165,10 +175,13 @@ func (d *daemon) runCheck(writer http.ResponseWriter, uristr string) error {
}

if connectionFailed {
out.DataAvailableOverBitswap.Error = "could not connect to peer"
out.DataAvailableOverBitswap.Error = errors.New("could not connect to peer")
} else {
// If so is the data available over Bitswap
bsOut := checkBitswapCID(ctx, testHost, c, *ai)
bsOut, err := vole.CheckBitswapCID(ctx, c, ma, false)
if err != nil {
return fmt.Errorf("server error: %w", err)
}
out.DataAvailableOverBitswap = *bsOut
}

Expand All @@ -189,7 +202,7 @@ type output struct {
ConnectionError string
PeerFoundInDHT map[string]int
CidInDHT bool
DataAvailableOverBitswap BsCheckOutput
DataAvailableOverBitswap vole.BsCheckOutput
}

func peerAddrsInDHT(ctx context.Context, d kademlia, messenger *dhtpb.ProtocolMessenger, p peer.ID) (map[string]int, error) {
Expand Down
18 changes: 18 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.21

require (
github.com/gavv/httpexpect/v2 v2.16.0
github.com/ipfs-shipyard/vole v0.0.0-20240403195339-2723366b1902
github.com/ipfs/boxo v0.18.0
github.com/ipfs/go-cid v0.4.1
github.com/libp2p/go-libp2p v0.33.2
Expand All @@ -15,15 +16,19 @@ require (
)

require (
github.com/Jorropo/jsync v1.0.1 // indirect
github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2 // indirect
github.com/VividCortex/ewma v1.1.1 // indirect
github.com/ajg/form v1.5.1 // indirect
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cheggaaa/pb/v3 v3.1.0 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/cskr/pubsub v1.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
Expand All @@ -47,13 +52,22 @@ require (
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/imkira/go-interpol v1.1.0 // indirect
github.com/ipfs/bbloom v0.0.4 // indirect
github.com/ipfs/go-block-format v0.2.0 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
github.com/ipfs/go-ipfs-delay v0.0.1 // indirect
github.com/ipfs/go-ipfs-pq v0.0.3 // indirect
github.com/ipfs/go-ipfs-util v0.0.3 // 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-log/v2 v2.5.1 // indirect
github.com/ipfs/go-metrics-interface v0.0.1 // indirect
github.com/ipfs/go-peertaskqueue v0.8.1 // indirect
github.com/ipld/go-codec-dagpb v1.6.0 // indirect
github.com/ipld/go-ipld-prime v0.21.0 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
Expand All @@ -66,15 +80,18 @@ require (
github.com/libp2p/go-flow-metrics v0.1.0 // indirect
github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect
github.com/libp2p/go-libp2p-kbucket v0.6.3 // indirect
github.com/libp2p/go-libp2p-mplex v0.9.0 // indirect
github.com/libp2p/go-libp2p-routing-helpers v0.7.3 // indirect
github.com/libp2p/go-libp2p-xor v0.1.0 // indirect
github.com/libp2p/go-mplex v0.7.0 // indirect
github.com/libp2p/go-nat v0.2.0 // indirect
github.com/libp2p/go-netroute v0.2.1 // indirect
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-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.12 // indirect
github.com/miekg/dns v1.1.58 // indirect
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect
github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect
Expand Down Expand Up @@ -105,6 +122,7 @@ require (
github.com/quic-go/quic-go v0.42.0 // indirect
github.com/quic-go/webtransport-go v0.7.0 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sanity-io/litter v1.5.5 // indirect
github.com/sergi/go-diff v1.0.0 // indirect
Expand Down
Loading

0 comments on commit fc535a3

Please sign in to comment.