Skip to content

Commit

Permalink
Merge pull request #1 from aschmahmann/feat/bitswap-timing
Browse files Browse the repository at this point in the history
add timing information to bitswap check
  • Loading branch information
Whyrusleeping authored Aug 23, 2021
2 parents 480e473 + c928c52 commit 2fe5a35
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package main
import (
"context"
"fmt"
"time"

"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/routing"
"time"

bsmsg "github.com/ipfs/go-bitswap/message"
bsmsgpb "github.com/ipfs/go-bitswap/message/pb"
Expand All @@ -16,6 +17,7 @@ import (
)

type BsCheckOutput struct {
Duration time.Duration
Found bool
Responded bool
Error string
Expand Down Expand Up @@ -45,8 +47,11 @@ func checkBitswapCID(ctx context.Context, h host.Host, c cid.Cid, ai peer.AddrIn

bs.SetDelegate(rcv)

start := time.Now()

if err := bs.SendMessage(ctx, target, msg); err != nil {
return &BsCheckOutput{
Duration: time.Since(start),
Found: false,
Responded: false,
Error: err.Error(),
Expand All @@ -68,6 +73,7 @@ loop:

if res.err != nil {
return &BsCheckOutput{
Duration: time.Since(start),
Found: false,
Responded: true,
Error: res.err.Error(),
Expand All @@ -81,6 +87,7 @@ loop:
for _, msgC := range res.msg.Blocks() {
if msgC.Cid().Equals(c) {
return &BsCheckOutput{
Duration: time.Since(start),
Found: true,
Responded: true,
Error: "",
Expand All @@ -91,6 +98,7 @@ loop:
for _, msgC := range res.msg.Haves() {
if msgC.Equals(c) {
return &BsCheckOutput{
Duration: time.Since(start),
Found: true,
Responded: true,
Error: "",
Expand All @@ -101,6 +109,7 @@ loop:
for _, msgC := range res.msg.DontHaves() {
if msgC.Equals(c) {
return &BsCheckOutput{
Duration: time.Since(start),
Found: false,
Responded: true,
Error: "",
Expand All @@ -110,6 +119,7 @@ loop:
}

return &BsCheckOutput{
Duration: time.Since(start),
Found: false,
Responded: false,
Error: "",
Expand Down

0 comments on commit 2fe5a35

Please sign in to comment.