-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: http blockbroker loads gateways from routing (#519)
Use the new http gateway block broker to load gateways from the routing. If we can find http gateways for a block we now use it, falling back to the default list of gateways if the routing is slow or it gives providers that fail to supply the block. One change here is that unless you are using sessions, trustless gateways become disposable so we can't sort them by reliability any more.
- Loading branch information
1 parent
2d070b9
commit 6a62d1c
Showing
11 changed files
with
191 additions
and
218 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
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
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 @@ | ||
import { isPrivateIp } from '@libp2p/utils/private-ip' | ||
import { DNS, HTTP, HTTPS } from '@multiformats/multiaddr-matcher' | ||
import { multiaddrToUri } from '@multiformats/multiaddr-to-uri' | ||
import { TrustlessGateway } from './trustless-gateway.js' | ||
import type { Routing } from '@helia/interface' | ||
import type { ComponentLogger } from '@libp2p/interface' | ||
import type { AbortOptions, Multiaddr } from '@multiformats/multiaddr' | ||
import type { CID } from 'multiformats/cid' | ||
|
||
export function filterNonHTTPMultiaddrs (multiaddrs: Multiaddr[], allowInsecure: boolean, allowLocal: boolean): Multiaddr[] { | ||
return multiaddrs.filter(ma => { | ||
if (HTTPS.matches(ma) || (allowInsecure && HTTP.matches(ma))) { | ||
if (allowLocal) { | ||
return true | ||
} | ||
|
||
if (DNS.matches(ma)) { | ||
return true | ||
} | ||
|
||
return isPrivateIp(ma.toOptions().host) === false | ||
} | ||
|
||
return false | ||
}) | ||
} | ||
|
||
export async function * findHttpGatewayProviders (cid: CID, routing: Routing, logger: ComponentLogger, allowInsecure: boolean, allowLocal: boolean, options?: AbortOptions): AsyncGenerator<TrustlessGateway> { | ||
for await (const provider of routing.findProviders(cid, options)) { | ||
// require http(s) addresses | ||
const httpAddresses = filterNonHTTPMultiaddrs(provider.multiaddrs, allowInsecure, allowLocal) | ||
|
||
if (httpAddresses.length === 0) { | ||
continue | ||
} | ||
|
||
// take first address? | ||
// /ip4/x.x.x.x/tcp/31337/http | ||
// /ip4/x.x.x.x/tcp/31337/https | ||
// etc | ||
const uri = multiaddrToUri(httpAddresses[0]) | ||
|
||
yield new TrustlessGateway(uri, logger) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.