From 3a9d78c11fb3401a038de662a30ee1940039442a Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Mon, 20 Nov 2023 14:09:26 +0100 Subject: [PATCH 01/10] feat: proxy all delegated routing --- go.mod | 73 +++++----- go.sum | 155 ++++++++++---------- server.go | 236 ++----------------------------- server_dht.go | 80 +++++++++++ server_routers.go | 349 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 556 insertions(+), 337 deletions(-) create mode 100644 server_dht.go create mode 100644 server_routers.go diff --git a/go.mod b/go.mod index a859958..1b65fa9 100644 --- a/go.mod +++ b/go.mod @@ -5,58 +5,58 @@ go 1.21 require ( github.com/ipfs/boxo v0.15.0 github.com/ipfs/go-cid v0.4.1 - github.com/libp2p/go-libp2p v0.32.0 - github.com/libp2p/go-libp2p-kad-dht v0.23.0 + github.com/libp2p/go-libp2p v0.32.1 + github.com/libp2p/go-libp2p-kad-dht v0.25.1 github.com/libp2p/go-libp2p-record v0.2.0 - github.com/libp2p/go-libp2p-routing-helpers v0.7.0 github.com/multiformats/go-multibase v0.2.0 github.com/urfave/cli/v2 v2.25.7 ) require ( + github.com/Jorropo/jsync v1.0.1 // 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/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/cpuguy83/go-md2man/v2 v2.0.3 // indirect github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/elastic/gosigar v0.14.2 // indirect github.com/flynn/noise v1.0.0 // indirect github.com/francoispqt/gojay v1.2.13 // indirect - github.com/go-logr/logr v1.2.4 // indirect + github.com/go-logr/logr v1.3.0 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/protobuf v1.5.3 // indirect github.com/google/gopacket v1.1.19 // indirect - github.com/google/pprof v0.0.0-20231023181126-ff6d637d2a7b // indirect - github.com/google/uuid v1.3.0 // indirect - github.com/gorilla/mux v1.8.0 // indirect - github.com/gorilla/websocket v1.5.0 // indirect + github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a // indirect + github.com/google/uuid v1.4.0 // indirect + github.com/gorilla/mux v1.8.1 // indirect + github.com/gorilla/websocket v1.5.1 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect - github.com/hashicorp/golang-lru v0.5.4 // indirect + github.com/hashicorp/golang-lru v1.0.2 // indirect github.com/huin/goupnp v1.3.0 // indirect github.com/ipfs/go-datastore v0.6.0 // indirect - github.com/ipfs/go-ipfs-util v0.0.2 // indirect + github.com/ipfs/go-ipfs-util v0.0.3 // indirect github.com/ipfs/go-log v1.0.5 // indirect github.com/ipfs/go-log/v2 v2.5.1 // 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 github.com/jbenet/goprocess v0.1.4 // indirect - github.com/klauspost/compress v1.17.2 // indirect - github.com/klauspost/cpuid/v2 v2.2.5 // indirect + github.com/klauspost/compress v1.17.3 // indirect + github.com/klauspost/cpuid/v2 v2.2.6 // indirect github.com/koron/go-ssdp v0.0.4 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-cidranger v1.1.0 // indirect github.com/libp2p/go-flow-metrics v0.1.0 // indirect github.com/libp2p/go-libp2p-asn-util v0.3.0 // indirect - github.com/libp2p/go-libp2p-kbucket v0.5.0 // indirect + github.com/libp2p/go-libp2p-kbucket v0.6.3 // 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-msgio v0.3.0 // indirect github.com/libp2p/go-nat v0.2.0 // indirect @@ -65,8 +65,8 @@ require ( 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.20 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect - github.com/miekg/dns v1.1.56 // indirect + github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect + github.com/miekg/dns v1.1.57 // indirect github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect github.com/minio/sha256-simd v1.0.1 // indirect @@ -80,43 +80,44 @@ require ( github.com/multiformats/go-multihash v0.2.3 // indirect github.com/multiformats/go-multistream v0.5.0 // indirect github.com/multiformats/go-varint v0.0.7 // indirect - github.com/onsi/ginkgo/v2 v2.13.0 // indirect + github.com/onsi/ginkgo/v2 v2.13.1 // 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 github.com/pkg/errors v0.9.1 // indirect github.com/polydawn/refmt v0.89.0 // indirect - github.com/prometheus/client_golang v1.16.0 // indirect - github.com/prometheus/client_model v0.4.0 // indirect - github.com/prometheus/common v0.44.0 // indirect - github.com/prometheus/procfs v0.11.1 // indirect + github.com/prometheus/client_golang v1.17.0 // indirect + github.com/prometheus/client_model v0.5.0 // indirect + github.com/prometheus/common v0.45.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect github.com/quic-go/qpack v0.4.0 // 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/qtls-go1-20 v0.4.1 // indirect + github.com/quic-go/quic-go v0.40.0 // indirect github.com/quic-go/webtransport-go v0.6.0 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/samber/lo v1.36.0 // indirect + github.com/samber/lo v1.38.1 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect go.opencensus.io v0.24.0 // indirect - go.opentelemetry.io/otel v1.14.0 // indirect - go.opentelemetry.io/otel/trace v1.14.0 // indirect + go.opentelemetry.io/otel v1.21.0 // indirect + go.opentelemetry.io/otel/metric v1.21.0 // indirect + go.opentelemetry.io/otel/trace v1.21.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 go.uber.org/multierr v1.11.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-20231006140011-7918f672742d // indirect - golang.org/x/mod v0.13.0 // indirect - golang.org/x/net v0.17.0 // indirect - golang.org/x/sync v0.4.0 // indirect - golang.org/x/sys v0.13.0 // indirect - golang.org/x/text v0.13.0 // indirect - golang.org/x/tools v0.14.0 // indirect - gonum.org/v1/gonum v0.11.0 // indirect + golang.org/x/crypto v0.15.0 // indirect + golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect + golang.org/x/mod v0.14.0 // indirect + golang.org/x/net v0.18.0 // indirect + golang.org/x/sync v0.5.0 // indirect + golang.org/x/sys v0.14.0 // indirect + golang.org/x/text v0.14.0 // indirect + golang.org/x/tools v0.15.0 // indirect + gonum.org/v1/gonum v0.14.0 // indirect google.golang.org/protobuf v1.31.0 // indirect lukechampine.com/blake3 v1.2.1 // indirect ) diff --git a/go.sum b/go.sum index f2ec137..b33570d 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,8 @@ dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/Jorropo/jsync v1.0.1 h1:6HgRolFZnsdfzRUj+ImB9og1JYOxQoReSywkHOGSaUU= +github.com/Jorropo/jsync v1.0.1/go.mod h1:jCOZj3vrBCri3bSU3ErUYvevKlnbssrXeCivybS5ABQ= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= @@ -50,8 +52,8 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= -github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM= +github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -88,8 +90,8 @@ github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aev github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= -github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= @@ -136,30 +138,30 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8= github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20231023181126-ff6d637d2a7b h1:RMpPgZTSApbPf7xaVel+QkoGPRLFLrwFO89uDUHEGf0= -github.com/google/pprof v0.0.0-20231023181126-ff6d637d2a7b/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= +github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a h1:fEBsGL/sjAuJrgah5XqmmYsTLzJp/TO9Lhy39gkverk= +github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c h1:7lF+Vz0LqiRidnzC1Oq86fpX1q/iEv2KJdrCtttYjT4= github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= -github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= @@ -170,8 +172,8 @@ github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= -github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c= +github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc= @@ -192,8 +194,8 @@ github.com/ipfs/go-ds-badger v0.0.7/go.mod h1:qt0/fWzZDoPW6jpQeqUjR5kBfhDNB65jd9 github.com/ipfs/go-ds-leveldb v0.1.0/go.mod h1:hqAW8y4bwX5LWcCtku2rFNX3vjDZCy5LZCg+cSZvYb8= github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw= github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc= -github.com/ipfs/go-ipfs-util v0.0.2 h1:59Sswnk1MFaiq+VcaknX7aYEyGyGDAA73ilhEK2POp8= -github.com/ipfs/go-ipfs-util v0.0.2/go.mod h1:CbPtkWJzjLdEcezDns2XYaehFVNXG9zrdrtMecczcsQ= +github.com/ipfs/go-ipfs-util v0.0.3 h1:2RFdGez6bu2ZlZdI+rWfIdbQb1KudQp3VGwPtdNCmE0= +github.com/ipfs/go-ipfs-util v0.0.3/go.mod h1:LHzG1a0Ig4G+iZ26UUOMjHd+lfM84LZCrn17xAKWBvs= github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= github.com/ipfs/go-log v1.0.5 h1:2dOuUCB1Z7uoczMWgAyDck5JLb72zHzrMnGnCNNbvY8= github.com/ipfs/go-log v1.0.5/go.mod h1:j0b8ZoR+7+R99LD9jZ6+AJsrzkPbSXbZfGakb5JPtIo= @@ -225,10 +227,10 @@ github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQL github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= -github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4= -github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= -github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= -github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/compress v1.17.3 h1:qkRjuerhUU1EmXLYGkSH6EZL+vPSxIrYjLNAK4slzwA= +github.com/klauspost/compress v1.17.3/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= +github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc= +github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0= github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk= @@ -251,22 +253,22 @@ github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZ github.com/libp2p/go-flow-metrics v0.0.3/go.mod h1:HeoSNUrOJVK1jEpDqVEiUOIXqhbnS27omG0uWU5slZs= github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFGkx3Q3WM= github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro= -github.com/libp2p/go-libp2p v0.32.0 h1:86I4B7nBUPIyTgw3+5Ibq6K7DdKRCuZw8URCfPc1hQM= -github.com/libp2p/go-libp2p v0.32.0/go.mod h1:hXXC3kXPlBZ1eu8Q2hptGrMB4mZ3048JUoS4EKaHW5c= +github.com/libp2p/go-libp2p v0.32.1 h1:wy1J4kZIZxOaej6NveTWCZmHiJ/kY7GoAqXgqNCnPps= +github.com/libp2p/go-libp2p v0.32.1/go.mod h1:hXXC3kXPlBZ1eu8Q2hptGrMB4mZ3048JUoS4EKaHW5c= github.com/libp2p/go-libp2p-asn-util v0.3.0 h1:gMDcMyYiZKkocGXDQ5nsUQyquC9+H+iLEQHwOCZ7s8s= github.com/libp2p/go-libp2p-asn-util v0.3.0/go.mod h1:B1mcOrKUE35Xq/ASTmQ4tN3LNzVVaMNmq2NACuqyB9w= github.com/libp2p/go-libp2p-core v0.2.4/go.mod h1:STh4fdfa5vDYr0/SzYYeqnt+E6KfEV5VxfIrm0bcI0g= github.com/libp2p/go-libp2p-core v0.3.0/go.mod h1:ACp3DmS3/N64c2jDzcV429ukDpicbL6+TrrxANBjPGw= -github.com/libp2p/go-libp2p-kad-dht v0.23.0 h1:sxE6LxLopp79eLeV695n7+c77V/Vn4AMF28AdM/XFqM= -github.com/libp2p/go-libp2p-kad-dht v0.23.0/go.mod h1:oO5N308VT2msnQI6qi5M61wzPmJYg7Tr9e16m5n7uDU= +github.com/libp2p/go-libp2p-kad-dht v0.25.1 h1:ofFNrf6MMEy4vi3R1VbJ7LOcTn3Csh0cDcaWHTxtWNA= +github.com/libp2p/go-libp2p-kad-dht v0.25.1/go.mod h1:6za56ncRHYXX4Nc2vn8z7CZK0P4QiMcrn77acKLM2Oo= github.com/libp2p/go-libp2p-kbucket v0.3.1/go.mod h1:oyjT5O7tS9CQurok++ERgc46YLwEpuGoFq9ubvoUOio= -github.com/libp2p/go-libp2p-kbucket v0.5.0 h1:g/7tVm8ACHDxH29BGrpsQlnNeu+6OF1A9bno/4/U1oA= -github.com/libp2p/go-libp2p-kbucket v0.5.0/go.mod h1:zGzGCpQd78b5BNTDGHNDLaTt9aDK/A02xeZp9QeFC4U= +github.com/libp2p/go-libp2p-kbucket v0.6.3 h1:p507271wWzpy2f1XxPzCQG9NiN6R6lHL9GiSErbQQo0= +github.com/libp2p/go-libp2p-kbucket v0.6.3/go.mod h1:RCseT7AH6eJWxxk2ol03xtP9pEHetYSPXOaJnOiD8i0= github.com/libp2p/go-libp2p-peerstore v0.1.4/go.mod h1:+4BDbDiiKf4PzpANZDAT+knVdLxvqh7hXOujessqdzs= github.com/libp2p/go-libp2p-record v0.2.0 h1:oiNUOCWno2BFuxt3my4i1frNrt7PerzB3queqa1NkQ0= github.com/libp2p/go-libp2p-record v0.2.0/go.mod h1:I+3zMkvvg5m2OcSdoL0KPljyJyvNDFGKX7QdlpYUcwk= -github.com/libp2p/go-libp2p-routing-helpers v0.7.0 h1:sirOYVD0wGWjkDwHZvinunIpaqPLBXkcnXApVHwZFGA= -github.com/libp2p/go-libp2p-routing-helpers v0.7.0/go.mod h1:R289GUxUMzRXIbWGSuUUTPrlVJZ3Y/pPz495+qgXJX8= +github.com/libp2p/go-libp2p-routing-helpers v0.7.3 h1:u1LGzAMVRK9Nqq5aYDVOiq/HaB93U9WWczBzGyAC5ZY= +github.com/libp2p/go-libp2p-routing-helpers v0.7.3/go.mod h1:cN4mJAD/7zfPKXBcs9ze31JGYAZgzdABEm+q/hkswb8= github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA= github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg= github.com/libp2p/go-libp2p-xor v0.1.0 h1:hhQwT4uGrBcuAkUGXADuPltalOdpf9aag9kaYNT2tLA= @@ -298,13 +300,13 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= -github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= +github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= +github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= -github.com/miekg/dns v1.1.56 h1:5imZaSeoRNvpM9SzWNhEcP9QliKiz20/dA2QabIGVnE= -github.com/miekg/dns v1.1.56/go.mod h1:cRm6Oo2C8TY9ZS/TqsSrseAcncm74lfK5G+ikN2SWWY= +github.com/miekg/dns v1.1.57 h1:Jzi7ApEIzwEPLHWRcafCN9LZSBbqQpxjt/wpgvg7wcM= +github.com/miekg/dns v1.1.57/go.mod h1:uqRjCRUuEAA6qsOiJvDd+CFo/vW+y5WR6SNmHE55hZk= github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c h1:bzE/A84HN25pxAuk9Eej1Kz9OUelF97nAc82bDquQI8= github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c/go.mod h1:0SQS9kMwD2VsyFEB++InYyBJroV/FRmBgcydeSUcJms= github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b h1:z78hV3sbSMAUoyUMM0I83AUIT6Hu17AWfgjzIbtrYFc= @@ -362,11 +364,11 @@ github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJE github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4= -github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= +github.com/onsi/ginkgo/v2 v2.13.1 h1:LNGfMbR2OVGBfXjvRZIZ2YCTQdGKtPLvuI1rMCCj3OU= +github.com/onsi/ginkgo/v2 v2.13.1/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= -github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= +github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg= +github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opencontainers/runtime-spec v1.1.0 h1:HHUyrt9mwHUjtasSbXSMvs4cyFxh+Bll4AjJ9odEGpg= github.com/opencontainers/runtime-spec v1.1.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= @@ -385,24 +387,24 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/polydawn/refmt v0.89.0 h1:ADJTApkvkeBZsN0tBTx8QjpD9JkmxbKp0cxfr9qszm4= github.com/polydawn/refmt v0.89.0/go.mod h1:/zvteZs/GwLtCgZ4BL6CBsk9IKIlexP43ObX9AxTqTw= github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8= -github.com/prometheus/client_golang v1.16.0/go.mod h1:Zsulrv/L9oM40tJ7T815tM89lFEugiJ9HzIqaAx4LKc= +github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q= +github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY= -github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= +github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= +github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY= -github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY= +github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM= +github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY= github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI= -github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= -github.com/quic-go/qtls-go1-20 v0.3.4 h1:MfFAPULvst4yoMgY9QmtpYmfij/em7O8UUi+bNVm7Cg= -github.com/quic-go/qtls-go1-20 v0.3.4/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k= -github.com/quic-go/quic-go v0.39.3 h1:o3YB6t2SR+HU/pgwF29kJ6g4jJIJEwEZ8CKia1h1TKg= -github.com/quic-go/quic-go v0.39.3/go.mod h1:T09QsDQWjLiQ74ZmacDfqZmhY/NLnw5BC40MANNNZ1Q= +github.com/quic-go/qtls-go1-20 v0.4.1 h1:D33340mCNDAIKBqXuAvexTNMUByrYmFYVfKfDN5nfFs= +github.com/quic-go/qtls-go1-20 v0.4.1/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k= +github.com/quic-go/quic-go v0.40.0 h1:GYd1iznlKm7dpHD7pOVpUvItgMPo/jrMgDWZhMCecqw= +github.com/quic-go/quic-go v0.40.0/go.mod h1:PeN7kuVJ4xZbxSv/4OX6S1USOX8MJvydwpTx31vx60c= github.com/quic-go/webtransport-go v0.6.0 h1:CvNsKqc4W2HljHJnoT+rMmbRJybShZ0YPFDD3NxaZLY= github.com/quic-go/webtransport-go v0.6.0/go.mod h1:9KjU4AEBqEQidGHNDkZrb8CAa1abRaosM2yGOyiikEc= github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtBsk= @@ -414,8 +416,8 @@ github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/samber/lo v1.36.0 h1:4LaOxH1mHnbDGhTVE0i1z8v/lWaQW8AIfOD3HU4mSaw= -github.com/samber/lo v1.36.0/go.mod h1:HLeWcJRRyLKp3+/XBJvOrerCQn9mhdKMHyd7IRlgeQ8= +github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM= +github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shurcooL/component v0.0.0-20170202220835-f88ec8f54cc4/go.mod h1:XhFIlyj5a1fBNx5aJTbKoIq0mNaPvOagO+HjB3EtxrY= github.com/shurcooL/events v0.0.0-20181021180414-410e4ca65f48/go.mod h1:5u70Mqkb5O5cxEA8nxTsgrgLehJeAw6Oc4Ab1c/P1HM= @@ -476,8 +478,6 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= -github.com/thoas/go-funk v0.9.1 h1:O549iLZqPpTUQ10ykd26sZhzD+rmR5pWhuElrhbC20M= -github.com/thoas/go-funk v0.9.1/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli v1.22.10/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= @@ -503,10 +503,12 @@ go.opencensus.io v0.22.1/go.mod h1:Ap50jQcDJrx6rB6VgeeFPtuPIf3wMRvRfrfYDO6+BmA= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= -go.opentelemetry.io/otel v1.14.0 h1:/79Huy8wbf5DnIPhemGB+zEPVwnN6fuQybr/SRXa6hM= -go.opentelemetry.io/otel v1.14.0/go.mod h1:o4buv+dJzx8rohcUeRmWUZhqupFvzWis188WlggnNeU= -go.opentelemetry.io/otel/trace v1.14.0 h1:wp2Mmvj41tDsyAJXiWDWpfNsOiIyd38fy85pyKcFq/M= -go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+gozhnZjy/rw9G8= +go.opentelemetry.io/otel v1.21.0 h1:hzLeKBZEL7Okw2mGzZ0cc4k/A7Fta0uoPgaJCr8fsFc= +go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znnUvNNEo= +go.opentelemetry.io/otel/metric v1.21.0 h1:tlYWfeo+Bocx5kLEloTjbcDwBuELRrIFxwdQ36PlJu4= +go.opentelemetry.io/otel/metric v1.21.0/go.mod h1:o1p3CA8nNHW8j5yuQLdc1eeqEaPfzug24uvsyIEJRWM= +go.opentelemetry.io/otel/trace v1.21.0 h1:WD9i5gzvoUPuXIXH24ZNBudiarZDKuekPqi/E8fpfLc= +go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= @@ -544,11 +546,11 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200602180216-279210d13fed/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA= +golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= -golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= +golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ= +golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -560,8 +562,8 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= -golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= +golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -580,8 +582,8 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= +golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -595,8 +597,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= -golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= +golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -621,15 +623,15 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -651,14 +653,14 @@ golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= -golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= +golang.org/x/tools v0.15.0 h1:zdAyfUGbYmuVokhzVmghFl2ZJh5QhcfebBgmVPFYA+8= +golang.org/x/tools v0.15.0/go.mod h1:hpksKq4dtpQWS1uQ61JkdqWM3LscIS6Slf+VVkm+wQk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gonum.org/v1/gonum v0.11.0 h1:f1IJhK4Km5tBJmaiJXtk/PkL4cdVX6J+tGiM187uT5E= -gonum.org/v1/gonum v0.11.0/go.mod h1:fSG4YDCxxUZQJ7rKsQrj0gMOg00Il0Z96/qMA4bVQhA= +gonum.org/v1/gonum v0.14.0 h1:2NiG67LD1tEH0D7kM+ps2V+fXmsAnpUeec7n8tcr4S0= +gonum.org/v1/gonum v0.14.0/go.mod h1:AoWeoz0becf9QMWtE8iWXNXc27fK4fNeHNf/oMejGfU= google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.1.0/go.mod h1:UGEZY7KEX120AnNLIHFMKIo4obdJhkp2tPbaPlQx13Y= @@ -693,7 +695,6 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/server.go b/server.go index 0363452..a839717 100644 --- a/server.go +++ b/server.go @@ -5,22 +5,12 @@ import ( "log" "net/http" "strconv" - "time" - "github.com/ipfs/boxo/ipns" "github.com/ipfs/boxo/routing/http/client" - "github.com/ipfs/boxo/routing/http/contentrouter" "github.com/ipfs/boxo/routing/http/server" - "github.com/ipfs/boxo/routing/http/types" - "github.com/ipfs/boxo/routing/http/types/iter" - "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p" dht "github.com/libp2p/go-libp2p-kad-dht" - "github.com/libp2p/go-libp2p-kad-dht/fullrt" - record "github.com/libp2p/go-libp2p-record" - routinghelpers "github.com/libp2p/go-libp2p-routing-helpers" "github.com/libp2p/go-libp2p/core/host" - "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/routing" rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager" ) @@ -33,7 +23,7 @@ func start(ctx context.Context, port int, runAcceleratedDHTClient bool, contentE var dhtRouting routing.Routing if runAcceleratedDHTClient { - wrappedDHT, err := newWrappedStandardAndAcceleratedDHTClient(ctx, h) + wrappedDHT, err := newBundledDHT(ctx, h) if err != nil { return err } @@ -61,16 +51,14 @@ func start(ctx context.Context, port int, runAcceleratedDHTClient bool, contentE return err } - proxy := &delegatedRoutingProxy{ - cr: crRouters, - pr: prRouters, - vs: ipnsRouters, - } - log.Printf("Listening on http://0.0.0.0:%d", port) log.Printf("Delegated Routing API on http://127.0.0.1:%d/routing/v1", port) - http.Handle("/", server.Handler(proxy)) + http.Handle("/", server.Handler(&composableRouter{ + providers: crRouters, + peers: prRouters, + ipns: ipnsRouters, + })) return http.ListenAndServe(":"+strconv.Itoa(port), nil) } @@ -108,222 +96,22 @@ func newHost(highOutboundLimits bool) (host.Host, error) { return h, nil } -type wrappedStandardAndAcceleratedDHTClient struct { - standard *dht.IpfsDHT - accelerated *fullrt.FullRT -} - -func newWrappedStandardAndAcceleratedDHTClient(ctx context.Context, h host.Host) (routing.Routing, error) { - standardDHT, err := dht.New(ctx, h, dht.Mode(dht.ModeClient), dht.BootstrapPeers(dht.GetDefaultBootstrapPeerAddrInfos()...)) - if err != nil { - return nil, err - } - - acceleratedDHT, err := fullrt.NewFullRT(h, "/ipfs", - fullrt.DHTOption( - dht.BucketSize(20), - dht.Validator(record.NamespacedValidator{ - "pk": record.PublicKeyValidator{}, - "ipns": ipns.Validator{}, - }), - dht.BootstrapPeers(dht.GetDefaultBootstrapPeerAddrInfos()...), - dht.Mode(dht.ModeClient), - )) - if err != nil { - return nil, err - } - - return &wrappedStandardAndAcceleratedDHTClient{ - standard: standardDHT, - accelerated: acceleratedDHT, - }, nil -} - -func (w *wrappedStandardAndAcceleratedDHTClient) Provide(ctx context.Context, c cid.Cid, b bool) error { - if w.accelerated.Ready() { - return w.accelerated.Provide(ctx, c, b) - } - return w.standard.Provide(ctx, c, b) -} - -func (w *wrappedStandardAndAcceleratedDHTClient) FindProvidersAsync(ctx context.Context, c cid.Cid, i int) <-chan peer.AddrInfo { - if w.accelerated.Ready() { - return w.accelerated.FindProvidersAsync(ctx, c, i) - } - return w.standard.FindProvidersAsync(ctx, c, i) -} - -func (w *wrappedStandardAndAcceleratedDHTClient) FindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo, error) { - if w.accelerated.Ready() { - return w.accelerated.FindPeer(ctx, p) - } - return w.standard.FindPeer(ctx, p) -} - -func (w *wrappedStandardAndAcceleratedDHTClient) PutValue(ctx context.Context, key string, value []byte, opts ...routing.Option) error { - if w.accelerated.Ready() { - return w.accelerated.PutValue(ctx, key, value, opts...) - } - return w.standard.PutValue(ctx, key, value, opts...) -} - -func (w *wrappedStandardAndAcceleratedDHTClient) GetValue(ctx context.Context, s string, opts ...routing.Option) ([]byte, error) { - if w.accelerated.Ready() { - return w.accelerated.GetValue(ctx, s, opts...) - } - return w.standard.GetValue(ctx, s, opts...) -} - -func (w *wrappedStandardAndAcceleratedDHTClient) SearchValue(ctx context.Context, s string, opts ...routing.Option) (<-chan []byte, error) { - if w.accelerated.Ready() { - return w.accelerated.SearchValue(ctx, s, opts...) - } - return w.standard.SearchValue(ctx, s, opts...) -} - -func (w *wrappedStandardAndAcceleratedDHTClient) Bootstrap(ctx context.Context) error { - return w.standard.Bootstrap(ctx) -} - -func getCombinedRouting(endpoints []string, dht routing.Routing) (routing.Routing, error) { +func getCombinedRouting(endpoints []string, dht routing.Routing) (server.ContentRouter, error) { if len(endpoints) == 0 { - return dht, nil + return dhtRouter{dht: dht}, nil } - var routers []routing.Routing + var routers []server.ContentRouter for _, endpoint := range endpoints { drclient, err := client.New(endpoint) if err != nil { return nil, err } - routers = append(routers, newWrappedDelegatedRouting(drclient)) + routers = append(routers, wrappedClient{Client: drclient}) } - return routinghelpers.Parallel{ - Routers: append(routers, dht), + return parallelRouter{ + routers: append(routers, dhtRouter{dht: dht}), }, nil } - -type wrappedDelegatedRouting struct { - routing.ValueStore - routing.PeerRouting - routing.ContentRouting -} - -func newWrappedDelegatedRouting(drc *client.Client) routing.Routing { - v := contentrouter.NewContentRoutingClient(drc) - - return &wrappedDelegatedRouting{ - ValueStore: v, - PeerRouting: v, - ContentRouting: v, - } -} - -func (c *wrappedDelegatedRouting) Bootstrap(ctx context.Context) error { - return routing.ErrNotSupported -} - -type delegatedRoutingProxy struct { - cr routing.ContentRouting - pr routing.PeerRouting - vs routing.ValueStore -} - -func (d *delegatedRoutingProxy) FindProviders(ctx context.Context, key cid.Cid, limit int) (iter.ResultIter[types.Record], error) { - ctx, cancel := context.WithCancel(ctx) - ch := d.cr.FindProvidersAsync(ctx, key, limit) - return iter.ToResultIter[types.Record](&peerChanIter{ - ch: ch, - cancel: cancel, - }), nil -} - -//lint:ignore SA1019 // ignore staticcheck -func (d *delegatedRoutingProxy) ProvideBitswap(ctx context.Context, req *server.BitswapWriteProvideRequest) (time.Duration, error) { - return 0, routing.ErrNotSupported -} - -func (d *delegatedRoutingProxy) FindPeers(ctx context.Context, pid peer.ID, limit int) (iter.ResultIter[*types.PeerRecord], error) { - ctx, cancel := context.WithCancel(ctx) - defer cancel() - - addr, err := d.pr.FindPeer(ctx, pid) - if err != nil { - return nil, err - } - - rec := &types.PeerRecord{ - Schema: types.SchemaPeer, - ID: &addr.ID, - } - - for _, addr := range addr.Addrs { - rec.Addrs = append(rec.Addrs, types.Multiaddr{Multiaddr: addr}) - } - - return iter.ToResultIter[*types.PeerRecord](iter.FromSlice[*types.PeerRecord]([]*types.PeerRecord{rec})), nil -} - -func (d *delegatedRoutingProxy) GetIPNS(ctx context.Context, name ipns.Name) (*ipns.Record, error) { - ctx, cancel := context.WithCancel(ctx) - defer cancel() - - raw, err := d.vs.GetValue(ctx, string(name.RoutingKey())) - if err != nil { - return nil, err - } - - return ipns.UnmarshalRecord(raw) -} - -func (d *delegatedRoutingProxy) PutIPNS(ctx context.Context, name ipns.Name, record *ipns.Record) error { - ctx, cancel := context.WithCancel(ctx) - defer cancel() - - raw, err := ipns.MarshalRecord(record) - if err != nil { - return err - } - - return d.vs.PutValue(ctx, string(name.RoutingKey()), raw) -} - -type peerChanIter struct { - ch <-chan peer.AddrInfo - cancel context.CancelFunc - next *peer.AddrInfo -} - -func (it *peerChanIter) Next() bool { - addr, ok := <-it.ch - if ok { - it.next = &addr - return true - } - it.next = nil - return false -} - -func (it *peerChanIter) Val() types.Record { - if it.next == nil { - return nil - } - - rec := &types.PeerRecord{ - Schema: types.SchemaPeer, - ID: &it.next.ID, - } - - for _, addr := range it.next.Addrs { - rec.Addrs = append(rec.Addrs, types.Multiaddr{Multiaddr: addr}) - } - - return rec -} - -func (it *peerChanIter) Close() error { - it.cancel() - return nil -} diff --git a/server_dht.go b/server_dht.go new file mode 100644 index 0000000..70cf291 --- /dev/null +++ b/server_dht.go @@ -0,0 +1,80 @@ +package main + +import ( + "context" + + "github.com/ipfs/boxo/ipns" + "github.com/ipfs/go-cid" + dht "github.com/libp2p/go-libp2p-kad-dht" + "github.com/libp2p/go-libp2p-kad-dht/fullrt" + record "github.com/libp2p/go-libp2p-record" + "github.com/libp2p/go-libp2p/core/host" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/routing" +) + +type bundledDHT struct { + standard *dht.IpfsDHT + fullRT *fullrt.FullRT +} + +func newBundledDHT(ctx context.Context, h host.Host) (routing.Routing, error) { + standardDHT, err := dht.New(ctx, h, dht.Mode(dht.ModeClient), dht.BootstrapPeers(dht.GetDefaultBootstrapPeerAddrInfos()...)) + if err != nil { + return nil, err + } + + fullRT, err := fullrt.NewFullRT(h, "/ipfs", + fullrt.DHTOption( + dht.BucketSize(20), + dht.Validator(record.NamespacedValidator{ + "pk": record.PublicKeyValidator{}, + "ipns": ipns.Validator{}, + }), + dht.BootstrapPeers(dht.GetDefaultBootstrapPeerAddrInfos()...), + dht.Mode(dht.ModeClient), + )) + if err != nil { + return nil, err + } + + return &bundledDHT{ + standard: standardDHT, + fullRT: fullRT, + }, nil +} + +func (b *bundledDHT) getDHT() routing.Routing { + if b.fullRT.Ready() { + return b.fullRT + } + return b.standard +} + +func (b *bundledDHT) Provide(ctx context.Context, c cid.Cid, brdcst bool) error { + return b.getDHT().Provide(ctx, c, brdcst) +} + +func (b *bundledDHT) FindProvidersAsync(ctx context.Context, c cid.Cid, i int) <-chan peer.AddrInfo { + return b.getDHT().FindProvidersAsync(ctx, c, i) +} + +func (b *bundledDHT) FindPeer(ctx context.Context, id peer.ID) (peer.AddrInfo, error) { + return b.getDHT().FindPeer(ctx, id) +} + +func (b *bundledDHT) PutValue(ctx context.Context, k string, v []byte, option ...routing.Option) error { + return b.getDHT().PutValue(ctx, k, v, option...) +} + +func (b *bundledDHT) GetValue(ctx context.Context, s string, option ...routing.Option) ([]byte, error) { + return b.getDHT().GetValue(ctx, s, option...) +} + +func (b *bundledDHT) SearchValue(ctx context.Context, s string, option ...routing.Option) (<-chan []byte, error) { + return b.getDHT().SearchValue(ctx, s, option...) +} + +func (b *bundledDHT) Bootstrap(ctx context.Context) error { + return b.standard.Bootstrap(ctx) +} diff --git a/server_routers.go b/server_routers.go new file mode 100644 index 0000000..9285063 --- /dev/null +++ b/server_routers.go @@ -0,0 +1,349 @@ +package main + +import ( + "context" + "errors" + "sync" + "time" + + "github.com/ipfs/boxo/ipns" + "github.com/ipfs/boxo/routing/http/client" + "github.com/ipfs/boxo/routing/http/server" + "github.com/ipfs/boxo/routing/http/types" + "github.com/ipfs/boxo/routing/http/types/iter" + "github.com/ipfs/go-cid" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/routing" +) + +var _ server.ContentRouter = composableRouter{} + +type composableRouter struct { + providers server.ContentRouter + peers server.ContentRouter + ipns server.ContentRouter +} + +func (r composableRouter) FindProviders(ctx context.Context, key cid.Cid, limit int) (iter.ResultIter[types.Record], error) { + return r.providers.FindProviders(ctx, key, limit) +} + +//lint:ignore SA1019 // ignore staticcheck +func (r composableRouter) ProvideBitswap(ctx context.Context, req *server.BitswapWriteProvideRequest) (time.Duration, error) { + return 0, routing.ErrNotSupported +} + +func (r composableRouter) FindPeers(ctx context.Context, pid peer.ID, limit int) (iter.ResultIter[*types.PeerRecord], error) { + return r.providers.FindPeers(ctx, pid, limit) +} + +func (r composableRouter) GetIPNS(ctx context.Context, name ipns.Name) (*ipns.Record, error) { + return r.ipns.GetIPNS(ctx, name) +} + +func (r composableRouter) PutIPNS(ctx context.Context, name ipns.Name, record *ipns.Record) error { + return r.ipns.PutIPNS(ctx, name, record) +} + +var _ server.ContentRouter = parallelRouter{} + +type parallelRouter struct { + routers []server.ContentRouter +} + +func (r parallelRouter) FindProviders(ctx context.Context, key cid.Cid, limit int) (iter.ResultIter[types.Record], error) { + switch len(r.routers) { + case 0: + return iter.ToResultIter(iter.FromSlice([]types.Record{})), nil + case 1: + return r.routers[0].FindProviders(ctx, key, limit) + } + + its := make([]iter.ResultIter[types.Record], len(r.routers)) + for i, ri := range r.routers { + var err error + its[i], err = ri.FindProviders(ctx, key, limit) + if err != nil { + for _, it := range its { + if it != nil { + _ = it.Close() + } + } + return nil, err + } + } + return &manyIter[types.Record]{it: its}, nil +} + +type manyIter[T any] struct { + it []iter.ResultIter[T] + next int +} + +func (mi *manyIter[T]) Next() bool { + for i, it := range mi.it { + if it.Next() { + mi.next = i + return true + } + } + + mi.next = -1 + return false +} + +func (mi *manyIter[T]) Val() iter.Result[T] { + if mi.next == -1 { + return iter.Result[T]{Err: errors.New("no next value")} + } + return mi.it[mi.next].Val() +} + +func (mi *manyIter[T]) Close() error { + var err error + for _, it := range mi.it { + err = errors.Join(err, it.Close()) + } + return err +} + +//lint:ignore SA1019 // ignore staticcheck +func (r parallelRouter) ProvideBitswap(ctx context.Context, req *server.BitswapWriteProvideRequest) (time.Duration, error) { + return 0, routing.ErrNotSupported +} + +func (r parallelRouter) FindPeers(ctx context.Context, pid peer.ID, limit int) (iter.ResultIter[*types.PeerRecord], error) { + switch len(r.routers) { + case 0: + return iter.ToResultIter(iter.FromSlice([]*types.PeerRecord{})), nil + case 1: + return r.routers[0].FindPeers(ctx, pid, limit) + } + + its := make([]iter.ResultIter[*types.PeerRecord], len(r.routers)) + for i, ri := range r.routers { + var err error + its[i], err = ri.FindPeers(ctx, pid, limit) + if err != nil { + for _, it := range its { + if it != nil { + _ = it.Close() + } + } + return nil, err + } + } + return &manyIter[*types.PeerRecord]{it: its}, nil +} + +func (r parallelRouter) GetIPNS(ctx context.Context, name ipns.Name) (*ipns.Record, error) { + switch len(r.routers) { + case 0: + return nil, routing.ErrNotFound + case 1: + return r.routers[0].GetIPNS(ctx, name) + } + + ctx, cancel := context.WithCancel(ctx) + defer cancel() + + results := make(chan struct { + val *ipns.Record + err error + }) + for _, ri := range r.routers { + go func(ri server.ContentRouter) { + value, err := ri.GetIPNS(ctx, name) + select { + case results <- struct { + val *ipns.Record + err error + }{ + val: value, + err: err, + }: + case <-ctx.Done(): + } + }(ri) + } + + var errs error + + for range r.routers { + select { + case res := <-results: + switch res.err { + case nil: + return res.val, nil + case routing.ErrNotFound, routing.ErrNotSupported: + continue + } + // If the context has expired, just return that error + // and ignore the other errors. + if ctx.Err() != nil { + return nil, ctx.Err() + } + + errs = errors.Join(errs, res.err) + case <-ctx.Done(): + return nil, ctx.Err() + } + } + + if errs == nil { + return nil, routing.ErrNotFound + } + + return nil, errs +} + +func (r parallelRouter) PutIPNS(ctx context.Context, name ipns.Name, record *ipns.Record) error { + switch len(r.routers) { + case 0: + return nil + case 1: + return r.routers[0].PutIPNS(ctx, name, record) + } + + ctx, cancel := context.WithCancel(ctx) + defer cancel() + + var wg sync.WaitGroup + results := make([]error, len(r.routers)) + wg.Add(len(r.routers)) + for i, ri := range r.routers { + go func(ri server.ContentRouter, i int) { + results[i] = ri.PutIPNS(ctx, name, record) + wg.Done() + }(ri, i) + } + wg.Wait() + + var errs error + for _, err := range results { + errs = errors.Join(errs, err) + } + return errs +} + +var _ server.ContentRouter = dhtRouter{} + +type dhtRouter struct { + dht routing.Routing +} + +func (d dhtRouter) FindProviders(ctx context.Context, key cid.Cid, limit int) (iter.ResultIter[types.Record], error) { + ctx, cancel := context.WithCancel(ctx) + ch := d.dht.FindProvidersAsync(ctx, key, limit) + return iter.ToResultIter[types.Record](&peerChanIter{ + ch: ch, + cancel: cancel, + }), nil +} + +func (d dhtRouter) FindPeers(ctx context.Context, pid peer.ID, limit int) (iter.ResultIter[*types.PeerRecord], error) { + ctx, cancel := context.WithCancel(ctx) + defer cancel() + + addr, err := d.dht.FindPeer(ctx, pid) + if err != nil { + return nil, err + } + + rec := &types.PeerRecord{ + Schema: types.SchemaPeer, + ID: &addr.ID, + } + + for _, addr := range addr.Addrs { + rec.Addrs = append(rec.Addrs, types.Multiaddr{Multiaddr: addr}) + } + + return iter.ToResultIter[*types.PeerRecord](iter.FromSlice[*types.PeerRecord]([]*types.PeerRecord{rec})), nil +} + +func (d dhtRouter) GetIPNS(ctx context.Context, name ipns.Name) (*ipns.Record, error) { + ctx, cancel := context.WithCancel(ctx) + defer cancel() + + raw, err := d.dht.GetValue(ctx, string(name.RoutingKey())) + if err != nil { + return nil, err + } + + return ipns.UnmarshalRecord(raw) +} + +func (d dhtRouter) PutIPNS(ctx context.Context, name ipns.Name, record *ipns.Record) error { + ctx, cancel := context.WithCancel(ctx) + defer cancel() + + raw, err := ipns.MarshalRecord(record) + if err != nil { + return err + } + + return d.dht.PutValue(ctx, string(name.RoutingKey()), raw) +} + +//lint:ignore SA1019 // ignore staticcheck +func (d dhtRouter) ProvideBitswap(ctx context.Context, req *server.BitswapWriteProvideRequest) (time.Duration, error) { + return 0, routing.ErrNotSupported +} + +type peerChanIter struct { + ch <-chan peer.AddrInfo + cancel context.CancelFunc + next *peer.AddrInfo +} + +func (it *peerChanIter) Next() bool { + addr, ok := <-it.ch + if ok { + it.next = &addr + return true + } + it.next = nil + return false +} + +func (it *peerChanIter) Val() types.Record { + if it.next == nil { + return nil + } + + rec := &types.PeerRecord{ + Schema: types.SchemaPeer, + ID: &it.next.ID, + } + + for _, addr := range it.next.Addrs { + rec.Addrs = append(rec.Addrs, types.Multiaddr{Multiaddr: addr}) + } + + return rec +} + +func (it *peerChanIter) Close() error { + it.cancel() + return nil +} + +var _ server.ContentRouter = wrappedClient{} + +type wrappedClient struct { + *client.Client +} + +func (d wrappedClient) FindProviders(ctx context.Context, cid cid.Cid, limit int) (iter.ResultIter[types.Record], error) { + return d.Client.FindProviders(ctx, cid) +} + +func (d wrappedClient) FindPeers(ctx context.Context, pid peer.ID, limit int) (iter.ResultIter[*types.PeerRecord], error) { + return d.Client.FindPeers(ctx, pid) +} + +//lint:ignore SA1019 // ignore staticcheck +func (d wrappedClient) ProvideBitswap(ctx context.Context, req *server.BitswapWriteProvideRequest) (time.Duration, error) { + return 0, routing.ErrNotSupported +} From 72cc034d712c600e3fda87cafa29fef8d65e91d7 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 30 Nov 2023 10:59:18 +0100 Subject: [PATCH 02/10] refactor: use generics for FindProviders and FindPeers --- server_routers.go | 81 ++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 44 deletions(-) diff --git a/server_routers.go b/server_routers.go index 9285063..bb4718c 100644 --- a/server_routers.go +++ b/server_routers.go @@ -52,27 +52,49 @@ type parallelRouter struct { } func (r parallelRouter) FindProviders(ctx context.Context, key cid.Cid, limit int) (iter.ResultIter[types.Record], error) { - switch len(r.routers) { + return find(r.routers, func(ri server.ContentRouter) (iter.ResultIter[types.Record], error) { + return ri.FindProviders(ctx, key, limit) + }) +} + +//lint:ignore SA1019 // ignore staticcheck +func (r parallelRouter) ProvideBitswap(ctx context.Context, req *server.BitswapWriteProvideRequest) (time.Duration, error) { + return 0, routing.ErrNotSupported +} + +func (r parallelRouter) FindPeers(ctx context.Context, pid peer.ID, limit int) (iter.ResultIter[*types.PeerRecord], error) { + return find(r.routers, func(ri server.ContentRouter) (iter.ResultIter[*types.PeerRecord], error) { + return ri.FindPeers(ctx, pid, limit) + }) +} + +func find[T any](routers []server.ContentRouter, call func(server.ContentRouter) (iter.ResultIter[T], error)) (iter.ResultIter[T], error) { + switch len(routers) { case 0: - return iter.ToResultIter(iter.FromSlice([]types.Record{})), nil + return iter.ToResultIter(iter.FromSlice([]T{})), nil case 1: - return r.routers[0].FindProviders(ctx, key, limit) + return call(routers[0]) } - its := make([]iter.ResultIter[types.Record], len(r.routers)) - for i, ri := range r.routers { - var err error - its[i], err = ri.FindProviders(ctx, key, limit) - if err != nil { - for _, it := range its { - if it != nil { - _ = it.Close() - } - } - return nil, err + its := make([]iter.ResultIter[T], 0, len(routers)) + var err error + for _, ri := range routers { + it, itErr := call(ri) + + if itErr != nil { + err = errors.Join(err, itErr) + } else { + its = append(its, it) } } - return &manyIter[types.Record]{it: its}, nil + + // If all iterators failed to be created, then return the error. + if len(its) == 0 { + return nil, err + } + + // Otherwise return manyIter with remaining iterators. + return &manyIter[T]{it: its}, nil } type manyIter[T any] struct { @@ -107,35 +129,6 @@ func (mi *manyIter[T]) Close() error { return err } -//lint:ignore SA1019 // ignore staticcheck -func (r parallelRouter) ProvideBitswap(ctx context.Context, req *server.BitswapWriteProvideRequest) (time.Duration, error) { - return 0, routing.ErrNotSupported -} - -func (r parallelRouter) FindPeers(ctx context.Context, pid peer.ID, limit int) (iter.ResultIter[*types.PeerRecord], error) { - switch len(r.routers) { - case 0: - return iter.ToResultIter(iter.FromSlice([]*types.PeerRecord{})), nil - case 1: - return r.routers[0].FindPeers(ctx, pid, limit) - } - - its := make([]iter.ResultIter[*types.PeerRecord], len(r.routers)) - for i, ri := range r.routers { - var err error - its[i], err = ri.FindPeers(ctx, pid, limit) - if err != nil { - for _, it := range its { - if it != nil { - _ = it.Close() - } - } - return nil, err - } - } - return &manyIter[*types.PeerRecord]{it: its}, nil -} - func (r parallelRouter) GetIPNS(ctx context.Context, name ipns.Name) (*ipns.Record, error) { switch len(r.routers) { case 0: From 27a543bb6e1b5f8680487ed8304ff0628f322832 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 30 Nov 2023 11:21:33 +0100 Subject: [PATCH 03/10] refactor: manyIter now channels --- server_routers.go | 52 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/server_routers.go b/server_routers.go index bb4718c..8fdfea1 100644 --- a/server_routers.go +++ b/server_routers.go @@ -52,7 +52,7 @@ type parallelRouter struct { } func (r parallelRouter) FindProviders(ctx context.Context, key cid.Cid, limit int) (iter.ResultIter[types.Record], error) { - return find(r.routers, func(ri server.ContentRouter) (iter.ResultIter[types.Record], error) { + return find(ctx, r.routers, func(ri server.ContentRouter) (iter.ResultIter[types.Record], error) { return ri.FindProviders(ctx, key, limit) }) } @@ -63,12 +63,12 @@ func (r parallelRouter) ProvideBitswap(ctx context.Context, req *server.BitswapW } func (r parallelRouter) FindPeers(ctx context.Context, pid peer.ID, limit int) (iter.ResultIter[*types.PeerRecord], error) { - return find(r.routers, func(ri server.ContentRouter) (iter.ResultIter[*types.PeerRecord], error) { + return find(ctx, r.routers, func(ri server.ContentRouter) (iter.ResultIter[*types.PeerRecord], error) { return ri.FindPeers(ctx, pid, limit) }) } -func find[T any](routers []server.ContentRouter, call func(server.ContentRouter) (iter.ResultIter[T], error)) (iter.ResultIter[T], error) { +func find[T any](ctx context.Context, routers []server.ContentRouter, call func(server.ContentRouter) (iter.ResultIter[T], error)) (iter.ResultIter[T], error) { switch len(routers) { case 0: return iter.ToResultIter(iter.FromSlice([]T{})), nil @@ -94,36 +94,56 @@ func find[T any](routers []server.ContentRouter, call func(server.ContentRouter) } // Otherwise return manyIter with remaining iterators. - return &manyIter[T]{it: its}, nil + return newManyIter(ctx, its), nil } type manyIter[T any] struct { - it []iter.ResultIter[T] - next int + ctx context.Context + its []iter.ResultIter[T] + nextCh chan int + next int } -func (mi *manyIter[T]) Next() bool { - for i, it := range mi.it { - if it.Next() { - mi.next = i - return true - } +func newManyIter[T any](ctx context.Context, its []iter.ResultIter[T]) *manyIter[T] { + nextCh := make(chan int) + + for i, it := range its { + go func(ch chan int, it iter.ResultIter[T], index int) { + for it.Next() { + ch <- index + } + }(nextCh, it, i) } - mi.next = -1 - return false + return &manyIter[T]{ + ctx: ctx, + its: its, + nextCh: nextCh, + next: -1, + } +} + +func (mi *manyIter[T]) Next() bool { + select { + case i := <-mi.nextCh: + mi.next = i + return true + case <-mi.ctx.Done(): + mi.next = -1 + return false + } } func (mi *manyIter[T]) Val() iter.Result[T] { if mi.next == -1 { return iter.Result[T]{Err: errors.New("no next value")} } - return mi.it[mi.next].Val() + return mi.its[mi.next].Val() } func (mi *manyIter[T]) Close() error { var err error - for _, it := range mi.it { + for _, it := range mi.its { err = errors.Join(err, it.Close()) } return err From 6b5640dc1c2f604ad94557b70b028204f615bc66 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 30 Nov 2023 11:30:58 +0100 Subject: [PATCH 04/10] refactor: cleanup names and interfaces --- server.go | 10 ++--- server_routers.go | 111 +++++++++++++++++++++++++++------------------- 2 files changed, 71 insertions(+), 50 deletions(-) diff --git a/server.go b/server.go index a839717..0638344 100644 --- a/server.go +++ b/server.go @@ -96,22 +96,22 @@ func newHost(highOutboundLimits bool) (host.Host, error) { return h, nil } -func getCombinedRouting(endpoints []string, dht routing.Routing) (server.ContentRouter, error) { +func getCombinedRouting(endpoints []string, dht routing.Routing) (router, error) { if len(endpoints) == 0 { - return dhtRouter{dht: dht}, nil + return libp2pRouter{routing: dht}, nil } - var routers []server.ContentRouter + var routers []router for _, endpoint := range endpoints { drclient, err := client.New(endpoint) if err != nil { return nil, err } - routers = append(routers, wrappedClient{Client: drclient}) + routers = append(routers, clientRouter{Client: drclient}) } return parallelRouter{ - routers: append(routers, dhtRouter{dht: dht}), + routers: append(routers, libp2pRouter{routing: dht}), }, nil } diff --git a/server_routers.go b/server_routers.go index 8fdfea1..bc3c312 100644 --- a/server_routers.go +++ b/server_routers.go @@ -16,59 +16,85 @@ import ( "github.com/libp2p/go-libp2p/core/routing" ) +type router interface { + providersRouter + peersRouter + ipnsRouter +} + +type providersRouter interface { + FindProviders(ctx context.Context, cid cid.Cid, limit int) (iter.ResultIter[types.Record], error) +} + +type peersRouter interface { + FindPeers(ctx context.Context, pid peer.ID, limit int) (iter.ResultIter[*types.PeerRecord], error) +} + +type ipnsRouter interface { + GetIPNS(ctx context.Context, name ipns.Name) (*ipns.Record, error) + PutIPNS(ctx context.Context, name ipns.Name, record *ipns.Record) error +} + var _ server.ContentRouter = composableRouter{} type composableRouter struct { - providers server.ContentRouter - peers server.ContentRouter - ipns server.ContentRouter + providers providersRouter + peers peersRouter + ipns ipnsRouter } func (r composableRouter) FindProviders(ctx context.Context, key cid.Cid, limit int) (iter.ResultIter[types.Record], error) { + if r.providers == nil { + return iter.ToResultIter(iter.FromSlice([]types.Record{})), nil + } return r.providers.FindProviders(ctx, key, limit) } -//lint:ignore SA1019 // ignore staticcheck -func (r composableRouter) ProvideBitswap(ctx context.Context, req *server.BitswapWriteProvideRequest) (time.Duration, error) { - return 0, routing.ErrNotSupported -} - func (r composableRouter) FindPeers(ctx context.Context, pid peer.ID, limit int) (iter.ResultIter[*types.PeerRecord], error) { - return r.providers.FindPeers(ctx, pid, limit) + if r.peers == nil { + return iter.ToResultIter(iter.FromSlice([]*types.PeerRecord{})), nil + } + return r.peers.FindPeers(ctx, pid, limit) } func (r composableRouter) GetIPNS(ctx context.Context, name ipns.Name) (*ipns.Record, error) { + if r.ipns == nil { + return nil, routing.ErrNotFound + } return r.ipns.GetIPNS(ctx, name) } func (r composableRouter) PutIPNS(ctx context.Context, name ipns.Name, record *ipns.Record) error { + if r.ipns == nil { + return nil + } return r.ipns.PutIPNS(ctx, name, record) } +//lint:ignore SA1019 // ignore staticcheck +func (r composableRouter) ProvideBitswap(ctx context.Context, req *server.BitswapWriteProvideRequest) (time.Duration, error) { + return 0, routing.ErrNotSupported +} + var _ server.ContentRouter = parallelRouter{} type parallelRouter struct { - routers []server.ContentRouter + routers []router } func (r parallelRouter) FindProviders(ctx context.Context, key cid.Cid, limit int) (iter.ResultIter[types.Record], error) { - return find(ctx, r.routers, func(ri server.ContentRouter) (iter.ResultIter[types.Record], error) { + return find(ctx, r.routers, func(ri router) (iter.ResultIter[types.Record], error) { return ri.FindProviders(ctx, key, limit) }) } -//lint:ignore SA1019 // ignore staticcheck -func (r parallelRouter) ProvideBitswap(ctx context.Context, req *server.BitswapWriteProvideRequest) (time.Duration, error) { - return 0, routing.ErrNotSupported -} - func (r parallelRouter) FindPeers(ctx context.Context, pid peer.ID, limit int) (iter.ResultIter[*types.PeerRecord], error) { - return find(ctx, r.routers, func(ri server.ContentRouter) (iter.ResultIter[*types.PeerRecord], error) { + return find(ctx, r.routers, func(ri router) (iter.ResultIter[*types.PeerRecord], error) { return ri.FindPeers(ctx, pid, limit) }) } -func find[T any](ctx context.Context, routers []server.ContentRouter, call func(server.ContentRouter) (iter.ResultIter[T], error)) (iter.ResultIter[T], error) { +func find[T any](ctx context.Context, routers []router, call func(router) (iter.ResultIter[T], error)) (iter.ResultIter[T], error) { switch len(routers) { case 0: return iter.ToResultIter(iter.FromSlice([]T{})), nil @@ -165,7 +191,7 @@ func (r parallelRouter) GetIPNS(ctx context.Context, name ipns.Name) (*ipns.Reco err error }) for _, ri := range r.routers { - go func(ri server.ContentRouter) { + go func(ri router) { value, err := ri.GetIPNS(ctx, name) select { case results <- struct { @@ -225,7 +251,7 @@ func (r parallelRouter) PutIPNS(ctx context.Context, name ipns.Name, record *ipn results := make([]error, len(r.routers)) wg.Add(len(r.routers)) for i, ri := range r.routers { - go func(ri server.ContentRouter, i int) { + go func(ri router, i int) { results[i] = ri.PutIPNS(ctx, name, record) wg.Done() }(ri, i) @@ -239,26 +265,31 @@ func (r parallelRouter) PutIPNS(ctx context.Context, name ipns.Name, record *ipn return errs } -var _ server.ContentRouter = dhtRouter{} +//lint:ignore SA1019 // ignore staticcheck +func (r parallelRouter) ProvideBitswap(ctx context.Context, req *server.BitswapWriteProvideRequest) (time.Duration, error) { + return 0, routing.ErrNotSupported +} + +var _ router = libp2pRouter{} -type dhtRouter struct { - dht routing.Routing +type libp2pRouter struct { + routing routing.Routing } -func (d dhtRouter) FindProviders(ctx context.Context, key cid.Cid, limit int) (iter.ResultIter[types.Record], error) { +func (d libp2pRouter) FindProviders(ctx context.Context, key cid.Cid, limit int) (iter.ResultIter[types.Record], error) { ctx, cancel := context.WithCancel(ctx) - ch := d.dht.FindProvidersAsync(ctx, key, limit) + ch := d.routing.FindProvidersAsync(ctx, key, limit) return iter.ToResultIter[types.Record](&peerChanIter{ ch: ch, cancel: cancel, }), nil } -func (d dhtRouter) FindPeers(ctx context.Context, pid peer.ID, limit int) (iter.ResultIter[*types.PeerRecord], error) { +func (d libp2pRouter) FindPeers(ctx context.Context, pid peer.ID, limit int) (iter.ResultIter[*types.PeerRecord], error) { ctx, cancel := context.WithCancel(ctx) defer cancel() - addr, err := d.dht.FindPeer(ctx, pid) + addr, err := d.routing.FindPeer(ctx, pid) if err != nil { return nil, err } @@ -275,11 +306,11 @@ func (d dhtRouter) FindPeers(ctx context.Context, pid peer.ID, limit int) (iter. return iter.ToResultIter[*types.PeerRecord](iter.FromSlice[*types.PeerRecord]([]*types.PeerRecord{rec})), nil } -func (d dhtRouter) GetIPNS(ctx context.Context, name ipns.Name) (*ipns.Record, error) { +func (d libp2pRouter) GetIPNS(ctx context.Context, name ipns.Name) (*ipns.Record, error) { ctx, cancel := context.WithCancel(ctx) defer cancel() - raw, err := d.dht.GetValue(ctx, string(name.RoutingKey())) + raw, err := d.routing.GetValue(ctx, string(name.RoutingKey())) if err != nil { return nil, err } @@ -287,7 +318,7 @@ func (d dhtRouter) GetIPNS(ctx context.Context, name ipns.Name) (*ipns.Record, e return ipns.UnmarshalRecord(raw) } -func (d dhtRouter) PutIPNS(ctx context.Context, name ipns.Name, record *ipns.Record) error { +func (d libp2pRouter) PutIPNS(ctx context.Context, name ipns.Name, record *ipns.Record) error { ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -296,12 +327,7 @@ func (d dhtRouter) PutIPNS(ctx context.Context, name ipns.Name, record *ipns.Rec return err } - return d.dht.PutValue(ctx, string(name.RoutingKey()), raw) -} - -//lint:ignore SA1019 // ignore staticcheck -func (d dhtRouter) ProvideBitswap(ctx context.Context, req *server.BitswapWriteProvideRequest) (time.Duration, error) { - return 0, routing.ErrNotSupported + return d.routing.PutValue(ctx, string(name.RoutingKey()), raw) } type peerChanIter struct { @@ -342,21 +368,16 @@ func (it *peerChanIter) Close() error { return nil } -var _ server.ContentRouter = wrappedClient{} +var _ router = clientRouter{} -type wrappedClient struct { +type clientRouter struct { *client.Client } -func (d wrappedClient) FindProviders(ctx context.Context, cid cid.Cid, limit int) (iter.ResultIter[types.Record], error) { +func (d clientRouter) FindProviders(ctx context.Context, cid cid.Cid, limit int) (iter.ResultIter[types.Record], error) { return d.Client.FindProviders(ctx, cid) } -func (d wrappedClient) FindPeers(ctx context.Context, pid peer.ID, limit int) (iter.ResultIter[*types.PeerRecord], error) { +func (d clientRouter) FindPeers(ctx context.Context, pid peer.ID, limit int) (iter.ResultIter[*types.PeerRecord], error) { return d.Client.FindPeers(ctx, pid) } - -//lint:ignore SA1019 // ignore staticcheck -func (d wrappedClient) ProvideBitswap(ctx context.Context, req *server.BitswapWriteProvideRequest) (time.Duration, error) { - return 0, routing.ErrNotSupported -} From aff76759d36c40c6c14a78e3247dc8c392372c16 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Thu, 30 Nov 2023 13:19:53 +0100 Subject: [PATCH 05/10] feat: add some tests --- go.mod | 7 +- server_routers_test.go | 297 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 303 insertions(+), 1 deletion(-) create mode 100644 server_routers_test.go diff --git a/go.mod b/go.mod index 1b65fa9..f6d15fd 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,8 @@ require ( github.com/libp2p/go-libp2p-kad-dht v0.25.1 github.com/libp2p/go-libp2p-record v0.2.0 github.com/multiformats/go-multibase v0.2.0 + github.com/multiformats/go-multihash v0.2.3 + github.com/stretchr/testify v1.8.4 github.com/urfave/cli/v2 v2.25.7 ) @@ -20,6 +22,7 @@ require ( 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.3 // 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.2.0 // indirect github.com/docker/go-units v0.5.0 // indirect @@ -77,7 +80,6 @@ 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-multicodec v0.9.0 // indirect - github.com/multiformats/go-multihash v0.2.3 // indirect github.com/multiformats/go-multistream v0.5.0 // indirect github.com/multiformats/go-varint v0.0.7 // indirect github.com/onsi/ginkgo/v2 v2.13.1 // indirect @@ -85,6 +87,7 @@ require ( github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/polydawn/refmt v0.89.0 // indirect github.com/prometheus/client_golang v1.17.0 // indirect github.com/prometheus/client_model v0.5.0 // indirect @@ -98,6 +101,7 @@ require ( github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/samber/lo v1.38.1 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect + github.com/stretchr/objx v0.5.0 // indirect github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect go.opencensus.io v0.24.0 // indirect @@ -119,5 +123,6 @@ require ( golang.org/x/tools v0.15.0 // indirect gonum.org/v1/gonum 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 ) diff --git a/server_routers_test.go b/server_routers_test.go new file mode 100644 index 0000000..8ac2709 --- /dev/null +++ b/server_routers_test.go @@ -0,0 +1,297 @@ +package main + +import ( + "context" + "crypto/rand" + "errors" + "testing" + "time" + + "github.com/ipfs/boxo/ipns" + "github.com/ipfs/boxo/path" + "github.com/ipfs/boxo/routing/http/types" + "github.com/ipfs/boxo/routing/http/types/iter" + "github.com/ipfs/go-cid" + "github.com/libp2p/go-libp2p/core/crypto" + "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/routing" + mh "github.com/multiformats/go-multihash" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" +) + +type mockRouter struct{ mock.Mock } + +var _ router = &mockRouter{} + +func (m *mockRouter) FindProviders(ctx context.Context, key cid.Cid, limit int) (iter.ResultIter[types.Record], error) { + args := m.Called(ctx, key, limit) + if arg0 := args.Get(0); arg0 == nil { + return nil, args.Error(1) + } + return args.Get(0).(iter.ResultIter[types.Record]), args.Error(1) +} + +func (m *mockRouter) FindPeers(ctx context.Context, pid peer.ID, limit int) (iter.ResultIter[*types.PeerRecord], error) { + args := m.Called(ctx, pid, limit) + if arg0 := args.Get(0); arg0 == nil { + return nil, args.Error(1) + } + return args.Get(0).(iter.ResultIter[*types.PeerRecord]), args.Error(1) +} + +func (m *mockRouter) GetIPNS(ctx context.Context, name ipns.Name) (*ipns.Record, error) { + args := m.Called(ctx, name) + if arg0 := args.Get(0); arg0 == nil { + return nil, args.Error(1) + } + return args.Get(0).(*ipns.Record), args.Error(1) +} + +func (m *mockRouter) PutIPNS(ctx context.Context, name ipns.Name, record *ipns.Record) error { + args := m.Called(ctx, name, record) + return args.Error(0) +} + +func makeName(t *testing.T) (crypto.PrivKey, ipns.Name) { + sk, _, err := crypto.GenerateEd25519Key(rand.Reader) + require.NoError(t, err) + + pid, err := peer.IDFromPrivateKey(sk) + require.NoError(t, err) + + return sk, ipns.NameFromPeer(pid) +} + +func makeIPNSRecord(t *testing.T, sk crypto.PrivKey, opts ...ipns.Option) (*ipns.Record, []byte) { + cid, err := cid.Decode("bafkreifjjcie6lypi6ny7amxnfftagclbuxndqonfipmb64f2km2devei4") + require.NoError(t, err) + + path := path.FromCid(cid) + eol := time.Now().Add(time.Hour * 48) + ttl := time.Second * 20 + + record, err := ipns.NewRecord(sk, path, 1, eol, ttl, opts...) + require.NoError(t, err) + + rawRecord, err := ipns.MarshalRecord(record) + require.NoError(t, err) + + return record, rawRecord +} + +func TestGetIPNS(t *testing.T) { + t.Parallel() + + sk, name := makeName(t) + rec, _ := makeIPNSRecord(t, sk) + + t.Run("OK (Multiple Composable, One Fails, One OK)", func(t *testing.T) { + ctx := context.Background() + + mr1 := &mockRouter{} + mr1.On("GetIPNS", mock.Anything, name).Return(rec, nil) + + mr2 := &mockRouter{} + mr2.On("GetIPNS", mock.Anything, name).Return(nil, routing.ErrNotFound) + + r := parallelRouter{ + routers: []router{ + composableRouter{ + ipns: mr1, + }, + composableRouter{ + ipns: mr2, + }, + }, + } + + getRec, err := r.GetIPNS(ctx, name) + require.NoError(t, err) + require.EqualValues(t, rec, getRec) + }) + + t.Run("OK (Multiple Parallel)", func(t *testing.T) { + ctx := context.Background() + + mr1 := &mockRouter{} + mr1.On("GetIPNS", mock.Anything, name).Return(nil, routing.ErrNotFound) + + mr2 := &mockRouter{} + mr2.On("GetIPNS", mock.Anything, name).Return(rec, nil) + + r := parallelRouter{ + routers: []router{ + composableRouter{ + ipns: parallelRouter{ + routers: []router{mr1, mr2}, + }, + }, + }, + } + + getRec, err := r.GetIPNS(ctx, name) + require.NoError(t, err) + require.EqualValues(t, rec, getRec) + }) + + t.Run("No Routers", func(t *testing.T) { + ctx := context.Background() + + r := parallelRouter{ + routers: []router{ + composableRouter{ + ipns: parallelRouter{}, + }, + }, + } + + _, err := r.GetIPNS(ctx, name) + require.ErrorIs(t, err, routing.ErrNotFound) + }) +} + +func TestPutIPNS(t *testing.T) { + t.Parallel() + + sk, name := makeName(t) + rec, _ := makeIPNSRecord(t, sk) + + t.Run("OK (Multiple Composable)", func(t *testing.T) { + ctx := context.Background() + + mr1 := &mockRouter{} + mr1.On("PutIPNS", mock.Anything, name, rec).Return(nil) + + mr2 := &mockRouter{} + mr2.On("PutIPNS", mock.Anything, name, rec).Return(nil) + + r := parallelRouter{ + routers: []router{ + composableRouter{ + ipns: mr1, + }, + composableRouter{ + ipns: mr2, + }, + }, + } + + err := r.PutIPNS(ctx, name, rec) + require.NoError(t, err) + + mr1.AssertExpectations(t) + mr2.AssertExpectations(t) + }) + + t.Run("OK (Multiple Parallel)", func(t *testing.T) { + ctx := context.Background() + + mr1 := &mockRouter{} + mr1.On("PutIPNS", mock.Anything, name, rec).Return(nil) + + mr2 := &mockRouter{} + mr2.On("PutIPNS", mock.Anything, name, rec).Return(nil) + + r := parallelRouter{ + routers: []router{ + composableRouter{ + ipns: parallelRouter{ + routers: []router{mr1, mr2}, + }, + }, + }, + } + + err := r.PutIPNS(ctx, name, rec) + require.NoError(t, err) + + mr1.AssertExpectations(t) + mr2.AssertExpectations(t) + }) + + t.Run("Failure of a Single Router (Multiple Composable)", func(t *testing.T) { + ctx := context.Background() + + mr1 := &mockRouter{} + mr1.On("PutIPNS", mock.Anything, name, rec).Return(errors.New("failed")) + + mr2 := &mockRouter{} + mr2.On("PutIPNS", mock.Anything, name, rec).Return(nil) + + r := parallelRouter{ + routers: []router{ + composableRouter{ + ipns: mr1, + }, + composableRouter{ + ipns: mr2, + }, + }, + } + + err := r.PutIPNS(ctx, name, rec) + require.ErrorContains(t, err, "failed") + + mr1.AssertExpectations(t) + mr2.AssertExpectations(t) + }) + + t.Run("Failure of a Single Router (Multiple Parallel)", func(t *testing.T) { + ctx := context.Background() + + mr1 := &mockRouter{} + mr1.On("PutIPNS", mock.Anything, name, mock.Anything).Return(errors.New("failed")) + + mr2 := &mockRouter{} + mr2.On("PutIPNS", mock.Anything, name, mock.Anything).Return(nil) + + r := parallelRouter{ + routers: []router{ + composableRouter{ + ipns: parallelRouter{ + routers: []router{mr1, mr2}, + }, + }, + }, + } + + err := r.PutIPNS(ctx, name, rec) + require.ErrorContains(t, err, "failed") + + mr1.AssertExpectations(t) + mr2.AssertExpectations(t) + }) +} + +func TestFindProviders(t *testing.T) { + t.Parallel() + + t.Run("Basic", func(t *testing.T) { + prefix := cid.NewPrefixV1(cid.Raw, mh.SHA2_256) + c, _ := prefix.Sum([]byte("foo")) + + ctx := context.Background() + + d := parallelRouter{} + it, err := d.FindProviders(ctx, c, 10) + + require.NoError(t, err) + require.False(t, it.Next()) + + mr1 := &mockRouter{} + mr1.On("FindProviders", mock.Anything, c, 10).Return(iter.ToResultIter(iter.FromSlice([]types.Record{})), nil) + + d = parallelRouter{ + routers: []router{ + &composableRouter{ + providers: mr1, + }, + }, + } + + it, err = d.FindProviders(ctx, c, 10) + require.NoError(t, err) + require.False(t, it.Next()) + }) +} From 12b42a94f22500e202b76e50a7f5f8163a3d6480 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Mon, 4 Dec 2023 10:12:48 +0100 Subject: [PATCH 06/10] refactor: ensure goroutine-safety of manyIter - use WaitGroup and select for ctx.Done() - call .Val right after .Next inside Goroutine --- server_routers.go | 67 ++++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/server_routers.go b/server_routers.go index bc3c312..4d58894 100644 --- a/server_routers.go +++ b/server_routers.go @@ -124,50 +124,69 @@ func find[T any](ctx context.Context, routers []router, call func(router) (iter. } type manyIter[T any] struct { - ctx context.Context - its []iter.ResultIter[T] - nextCh chan int - next int + ctx context.Context + wg sync.WaitGroup + its []iter.ResultIter[T] + ch chan iter.Result[T] + val iter.Result[T] + done bool } func newManyIter[T any](ctx context.Context, its []iter.ResultIter[T]) *manyIter[T] { - nextCh := make(chan int) + mi := &manyIter[T]{ + ctx: ctx, + its: its, + ch: make(chan iter.Result[T]), + } - for i, it := range its { - go func(ch chan int, it iter.ResultIter[T], index int) { + for _, it := range its { + mi.wg.Add(1) + go func(it iter.ResultIter[T]) { + defer mi.wg.Done() for it.Next() { - ch <- index + select { + case mi.ch <- it.Val(): + case <-ctx.Done(): + return + } } - }(nextCh, it, i) + }(it) } - return &manyIter[T]{ - ctx: ctx, - its: its, - nextCh: nextCh, - next: -1, - } + go func() { + mi.wg.Wait() + close(mi.ch) + }() + + return mi } func (mi *manyIter[T]) Next() bool { + if mi.done { + return false + } + select { - case i := <-mi.nextCh: - mi.next = i - return true + case val, ok := <-mi.ch: + if ok { + mi.val = val + } else { + mi.done = true + } case <-mi.ctx.Done(): - mi.next = -1 - return false + mi.done = true } + + return !mi.done } func (mi *manyIter[T]) Val() iter.Result[T] { - if mi.next == -1 { - return iter.Result[T]{Err: errors.New("no next value")} - } - return mi.its[mi.next].Val() + return mi.val } func (mi *manyIter[T]) Close() error { + mi.done = true + mi.wg.Wait() var err error for _, it := range mi.its { err = errors.Join(err, it.Close()) From a71edebe55d9ecafcd816be493b0df0007b5abc4 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Mon, 4 Dec 2023 12:45:09 +0100 Subject: [PATCH 07/10] test: add some tests for manyIter --- server_routers_test.go | 202 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) diff --git a/server_routers_test.go b/server_routers_test.go index 8ac2709..204e347 100644 --- a/server_routers_test.go +++ b/server_routers_test.go @@ -295,3 +295,205 @@ func TestFindProviders(t *testing.T) { require.False(t, it.Next()) }) } + +type mockIter[T any] struct { + ctx context.Context + ch chan iter.Result[T] + waitVal chan time.Time + val iter.Result[T] + done bool +} + +var _ iter.ResultIter[int] = &mockIter[int]{} + +func newMockIter[T any](ctx context.Context) *mockIter[T] { + it := &mockIter[T]{ + ctx: ctx, + ch: make(chan iter.Result[T]), + } + + return it +} + +func newMockIters[T any](ctx context.Context, count int) []*mockIter[T] { + var arr []*mockIter[T] + + for count > 0 { + arr = append(arr, newMockIter[T](ctx)) + count-- + } + + return arr +} + +func (m *mockIter[T]) Next() bool { + if m.done { + return false + } + + select { + case v, ok := <-m.ch: + if !ok { + m.done = true + } else { + m.val = v + } + case <-m.ctx.Done(): + m.done = true + } + + return !m.done +} + +func (m *mockIter[T]) Val() iter.Result[T] { + if m.waitVal != nil { + <-m.waitVal + } + + return m.val +} + +func (m *mockIter[T]) Close() error { + m.done = true + return nil +} + +func mockItersAsInterface[T any](originalSlice []*mockIter[T]) []iter.ResultIter[T] { + var newSlice []iter.ResultIter[T] + + for _, v := range originalSlice { + newSlice = append(newSlice, v) + } + + return newSlice +} + +func TestManyIter(t *testing.T) { + t.Parallel() + + t.Run("Sequence", func(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + its := newMockIters[int](ctx, 2) + manyIter := newManyIter(ctx, mockItersAsInterface(its)) + + go func() { + its[0].ch <- iter.Result[int]{Val: 0} + time.Sleep(time.Millisecond * 50) + + its[1].ch <- iter.Result[int]{Val: 1} + time.Sleep(time.Millisecond * 50) + + its[0].ch <- iter.Result[int]{Val: 0} + time.Sleep(time.Millisecond * 50) + + its[0].ch <- iter.Result[int]{Val: 0} + close(its[0].ch) + time.Sleep(time.Millisecond * 50) + + its[1].ch <- iter.Result[int]{Val: 1} + time.Sleep(time.Millisecond * 50) + + close(its[1].ch) + }() + + results, err := iter.ReadAllResults(manyIter) + require.NoError(t, err) + require.Equal(t, []int{0, 1, 0, 0, 1}, results) + require.False(t, manyIter.Next()) + require.NoError(t, manyIter.Close()) + }) + + t.Run("Closed Iterator", func(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + its := newMockIters[int](ctx, 5) + manyIter := newManyIter(ctx, mockItersAsInterface(its)) + + go func() { + close(its[0].ch) + close(its[1].ch) + close(its[2].ch) + close(its[3].ch) + + its[4].ch <- iter.Result[int]{Val: 4} + time.Sleep(time.Millisecond * 50) + + its[4].ch <- iter.Result[int]{Val: 4} + time.Sleep(time.Millisecond * 50) + + close(its[4].ch) + }() + + results, err := iter.ReadAllResults(manyIter) + require.NoError(t, err) + require.Equal(t, []int{4, 4}, results) + require.False(t, manyIter.Next()) + require.NoError(t, manyIter.Close()) + }) + + t.Run("Context Canceled", func(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + its := newMockIters[int](ctx, 5) + manyIter := newManyIter(ctx, mockItersAsInterface(its)) + + go func() { + its[3].ch <- iter.Result[int]{Val: 3} + time.Sleep(time.Millisecond * 50) + + its[2].ch <- iter.Result[int]{Val: 2} + time.Sleep(time.Millisecond * 50) + + cancel() + }() + + results, err := iter.ReadAllResults(manyIter) + require.NoError(t, err) + require.Equal(t, []int{3, 2}, results) + require.False(t, manyIter.Next()) + require.NoError(t, manyIter.Close()) + }) + + t.Run("Context Canceled After .Next Returns", func(t *testing.T) { + t.Parallel() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + its := newMockIters[int](ctx, 5) + manyIter := newManyIter(ctx, mockItersAsInterface(its)) + + go func() { + its[1].ch <- iter.Result[int]{Val: 1} + time.Sleep(time.Millisecond * 50) + + its[4].ch <- iter.Result[int]{Val: 4} + time.Sleep(time.Millisecond * 50) + + its[3].waitVal = make(chan time.Time) + its[3].ch <- iter.Result[int]{Val: 3} + time.Sleep(time.Millisecond * 50) + + cancel() + time.Sleep(time.Millisecond * 50) + + its[3].waitVal <- time.Now() + }() + + results, err := iter.ReadAllResults(manyIter) + require.NoError(t, err) + require.Equal(t, []int{1, 4}, results) + require.False(t, manyIter.Next()) + require.NoError(t, manyIter.Close()) + }) +} From ad1b8e23c596551af6d5745accb63316ee154407 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Mon, 4 Dec 2023 15:03:47 +0100 Subject: [PATCH 08/10] add some basic tests --- go.mod | 2 +- server.go | 3 + server_routers.go | 6 ++ server_routers_test.go | 184 +++++++++++++++++++++++++++++++++++++++-- 4 files changed, 189 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index f6d15fd..8eabb43 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.21 require ( github.com/ipfs/boxo v0.15.0 github.com/ipfs/go-cid v0.4.1 + github.com/ipfs/go-log v1.0.5 github.com/libp2p/go-libp2p v0.32.1 github.com/libp2p/go-libp2p-kad-dht v0.25.1 github.com/libp2p/go-libp2p-record v0.2.0 @@ -45,7 +46,6 @@ require ( github.com/huin/goupnp v1.3.0 // indirect github.com/ipfs/go-datastore v0.6.0 // indirect github.com/ipfs/go-ipfs-util v0.0.3 // indirect - github.com/ipfs/go-log v1.0.5 // indirect github.com/ipfs/go-log/v2 v2.5.1 // indirect github.com/ipld/go-ipld-prime v0.21.0 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect diff --git a/server.go b/server.go index 0638344..1ff646e 100644 --- a/server.go +++ b/server.go @@ -8,6 +8,7 @@ import ( "github.com/ipfs/boxo/routing/http/client" "github.com/ipfs/boxo/routing/http/server" + logging "github.com/ipfs/go-log" "github.com/libp2p/go-libp2p" dht "github.com/libp2p/go-libp2p-kad-dht" "github.com/libp2p/go-libp2p/core/host" @@ -15,6 +16,8 @@ import ( rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager" ) +var logger = logging.Logger("someguy") + func start(ctx context.Context, port int, runAcceleratedDHTClient bool, contentEndpoints, peerEndpoints, ipnsEndpoints []string) error { h, err := newHost(runAcceleratedDHTClient) if err != nil { diff --git a/server_routers.go b/server_routers.go index 4d58894..b58e3fa 100644 --- a/server_routers.go +++ b/server_routers.go @@ -116,7 +116,10 @@ func find[T any](ctx context.Context, routers []router, call func(router) (iter. // If all iterators failed to be created, then return the error. if len(its) == 0 { + logger.Warnf("failed to create all iterators: %w", err) return nil, err + } else if err != nil { + logger.Warnf("failed to create some iterators: %w", err) } // Otherwise return manyIter with remaining iterators. @@ -191,6 +194,9 @@ func (mi *manyIter[T]) Close() error { for _, it := range mi.its { err = errors.Join(err, it.Close()) } + if err != nil { + logger.Warnf("errors on closing iterators: %w", err) + } return err } diff --git a/server_routers_test.go b/server_routers_test.go index 204e347..9a9cb9c 100644 --- a/server_routers_test.go +++ b/server_routers_test.go @@ -15,7 +15,7 @@ import ( "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/routing" - mh "github.com/multiformats/go-multihash" + "github.com/multiformats/go-multihash" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" ) @@ -264,14 +264,27 @@ func TestPutIPNS(t *testing.T) { }) } +func makeCID() cid.Cid { + buf := make([]byte, 63) + _, err := rand.Read(buf) + if err != nil { + panic(err) + } + mh, err := multihash.Encode(buf, multihash.SHA2_256) + if err != nil { + panic(err) + } + c := cid.NewCidV1(cid.Raw, mh) + return c +} + func TestFindProviders(t *testing.T) { t.Parallel() t.Run("Basic", func(t *testing.T) { - prefix := cid.NewPrefixV1(cid.Raw, mh.SHA2_256) - c, _ := prefix.Sum([]byte("foo")) - ctx := context.Background() + c := makeCID() + peers := []peer.ID{"peer1", "peer2", "peer3"} d := parallelRouter{} it, err := d.FindProviders(ctx, c, 10) @@ -280,19 +293,180 @@ func TestFindProviders(t *testing.T) { require.False(t, it.Next()) mr1 := &mockRouter{} - mr1.On("FindProviders", mock.Anything, c, 10).Return(iter.ToResultIter(iter.FromSlice([]types.Record{})), nil) + mr1Iter := newMockIter[types.Record](ctx) + mr1.On("FindProviders", mock.Anything, c, 10).Return(mr1Iter, nil) + + mr2 := &mockRouter{} + mr2Iter := newMockIter[types.Record](ctx) + mr2.On("FindProviders", mock.Anything, c, 10).Return(mr2Iter, nil) d = parallelRouter{ routers: []router{ &composableRouter{ providers: mr1, }, + mr2, }, } + go func() { + mr1Iter.ch <- iter.Result[types.Record]{Val: &types.PeerRecord{Schema: "peer", ID: &peers[0]}} + mr2Iter.ch <- iter.Result[types.Record]{Val: &types.PeerRecord{Schema: "peer", ID: &peers[0]}} + mr1Iter.ch <- iter.Result[types.Record]{Val: &types.PeerRecord{Schema: "peer", ID: &peers[1]}} + mr1Iter.ch <- iter.Result[types.Record]{Val: &types.PeerRecord{Schema: "peer", ID: &peers[2]}} + close(mr1Iter.ch) + + mr2Iter.ch <- iter.Result[types.Record]{Val: &types.PeerRecord{Schema: "peer", ID: &peers[1]}} + close(mr2Iter.ch) + }() + it, err = d.FindProviders(ctx, c, 10) + require.NoError(t, err) + + results, err := iter.ReadAllResults(it) + require.NoError(t, err) + require.Len(t, results, 5) + }) + + t.Run("Failed to Create All Iterators", func(t *testing.T) { + ctx := context.Background() + c := makeCID() + + mr1 := &mockRouter{} + mr1.On("FindProviders", mock.Anything, c, 10).Return(nil, errors.New("error a")) + + mr2 := &mockRouter{} + mr2.On("FindProviders", mock.Anything, c, 10).Return(nil, errors.New("error b")) + + d := parallelRouter{ + routers: []router{ + mr1, mr2, + }, + } + + _, err := d.FindProviders(ctx, c, 10) + require.ErrorContains(t, err, "error a") + require.ErrorContains(t, err, "error b") + }) + + t.Run("Failed to Create One Iterator", func(t *testing.T) { + ctx := context.Background() + pid := peer.ID("hello") + c := makeCID() + + mr1 := &mockRouter{} + mr1.On("FindProviders", mock.Anything, c, 10).Return(iter.ToResultIter(iter.FromSlice([]types.Record{&types.PeerRecord{Schema: "peer", ID: &pid}})), nil) + + mr2 := &mockRouter{} + mr2.On("FindProviders", mock.Anything, c, 10).Return(nil, errors.New("error b")) + + d := parallelRouter{ + routers: []router{ + mr1, mr2, + }, + } + + it, err := d.FindProviders(ctx, c, 10) + require.NoError(t, err) + + results, err := iter.ReadAllResults(it) + require.NoError(t, err) + require.Len(t, results, 1) + }) +} + +func TestFindPeers(t *testing.T) { + t.Parallel() + + t.Run("Basic", func(t *testing.T) { + ctx := context.Background() + pid := peer.ID("hello") + + d := parallelRouter{} + it, err := d.FindPeers(ctx, pid, 10) + require.NoError(t, err) require.False(t, it.Next()) + + mr1 := &mockRouter{} + mr1Iter := newMockIter[*types.PeerRecord](ctx) + mr1.On("FindPeers", mock.Anything, pid, 10).Return(mr1Iter, nil) + + mr2 := &mockRouter{} + mr2Iter := newMockIter[*types.PeerRecord](ctx) + mr2.On("FindPeers", mock.Anything, pid, 10).Return(mr2Iter, nil) + + d = parallelRouter{ + routers: []router{ + &composableRouter{ + peers: mr1, + }, + mr2, + }, + } + + go func() { + mr1Iter.ch <- iter.Result[*types.PeerRecord]{Val: &types.PeerRecord{Schema: "peer", ID: &pid}} + mr2Iter.ch <- iter.Result[*types.PeerRecord]{Val: &types.PeerRecord{Schema: "peer", ID: &pid}} + mr1Iter.ch <- iter.Result[*types.PeerRecord]{Val: &types.PeerRecord{Schema: "peer", ID: &pid}} + mr1Iter.ch <- iter.Result[*types.PeerRecord]{Val: &types.PeerRecord{Schema: "peer", ID: &pid}} + close(mr1Iter.ch) + + mr2Iter.ch <- iter.Result[*types.PeerRecord]{Val: &types.PeerRecord{Schema: "peer", ID: &pid}} + close(mr2Iter.ch) + }() + + it, err = d.FindPeers(ctx, pid, 10) + require.NoError(t, err) + + results, err := iter.ReadAllResults(it) + require.NoError(t, err) + require.Len(t, results, 5) + }) + + t.Run("Failed to Create All Iterators", func(t *testing.T) { + ctx := context.Background() + pid := peer.ID("hello") + + mr1 := &mockRouter{} + mr1.On("FindPeers", mock.Anything, pid, 10).Return(nil, errors.New("error a")) + + mr2 := &mockRouter{} + mr2.On("FindPeers", mock.Anything, pid, 10).Return(nil, errors.New("error b")) + + d := parallelRouter{ + routers: []router{ + mr1, mr2, + }, + } + + _, err := d.FindPeers(ctx, pid, 10) + require.ErrorContains(t, err, "error a") + require.ErrorContains(t, err, "error b") + }) + + t.Run("Failed to Create One Iterator", func(t *testing.T) { + ctx := context.Background() + pid := peer.ID("hello") + + mr1 := &mockRouter{} + mr1.On("FindPeers", mock.Anything, pid, 10).Return(iter.ToResultIter(iter.FromSlice([]*types.PeerRecord{&types.PeerRecord{Schema: "peer", ID: &pid}})), nil) + + mr2 := &mockRouter{} + mr2.On("FindPeers", mock.Anything, pid, 10).Return(nil, errors.New("error b")) + + d := parallelRouter{ + routers: []router{ + mr1, mr2, + }, + } + + it, err := d.FindPeers(ctx, pid, 10) + require.NoError(t, err) + + results, err := iter.ReadAllResults(it) + require.NoError(t, err) + require.Len(t, results, 1) }) } From fabe115471265f87130b591a2dcf1fd520b54954 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Tue, 5 Dec 2023 14:20:55 +0100 Subject: [PATCH 09/10] fmt --- server_routers_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server_routers_test.go b/server_routers_test.go index 9a9cb9c..2ef826d 100644 --- a/server_routers_test.go +++ b/server_routers_test.go @@ -450,7 +450,7 @@ func TestFindPeers(t *testing.T) { pid := peer.ID("hello") mr1 := &mockRouter{} - mr1.On("FindPeers", mock.Anything, pid, 10).Return(iter.ToResultIter(iter.FromSlice([]*types.PeerRecord{&types.PeerRecord{Schema: "peer", ID: &pid}})), nil) + mr1.On("FindPeers", mock.Anything, pid, 10).Return(iter.ToResultIter(iter.FromSlice([]*types.PeerRecord{{Schema: "peer", ID: &pid}})), nil) mr2 := &mockRouter{} mr2.On("FindPeers", mock.Anything, pid, 10).Return(nil, errors.New("error b")) From cb65e7535cd5ac95da38ad33c3a72dbe9ba336f8 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Mon, 15 Jan 2024 15:50:47 +0100 Subject: [PATCH 10/10] address feedback --- server_routers.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/server_routers.go b/server_routers.go index b58e3fa..fa32bd7 100644 --- a/server_routers.go +++ b/server_routers.go @@ -108,6 +108,7 @@ func find[T any](ctx context.Context, routers []router, call func(router) (iter. it, itErr := call(ri) if itErr != nil { + logger.Warnf("error from router: %w", itErr) err = errors.Join(err, itErr) } else { its = append(its, it) @@ -127,19 +128,23 @@ func find[T any](ctx context.Context, routers []router, call func(router) (iter. } type manyIter[T any] struct { - ctx context.Context - wg sync.WaitGroup - its []iter.ResultIter[T] - ch chan iter.Result[T] - val iter.Result[T] - done bool + ctx context.Context + cancel context.CancelFunc + wg sync.WaitGroup + its []iter.ResultIter[T] + ch chan iter.Result[T] + val iter.Result[T] + done bool } func newManyIter[T any](ctx context.Context, its []iter.ResultIter[T]) *manyIter[T] { + ctx, cancel := context.WithCancel(ctx) + mi := &manyIter[T]{ - ctx: ctx, - its: its, - ch: make(chan iter.Result[T]), + ctx: ctx, + cancel: cancel, + its: its, + ch: make(chan iter.Result[T]), } for _, it := range its { @@ -189,6 +194,7 @@ func (mi *manyIter[T]) Val() iter.Result[T] { func (mi *manyIter[T]) Close() error { mi.done = true + mi.cancel() mi.wg.Wait() var err error for _, it := range mi.its {