Skip to content

Commit a1d7874

Browse files
authored
fix: Add IPV4 Range Filtering for Backblaze B2 API Integration (#1467)
Currently the B2 Native API only supports IPV4 and Facebook requires IPV6. This change forces an IPV4 DNS resolution when looking up the B2 Authorize endpoint DNS. This change was tested locally by running the BackblazeIntegrationTest while setting `java.net.preferIPv6Addresses=true` ``` BUILD SUCCESSFUL in 1s 24 actionable tasks: 2 executed, 22 up-to-date INFO 2025-07-25T12:07:22.601918-05:00 Region extracted from s3ApiUrl: us-east-005 SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. DEBUG 2025-07-25T12:07:22.961639-05:00 Uploading 'test-upload-1753463242960' with file size 14 bytes ```
1 parent 35e9dab commit a1d7874

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

extensions/data-transfer/portability-data-transfer-backblaze/src/main/java/org/datatransferproject/datatransfer/backblaze/common/BackblazeDataTransferClientFactory.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ public BackblazeDataTransferClient getOrCreateB2Client( UUID jobId,
4949
SIZE_THRESHOLD_FOR_MULTIPART_UPLOAD,
5050
PART_SIZE_FOR_MULTIPART_UPLOAD);
5151
String exportService = JobMetadata.getExportService();
52-
backblazeDataTransferClient.init(authData.getToken(), authData.getSecret(), exportService, HttpClientBuilder.create().build());
52+
CustomIPv4DnsResolver customDnsResolver = new CustomIPv4DnsResolver();
53+
backblazeDataTransferClient.init(
54+
authData.getToken(),
55+
authData.getSecret(),
56+
exportService,
57+
HttpClientBuilder.create().setDnsResolver(customDnsResolver).build()
58+
);
5359
backblazeDataTransferClientMap.put(jobId, backblazeDataTransferClient);
5460
}
5561
return backblazeDataTransferClientMap.get(jobId);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.datatransferproject.datatransfer.backblaze.common;
2+
3+
import org.apache.http.impl.conn.SystemDefaultDnsResolver;
4+
import org.apache.http.conn.DnsResolver;
5+
import java.net.InetAddress;
6+
import java.net.UnknownHostException;
7+
import java.util.Arrays;
8+
9+
// This class is only required because Backblaze only supports IPV4 on the B2 Native APIs, the S3
10+
// compatible APIs support IPV6. This can be deleted when all B2 API endpoints support IPV6.
11+
public class CustomIPv4DnsResolver implements DnsResolver {
12+
private final SystemDefaultDnsResolver systemDefaultDnsResolver = new SystemDefaultDnsResolver();
13+
14+
@Override
15+
public InetAddress[] resolve(String host) throws UnknownHostException {
16+
// Filter to return only IPv4 addresses
17+
return Arrays.stream(systemDefaultDnsResolver.resolve(host))
18+
.filter(inetAddress -> inetAddress.getAddress().length == 4)
19+
.toArray(InetAddress[]::new);
20+
}
21+
}
22+

0 commit comments

Comments
 (0)