-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libp2p retrieval transports endpoint (#723)
* feat: libp2p retrieval transports endpoint * refactor: transports protocol can have multiple multiaddresses * feat: boost provider retrieval-transports CLI command * docs: add known protocols to transports ipld schema
- Loading branch information
Showing
11 changed files
with
428 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/multiformats/go-multiaddr" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestMultiaddrToNative(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
proto string | ||
ma string | ||
expected string | ||
}{{ | ||
name: "http", | ||
proto: "http", | ||
ma: "/dns/foo.com/http", | ||
expected: "http://foo.com", | ||
}, { | ||
name: "http IP 4 address", | ||
proto: "http", | ||
ma: "/ip4/192.168.0.1/tcp/80/http", | ||
expected: "http://192.168.0.1:80", | ||
}, { | ||
name: "https", | ||
proto: "https", | ||
ma: "/dns/foo.com/tcp/443/https", | ||
expected: "https://foo.com:443", | ||
}, { | ||
name: "unknown protocol", | ||
proto: "fancynewproto", | ||
ma: "/dns/foo.com/tcp/80/http", | ||
expected: "", | ||
}} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
ma, err := multiaddr.NewMultiaddr(tc.ma) | ||
require.NoError(t, err) | ||
res := multiaddrToNative(tc.proto, ma) | ||
require.Equal(t, tc.expected, res) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package modules | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/filecoin-project/boost/node/config" | ||
"github.com/filecoin-project/boost/retrievalmarket/lp2pimpl" | ||
"github.com/filecoin-project/boost/retrievalmarket/types" | ||
"github.com/libp2p/go-libp2p-core/host" | ||
"github.com/multiformats/go-multiaddr" | ||
"go.uber.org/fx" | ||
) | ||
|
||
func NewTransportsListener(cfg *config.Boost) func(h host.Host) (*lp2pimpl.TransportsListener, error) { | ||
return func(h host.Host) (*lp2pimpl.TransportsListener, error) { | ||
protos := []types.Protocol{} | ||
|
||
// Get the libp2p addresses from the Host | ||
if len(h.Addrs()) > 0 { | ||
protos = append(protos, types.Protocol{ | ||
Name: "libp2p", | ||
Addresses: h.Addrs(), | ||
}) | ||
} | ||
|
||
// If there's an http retrieval address specified, add HTTP to the list | ||
// of supported protocols | ||
if cfg.Dealmaking.HTTPRetrievalMultiaddr != "" { | ||
maddr, err := multiaddr.NewMultiaddr(cfg.Dealmaking.HTTPRetrievalMultiaddr) | ||
if err != nil { | ||
msg := "HTTPRetrievalURL must be in multi-address format. " | ||
msg += "Could not parse '%s' as multiaddr: %w" | ||
return nil, fmt.Errorf(msg, cfg.Dealmaking.HTTPRetrievalMultiaddr, err) | ||
} | ||
|
||
protos = append(protos, types.Protocol{ | ||
Name: "http", | ||
Addresses: []multiaddr.Multiaddr{maddr}, | ||
}) | ||
} | ||
|
||
return lp2pimpl.NewTransportsListener(h, protos), nil | ||
} | ||
} | ||
|
||
func HandleRetrievalTransports(lc fx.Lifecycle, l *lp2pimpl.TransportsListener) { | ||
lc.Append(fx.Hook{ | ||
OnStart: func(ctx context.Context) error { | ||
log.Debug("starting retrieval transports listener") | ||
l.Start() | ||
return nil | ||
}, | ||
OnStop: func(context.Context) error { | ||
log.Debug("stopping retrieval transports listener") | ||
l.Stop() | ||
return nil | ||
}, | ||
}) | ||
} |
Oops, something went wrong.