Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "2"

run:
timeout: 10m

issues:
max-issues-per-linter: 0
max-same-issues: 0

linters:
enable:
- ineffassign
- misspell
- unconvert
- unused
- usestdlibvars

disable:
- errcheck

formatters:
enable:
- gci
- gofumpt

severity:
default: warning
1 change: 0 additions & 1 deletion bitswap/network/http_multiaddr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func TestExtractHTTPAddress(t *testing.T) {
expectErr: false,
},
{

name: "Valid HTTPS multiaddress with DNS",
maStr: "/dns4/example.com/tcp/443/https",
want: &url.URL{
Expand Down
1 change: 0 additions & 1 deletion bitswap/network/httpnet/cooldown.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func (ct *cooldownTracker) fillSenderURLs(urls []network.ParsedURL) []*senderURL
surls := make([]*senderURL, len(urls))
ct.urlsLock.RLock()
{

for i, u := range urls {
var cooldown time.Time
dl, ok := ct.urls[u.URL.Host]
Expand Down
2 changes: 1 addition & 1 deletion bitswap/network/httpnet/error_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestErrorTracker_ConcurrentAccess(t *testing.T) {
wg.Add(1)
go func() {
defer wg.Done()
for j := 0; j < int(threshold)/numRoutines; j++ {
for j := 0; j < threshold/numRoutines; j++ {
et.logErrors(p, 1, threshold)
}
}()
Expand Down
17 changes: 8 additions & 9 deletions bitswap/network/httpnet/httpnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ import (

var log = logging.Logger("httpnet")

var ErrNoHTTPAddresses = errors.New("AddrInfo does not contain any valid HTTP addresses")
var ErrNoSuccess = errors.New("connection failed to all HTTP endpoints")
var ErrNotConnected = errors.New("no HTTP connection has been setup to this peer")
var (
ErrNoHTTPAddresses = errors.New("AddrInfo does not contain any valid HTTP addresses")
ErrNoSuccess = errors.New("none of the peer HTTP endpoints responded successfully to request")
ErrNotConnected = errors.New("no HTTP connection has been setup to this peer")
)

var _ network.BitSwapNetwork = (*Network)(nil)

var (
// DefaultUserAgent is sent as a header in all requests.
DefaultUserAgent = defaultUserAgent() // Usually will result in a "boxo@commitID"
)
// DefaultUserAgent is sent as a header in all requests.
var DefaultUserAgent = defaultUserAgent() // Usually will result in a "boxo@commitID"

// Defaults for the configurable options.
const (
Expand Down Expand Up @@ -349,7 +349,6 @@ func (ht *Network) Stop() {
// Ping triggers a ping to the given peer and returns the latency.
func (ht *Network) Ping(ctx context.Context, p peer.ID) ping.Result {
return ht.pinger.ping(ctx, p)

}

// Latency returns the EWMA latency for the given peer.
Expand Down Expand Up @@ -524,7 +523,7 @@ func (ht *Network) connectToURL(ctx context.Context, p peer.ID, u network.Parsed

// probe success.
// FIXME: Storacha returns 410 for our probe.
if resp.StatusCode == 200 || resp.StatusCode == 204 || resp.StatusCode == 410 {
if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNoContent || resp.StatusCode == http.StatusGone {
return nil
}

Expand Down
16 changes: 6 additions & 10 deletions bitswap/network/httpnet/httpnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ import (
manet "github.com/multiformats/go-multiaddr/net"
)

var errorCid = cid.MustParse("bafkreiachshsblgr5kv3mzbgfgmvuhllwe2f6fasm6mykzwsi4l7odq464") // "errorcid"
var slowCid = cid.MustParse("bafkreidhph5i4jevaun4eqjxolqgn3rfpoknj35ocyos3on57iriwpaujm") // "slowcid"
var backoffCid = cid.MustParse("bafkreid6g5qrufgqj46djic7ntjnppaj5bg4urppjoyywrxwegvltrmqbu") // "backoff"
var (
errorCid = cid.MustParse("bafkreiachshsblgr5kv3mzbgfgmvuhllwe2f6fasm6mykzwsi4l7odq464") // "errorcid"
slowCid = cid.MustParse("bafkreidhph5i4jevaun4eqjxolqgn3rfpoknj35ocyos3on57iriwpaujm") // "slowcid"
backoffCid = cid.MustParse("bafkreid6g5qrufgqj46djic7ntjnppaj5bg4urppjoyywrxwegvltrmqbu") // "backoff"
)

var _ network.Receiver = (*mockRecv)(nil)

Expand Down Expand Up @@ -92,7 +94,6 @@ func (recv *mockRecv) waitDisconnected(seconds int) error {
}

func (recv *mockRecv) ReceiveError(err error) {

}

func (recv *mockRecv) PeerConnected(p peer.ID) {
Expand All @@ -113,7 +114,6 @@ func mockReceiver(t *testing.T) *mockRecv {
waitConnectedCh: make(chan struct{}, 1),
waitDisconnectedCh: make(chan struct{}, 1),
}

}

func mockNet(t *testing.T) mocknet.Mocknet {
Expand Down Expand Up @@ -169,7 +169,6 @@ func makeMessage(wantlist []cid.Cid, wantType pb.Message_Wantlist_WantType, send
wantType,
sendDontHave,
)

}
return msg
}
Expand Down Expand Up @@ -248,7 +247,7 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
}

rw.WriteHeader(http.StatusOK)
if r.Method == "HEAD" {
if r.Method == http.MethodHead {
return
}

Expand Down Expand Up @@ -397,7 +396,6 @@ func TestBestURL(t *testing.T) {
if err == nil {
t.Fatal("expected error since only urls failed too many times")
}

}

func TestConnectErrors(t *testing.T) {
Expand Down Expand Up @@ -439,7 +437,6 @@ func TestConnectErrors(t *testing.T) {
if !strings.Contains(err.Error(), "denylist") {
t.Error("wrong error")
}

}

func TestSendMessage(t *testing.T) {
Expand Down Expand Up @@ -534,7 +531,6 @@ func TestSendMessageWithPartialResponse(t *testing.T) {
t.Error("block should not have been received")
}
}

}

func TestSendMessageSendHavesAndDontHaves(t *testing.T) {
Expand Down
24 changes: 12 additions & 12 deletions bitswap/network/httpnet/msg_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
// request can take.
DefaultSendTimeout = 5 * time.Second
// SendErrorBackoff specifies how long to wait between retries to the
// same endpoint after failure. It is overriden by Retry-After
// same endpoint after failure. It is overridden by Retry-After
// headers and must be at least 50ms.
DefaultSendErrorBackoff = time.Second
)
Expand Down Expand Up @@ -176,7 +176,7 @@ func (err senderError) Error() string {
return err.Err.Error()
}

// tryURL attemps to make a request to the given URL using the given entry.
// tryURL attempts to make a request to the given URL using the given entry.
// Blocks, Haves etc. are recorded in the given response. cancellations are
// processed. tryURL returns an error so that it can be decided what to do next:
// i.e. retry, or move to next item in wantlist, or abort completely.
Expand All @@ -190,11 +190,11 @@ func (sender *httpMsgSender) tryURL(ctx context.Context, u *senderURL, entry bsm

var method string

switch {
case entry.WantType == pb.Message_Wantlist_Block:
method = "GET"
case entry.WantType == pb.Message_Wantlist_Have:
method = "HEAD"
switch entry.WantType {
case pb.Message_Wantlist_Block:
method = http.MethodGet
case pb.Message_Wantlist_Have:
method = http.MethodHead
default:
panic("unknown bitswap entry type")
}
Expand All @@ -204,7 +204,7 @@ func (sender *httpMsgSender) tryURL(ctx context.Context, u *senderURL, entry bsm
// is worse than downloading some extra bytes. We do abort if the
// context WAS already cancelled before making the request.
if err := ctx.Err(); err != nil {
log.Debugf("aborted before sending: %s %q", method, u.ParsedURL.URL)
log.Debugf("aborted before sending: %s %q", method, u.URL)
return nil, &senderError{
Type: typeContext,
Err: err,
Expand Down Expand Up @@ -329,7 +329,7 @@ func (sender *httpMsgSender) tryURL(ctx context.Context, u *senderURL, entry bsm
}
log.Debugf("%s %q -> %d (%d bytes)", req.Method, req.URL, statusCode, len(body))

if req.Method == "HEAD" {
if req.Method == http.MethodHead {
return nil, nil
}
// GET
Expand All @@ -354,7 +354,7 @@ func (sender *httpMsgSender) tryURL(ctx context.Context, u *senderURL, entry bsm
// Retry-After. They are used to signal that a block cannot
// be fetched too, not only fatal server issues, which poses a
// difficult overlap. Current approach treats these errors as
// non fatal if they don't happen repeteadly:
// non fatal if they don't happen repeatedly:
// - By default we disconnect on server errors: MaxRetries = 1.
// - First try errors. We add default backoff if non specified.
// - Retry same CID. If it fails again, count that as server
Expand All @@ -364,7 +364,7 @@ func (sender *httpMsgSender) tryURL(ctx context.Context, u *senderURL, entry bsm

// In practice, our wantlists should be 1/3 elements. It
// doesn't make sense to tolerate 5 server errors for 3
// requests as we will repeteadly hit broken servers that way.
// requests as we will repeatedly hit broken servers that way.
// It is always better if endpoints keep these errors for
// server issues, and simply return 404 when they cannot find
// the content but everything else is fine.
Expand Down Expand Up @@ -402,7 +402,7 @@ func (sender *httpMsgSender) tryURL(ctx context.Context, u *senderURL, entry bsm
}

// SendMsg performs an http request for the wanted cids per the msg's
// Wantlist. It reads the response and records it in a reponse BitswapMessage
// Wantlist. It reads the response and records it in a response BitswapMessage
// which is forwarded to the receivers (in a separate goroutine).
func (sender *httpMsgSender) SendMsg(ctx context.Context, msg bsmsg.BitSwapMessage) error {
// SendMsg gets called from MessageQueue and returning an error
Expand Down
4 changes: 1 addition & 3 deletions bitswap/network/httpnet/pinger.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (pngr *pinger) ping(ctx context.Context, p peer.ID) ping.Result {
}
result.RTT = result.RTT / time.Duration(len(urls)-lenErrors)

//log.Debugf("ping latency %s %s", p, result.RTT)
// log.Debugf("ping latency %s %s", p, result.RTT)
pngr.recordLatency(p, result.RTT)
return result
}
Expand Down Expand Up @@ -144,7 +144,6 @@ func (pngr *pinger) startPinging(p peer.ID) {
}
}
}(ctx, p)

}

func (pngr *pinger) stopPinging(p peer.ID) {
Expand All @@ -160,7 +159,6 @@ func (pngr *pinger) stopPinging(p peer.ID) {
pngr.latenciesLock.Lock()
delete(pngr.latencies, p)
pngr.latenciesLock.Unlock()

}

func (pngr *pinger) isPinging(p peer.ID) bool {
Expand Down
1 change: 1 addition & 0 deletions bitswap/network/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func (rt *router) Protect(p peer.ID, tag string) {
}
rt.Bitswap.Protect(p, tag)
}

func (rt *router) Unprotect(p peer.ID, tag string) bool {
pi := rt.Peerstore.PeerInfo(p)
htaddrs, _ := SplitHTTPAddrs(pi)
Expand Down
30 changes: 13 additions & 17 deletions examples/bitswap-transfer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,27 @@ import (
"strconv"
"strings"

"github.com/ipfs/go-datastore"
dsync "github.com/ipfs/go-datastore/sync"

"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"

"github.com/ipfs/go-cid"
"github.com/multiformats/go-multiaddr"
"github.com/multiformats/go-multicodec"

bsclient "github.com/ipfs/boxo/bitswap/client"
bsnet "github.com/ipfs/boxo/bitswap/network/bsnet"
bsserver "github.com/ipfs/boxo/bitswap/server"
"github.com/ipfs/boxo/blockservice"
blockstore "github.com/ipfs/boxo/blockstore"
chunker "github.com/ipfs/boxo/chunker"
offline "github.com/ipfs/boxo/exchange/offline"
"github.com/ipfs/boxo/files"
"github.com/ipfs/boxo/ipld/merkledag"
unixfile "github.com/ipfs/boxo/ipld/unixfs/file"
"github.com/ipfs/boxo/ipld/unixfs/importer/balanced"
uih "github.com/ipfs/boxo/ipld/unixfs/importer/helpers"

bsclient "github.com/ipfs/boxo/bitswap/client"
bsnet "github.com/ipfs/boxo/bitswap/network/bsnet"
bsserver "github.com/ipfs/boxo/bitswap/server"
"github.com/ipfs/boxo/files"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-datastore"
dsync "github.com/ipfs/go-datastore/sync"
"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/multiformats/go-multiaddr"
"github.com/multiformats/go-multicodec"
)

const exampleBinaryName = "bitswap-transfer"
Expand Down
1 change: 0 additions & 1 deletion examples/bitswap-transfer/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"

"github.com/ipfs/go-cid"

"github.com/libp2p/go-libp2p/core/peer"
)

Expand Down
1 change: 0 additions & 1 deletion fetcher/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
"github.com/ipld/go-ipld-prime"

// used to make sure we have dagcbor encoding
_ "github.com/ipld/go-ipld-prime/codec/dagcbor"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
Expand Down
1 change: 0 additions & 1 deletion gateway/assets/test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/ipfs/boxo/gateway/assets"
"github.com/ipfs/go-cid"

// Ensure basic codecs are registered.
_ "github.com/ipld/go-ipld-prime/codec/cbor"
_ "github.com/ipld/go-ipld-prime/codec/dagcbor"
Expand Down
1 change: 0 additions & 1 deletion gateway/backend_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/ipld/go-car/v2/storage"
dagpb "github.com/ipld/go-codec-dagpb"
"github.com/ipld/go-ipld-prime"

// Ensure basic codecs are registered.
_ "github.com/ipld/go-ipld-prime/codec/cbor"
_ "github.com/ipld/go-ipld-prime/codec/dagcbor"
Expand Down
3 changes: 0 additions & 3 deletions gateway/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,6 @@ func TestRedirects(t *testing.T) {
// Check Redirect target contains all query parameters
redirectURL := res.Header.Get("Location")
require.Equal(t, expectedTargetURL, redirectURL)

}

do(http.MethodGet)
Expand Down Expand Up @@ -899,7 +898,6 @@ func TestRedirects(t *testing.T) {
// Check Redirect target contains all query parameters
redirectURL := res.Header.Get("Location")
require.Equal(t, expectedTargetURL, redirectURL)

}

do(http.MethodGet)
Expand Down Expand Up @@ -944,7 +942,6 @@ func TestRedirects(t *testing.T) {
// Check Redirect target contains all query parameters
redirectURL := res.Header.Get("Location")
require.Equal(t, expectedTargetURL, redirectURL)

}

do(http.MethodGet)
Expand Down
1 change: 0 additions & 1 deletion gateway/handler_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/ipfs/boxo/gateway/assets"
"github.com/ipfs/boxo/path"
"github.com/ipfs/go-cid"

// Ensure basic codecs are registered.
_ "github.com/ipld/go-ipld-prime/codec/cbor"
_ "github.com/ipld/go-ipld-prime/codec/dagcbor"
Expand Down
1 change: 0 additions & 1 deletion ipld/merkledag/merkledag.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
format "github.com/ipfs/go-ipld-format"
legacy "github.com/ipfs/go-ipld-legacy"
dagpb "github.com/ipld/go-codec-dagpb"

// blank import is used to register the IPLD raw codec
_ "github.com/ipld/go-ipld-prime/codec/raw"
basicnode "github.com/ipld/go-ipld-prime/node/basic"
Expand Down
Loading
Loading