Skip to content

Commit

Permalink
Merge pull request #52 from ipfs/simplify-output
Browse files Browse the repository at this point in the history
Rename CIDinDHT to ProviderRecordFromPeerInDHT
  • Loading branch information
2color committed Aug 30, 2024
2 parents 6c45882 + 712128d commit efc30fe
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 52 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ The results of the check are expressed by the `peerCheckOutput` type:

```go
type peerCheckOutput struct {
ConnectionError string
PeerFoundInDHT map[string]int
CidInDHT bool
ConnectionMaddrs string[]
DataAvailableOverBitswap BitswapCheckOutput
ConnectionError string
PeerFoundInDHT map[string]int
ProviderRecordFromPeerInDHT bool
ConnectionMaddrs []string
DataAvailableOverBitswap BitswapCheckOutput
}

type BitswapCheckOutput struct {
Expand All @@ -118,9 +118,9 @@ type BitswapCheckOutput struct {
}
```

1. Is the CID (really multihash) advertised in the DHT (or later IPNI)?
1. Is the CID (really multihash) advertised in the DHT by the Passed PeerID (or later IPNI)?

- `CidInDHT`
- `ProviderRecordFromPeerInDHT`

2. Are the peer's addresses discoverable (particularly useful if the announcements are DHT based, but also independently useful)

Expand All @@ -143,8 +143,7 @@ type BitswapCheckOutput struct {

The ipfs-check server is instrumented and exposes two Prometheus metrics endpoints:

- `/metrics/libp2p` exposes [go-libp2p metrics](https://blog.libp2p.io/2023-08-15-metrics-in-go-libp2p/).
- `/metrics/http` exposes http metrics for the check endpoint.
- `/metrics` exposes [go-libp2p metrics](https://blog.libp2p.io/2023-08-15-metrics-in-go-libp2p/) and http metrics for the check endpoint.

### Securing the metrics endpoints

Expand Down
46 changes: 13 additions & 33 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/routing"
"github.com/libp2p/go-libp2p/p2p/net/connmgr"
"github.com/libp2p/go-libp2p/p2p/protocol/identify"
"github.com/multiformats/go-multiaddr"
manet "github.com/multiformats/go-multiaddr/net"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -209,11 +208,11 @@ func (d *daemon) runCidCheck(ctx context.Context, cidStr string) (cidCheckOutput
}

type peerCheckOutput struct {
ConnectionError string
PeerFoundInDHT map[string]int
CidInDHT bool
ConnectionMaddrs []string
DataAvailableOverBitswap BitswapCheckOutput
ConnectionError string
PeerFoundInDHT map[string]int
ProviderRecordFromPeerInDHT bool
ConnectionMaddrs []string
DataAvailableOverBitswap BitswapCheckOutput
}

// runPeerCheck checks the connectivity and Bitswap availability of a CID from a given peer (either with just peer ID or specific multiaddr)
Expand All @@ -240,7 +239,7 @@ func (d *daemon) runPeerCheck(ctx context.Context, maStr, cidStr string) (*peerC

connectionFailed := false

out.CidInDHT = providerRecordForPeerInDHT(ctx, d.dht, c, ai.ID)
out.ProviderRecordFromPeerInDHT = ProviderRecordFromPeerInDHT(ctx, d.dht, c, ai.ID)

addrMap, peerAddrDHTErr := peerAddrsInDHT(ctx, d.dht, d.dhtMessenger, ai.ID)
out.PeerFoundInDHT = addrMap
Expand Down Expand Up @@ -277,36 +276,17 @@ func (d *daemon) runPeerCheck(ctx context.Context, maStr, cidStr string) (*peerC
_, connErr := testHost.NewStream(dialCtx, ai.ID, "/ipfs/bitswap/1.2.0", "/ipfs/bitswap/1.1.0", "/ipfs/bitswap/1.0.0", "/ipfs/bitswap")
dialCancel()
if connErr != nil {
log.Printf("Error connecting to peer %s: %v", ai.ID, connErr)
ids, ok := testHost.(interface{ IDService() identify.IDService })
if ok {
log.Printf("Own observed addrs: %v", ids.IDService().OwnObservedAddrs())
}

// Log all open connections
for _, conn := range testHost.Network().Conns() {
log.Printf("Open connection: Peer ID: %s, Remote Addr: %s, Local Addr: %s",
conn.RemotePeer(),
conn.RemoteMultiaddr(),
conn.LocalMultiaddr(),
)
}
out.ConnectionError = connErr.Error()
connectionFailed = true
return out, nil
}
}

if connectionFailed {
out.DataAvailableOverBitswap.Error = "could not connect to peer"
} else {
// If so is the data available over Bitswap?
out.DataAvailableOverBitswap = checkBitswapCID(ctx, testHost, c, ma)
// If so is the data available over Bitswap?
out.DataAvailableOverBitswap = checkBitswapCID(ctx, testHost, c, ma)

// Get the direct connection in case it was hole punched and we have both a limited connection
// directMaddr := getDirectMaddr()
for _, c := range testHost.Network().ConnsToPeer(ai.ID) {
out.ConnectionMaddrs = append(out.ConnectionMaddrs, c.RemoteMultiaddr().String())
}
// Get all connection maddrs to the peer (in case we hole punched, there will usually be two: limited relay and direct)
for _, c := range testHost.Network().ConnsToPeer(ai.ID) {
out.ConnectionMaddrs = append(out.ConnectionMaddrs, c.RemoteMultiaddr().String())
}

return out, nil
Expand Down Expand Up @@ -383,7 +363,7 @@ func peerAddrsInDHT(ctx context.Context, d kademlia, messenger *dhtpb.ProtocolMe
return addrMap, nil
}

func providerRecordForPeerInDHT(ctx context.Context, d kademlia, c cid.Cid, p peer.ID) bool {
func ProviderRecordFromPeerInDHT(ctx context.Context, d kademlia, c cid.Cid, p peer.ID) bool {
queryCtx, cancel := context.WithCancel(ctx)
defer cancel()
provsCh := d.FindProvidersAsync(queryCtx, c, 0)
Expand Down
6 changes: 3 additions & 3 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestBasicIntegration(t *testing.T) {

obj := test.Query(t, "http://localhost:1234", testCid.String(), hostAddr.String())

obj.Value("CidInDHT").Boolean().IsTrue()
obj.Value("ProviderRecordFromPeerInDHT").Boolean().IsTrue()
obj.Value("ConnectionError").String().IsEmpty()
obj.Value("ConnectionMaddrs").Array().ContainsAll(h.Addrs()[0])
obj.Value("DataAvailableOverBitswap").Object().Value("Error").String().IsEmpty()
Expand All @@ -135,7 +135,7 @@ func TestBasicIntegration(t *testing.T) {

obj := test.Query(t, "http://localhost:1234", testCid.String(), hostAddr.String())

obj.Value("CidInDHT").Boolean().IsFalse()
obj.Value("ProviderRecordFromPeerInDHT").Boolean().IsFalse()
obj.Value("ConnectionError").String().IsEmpty()
obj.Value("ConnectionMaddrs").Array().ContainsAll(h.Addrs()[0])
obj.Value("DataAvailableOverBitswap").Object().Value("Error").String().IsEmpty()
Expand All @@ -153,7 +153,7 @@ func TestBasicIntegration(t *testing.T) {

obj := test.Query(t, "http://localhost:1234", testCid.String(), hostAddr.String())

obj.Value("CidInDHT").Boolean().IsTrue()
obj.Value("ProviderRecordFromPeerInDHT").Boolean().IsTrue()
obj.Value("ConnectionError").String().IsEmpty()
obj.Value("ConnectionMaddrs").Array().ContainsAll(h.Addrs()[0])
obj.Value("DataAvailableOverBitswap").Object().Value("Error").String().IsEmpty()
Expand Down
10 changes: 5 additions & 5 deletions test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestEmptyDirOnBoostrapPeer(t *testing.T) {
}
obj := Q(t, EMPTY_DIR_CID, BOOTSTRAP_PEER_ADDR)

obj.Value("CidInDHT").Boolean().IsTrue()
obj.Value("ProviderRecordFromPeerInDHT").Boolean().IsTrue()
obj.Value("ConnectionError").String().IsEmpty()
obj.Value("DataAvailableOverBitswap").Object().Value("Error").String().IsEmpty()
obj.Value("DataAvailableOverBitswap").Object().Value("Found").Boolean().IsTrue()
Expand All @@ -51,7 +51,7 @@ func TestWikipediaOnSomeProviderPeer(t *testing.T) {
t.Skip("Skipping e2e tests")
}
obj := Q(t, WIKIPEDIA_CID, WIKIPEDIA_PEER_ADDR)
obj.Value("CidInDHT").Boolean().IsTrue()
obj.Value("ProviderRecordFromPeerInDHT").Boolean().IsTrue()
// It seems that most peers do not provide over bitswap:
// obj.Value("ConnectionError").String().IsEmpty()
// obj.Value("DataAvailableOverBitswap").Object().Value("Error").String().IsEmpty()
Expand All @@ -72,7 +72,7 @@ func TestRandomFileOnBootstrapPeer(t *testing.T) {
time.Sleep(60 * time.Second)
obj := Q(t, randomFileCid, BOOTSTRAP_PEER_ADDR)

obj.Value("CidInDHT").Boolean().IsTrue()
obj.Value("ProviderRecordFromPeerInDHT").Boolean().IsTrue()
obj.Value("ConnectionError").String().IsEmpty()
obj.Value("DataAvailableOverBitswap").Object().Value("Error").String().IsEmpty()
obj.Value("DataAvailableOverBitswap").Object().Value("Found").Boolean().IsTrue()
Expand All @@ -97,7 +97,7 @@ func TestRandomFileOnLocalPeer(t *testing.T) {
time.Sleep(25 * time.Second)
obj := Q(t, randomFileCid, localAddr)

obj.Value("CidInDHT").Boolean().IsTrue()
obj.Value("ProviderRecordFromPeerInDHT").Boolean().IsTrue()
obj.Value("ConnectionError").String().IsEmpty()
obj.Value("DataAvailableOverBitswap").Object().Value("Error").String().IsEmpty()
obj.Value("DataAvailableOverBitswap").Object().Value("Found").Boolean().IsTrue()
Expand All @@ -115,7 +115,7 @@ func TestRandomFileNeverUploadedOnBootstrapPeer(t *testing.T) {

obj := Q(t, randomFileCid, BOOTSTRAP_PEER_ADDR)

obj.Value("CidInDHT").Boolean().IsFalse()
obj.Value("ProviderRecordFromPeerInDHT").Boolean().IsFalse()
obj.Value("DataAvailableOverBitswap").Object().Value("Found").Boolean().IsFalse()
obj.Value("DataAvailableOverBitswap").Object().Value("Responded").Boolean().IsTrue()
}
2 changes: 1 addition & 1 deletion test/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func GetEnv(key string, fallback string) string {
Example of outputs:
```json
{
"CidInDHT": true,
"ProviderRecordFromPeerInDHT": true,
"ConnectionError": "no addresses",
"DataAvailableOverBitswap": {
"Duration": 0,
Expand Down
2 changes: 1 addition & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ <h2 class="f4">What does it mean if I get an error?</h2>
}
}

if (respObj.CidInDHT === true) {
if (respObj.ProviderRecordFromPeerInDHT === true) {
outText += "✅ Found multihash advertised in the dht\n"
} else {
outText += "❌ Could not find the multihash in the dht\n"
Expand Down

0 comments on commit efc30fe

Please sign in to comment.