Skip to content

Commit

Permalink
Fixed cannot reload RuleResolver when no rule is activated
Browse files Browse the repository at this point in the history
  • Loading branch information
PeratX committed Dec 18, 2017
1 parent 57191b8 commit ace52e1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
6 changes: 4 additions & 2 deletions app/src/main/java/org/itxtech/daedalus/Daedalus.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static <T> T parseJson(Class<T> beanClass, JsonReader reader) throws Json
return gson.fromJson(reader, beanClass);
}

public static void initHostsResolver() {
public static void initRuleResolver() {
if (Daedalus.getPrefs().getBoolean("settings_local_rules_resolution", false)) {
ArrayList<String> pendingLoad = new ArrayList<>();
ArrayList<Rule> usingRules = configurations.getUsingRules();
Expand All @@ -161,6 +161,8 @@ public static void initHostsResolver() {
RuleResolver.startLoadDnsmasq(arr);
break;
}
} else {
RuleResolver.clear();
}
} else {
RuleResolver.clear();
Expand All @@ -171,7 +173,7 @@ public static void initHostsResolver() {
public static void setRulesChanged() {
if (DaedalusVpnService.isActivated() &&
getPrefs().getBoolean("settings_allow_dynamic_rule_reload", false)) {
initHostsResolver();
initRuleResolver();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
this.notification = builder;
}

Daedalus.initHostsResolver();
Daedalus.initRuleResolver();
DNSServerHelper.buildPortCache();

if (this.mThread == null) {
Expand Down
14 changes: 8 additions & 6 deletions app/src/main/java/org/itxtech/daedalus/util/RuleResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public class RuleResolver implements Runnable {
private static int mode = MODE_HOSTS;
private static String[] hostsFiles;
private static String[] dnsmasqFiles;
private static HashMap<String, String> rulesA;
private static HashMap<String, String> rulesAAAA;
private static HashMap<String, String> rulesA = new HashMap<>();
private static HashMap<String, String> rulesAAAA = new HashMap<>();
private static boolean shutdown = false;

public RuleResolver() {
Expand All @@ -61,18 +61,20 @@ public static void startLoadDnsmasq(String[] loadPath) {
}

public static void clear() {
rulesA = null;
rulesAAAA = null;
rulesA = new HashMap<>();
rulesAAAA = new HashMap<>();
}

public static String resolve(String hostname, Record.TYPE type) {
HashMap<String, String> rules = null;
HashMap<String, String> rules;
if (type == Record.TYPE.A) {
rules = rulesA;
} else if (type == Record.TYPE.AAAA) {
rules = rulesAAAA;
} else {
return null;
}
if (rules == null) {
if (rules.size() == 0) {
return null;
}
if (rules.containsKey(hostname)) {
Expand Down

0 comments on commit ace52e1

Please sign in to comment.