diff --git a/config/routing.go b/config/routing.go index 7f5e48aa262b..ede8f0f9ea91 100644 --- a/config/routing.go +++ b/config/routing.go @@ -28,7 +28,7 @@ type Router struct { Type RouterType // Parameters are extra configuration that this router might need. - // A common one for reframe router is "Endpoint". + // A common one for HTTP router is "Endpoint". Parameters interface{} } @@ -81,8 +81,6 @@ func (r *RouterParser) UnmarshalJSON(b []byte) error { switch out.Type { case RouterTypeHTTP: p = &HTTPRouterParams{} - case RouterTypeReframe: - p = &ReframeRouterParams{} case RouterTypeDHT: p = &DHTRouterParams{} case RouterTypeSequential: @@ -106,7 +104,6 @@ func (r *RouterParser) UnmarshalJSON(b []byte) error { type RouterType string const ( - RouterTypeReframe RouterType = "reframe" // More info here: https://github.com/ipfs/specs/tree/main/reframe . Actually deprecated. RouterTypeHTTP RouterType = "http" // HTTP JSON API for delegated routing systems (IPIP-337). RouterTypeDHT RouterType = "dht" // DHT router. RouterTypeSequential RouterType = "sequential" // Router helper to execute several routers sequentially. @@ -133,12 +130,6 @@ const ( var MethodNameList = []MethodName{MethodNameProvide, MethodNameFindPeers, MethodNameFindProviders, MethodNameGetIPNS, MethodNamePutIPNS} -type ReframeRouterParams struct { - // Endpoint is the URL where the routing implementation will point to get the information. - // Usually used for reframe Routers. - Endpoint string -} - type HTTPRouterParams struct { // Endpoint is the URL where the routing implementation will point to get the information. Endpoint string diff --git a/config/routing_test.go b/config/routing_test.go index 49068f976d96..4dfc54ccbd2d 100644 --- a/config/routing_test.go +++ b/config/routing_test.go @@ -23,12 +23,6 @@ func TestRouterParameters(t *testing.T) { PublicIPNetwork: false, }, }}, - "router-reframe": {Router{ - Type: RouterTypeReframe, - Parameters: ReframeRouterParams{ - Endpoint: "reframe-endpoint", - }, - }}, "router-parallel": {Router{ Type: RouterTypeParallel, Parameters: ComposableRouterParams{ @@ -39,7 +33,7 @@ func TestRouterParameters(t *testing.T) { IgnoreErrors: true, }, { - RouterName: "router-reframe", + RouterName: "router-dht", Timeout: Duration{10 * time.Second}, IgnoreErrors: false, ExecuteAfter: &OptionalDuration{&sec}, @@ -58,7 +52,7 @@ func TestRouterParameters(t *testing.T) { IgnoreErrors: true, }, { - RouterName: "router-reframe", + RouterName: "router-dht", Timeout: Duration{10 * time.Second}, IgnoreErrors: false, }, @@ -69,7 +63,7 @@ func TestRouterParameters(t *testing.T) { }, Methods: Methods{ MethodNameFindPeers: { - RouterName: "router-reframe", + RouterName: "router-dht", }, MethodNameFindProviders: { RouterName: "router-dht", @@ -99,9 +93,6 @@ func TestRouterParameters(t *testing.T) { dhtp := r2.Routers["router-dht"].Parameters require.IsType(&DHTRouterParams{}, dhtp) - rp := r2.Routers["router-reframe"].Parameters - require.IsType(&ReframeRouterParams{}, rp) - sp := r2.Routers["router-sequential"].Parameters require.IsType(&ComposableRouterParams{}, sp) @@ -109,68 +100,24 @@ func TestRouterParameters(t *testing.T) { require.IsType(&ComposableRouterParams{}, pp) } -func TestRouterMissingParameters(t *testing.T) { - require := require.New(t) - - r := Routing{ - Type: NewOptionalString("custom"), - Routers: map[string]RouterParser{ - "router-wrong-reframe": {Router{ - Type: RouterTypeReframe, - Parameters: DHTRouterParams{ - Mode: "auto", - AcceleratedDHTClient: true, - PublicIPNetwork: false, - }, - }}, - }, - Methods: Methods{ - MethodNameFindPeers: { - RouterName: "router-wrong-reframe", - }, - MethodNameFindProviders: { - RouterName: "router-wrong-reframe", - }, - MethodNameGetIPNS: { - RouterName: "router-wrong-reframe", - }, - MethodNameProvide: { - RouterName: "router-wrong-reframe", - }, - MethodNamePutIPNS: { - RouterName: "router-wrong-reframe", - }, - }, - } - - out, err := json.Marshal(r) - require.NoError(err) - - r2 := &Routing{} - - err = json.Unmarshal(out, r2) - require.NoError(err) - require.Empty(r2.Routers["router-wrong-reframe"].Parameters.(*ReframeRouterParams).Endpoint) -} - func TestMethods(t *testing.T) { require := require.New(t) methodsOK := Methods{ MethodNameFindPeers: { - RouterName: "router-wrong-reframe", + RouterName: "router-wrong", }, MethodNameFindProviders: { - RouterName: "router-wrong-reframe", + RouterName: "router-wrong", }, MethodNameGetIPNS: { - RouterName: "router-wrong-reframe", + RouterName: "router-wrong", }, MethodNameProvide: { - RouterName: "router-wrong-reframe", + RouterName: "router-wrong", }, MethodNamePutIPNS: { - RouterName: "router-wrong-reframe", + RouterName: "router-wrong", }, } @@ -178,16 +125,16 @@ func TestMethods(t *testing.T) { methodsMissing := Methods{ MethodNameFindPeers: { - RouterName: "router-wrong-reframe", + RouterName: "router-wrong", }, MethodNameGetIPNS: { - RouterName: "router-wrong-reframe", + RouterName: "router-wrong", }, MethodNameProvide: { - RouterName: "router-wrong-reframe", + RouterName: "router-wrong", }, MethodNamePutIPNS: { - RouterName: "router-wrong-reframe", + RouterName: "router-wrong", }, } diff --git a/core/core_test.go b/core/core_test.go index 9653cd7bd764..42dd543d767b 100644 --- a/core/core_test.go +++ b/core/core_test.go @@ -1,29 +1,14 @@ package core import ( - "crypto/rand" - "errors" - "fmt" - "net/http/httptest" - "path" "testing" - "time" context "context" - "github.com/ipfs/boxo/ipns" - ipfspath "github.com/ipfs/boxo/path" - "github.com/ipfs/go-cid" - "github.com/ipfs/go-delegated-routing/client" - "github.com/ipfs/kubo/core/node/libp2p" "github.com/ipfs/kubo/repo" - "github.com/libp2p/go-libp2p/core/crypto" - peer "github.com/libp2p/go-libp2p/core/peer" - "github.com/stretchr/testify/require" datastore "github.com/ipfs/go-datastore" syncds "github.com/ipfs/go-datastore/sync" - drs "github.com/ipfs/go-delegated-routing/server" config "github.com/ipfs/kubo/config" ) @@ -80,285 +65,3 @@ var testIdentity = config.Identity{ PeerID: "QmNgdzLieYi8tgfo2WfTUzNVH5hQK9oAYGVf6dxN12NrHt", PrivKey: "CAASrRIwggkpAgEAAoICAQCwt67GTUQ8nlJhks6CgbLKOx7F5tl1r9zF4m3TUrG3Pe8h64vi+ILDRFd7QJxaJ/n8ux9RUDoxLjzftL4uTdtv5UXl2vaufCc/C0bhCRvDhuWPhVsD75/DZPbwLsepxocwVWTyq7/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UwysnC29D+LUdQEQQ4qOm+gFAOtrWU62zMkXJ4iLt8Ify6kbrvsRXgbhQIzzGS7WH9XDarj0eZciuslr15TLMC1Azadf+cXHLR9gMHA13mT9vYIQKCAQA/DjGv8cKCkAvf7s2hqROGYAs6Jp8yhrsN1tYOwAPLRhtnCs+rLrg17M2vDptLlcRuI/vIElamdTmylRpjUQpX7yObzLO73nfVhpwRJVMdGU394iBIDncQ+JoHfUwgqJskbUM40dvZdyjbrqc/Q/4z+hbZb+oN/GXb8sVKBATPzSDMKQ/xqgisYIw+wmDPStnPsHAaIWOtni47zIgilJzD0WEk78/YjmPbUrboYvWziK5JiRRJFA1rkQqV1c0M+OXixIm+/yS8AksgCeaHr0WUieGcJtjT9uE8vyFop5ykhRiNxy9wGaq6i7IEecsrkd6DqxDHWkwhFuO1bSE83q/VAoIBAEA+RX1i/SUi08p71ggUi9WFMqXmzELp1L3hiEjOc2AklHk2rPxsaTh9+G95BvjhP7fRa/Yga+yDtYuyjO99nedStdNNSg03aPXILl9gs3r2dPiQKUEXZJ3FrH6tkils/8BlpOIRfbkszrdZIKTO9GCdLWQ30dQITDACs8zV/1GFGrHFrqnnMe/NpIFHWNZJ0/WZMi8wgWO6Ik8jHEpQtVXRiXLqy7U6hk170pa4GHOzvftfPElOZZjy9qn7KjdAQqy6spIrAE94OEL+fBgbHQZGLpuTlj6w6YGbMtPU8uo7sXKoc6WOCb68JWft3tejGLDa1946HAWqVM9B/UcneNc=", } - -var errNotSupported = errors.New("method not supported") - -func TestDelegatedRoutingSingle(t *testing.T) { - require := require.New(t) - - pID1, priv1, err := GeneratePeerID() - require.NoError(err) - - pID2, _, err := GeneratePeerID() - require.NoError(err) - - theID := path.Join("/ipns", string(pID1)) - theErrorID := path.Join("/ipns", string(pID2)) - - d := &delegatedRoutingService{ - goodPeerID: pID1, - badPeerID: pID2, - pk1: priv1, - } - - url := StartRoutingServer(t, d) - n := GetNode(t, url) - - ctx := context.Background() - - v, err := n.Routing.GetValue(ctx, theID) - require.NoError(err) - require.NotNil(v) - require.Contains(string(v), "RECORD FROM SERVICE 0") - - v, err = n.Routing.GetValue(ctx, theErrorID) - require.Nil(v) - require.Error(err) - - err = n.Routing.PutValue(ctx, theID, v) - require.NoError(err) - -} - -func TestDelegatedRoutingMulti(t *testing.T) { - require := require.New(t) - - pID1, priv1, err := GeneratePeerID() - require.NoError(err) - - pID2, priv2, err := GeneratePeerID() - require.NoError(err) - - theID1 := path.Join("/ipns", string(pID1)) - theID2 := path.Join("/ipns", string(pID2)) - - d1 := &delegatedRoutingService{ - goodPeerID: pID1, - badPeerID: pID2, - pk1: priv1, - serviceID: 1, - } - - url1 := StartRoutingServer(t, d1) - - d2 := &delegatedRoutingService{ - goodPeerID: pID2, - badPeerID: pID1, - pk1: priv2, - serviceID: 2, - } - - url2 := StartRoutingServer(t, d2) - - n := GetNode(t, url1, url2) - - ctx := context.Background() - - v, err := n.Routing.GetValue(ctx, theID1) - require.NoError(err) - require.NotNil(v) - require.Contains(string(v), "RECORD FROM SERVICE 1") - - v, err = n.Routing.GetValue(ctx, theID2) - require.NoError(err) - require.NotNil(v) - require.Contains(string(v), "RECORD FROM SERVICE 2") -} - -func StartRoutingServer(t *testing.T, d drs.DelegatedRoutingService) string { - t.Helper() - - f := drs.DelegatedRoutingAsyncHandler(d) - svr := httptest.NewServer(f) - t.Cleanup(func() { - svr.Close() - }) - - return svr.URL -} - -func GetNode(t *testing.T, reframeURLs ...string) *IpfsNode { - t.Helper() - - routers := make(config.Routers) - var routerNames []string - for i, ru := range reframeURLs { - rn := fmt.Sprintf("reframe-%d", i) - routerNames = append(routerNames, rn) - routers[rn] = - config.RouterParser{ - Router: config.Router{ - Type: config.RouterTypeReframe, - Parameters: &config.ReframeRouterParams{ - Endpoint: ru, - }, - }, - } - } - - var crs []config.ConfigRouter - for _, rn := range routerNames { - crs = append(crs, config.ConfigRouter{ - RouterName: rn, - IgnoreErrors: true, - Timeout: config.Duration{Duration: time.Minute}, - }) - } - - const parallelRouterName = "parallel-router" - - routers[parallelRouterName] = config.RouterParser{ - Router: config.Router{ - Type: config.RouterTypeParallel, - Parameters: &config.ComposableRouterParams{ - Routers: crs, - }, - }, - } - cfg := config.Config{ - Identity: testIdentity, - Addresses: config.Addresses{ - Swarm: []string{"/ip4/0.0.0.0/tcp/0", "/ip4/0.0.0.0/udp/0/quic"}, - API: []string{"/ip4/127.0.0.1/tcp/0"}, - }, - Routing: config.Routing{ - Type: config.NewOptionalString("custom"), - Routers: routers, - Methods: config.Methods{ - config.MethodNameFindPeers: config.Method{ - RouterName: parallelRouterName, - }, - config.MethodNameFindProviders: config.Method{ - RouterName: parallelRouterName, - }, - config.MethodNameGetIPNS: config.Method{ - RouterName: parallelRouterName, - }, - config.MethodNameProvide: config.Method{ - RouterName: parallelRouterName, - }, - config.MethodNamePutIPNS: config.Method{ - RouterName: parallelRouterName, - }, - }, - }, - } - - r := &repo.Mock{ - C: cfg, - D: syncds.MutexWrap(datastore.NewMapDatastore()), - } - - n, err := NewNode(context.Background(), - &BuildCfg{ - Repo: r, - Online: true, - Routing: libp2p.ConstructDelegatedRouting( - cfg.Routing.Routers, - cfg.Routing.Methods, - cfg.Identity.PeerID, - cfg.Addresses, - cfg.Identity.PrivKey, - ), - }, - ) - require.NoError(t, err) - - return n -} - -func GeneratePeerID() (peer.ID, crypto.PrivKey, error) { - priv, pk, err := crypto.GenerateEd25519Key(rand.Reader) - if err != nil { - return peer.ID(""), nil, err - } - - pid, err := peer.IDFromPublicKey(pk) - return pid, priv, err -} - -type delegatedRoutingService struct { - goodPeerID, badPeerID peer.ID - pk1 crypto.PrivKey - serviceID int -} - -func (drs *delegatedRoutingService) FindProviders(ctx context.Context, key cid.Cid) (<-chan client.FindProvidersAsyncResult, error) { - return nil, errNotSupported -} - -func (drs *delegatedRoutingService) Provide(ctx context.Context, req *client.ProvideRequest) (<-chan client.ProvideAsyncResult, error) { - return nil, errNotSupported -} - -func (drs *delegatedRoutingService) GetIPNS(ctx context.Context, id []byte) (<-chan client.GetIPNSAsyncResult, error) { - ctx, cancel := context.WithCancel(ctx) - ch := make(chan client.GetIPNSAsyncResult) - go func() { - defer close(ch) - defer cancel() - - var out client.GetIPNSAsyncResult - switch peer.ID(id) { - case drs.goodPeerID: - rec, err := ipns.NewRecord(drs.pk1, ipfspath.Path(fmt.Sprintf("RECORD FROM SERVICE %d", drs.serviceID)), 0, time.Now().Add(10*time.Hour), 100*time.Hour, ipns.CompatibleWithV1(true)) - if err != nil { - log.Fatal(err) - } - ieb, err := ipns.MarshalRecord(rec) - if err != nil { - log.Fatal(err) - } - - out = client.GetIPNSAsyncResult{ - Record: ieb, - Err: nil, - } - case drs.badPeerID: - out = client.GetIPNSAsyncResult{ - Record: nil, - Err: errors.New("THE ERROR"), - } - default: - return - } - - select { - case <-ctx.Done(): - return - case ch <- out: - } - }() - - return ch, nil - -} - -func (drs *delegatedRoutingService) PutIPNS(ctx context.Context, id []byte, record []byte) (<-chan client.PutIPNSAsyncResult, error) { - ctx, cancel := context.WithCancel(ctx) - ch := make(chan client.PutIPNSAsyncResult) - go func() { - defer close(ch) - defer cancel() - - var out client.PutIPNSAsyncResult - switch peer.ID(id) { - case drs.goodPeerID: - out = client.PutIPNSAsyncResult{} - case drs.badPeerID: - out = client.PutIPNSAsyncResult{ - Err: fmt.Errorf("THE ERROR %d", drs.serviceID), - } - default: - return - } - - select { - case <-ctx.Done(): - return - case ch <- out: - } - }() - - return ch, nil -} diff --git a/docs/examples/kubo-as-a-library/go.mod b/docs/examples/kubo-as-a-library/go.mod index c103cab71d9d..4a3291e35dd0 100644 --- a/docs/examples/kubo-as-a-library/go.mod +++ b/docs/examples/kubo-as-a-library/go.mod @@ -7,7 +7,7 @@ go 1.18 replace github.com/ipfs/kubo => ./../../.. require ( - github.com/ipfs/boxo v0.10.1-0.20230612090609-11f817fc465d + github.com/ipfs/boxo v0.10.1-0.20230613102120-8bf25bd2d6f1 github.com/ipfs/kubo v0.0.0-00010101000000-000000000000 github.com/libp2p/go-libp2p v0.27.5 github.com/multiformats/go-multiaddr v0.9.0 @@ -65,7 +65,6 @@ require ( github.com/ipfs/go-cid v0.4.1 // indirect github.com/ipfs/go-cidutil v0.1.0 // indirect github.com/ipfs/go-datastore v0.6.0 // indirect - github.com/ipfs/go-delegated-routing v0.8.0 // indirect github.com/ipfs/go-ds-badger v0.3.0 // indirect github.com/ipfs/go-ds-flatfs v0.5.1 // indirect github.com/ipfs/go-ds-leveldb v0.5.0 // indirect @@ -88,7 +87,6 @@ require ( github.com/ipfs/go-metrics-interface v0.0.1 // indirect github.com/ipfs/go-peertaskqueue v0.8.1 // indirect github.com/ipfs/go-unixfsnode v1.7.1 // indirect - github.com/ipld/edelweiss v0.2.0 // indirect github.com/ipld/go-codec-dagpb v1.6.0 // indirect github.com/ipld/go-ipld-prime v0.20.0 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect diff --git a/docs/examples/kubo-as-a-library/go.sum b/docs/examples/kubo-as-a-library/go.sum index 1700076efbcb..30d7491722e9 100644 --- a/docs/examples/kubo-as-a-library/go.sum +++ b/docs/examples/kubo-as-a-library/go.sum @@ -319,8 +319,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs= github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0= -github.com/ipfs/boxo v0.10.1-0.20230612090609-11f817fc465d h1:59AAX3a0HibI9LLo3jIRvSVWzkLoWXptGgGB8ZwWgCc= -github.com/ipfs/boxo v0.10.1-0.20230612090609-11f817fc465d/go.mod h1:vRJqn2gSu+LkTTVGzxRJxggmiHXnWl0Ws5/YAwQbJLM= +github.com/ipfs/boxo v0.10.1-0.20230613102120-8bf25bd2d6f1 h1:ZuxwglmPtQG0pMu45Cid1zt3HeaNgZDj6ceh6ULv3Ns= +github.com/ipfs/boxo v0.10.1-0.20230613102120-8bf25bd2d6f1/go.mod h1:vRJqn2gSu+LkTTVGzxRJxggmiHXnWl0Ws5/YAwQbJLM= github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA= github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU= github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY= @@ -343,8 +343,6 @@ github.com/ipfs/go-datastore v0.1.1/go.mod h1:w38XXW9kVFNp57Zj5knbKWM2T+KOZCGDRV github.com/ipfs/go-datastore v0.5.0/go.mod h1:9zhEApYMTl17C8YDp7JmU7sQZi2/wqiYh73hakZ90Bk= github.com/ipfs/go-datastore v0.6.0 h1:JKyz+Gvz1QEZw0LsX1IBn+JFCJQH4SJVFtM4uWU0Myk= github.com/ipfs/go-datastore v0.6.0/go.mod h1:rt5M3nNbSO/8q1t4LNkLyUwRs8HupMeN/8O4Vn9YAT8= -github.com/ipfs/go-delegated-routing v0.8.0 h1:faiRi4k8YioTxU2x7+pnrLQjR7jIQhGWN2JvCwcQ/aU= -github.com/ipfs/go-delegated-routing v0.8.0/go.mod h1:18Dds6ZoNTsff9S/7R49Nh2t2YNXIIKR/RLQmBZdjjY= github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk= github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= github.com/ipfs/go-ds-badger v0.0.7/go.mod h1:qt0/fWzZDoPW6jpQeqUjR5kBfhDNB65jd9YlmAvpQBk= @@ -412,8 +410,6 @@ github.com/ipfs/go-unixfs v0.4.5 h1:wj8JhxvV1G6CD7swACwSKYa+NgtdWC1RUit+gFnymDU= github.com/ipfs/go-unixfsnode v1.7.1 h1:RRxO2b6CSr5UQ/kxnGzaChTjp5LWTdf3Y4n8ANZgB/s= github.com/ipfs/go-unixfsnode v1.7.1/go.mod h1:PVfoyZkX1B34qzT3vJO4nsLUpRCyhnMuHBznRcXirlk= github.com/ipfs/go-verifcid v0.0.2 h1:XPnUv0XmdH+ZIhLGKg6U2vaPaRDXb9urMyNVCE7uvTs= -github.com/ipld/edelweiss v0.2.0 h1:KfAZBP8eeJtrLxLhi7r3N0cBCo7JmwSRhOJp3WSpNjk= -github.com/ipld/edelweiss v0.2.0/go.mod h1:FJAzJRCep4iI8FOFlRriN9n0b7OuX3T/S9++NpBDmA4= github.com/ipld/go-car/v2 v2.9.1-0.20230325062757-fff0e4397a3d h1:22g+x1tgWSXK34i25qjs+afr7basaneEkHaglBshd2g= github.com/ipld/go-codec-dagpb v1.6.0 h1:9nYazfyu9B1p3NAgfVdpRco3Fs2nFC72DqVsMj6rOcc= github.com/ipld/go-codec-dagpb v1.6.0/go.mod h1:ANzFhfP2uMJxRBr8CE+WQWs5UsNa0pYtmKZ+agnUw9s= diff --git a/go.mod b/go.mod index ec99e6c1eb39..3001adb4b6c6 100644 --- a/go.mod +++ b/go.mod @@ -16,12 +16,11 @@ require ( github.com/gogo/protobuf v1.3.2 github.com/google/uuid v1.3.0 github.com/hashicorp/go-multierror v1.1.1 - github.com/ipfs/boxo v0.10.1-0.20230612090609-11f817fc465d + github.com/ipfs/boxo v0.10.1-0.20230613102120-8bf25bd2d6f1 github.com/ipfs/go-block-format v0.1.2 github.com/ipfs/go-cid v0.4.1 github.com/ipfs/go-cidutil v0.1.0 github.com/ipfs/go-datastore v0.6.0 - github.com/ipfs/go-delegated-routing v0.8.0 github.com/ipfs/go-detect-race v0.0.1 github.com/ipfs/go-ds-badger v0.3.0 github.com/ipfs/go-ds-flatfs v0.5.1 @@ -140,7 +139,6 @@ require ( github.com/ipfs/go-ipld-cbor v0.0.6 // indirect github.com/ipfs/go-libipfs v0.7.0 // indirect github.com/ipfs/go-peertaskqueue v0.8.1 // indirect - github.com/ipld/edelweiss v0.2.0 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/klauspost/compress v1.16.4 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect diff --git a/go.sum b/go.sum index 0a002e68c53c..68de6703663a 100644 --- a/go.sum +++ b/go.sum @@ -354,8 +354,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs= github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0= -github.com/ipfs/boxo v0.10.1-0.20230612090609-11f817fc465d h1:59AAX3a0HibI9LLo3jIRvSVWzkLoWXptGgGB8ZwWgCc= -github.com/ipfs/boxo v0.10.1-0.20230612090609-11f817fc465d/go.mod h1:vRJqn2gSu+LkTTVGzxRJxggmiHXnWl0Ws5/YAwQbJLM= +github.com/ipfs/boxo v0.10.1-0.20230613102120-8bf25bd2d6f1 h1:ZuxwglmPtQG0pMu45Cid1zt3HeaNgZDj6ceh6ULv3Ns= +github.com/ipfs/boxo v0.10.1-0.20230613102120-8bf25bd2d6f1/go.mod h1:vRJqn2gSu+LkTTVGzxRJxggmiHXnWl0Ws5/YAwQbJLM= github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA= github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU= github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY= @@ -378,8 +378,6 @@ github.com/ipfs/go-datastore v0.1.1/go.mod h1:w38XXW9kVFNp57Zj5knbKWM2T+KOZCGDRV github.com/ipfs/go-datastore v0.5.0/go.mod h1:9zhEApYMTl17C8YDp7JmU7sQZi2/wqiYh73hakZ90Bk= github.com/ipfs/go-datastore v0.6.0 h1:JKyz+Gvz1QEZw0LsX1IBn+JFCJQH4SJVFtM4uWU0Myk= github.com/ipfs/go-datastore v0.6.0/go.mod h1:rt5M3nNbSO/8q1t4LNkLyUwRs8HupMeN/8O4Vn9YAT8= -github.com/ipfs/go-delegated-routing v0.8.0 h1:faiRi4k8YioTxU2x7+pnrLQjR7jIQhGWN2JvCwcQ/aU= -github.com/ipfs/go-delegated-routing v0.8.0/go.mod h1:18Dds6ZoNTsff9S/7R49Nh2t2YNXIIKR/RLQmBZdjjY= github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk= github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= github.com/ipfs/go-ds-badger v0.0.7/go.mod h1:qt0/fWzZDoPW6jpQeqUjR5kBfhDNB65jd9YlmAvpQBk= @@ -451,8 +449,6 @@ github.com/ipfs/go-unixfs v0.4.5 h1:wj8JhxvV1G6CD7swACwSKYa+NgtdWC1RUit+gFnymDU= github.com/ipfs/go-unixfsnode v1.7.1 h1:RRxO2b6CSr5UQ/kxnGzaChTjp5LWTdf3Y4n8ANZgB/s= github.com/ipfs/go-unixfsnode v1.7.1/go.mod h1:PVfoyZkX1B34qzT3vJO4nsLUpRCyhnMuHBznRcXirlk= github.com/ipfs/go-verifcid v0.0.2 h1:XPnUv0XmdH+ZIhLGKg6U2vaPaRDXb9urMyNVCE7uvTs= -github.com/ipld/edelweiss v0.2.0 h1:KfAZBP8eeJtrLxLhi7r3N0cBCo7JmwSRhOJp3WSpNjk= -github.com/ipld/edelweiss v0.2.0/go.mod h1:FJAzJRCep4iI8FOFlRriN9n0b7OuX3T/S9++NpBDmA4= github.com/ipld/go-car v0.5.0 h1:kcCEa3CvYMs0iE5BzD5sV7O2EwMiCIp3uF8tA6APQT8= github.com/ipld/go-car/v2 v2.9.1-0.20230325062757-fff0e4397a3d h1:22g+x1tgWSXK34i25qjs+afr7basaneEkHaglBshd2g= github.com/ipld/go-codec-dagpb v1.6.0 h1:9nYazfyu9B1p3NAgfVdpRco3Fs2nFC72DqVsMj6rOcc= diff --git a/routing/delegated.go b/routing/delegated.go index 90a9c08071b3..26340fb72016 100644 --- a/routing/delegated.go +++ b/routing/delegated.go @@ -10,8 +10,6 @@ import ( drclient "github.com/ipfs/boxo/routing/http/client" "github.com/ipfs/boxo/routing/http/contentrouter" "github.com/ipfs/go-datastore" - drc "github.com/ipfs/go-delegated-routing/client" - drp "github.com/ipfs/go-delegated-routing/gen/proto" logging "github.com/ipfs/go-log" version "github.com/ipfs/kubo" "github.com/ipfs/kubo/config" @@ -25,7 +23,6 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/routing" ma "github.com/multiformats/go-multiaddr" - "github.com/multiformats/go-multicodec" "go.opencensus.io/stats/view" ) @@ -96,8 +93,6 @@ func parse(visited map[string]bool, switch cfg.Type { case config.RouterTypeHTTP: router, err = httpRoutingFromConfig(cfg.Router, extraHTTP) - case config.RouterTypeReframe: - router, err = reframeRoutingFromConfig(cfg.Router, extraHTTP) case config.RouterTypeDHT: router, err = dhtRoutingFromConfig(cfg.Router, extraDHT) case config.RouterTypeParallel: @@ -232,67 +227,6 @@ func httpRoutingFromConfig(conf config.Router, extraHTTP *ExtraHTTPParams) (rout }, nil } -func reframeRoutingFromConfig(conf config.Router, extraReframe *ExtraHTTPParams) (routing.Routing, error) { - var dr drp.DelegatedRouting_Client - - params := conf.Parameters.(*config.ReframeRouterParams) - - if params.Endpoint == "" { - return nil, NewParamNeededErr("Endpoint", conf.Type) - } - - // Increase per-host connection pool since we are making lots of concurrent requests. - transport := http.DefaultTransport.(*http.Transport).Clone() - transport.MaxIdleConns = 500 - transport.MaxIdleConnsPerHost = 100 - - delegateHTTPClient := &http.Client{ - Transport: transport, - } - dr, err := drp.New_DelegatedRouting_Client(params.Endpoint, - drp.DelegatedRouting_Client_WithHTTPClient(delegateHTTPClient), - ) - if err != nil { - return nil, err - } - - var c *drc.Client - - err = view.Register(drc.DefaultViews...) - if err != nil { - return nil, fmt.Errorf("registering delegated routing views: %w", err) - } - - // this path is for tests only - if extraReframe == nil { - c, err = drc.NewClient(dr, nil, nil) - if err != nil { - return nil, err - } - } else { - prov, err := createProvider(extraReframe.PeerID, extraReframe.Addrs) - if err != nil { - return nil, err - } - - key, err := decodePrivKey(extraReframe.PrivKeyB64) - if err != nil { - return nil, err - } - - c, err = drc.NewClient(dr, prov, key) - if err != nil { - return nil, err - } - } - - crc := drc.NewContentRoutingClient(c) - return &reframeRoutingWrapper{ - Client: c, - ContentRoutingClient: crc, - }, nil -} - func decodePrivKey(keyB64 string) (ic.PrivKey, error) { pk, err := base64.StdEncoding.DecodeString(keyB64) if err != nil { @@ -324,19 +258,6 @@ func createAddrInfo(peerID string, addrs []string) (peer.AddrInfo, error) { }, nil } -func createProvider(peerID string, addrs []string) (*drc.Provider, error) { - addrInfo, err := createAddrInfo(peerID, addrs) - if err != nil { - return nil, err - } - return &drc.Provider{ - Peer: addrInfo, - ProviderProto: []drc.TransferProtocol{ - {Codec: multicodec.TransportBitswap}, - }, - }, nil -} - type ExtraDHTParams struct { BootstrapPeers []peer.AddrInfo Host host.Host diff --git a/routing/delegated_test.go b/routing/delegated_test.go index ee7543114d92..da0210f5ebbf 100644 --- a/routing/delegated_test.go +++ b/routing/delegated_test.go @@ -1,68 +1,27 @@ package routing import ( + "crypto/rand" "encoding/base64" "testing" "github.com/ipfs/kubo/config" - crypto "github.com/libp2p/go-libp2p/core/crypto" - peer "github.com/libp2p/go-libp2p/core/peer" + "github.com/libp2p/go-libp2p/core/crypto" + "github.com/libp2p/go-libp2p/core/peer" "github.com/stretchr/testify/require" ) -func TestReframeRoutingFromConfig(t *testing.T) { +func TestParser(t *testing.T) { require := require.New(t) - r, err := reframeRoutingFromConfig(config.Router{ - Type: config.RouterTypeReframe, - Parameters: &config.ReframeRouterParams{}, - }, nil) - - require.Nil(r) - require.EqualError(err, "configuration param 'Endpoint' is needed for reframe delegated routing types") - - r, err = reframeRoutingFromConfig(config.Router{ - Type: config.RouterTypeReframe, - Parameters: &config.ReframeRouterParams{ - Endpoint: "test", - }, - }, nil) - - require.NoError(err) - require.NotNil(r) - - priv, pub, err := crypto.GenerateKeyPair(crypto.RSA, 2048) - require.NoError(err) - - id, err := peer.IDFromPublicKey(pub) - require.NoError(err) - - privM, err := crypto.MarshalPrivateKey(priv) + pid, sk, err := generatePeerID() require.NoError(err) - r, err = reframeRoutingFromConfig(config.Router{ - Type: config.RouterTypeReframe, - Parameters: &config.ReframeRouterParams{ - Endpoint: "test", - }, - }, &ExtraHTTPParams{ - PeerID: id.String(), - Addrs: []string{"/ip4/0.0.0.0/tcp/4001"}, - PrivKeyB64: base64.StdEncoding.EncodeToString(privM), - }) - - require.NotNil(r) - require.NoError(err) -} - -func TestParser(t *testing.T) { - require := require.New(t) - router, err := Parse(config.Routers{ "r1": config.RouterParser{ Router: config.Router{ - Type: config.RouterTypeReframe, - Parameters: &config.ReframeRouterParams{ + Type: config.RouterTypeHTTP, + Parameters: &config.HTTPRouterParams{ Endpoint: "testEndpoint", }, }, @@ -95,7 +54,10 @@ func TestParser(t *testing.T) { config.MethodNameProvide: config.Method{ RouterName: "r2", }, - }, &ExtraDHTParams{}, nil) + }, &ExtraDHTParams{}, &ExtraHTTPParams{ + PeerID: string(pid), + PrivKeyB64: sk, + }) require.NoError(err) @@ -109,27 +71,30 @@ func TestParser(t *testing.T) { func TestParserRecursive(t *testing.T) { require := require.New(t) + pid, sk, err := generatePeerID() + require.NoError(err) + router, err := Parse(config.Routers{ - "reframe1": config.RouterParser{ + "http1": config.RouterParser{ Router: config.Router{ - Type: config.RouterTypeReframe, - Parameters: &config.ReframeRouterParams{ + Type: config.RouterTypeHTTP, + Parameters: &config.HTTPRouterParams{ Endpoint: "testEndpoint1", }, }, }, - "reframe2": config.RouterParser{ + "http2": config.RouterParser{ Router: config.Router{ - Type: config.RouterTypeReframe, - Parameters: &config.ReframeRouterParams{ + Type: config.RouterTypeHTTP, + Parameters: &config.HTTPRouterParams{ Endpoint: "testEndpoint2", }, }, }, - "reframe3": config.RouterParser{ + "http3": config.RouterParser{ Router: config.Router{ - Type: config.RouterTypeReframe, - Parameters: &config.ReframeRouterParams{ + Type: config.RouterTypeHTTP, + Parameters: &config.HTTPRouterParams{ Endpoint: "testEndpoint3", }, }, @@ -140,10 +105,10 @@ func TestParserRecursive(t *testing.T) { Parameters: &config.ComposableRouterParams{ Routers: []config.ConfigRouter{ { - RouterName: "reframe1", + RouterName: "http1", }, { - RouterName: "reframe2", + RouterName: "http2", }, }, }, @@ -158,7 +123,7 @@ func TestParserRecursive(t *testing.T) { RouterName: "composable1", }, { - RouterName: "reframe3", + RouterName: "http3", }, }, }, @@ -180,7 +145,10 @@ func TestParserRecursive(t *testing.T) { config.MethodNameProvide: config.Method{ RouterName: "composable2", }, - }, &ExtraDHTParams{}, nil) + }, &ExtraDHTParams{}, &ExtraHTTPParams{ + PeerID: string(pid), + PrivKeyB64: sk, + }) require.NoError(err) @@ -237,3 +205,23 @@ func TestParserRecursiveLoop(t *testing.T) { require.ErrorContains(err, "dependency loop creating router with name \"composable2\"") } + +func generatePeerID() (string, string, error) { + sk, pk, err := crypto.GenerateEd25519Key(rand.Reader) + if err != nil { + return "", "", err + } + + bytes, err := crypto.MarshalPrivateKey(sk) + if err != nil { + return "", "", err + } + + enc := base64.StdEncoding.EncodeToString(bytes) + if err != nil { + return "", "", err + } + + pid, err := peer.IDFromPublicKey(pk) + return pid.String(), enc, err +} diff --git a/routing/wrapper.go b/routing/wrapper.go index d4215ca9c900..f6a753843cdf 100644 --- a/routing/wrapper.go +++ b/routing/wrapper.go @@ -3,39 +3,11 @@ package routing import ( "context" - "github.com/ipfs/go-cid" - drc "github.com/ipfs/go-delegated-routing/client" routinghelpers "github.com/libp2p/go-libp2p-routing-helpers" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/routing" ) -var _ routing.Routing = &reframeRoutingWrapper{} -var _ routinghelpers.ProvideManyRouter = &reframeRoutingWrapper{} - -// reframeRoutingWrapper is a wrapper needed to construct the routing.Routing interface from -// delegated-routing library. -type reframeRoutingWrapper struct { - *drc.Client - *drc.ContentRoutingClient -} - -func (c *reframeRoutingWrapper) Provide(ctx context.Context, id cid.Cid, announce bool) error { - return c.ContentRoutingClient.Provide(ctx, id, announce) -} - -func (c *reframeRoutingWrapper) FindProvidersAsync(ctx context.Context, cid cid.Cid, count int) <-chan peer.AddrInfo { - return c.ContentRoutingClient.FindProvidersAsync(ctx, cid, count) -} - -func (c *reframeRoutingWrapper) Bootstrap(ctx context.Context) error { - return nil -} - -func (c *reframeRoutingWrapper) FindPeer(ctx context.Context, id peer.ID) (peer.AddrInfo, error) { - return peer.AddrInfo{}, routing.ErrNotSupported -} - type ProvideManyRouter interface { routinghelpers.ProvideManyRouter routing.Routing diff --git a/test/dependencies/go.mod b/test/dependencies/go.mod index 208e50810d33..badc798c6f74 100644 --- a/test/dependencies/go.mod +++ b/test/dependencies/go.mod @@ -7,7 +7,7 @@ replace github.com/ipfs/kubo => ../../ require ( github.com/Kubuxu/gocovmerge v0.0.0-20161216165753-7ecaa51963cd github.com/golangci/golangci-lint v1.49.0 - github.com/ipfs/boxo v0.10.1-0.20230612090609-11f817fc465d + github.com/ipfs/boxo v0.10.1-0.20230613102120-8bf25bd2d6f1 github.com/ipfs/go-cid v0.4.1 github.com/ipfs/go-cidutil v0.1.0 github.com/ipfs/go-datastore v0.6.0 diff --git a/test/dependencies/go.sum b/test/dependencies/go.sum index 6e237473d6b9..75a0edabf645 100644 --- a/test/dependencies/go.sum +++ b/test/dependencies/go.sum @@ -412,8 +412,8 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs= github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0= -github.com/ipfs/boxo v0.10.1-0.20230612090609-11f817fc465d h1:59AAX3a0HibI9LLo3jIRvSVWzkLoWXptGgGB8ZwWgCc= -github.com/ipfs/boxo v0.10.1-0.20230612090609-11f817fc465d/go.mod h1:vRJqn2gSu+LkTTVGzxRJxggmiHXnWl0Ws5/YAwQbJLM= +github.com/ipfs/boxo v0.10.1-0.20230613102120-8bf25bd2d6f1 h1:ZuxwglmPtQG0pMu45Cid1zt3HeaNgZDj6ceh6ULv3Ns= +github.com/ipfs/boxo v0.10.1-0.20230613102120-8bf25bd2d6f1/go.mod h1:vRJqn2gSu+LkTTVGzxRJxggmiHXnWl0Ws5/YAwQbJLM= github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA= github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU= github.com/ipfs/go-block-format v0.1.2 h1:GAjkfhVx1f4YTODS6Esrj1wt2HhrtwTnhEr+DyPUaJo=