Skip to content

Commit

Permalink
Fix graph IPFS connection failure due to the unsupported /api/v0/file…
Browse files Browse the repository at this point in the history
…s/stat HTTP API
  • Loading branch information
TonioMacaronio committed Dec 14, 2023
1 parent afa9e8b commit f763f8d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
17 changes: 5 additions & 12 deletions core/src/link_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ impl LinkResolverTrait for LinkResolver {
}
trace!(logger, "IPFS cache miss"; "hash" => &path);

let (size, client) = select_fastest_client_with_stat(
let (_size, client) = select_fastest_client_with_stat(
self.clients.cheap_clone(),
logger.cheap_clone(),
StatApi::Files,
StatApi::Block,
path.clone(),
self.timeout,
self.retry,
Expand All @@ -182,7 +182,6 @@ impl LinkResolverTrait for LinkResolver {

let max_cache_file_size = self.env_vars.mappings.max_ipfs_cache_file_size;
let max_file_size = self.env_vars.mappings.max_ipfs_file_bytes;
restrict_file_size(&path, size, max_file_size)?;

let req_path = path.clone();
let timeout = self.timeout;
Expand Down Expand Up @@ -215,7 +214,7 @@ impl LinkResolverTrait for LinkResolver {

async fn get_block(&self, logger: &Logger, link: &Link) -> Result<Vec<u8>, Error> {
trace!(logger, "IPFS block get"; "hash" => &link.link);
let (size, client) = select_fastest_client_with_stat(
let (_size, client) = select_fastest_client_with_stat(
self.clients.cheap_clone(),
logger.cheap_clone(),
StatApi::Block,
Expand All @@ -225,9 +224,6 @@ impl LinkResolverTrait for LinkResolver {
)
.await?;

let max_file_size = self.env_vars.mappings.max_ipfs_file_bytes;
restrict_file_size(&link.link, size, max_file_size)?;

let link = link.link.clone();
let data = retry_policy(self.retry, "ipfs.getBlock", &logger)
.run(move || {
Expand All @@ -247,19 +243,16 @@ impl LinkResolverTrait for LinkResolver {
// Discard the `/ipfs/` prefix (if present) to get the hash.
let path = link.link.trim_start_matches("/ipfs/");

let (size, client) = select_fastest_client_with_stat(
let (_size, client) = select_fastest_client_with_stat(
self.clients.cheap_clone(),
logger.cheap_clone(),
StatApi::Files,
StatApi::Block,
path.to_string(),
self.timeout,
self.retry,
)
.await?;

let max_file_size = self.env_vars.mappings.max_ipfs_map_file_size;
restrict_file_size(path, size, max_file_size)?;

let mut stream = client.cat(path, None).await?.fuse().boxed().compat();

let mut buf = BytesMut::with_capacity(1024);
Expand Down
7 changes: 4 additions & 3 deletions docker/start
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ save_coredumps() {
wait_for_ipfs() {
# Take the IPFS URL in $1 apart and extract host and port. If no explicit
# host is given, use 443 for https, and 80 otherwise
if [[ "$1" =~ ^((https?)://)?([^:/]+)(:([0-9]+))? ]]
if [[ "$1" =~ ^((https?)://)?(([^@]+)@)?([^:/]+)(:([0-9]+))? ]]
then
proto=${BASH_REMATCH[2]:-http}
host=${BASH_REMATCH[3]}
port=${BASH_REMATCH[5]}
user=${BASH_REMATCH[4]}
host=${BASH_REMATCH[5]}
port=${BASH_REMATCH[7]}
if [ -z "$port" ]
then
[ "$proto" = "https" ] && port=443 || port=80
Expand Down

0 comments on commit f763f8d

Please sign in to comment.