-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement ipni-sync http over libp2p #113
Conversation
Use the new libp2phttp functionality for serving and requesting ipnisync over libp2p.
Codecov ReportPatch coverage:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the GitHub App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## main #113 +/- ##
==========================================
+ Coverage 54.03% 61.20% +7.17%
==========================================
Files 67 57 -10
Lines 5341 4916 -425
==========================================
+ Hits 2886 3009 +123
+ Misses 2140 1581 -559
- Partials 315 326 +11
☔ View full report in Codecov by Sentry. |
- Update comments - Add HttpTimeout option for subscriber
Add option to use retryable http client
…This supports legacy HTTP served without IPNI path.
From @MarcoPolo in #103, here |
- Change AsyncErr to Err in SyncFinished - Move old p2p head client/server (legs protocol ID) into dtsync, since that is the only place it is used. - Add tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
dagsync/ipnisync/sync.go
Outdated
"github.com/multiformats/go-multihash" | ||
) | ||
|
||
const defaultHttpTimeout = 10 * time.Second | ||
const ProtocolID = protocol.ID("/ipnisync/v1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too late to change this to /ipni/sync/v1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to match the HTTP path, which is /ipni/v1/ad/
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure http path as libp2p protocol ID makes sense? That protocol exposes multiple paths right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only one path. As per spec the only path is /ipni/v1/ad/
, which is followed by the resource head
or the CID to fetch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the libp2phttp
package, the protocol ID maps to a specific HTTP path, so it seems to make sense that they should be the same.
@MarcoPolo Recommendation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to use the IPNIPath as the protocol ID. I provided an explanation in the comment here.
Serve ipnisync HTTP over libp2p
This PR makes use of the new libp2phttp functionality for serving and requesting ipnisync over libp2p.
The new publisher can publish ipnisync-http over libp2p if supplied with a stream host, over plain HTTP if supplied with a listen address, or both. The publisher also works as an HTTP handler to allow it to be used with existing HTTP listeners.
The sync client works with ipnisync-http over libp2p, plain HTTP, and legacy data-transfer sync. It is able to detect which protocol and transport to use with any provider, new or old.
Protocol negotiation
When a
Syncer
is created to sync with a specific advertisement publisher, it first uses libp2phttp to negotiate with the publisher whether to use HTTP with or without libp2p. If the publisher is an older publisher that does not support this negotiation, then the client tries to use plain HTTP or the legacy data-transfer/graphsync protocol depending on the publisher address.If a publisher is newer, but uses an existing HTTP server, it can still support protocol negotiation by supporting the
/.well-known/
HTTP endpoint. Here is an example of adding support for this. This is optional, and the cost for not supporting it is one additional HTTP round trip between the indexer and publisher per sync operation.API Changes
This PR has some minor
ipnisync
API changes to be aware of.Publisher API Changes:
NewPublisher
function does not take a single HTTP listen address as its first argument. It now takes a list of HTTP address as an option,WithHTTPListenAddrs
, since HTTP listen addresses are not required when using a libp2p stream host or with an existing HTTP server.NewPublisher
can be given a libp2p stream host to serve advertisements, by specifying the optionWithStreamHost
.dagsync/p2p/protocol/head
package has moved todagsync/dtsync/head
since it is only used indtsync
. This should not affect any external applications.WithServer
has been renamed toWithStartServer
.WithRequireTLS
tells whether to require https or allow the publisher to serve non-secure http. Default is false, allowing non-secure HTTP.Sync client API changes:
NewSync
function does not take anhttp.Client
. Options are used to configure a default or retryable HTTP client.NewSync
function:ClientAuthServerPeerID
tells the sync client that it must authenticate the Server's PeerID.ClientHTTPTimeout
specifies a time limit for HTTP requestsClientStreamHost
specifies an optional stream based libp2p hostClientHTTPRetry
configures a retriable HTTP clientNewSyncer
function now takes a singlepeer.AddrInfo
instead of a separatepeer.ID
and[]multiaddr.Multiaddr
arguments.dagsync.Subscriber
API changes:NewSubscriber
no longer has aHttpClient
option. It now supports the following options:HttpTimeout
which is passed through to the theClientHttpTimeout
optionRetryableHTTPClient
which is passed through to theClientHTTPRetry
option.