Skip to content
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

fix unmodifiable List type #20

Merged
merged 1 commit into from
May 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions android/tool/src/main/java/io/netbird/client/tool/DNSWatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

import io.netbird.gomobile.android.DNSList;
Expand Down Expand Up @@ -67,8 +68,7 @@ private DNSList readActiveDns() {
isPrivateDnsActive = props.isPrivateDnsActive();
}

List<InetAddress> list = props.getDnsServers();
extendWithFallbackDNS(list);
List<InetAddress> list = extendWithFallbackDNS(props.getDnsServers());
return toDnsList(list);
}

Expand All @@ -84,8 +84,8 @@ private void registerNetworkCallback() {
}

private synchronized void onNewDNSList(LinkProperties linkProperties) {
List<InetAddress> newDNSList = linkProperties.getDnsServers();
extendWithFallbackDNS(newDNSList);
List<InetAddress> newDNSList = extendWithFallbackDNS(linkProperties.getDnsServers());


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
isPrivateDnsActive = linkProperties.isPrivateDnsActive();
Expand Down Expand Up @@ -117,16 +117,22 @@ private synchronized void onNewDNSList(LinkProperties linkProperties) {
}
}

private void extendWithFallbackDNS(List<InetAddress> dnsServers) {
private List<InetAddress> extendWithFallbackDNS(List<InetAddress> dnsServers) {
List<InetAddress> modifiableDnsServers = new ArrayList<>(dnsServers);

if (dnsServers.isEmpty()) {
return;
return modifiableDnsServers;
}
if (dnsServers.get(0).isLinkLocalAddress()) {
try {
InetAddress addr = InetAddress.getByName("1.1.1.1");
dnsServers.add(0, addr);
} catch (UnknownHostException e) {}

if (!dnsServers.get(0).isLinkLocalAddress()) {
return modifiableDnsServers;
}

try {
InetAddress addr = InetAddress.getByName("1.1.1.1");
modifiableDnsServers.add(0, addr);
} catch (UnknownHostException e) {}
return modifiableDnsServers;
}

private void notifyDnsWatcher(DNSList dnsServers) throws Exception {
Expand Down
Loading