Skip to content

Commit

Permalink
Delegated Routing.
Browse files Browse the repository at this point in the history
Implementation of Reframe specs (https://github.com/ipfs/specs/blob/master/REFRAME.md) using go-delegated-routing library.
  • Loading branch information
ajnavarro committed Jun 22, 2022
1 parent 058803f commit 35ba77c
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 11 deletions.
14 changes: 8 additions & 6 deletions config/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package config

// Addresses stores the (string) multiaddr addresses for the node.
type Addresses struct {
Swarm []string // addresses for the swarm to listen on
Announce []string // swarm addresses to announce to the network, if len > 0 replaces auto detected addresses
AppendAnnounce []string // similar to Announce but doesn't overwrite auto detected addresses, they are just appended
NoAnnounce []string // swarm addresses not to announce to the network
API Strings // address for the local API (RPC)
Gateway Strings // address to listen on for IPFS HTTP object gateway
Swarm []string // addresses for the swarm to listen on
Announce []string // swarm addresses to announce to the network, if len > 0 replaces auto detected addresses
AppendAnnounce []string // similar to Announce but doesn't overwrite auto detected addresses, they are just appended
NoAnnounce []string // swarm addresses not to announce to the network
ExtraReframeRouters []string // allows to add other resolvers using the Reframe spec: https://github.com/ipfs/specs/blob/master/REFRAME.md
API Strings // address for the local API (RPC)
Gateway Strings // address to listen on for IPFS HTTP object gateway

}
11 changes: 6 additions & 5 deletions config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,12 @@ func addressesConfig() Addresses {
"/ip4/0.0.0.0/udp/4001/quic",
"/ip6/::/udp/4001/quic",
},
Announce: []string{},
AppendAnnounce: []string{},
NoAnnounce: []string{},
API: Strings{"/ip4/127.0.0.1/tcp/5001"},
Gateway: Strings{"/ip4/127.0.0.1/tcp/8080"},
Announce: []string{},
AppendAnnounce: []string{},
NoAnnounce: []string{},
ExtraReframeRouters: []string{},
API: Strings{"/ip4/127.0.0.1/tcp/5001"},
Gateway: Strings{"/ip4/127.0.0.1/tcp/8080"},
}
}

Expand Down
1 change: 1 addition & 0 deletions core/node/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {

fx.Provide(libp2p.Routing),
fx.Provide(libp2p.BaseRouting(cfg.Experimental.AcceleratedDHTClient)),
fx.Provide(libp2p.DelegatedRouting(cfg.Addresses.ExtraReframeRouters)),
maybeProvide(libp2p.PubsubRouter, bcfg.getOpt("ipnsps")),

maybeProvide(libp2p.BandwidthCounter, !cfg.Swarm.DisableBandwidthMetrics),
Expand Down
53 changes: 53 additions & 0 deletions core/node/libp2p/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import (
"sort"
"time"

"github.com/ipfs/go-cid"
"github.com/ipfs/go-ipfs/core/node/helpers"

drc "github.com/ipfs/go-delegated-routing/client"
drp "github.com/ipfs/go-delegated-routing/gen/proto"
config "github.com/ipfs/go-ipfs/config"
"github.com/ipfs/go-ipfs/repo"
"github.com/libp2p/go-libp2p-core/host"
Expand Down Expand Up @@ -127,6 +130,56 @@ func BaseRouting(experimentalDHTClient bool) interface{} {
}
}

type delegatedRouterOut struct {
fx.Out

Routers []Router `group:"routers,flatten"`
}

func DelegatedRouting(urls []string) interface{} {
return func() (delegatedRouterOut, error) {
out := delegatedRouterOut{}

for _, u := range urls {
var dr drp.DelegatedRouting_Client
dr, err := drp.New_DelegatedRouting_Client(u)
if err != nil {
return out, err
}

c := drc.NewClient(dr)
crc := drc.NewContentRoutingClient(c)
out.Routers = append(out.Routers, Router{Routing: &routingWrapper{
Client: c,
ContentRoutingClient: crc,
}})
}

return out, nil
}
}

var _ routing.Routing = &routingWrapper{}

// routingWrapper is a wrapper needed to construct the routing.Routing interface from
// delegated-routing library.
type routingWrapper struct {
*drc.Client
*drc.ContentRoutingClient
}

func (c *routingWrapper) FindProvidersAsync(ctx context.Context, cid cid.Cid, count int) <-chan peer.AddrInfo {
return c.ContentRoutingClient.FindProvidersAsync(ctx, cid, count)
}

func (c *routingWrapper) Bootstrap(ctx context.Context) error {
return nil
}

func (c *routingWrapper) FindPeer(ctx context.Context, id peer.ID) (peer.AddrInfo, error) {
return peer.AddrInfo{}, routing.ErrNotSupported
}

type p2pOnlineRoutingIn struct {
fx.In

Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ require (
github.com/ipfs/go-log/v2 v2.5.1
)

require github.com/ipld/edelweiss v0.1.1-0.20220523211122-2134034b3e81 // indirect

require (
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect
github.com/Kubuxu/go-os-helper v0.0.1 // indirect
Expand Down Expand Up @@ -173,6 +175,7 @@ require (
github.com/huin/goupnp v1.0.3 // indirect
github.com/ipfs/bbloom v0.0.4 // indirect
github.com/ipfs/go-bitfield v1.0.0 // indirect
github.com/ipfs/go-delegated-routing v0.2.1-0.20220524163630-968b11329985
github.com/ipfs/go-ipfs-delay v0.0.1 // indirect
github.com/ipfs/go-ipfs-ds-help v1.1.0 // indirect
github.com/ipfs/go-ipfs-pq v0.0.2 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ github.com/ipfs/go-datastore v0.4.5/go.mod h1:eXTcaaiN6uOlVCLS9GjJUJtlvJfM3xk23w
github.com/ipfs/go-datastore v0.5.0/go.mod h1:9zhEApYMTl17C8YDp7JmU7sQZi2/wqiYh73hakZ90Bk=
github.com/ipfs/go-datastore v0.5.1 h1:WkRhLuISI+XPD0uk3OskB0fYFSyqK8Ob5ZYew9Qa1nQ=
github.com/ipfs/go-datastore v0.5.1/go.mod h1:9zhEApYMTl17C8YDp7JmU7sQZi2/wqiYh73hakZ90Bk=
github.com/ipfs/go-delegated-routing v0.2.1-0.20220524163630-968b11329985 h1:Zd6mW1YEd5byQPw5qhJxYUSJeDhSJBG2q5jQg9N5ADg=
github.com/ipfs/go-delegated-routing v0.2.1-0.20220524163630-968b11329985/go.mod h1:eVvUPhPqkJBHDvekHy+g3ixUck11Vi5qPuOpZ5u/XE0=
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.2/go.mod h1:Y3QpeSFWQf6MopLTiZD+VT6IC1yZqaGmjvRcKeSGij8=
Expand Down Expand Up @@ -648,6 +650,8 @@ github.com/ipfs/interface-go-ipfs-core v0.7.0 h1:7tb+2upz8oCcjIyjo1atdMk+P+u7wPm
github.com/ipfs/interface-go-ipfs-core v0.7.0/go.mod h1:lF27E/nnSPbylPqKVXGZghal2hzifs3MmjyiEjnc9FY=
github.com/ipfs/tar-utils v0.0.2 h1:UNgHB4x/PPzbMkmJi+7EqC9LNMPDztOVSnx1HAqSNg4=
github.com/ipfs/tar-utils v0.0.2/go.mod h1:4qlnRWgTVljIMhSG2SqRYn66NT+3wrv/kZt9V+eqxDM=
github.com/ipld/edelweiss v0.1.1-0.20220523211122-2134034b3e81 h1:cu+XHovL7JOm7Fs6YL7ht3zK7QIMK617ZBptJqjz2mo=
github.com/ipld/edelweiss v0.1.1-0.20220523211122-2134034b3e81/go.mod h1:14NnBVHgrPO8cqDnKg7vc69LGI0aCAcax6mj21+99ec=
github.com/ipld/go-car v0.3.2 h1:V9wt/80FNfbMRWSD98W5br6fyjUAyVgI2lDOTZX16Lg=
github.com/ipld/go-car v0.3.2/go.mod h1:WEjynkVt04dr0GwJhry0KlaTeSDEiEYyMPOxDBQ17KE=
github.com/ipld/go-car/v2 v2.1.1 h1:saaKz4nC0AdfCGHLYKeXLGn8ivoPC54fyS55uyOLKwA=
Expand All @@ -663,6 +667,7 @@ github.com/ipld/go-ipld-prime v0.11.0/go.mod h1:+WIAkokurHmZ/KwzDOMUuoeJgaRQktHt
github.com/ipld/go-ipld-prime v0.12.3/go.mod h1:PaeLYq8k6dJLmDUSLrzkEpoGV4PEfe/1OtFN/eALOc8=
github.com/ipld/go-ipld-prime v0.14.0/go.mod h1:9ASQLwUFLptCov6lIYc70GRB4V7UTyLD0IJtrDJe6ZM=
github.com/ipld/go-ipld-prime v0.14.1/go.mod h1:QcE4Y9n/ZZr8Ijg5bGPT0GqYWgZ1704nH0RDcQtgTP0=
github.com/ipld/go-ipld-prime v0.14.4-0.20211217152141-008fd70fc96f/go.mod h1:QcE4Y9n/ZZr8Ijg5bGPT0GqYWgZ1704nH0RDcQtgTP0=
github.com/ipld/go-ipld-prime v0.16.0 h1:RS5hhjB/mcpeEPJvfyj0qbOj/QL+/j05heZ0qa97dVo=
github.com/ipld/go-ipld-prime v0.16.0/go.mod h1:axSCuOCBPqrH+gvXr2w9uAOulJqBPhHPT2PjoiiU1qA=
github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20211210234204-ce2a1c70cd73 h1:TsyATB2ZRRQGTwafJdgEUQkmjOExRV0DNokcihZxbnQ=
Expand Down

0 comments on commit 35ba77c

Please sign in to comment.