@cryptotaxi247 / kubo / commits / df828c0a4

feature: delegated-routing: Add HTTP delegated routing.

Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>

Antonio Navarro Perez committed Dec 5, 2022 at 18:43 UTC df828c0a4787ca440cdcdb3cb25935f335747dab
9 files changed +152 -20
config/routing.go
+26
@@ -3,6 +3,7 @@ package config
3 import (
4 "encoding/json"
5 "fmt"
6 + "runtime"
7 )
8
9 // Routing defines configuration options for libp2p routing
@@ -78,6 +79,8 @@ func (r *RouterParser) UnmarshalJSON(b []byte) error {
79
80 var p interface{}
81 switch out.Type {
82 + case RouterTypeHttp:
83 + p = &HttpRouterParams{}
84 case RouterTypeReframe:
85 p = &ReframeRouterParams{}
86 case RouterTypeDHT:
@@ -104,6 +107,7 @@ type RouterType string
107
108 const (
109 RouterTypeReframe RouterType = "reframe"
110 + RouterTypeHttp RouterType = "http"
111 RouterTypeDHT RouterType = "dht"
112 RouterTypeSequential RouterType = "sequential"
113 RouterTypeParallel RouterType = "parallel"
@@ -135,6 +139,28 @@ type ReframeRouterParams struct {
139 Endpoint string
140 }
141
142 +type HttpRouterParams struct {
143 + // Endpoint is the URL where the routing implementation will point to get the information.
144 + Endpoint string
145 +
146 + // MaxProvideBatchSize determines the maximum amount of CIDs sent per batch.
147 + // Servers might not accept more than 100 elements per batch. 100 elements by default.
148 + MaxProvideBatchSize int
149 +
150 + // MaxProvideConcurrency determines the number of threads used when providing content. GOMAXPROCS by default.
151 + MaxProvideConcurrency int
152 +}
153 +
154 +func (hrp *HttpRouterParams) FillDefaults() {
155 + if hrp.MaxProvideBatchSize == 0 {
156 + hrp.MaxProvideBatchSize = 100
157 + }
158 +
159 + if hrp.MaxProvideConcurrency == 0 {
160 + hrp.MaxProvideConcurrency = runtime.GOMAXPROCS(0)
161 + }
162 +}
163 +
164 type DHTRouterParams struct {
165 Mode DHTMode
166 AcceleratedDHTClient bool `json:",omitempty"`
core/node/libp2p/routingopt.go
+1 -1
@@ -71,7 +71,7 @@ func ConstructDelegatedRouting(routers config.Routers, methods config.Methods, p
71 Datastore: dstore,
72 Context: ctx,
73 },
74 - &irouting.ExtraReframeParams{
74 + &irouting.ExtraHTTPParams{
75 PeerID: peerID,
76 Addrs: addrs,
77 PrivKeyB64: privKey,
docs/examples/kubo-as-a-library/go.mod
+3 -1
@@ -53,6 +53,7 @@ require (
53 github.com/golang/snappy v0.0.4 // indirect
54 github.com/google/gopacket v1.1.19 // indirect
55 github.com/google/uuid v1.3.0 // indirect
56 + github.com/gorilla/mux v1.8.0 // indirect
57 github.com/gorilla/websocket v1.5.0 // indirect
58 github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
59 github.com/hannahhoward/go-pubsub v0.0.0-20200423002714-8d62886cc36e // indirect
@@ -95,6 +96,7 @@ require (
96 github.com/ipfs/go-ipld-git v0.1.1 // indirect
97 github.com/ipfs/go-ipld-legacy v0.1.1 // indirect
98 github.com/ipfs/go-ipns v0.3.0 // indirect
99 + github.com/ipfs/go-libipfs v0.0.0-20221130104825-592a45ae3796 // indirect
100 github.com/ipfs/go-log v1.0.5 // indirect
101 github.com/ipfs/go-log/v2 v2.5.1 // indirect
102 github.com/ipfs/go-merkledag v0.8.1 // indirect
@@ -173,9 +175,9 @@ require (
175 github.com/prometheus/common v0.37.0 // indirect
176 github.com/prometheus/procfs v0.8.0 // indirect
177 github.com/raulk/go-watchdog v1.3.0 // indirect
178 + github.com/samber/lo v1.36.0 // indirect
179 github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
180 github.com/spaolacci/murmur3 v1.1.0 // indirect
178 - github.com/stretchr/objx v0.4.0 // indirect
181 github.com/syndtr/goleveldb v1.0.0 // indirect
182 github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc // indirect
183 github.com/whyrusleeping/cbor-gen v0.0.0-20210219115102-f37d292932f2 // indirect
docs/examples/kubo-as-a-library/go.sum
+7 -2
@@ -360,6 +360,7 @@ github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c/go.mod h1:wJfORR
360 github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
361 github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
362 github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
363 +github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
364 github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
365 github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
366 github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
@@ -571,6 +572,8 @@ github.com/ipfs/go-ipld-legacy v0.1.1/go.mod h1:8AyKFCjgRPsQFf15ZQgDB8Din4DML/fO
572 github.com/ipfs/go-ipns v0.1.2/go.mod h1:ioQ0j02o6jdIVW+bmi18f4k2gRf0AV3kZ9KeHYHICnQ=
573 github.com/ipfs/go-ipns v0.3.0 h1:ai791nTgVo+zTuq2bLvEGmWP1M0A6kGTXUsgv/Yq67A=
574 github.com/ipfs/go-ipns v0.3.0/go.mod h1:3cLT2rbvgPZGkHJoPO1YMJeh6LtkxopCkKFcio/wE24=
575 +github.com/ipfs/go-libipfs v0.0.0-20221130104825-592a45ae3796 h1:2aZUmUq+4C8Vk+pbZk3IU48H2GAZ5/kOTrbuCwIt9HI=
576 +github.com/ipfs/go-libipfs v0.0.0-20221130104825-592a45ae3796/go.mod h1:gAc/IsxQh4HwAOeSCKM1ONfzCQfNbm9E8QqEVfiPfOU=
577 github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM=
578 github.com/ipfs/go-log v1.0.2/go.mod h1:1MNjMxe0u6xvJZgeqbJ8vdo2TKaGwZ1a0Bpza+sr2Sk=
579 github.com/ipfs/go-log v1.0.3/go.mod h1:OsLySYkwIbiSUR/yBTdv1qPtcE4FW3WPWk/ewz9Ru+A=
@@ -1338,6 +1341,8 @@ github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR
1341 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
1342 github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd/go.mod h1:hPqNNc0+uJM6H+SuU8sEs5K5IQeKccPqeSjfgcKGgPk=
1343 github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
1344 +github.com/samber/lo v1.36.0 h1:4LaOxH1mHnbDGhTVE0i1z8v/lWaQW8AIfOD3HU4mSaw=
1345 +github.com/samber/lo v1.36.0/go.mod h1:HLeWcJRRyLKp3+/XBJvOrerCQn9mhdKMHyd7IRlgeQ8=
1346 github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
1347 github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
1348 github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
@@ -1401,8 +1406,7 @@ github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3
1406 github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
1407 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1408 github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1404 -github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4=
1405 -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
1409 +github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
1410 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
1411 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
1412 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
@@ -1414,6 +1418,7 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs
1418 github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
1419 github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
1420 github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
1421 +github.com/thoas/go-funk v0.9.1 h1:O549iLZqPpTUQ10ykd26sZhzD+rmR5pWhuElrhbC20M=
1422 github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
1423 github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c h1:u6SKchux2yDvFQnDHS3lPnIRmfVJ5Sxy3ao2SIdysLQ=
1424 github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c/go.mod h1:hzIxponao9Kjc7aWznkXaL4U4TWaDSs8zcsY4Ka08nM=
go.mod
+2
@@ -150,6 +150,7 @@ require (
150 github.com/golang/snappy v0.0.4 // indirect
151 github.com/google/gopacket v1.1.19 // indirect
152 github.com/google/uuid v1.3.0 // indirect
153 + github.com/gorilla/mux v1.8.0 // indirect
154 github.com/gorilla/websocket v1.5.0 // indirect
155 github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
156 github.com/hannahhoward/go-pubsub v0.0.0-20200423002714-8d62886cc36e // indirect
@@ -220,6 +221,7 @@ require (
221 github.com/prometheus/statsd_exporter v0.21.0 // indirect
222 github.com/raulk/go-watchdog v1.3.0 // indirect
223 github.com/rs/cors v1.7.0 // indirect
224 + github.com/samber/lo v1.36.0 // indirect
225 github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
226 github.com/spaolacci/murmur3 v1.1.0 // indirect
227 github.com/texttheater/golang-levenshtein v0.0.0-20180516184445-d188e65d659e // indirect
go.sum
+4
@@ -378,6 +378,7 @@ github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c/go.mod h1:wJfORR
378 github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
379 github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
380 github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
381 +github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
382 github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
383 github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
384 github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
@@ -1399,6 +1400,8 @@ github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR
1400 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
1401 github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd/go.mod h1:hPqNNc0+uJM6H+SuU8sEs5K5IQeKccPqeSjfgcKGgPk=
1402 github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
1403 +github.com/samber/lo v1.36.0 h1:4LaOxH1mHnbDGhTVE0i1z8v/lWaQW8AIfOD3HU4mSaw=
1404 +github.com/samber/lo v1.36.0/go.mod h1:HLeWcJRRyLKp3+/XBJvOrerCQn9mhdKMHyd7IRlgeQ8=
1405 github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
1406 github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
1407 github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
@@ -1480,6 +1483,7 @@ github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpP
1483 github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
1484 github.com/texttheater/golang-levenshtein v0.0.0-20180516184445-d188e65d659e h1:T5PdfK/M1xyrHwynxMIVMWLS7f/qHwfslZphxtGnw7s=
1485 github.com/texttheater/golang-levenshtein v0.0.0-20180516184445-d188e65d659e/go.mod h1:XDKHRm5ThF8YJjx001LtgelzsoaEcvnA7lVWz9EeX3g=
1486 +github.com/thoas/go-funk v0.9.1 h1:O549iLZqPpTUQ10ykd26sZhzD+rmR5pWhuElrhbC20M=
1487 github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk=
1488 github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
1489 github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c h1:u6SKchux2yDvFQnDHS3lPnIRmfVJ5Sxy3ao2SIdysLQ=
routing/delegated.go
+76 -15
@@ -10,6 +10,8 @@ import (
10 "github.com/ipfs/go-datastore"
11 drc "github.com/ipfs/go-delegated-routing/client"
12 drp "github.com/ipfs/go-delegated-routing/gen/proto"
13 + drclient "github.com/ipfs/go-libipfs/routing/http/client"
14 + "github.com/ipfs/go-libipfs/routing/http/contentrouter"
15 logging "github.com/ipfs/go-log"
16 "github.com/ipfs/kubo/config"
17 dht "github.com/libp2p/go-libp2p-kad-dht"
@@ -28,7 +30,7 @@ import (
30
31 var log = logging.Logger("routing/delegated")
32
31 -func Parse(routers config.Routers, methods config.Methods, extraDHT *ExtraDHTParams, extraReframe *ExtraReframeParams) (routing.Routing, error) {
33 +func Parse(routers config.Routers, methods config.Methods, extraDHT *ExtraDHTParams, extraHTTP *ExtraHTTPParams) (routing.Routing, error) {
34 if err := methods.Check(); err != nil {
35 return nil, err
36 }
@@ -38,7 +40,7 @@ func Parse(routers config.Routers, methods config.Methods, extraDHT *ExtraDHTPar
40
41 // Create all needed routers from method names
42 for mn, m := range methods {
41 - router, err := parse(make(map[string]bool), createdRouters, m.RouterName, routers, extraDHT, extraReframe)
43 + router, err := parse(make(map[string]bool), createdRouters, m.RouterName, routers, extraDHT, extraHTTP)
44 if err != nil {
45 return nil, err
46 }
@@ -67,7 +69,7 @@ func parse(visited map[string]bool,
69 routerName string,
70 routersCfg config.Routers,
71 extraDHT *ExtraDHTParams,
70 - extraReframe *ExtraReframeParams,
72 + extraHTTP *ExtraHTTPParams,
73 ) (routing.Routing, error) {
74 // check if we already created it
75 r, ok := createdRouters[routerName]
@@ -91,15 +93,17 @@ func parse(visited map[string]bool,
93 var router routing.Routing
94 var err error
95 switch cfg.Type {
96 + case config.RouterTypeHttp:
97 + router, err = httpRoutingFromConfig(cfg.Router, extraHTTP)
98 case config.RouterTypeReframe:
95 - router, err = reframeRoutingFromConfig(cfg.Router, extraReframe)
99 + router, err = reframeRoutingFromConfig(cfg.Router, extraHTTP)
100 case config.RouterTypeDHT:
101 router, err = dhtRoutingFromConfig(cfg.Router, extraDHT)
102 case config.RouterTypeParallel:
103 crp := cfg.Parameters.(*config.ComposableRouterParams)
104 var pr []*routinghelpers.ParallelRouter
105 for _, cr := range crp.Routers {
102 - ri, err := parse(visited, createdRouters, cr.RouterName, routersCfg, extraDHT, extraReframe)
106 + ri, err := parse(visited, createdRouters, cr.RouterName, routersCfg, extraDHT, extraHTTP)
107 if err != nil {
108 return nil, err
109 }
@@ -118,7 +122,7 @@ func parse(visited map[string]bool,
122 crp := cfg.Parameters.(*config.ComposableRouterParams)
123 var sr []*routinghelpers.SequentialRouter
124 for _, cr := range crp.Routers {
121 - ri, err := parse(visited, createdRouters, cr.RouterName, routersCfg, extraDHT, extraReframe)
125 + ri, err := parse(visited, createdRouters, cr.RouterName, routersCfg, extraDHT, extraHTTP)
126 if err != nil {
127 return nil, err
128 }
@@ -147,13 +151,62 @@ func parse(visited map[string]bool,
151 return router, nil
152 }
153
150 -type ExtraReframeParams struct {
154 +type ExtraHTTPParams struct {
155 PeerID string
156 Addrs []string
157 PrivKeyB64 string
158 }
159
156 -func reframeRoutingFromConfig(conf config.Router, extraReframe *ExtraReframeParams) (routing.Routing, error) {
160 +func httpRoutingFromConfig(conf config.Router, extraHTTP *ExtraHTTPParams) (routing.Routing, error) {
161 + params := conf.Parameters.(*config.HttpRouterParams)
162 + if params.Endpoint == "" {
163 + return nil, NewParamNeededErr("Endpoint", conf.Type)
164 + }
165 +
166 + params.FillDefaults()
167 +
168 + // Increase per-host connection pool since we are making lots of concurrent requests.
169 + transport := http.DefaultTransport.(*http.Transport).Clone()
170 + transport.MaxIdleConns = 500
171 + transport.MaxIdleConnsPerHost = 100
172 +
173 + delegateHTTPClient := &http.Client{
174 + Transport: transport,
175 + }
176 +
177 + key, err := decodePrivKey(extraHTTP.PrivKeyB64)
178 + if err != nil {
179 + return nil, err
180 + }
181 +
182 + addrInfo, err := createAddrInfo(extraHTTP.PeerID, extraHTTP.Addrs)
183 + if err != nil {
184 + return nil, err
185 + }
186 +
187 + cli, err := drclient.New(
188 + params.Endpoint,
189 + drclient.WithHTTPClient(delegateHTTPClient),
190 + drclient.WithIdentity(key),
191 + drclient.WithProviderInfo(addrInfo.ID, addrInfo.Addrs),
192 + )
193 + if err != nil {
194 + return nil, err
195 + }
196 +
197 + cr := contentrouter.NewContentRoutingClient(
198 + cli,
199 + contentrouter.WithMaxProvideBatchSize(params.MaxProvideBatchSize),
200 + contentrouter.WithMaxProvideConcurrency(params.MaxProvideConcurrency),
201 + )
202 +
203 + return &httpRoutingWrapper{
204 + ContentRouting: cr,
205 + ProvideManyRouter: cr,
206 + }, nil
207 +}
208 +
209 +func reframeRoutingFromConfig(conf config.Router, extraReframe *ExtraHTTPParams) (routing.Routing, error) {
210 var dr drp.DelegatedRouting_Client
211
212 params := conf.Parameters.(*config.ReframeRouterParams)
@@ -223,27 +276,35 @@ func decodePrivKey(keyB64 string) (ic.PrivKey, error) {
276 return ic.UnmarshalPrivateKey(pk)
277 }
278
226 -func createProvider(peerID string, addrs []string) (*drc.Provider, error) {
279 +func createAddrInfo(peerID string, addrs []string) (peer.AddrInfo, error) {
280 pID, err := peer.Decode(peerID)
281 if err != nil {
229 - return nil, err
282 + return peer.AddrInfo{}, err
283 }
284
285 var mas []ma.Multiaddr
286 for _, a := range addrs {
287 m, err := ma.NewMultiaddr(a)
288 if err != nil {
236 - return nil, err
289 + return peer.AddrInfo{}, err
290 }
291
292 mas = append(mas, m)
293 }
294
295 + return peer.AddrInfo{
296 + ID: pID,
297 + Addrs: mas,
298 + }, nil
299 +}
300 +
301 +func createProvider(peerID string, addrs []string) (*drc.Provider, error) {
302 + addrInfo, err := createAddrInfo(peerID, addrs)
303 + if err != nil {
304 + return nil, err
305 + }
306 return &drc.Provider{
243 - Peer: peer.AddrInfo{
244 - ID: pID,
245 - Addrs: mas,
246 - },
307 + Peer: addrInfo,
308 ProviderProto: []drc.TransferProtocol{
309 {Codec: multicodec.TransportBitswap},
310 },
routing/delegated_test.go
+1 -1
@@ -45,7 +45,7 @@ func TestReframeRoutingFromConfig(t *testing.T) {
45 Parameters: &config.ReframeRouterParams{
46 Endpoint: "test",
47 },
48 - }, &ExtraReframeParams{
48 + }, &ExtraHTTPParams{
49 PeerID: id.String(),
50 Addrs: []string{"/ip4/0.0.0.0/tcp/4001"},
51 PrivKeyB64: base64.StdEncoding.EncodeToString(privM),
routing/wrapper.go
+32
@@ -40,3 +40,35 @@ type ProvideManyRouter interface {
40 routinghelpers.ProvideManyRouter
41 routing.Routing
42 }
43 +
44 +var _ routing.Routing = &httpRoutingWrapper{}
45 +var _ routinghelpers.ProvideManyRouter = &httpRoutingWrapper{}
46 +
47 +// httpRoutingWrapper is a wrapper needed to construct the routing.Routing interface from
48 +// http delegated routing.
49 +type httpRoutingWrapper struct {
50 + routing.ContentRouting
51 + routinghelpers.ProvideManyRouter
52 +}
53 +
54 +func (c *httpRoutingWrapper) Bootstrap(ctx context.Context) error {
55 + return nil
56 +}
57 +
58 +func (c *httpRoutingWrapper) FindPeer(ctx context.Context, id peer.ID) (peer.AddrInfo, error) {
59 + return peer.AddrInfo{}, routing.ErrNotSupported
60 +}
61 +
62 +func (c *httpRoutingWrapper) PutValue(context.Context, string, []byte, ...routing.Option) error {
63 + return routing.ErrNotSupported
64 +}
65 +
66 +func (c *httpRoutingWrapper) GetValue(context.Context, string, ...routing.Option) ([]byte, error) {
67 + return nil, routing.ErrNotSupported
68 +}
69 +
70 +func (c *httpRoutingWrapper) SearchValue(context.Context, string, ...routing.Option) (<-chan []byte, error) {
71 + out := make(chan []byte)
72 + close(out)
73 + return out, routing.ErrNotSupported
74 +}