www.fgks.org   »   [go: up one dir, main page]

Skip to content

Commit

Permalink
Add VoIP.DebugOption.TEST_INVALID_SERVERS
Browse files Browse the repository at this point in the history
  • Loading branch information
vkryl committed Apr 25, 2024
1 parent ccefce2 commit fb0146a
Showing 1 changed file with 51 additions and 3 deletions.
54 changes: 51 additions & 3 deletions app/src/main/java/org/thunderdog/challegram/voip/VoIP.java
Expand Up @@ -116,7 +116,8 @@ public static boolean isForceDisabled (String version) {
DebugOption.ONLY_TELEGRAM_REFLECTOR_SERVERS,
DebugOption.ONLY_WEBRTC_SERVERS,
DebugOption.ONLY_WEBRTC_TURN_SERVERS,
DebugOption.ONLY_WEBRTC_NON_TURN_SERVERS
DebugOption.ONLY_WEBRTC_NON_TURN_SERVERS,
DebugOption.TEST_INVALID_SERVERS
}, flag = true)
public @interface DebugOption {
int
Expand All @@ -128,7 +129,8 @@ public static boolean isForceDisabled (String version) {
ONLY_TELEGRAM_REFLECTOR_SERVERS = 1 << 5,
ONLY_WEBRTC_SERVERS = 1 << 6,
ONLY_WEBRTC_TURN_SERVERS = 1 << 7,
ONLY_WEBRTC_NON_TURN_SERVERS = 1 << 8;
ONLY_WEBRTC_NON_TURN_SERVERS = 1 << 8,
TEST_INVALID_SERVERS = 1 << 9;

@DebugOption int SERVER_FILTERS_MASK =
ONLY_TELEGRAM_REFLECTOR_SERVERS |
Expand Down Expand Up @@ -156,7 +158,8 @@ public static int[] getAllDebugOptions () {
DebugOption.ONLY_TELEGRAM_REFLECTOR_SERVERS,
DebugOption.ONLY_WEBRTC_SERVERS,
DebugOption.ONLY_WEBRTC_TURN_SERVERS,
DebugOption.ONLY_WEBRTC_NON_TURN_SERVERS
DebugOption.ONLY_WEBRTC_NON_TURN_SERVERS,
DebugOption.TEST_INVALID_SERVERS
};
}

Expand All @@ -180,6 +183,8 @@ public static String getDebugOptionName (@DebugOption int option) {
return "Only TURN servers (crash if none)";
case DebugOption.ONLY_WEBRTC_NON_TURN_SERVERS:
return "Only non-TURN servers (crash if none)";
case DebugOption.TEST_INVALID_SERVERS:
return "Test handling non-existing servers";
}
return null;
}
Expand Down Expand Up @@ -207,6 +212,7 @@ private static void validateModifiedCallServer (TdApi.CallServer server) {
public static boolean needModifyCallServers () {
return isDebugOptionEnabled(
DebugOption.DISABLE_IPV4 |
DebugOption.TEST_INVALID_SERVERS |
DebugOption.SERVER_FILTERS_MASK
);
}
Expand All @@ -215,6 +221,7 @@ public static TdApi.CallServer[] modifyCallServers (TdApi.CallServer[] servers)
if (!needModifyCallServers()) {
return servers;
}
final boolean testInvalidServers = isDebugOptionEnabled(DebugOption.TEST_INVALID_SERVERS);
final boolean disableIpv4 = isDebugOptionEnabled(DebugOption.DISABLE_IPV4);
final int filterOption = debugOptions & DebugOption.SERVER_FILTERS_MASK;
final Filter<TdApi.CallServer> filter;
Expand All @@ -240,6 +247,8 @@ public static TdApi.CallServer[] modifyCallServers (TdApi.CallServer[] servers)
filter = null;
break;
}
int telegramReflectorCount = 0;
int webrtcReflectorCount = 0;
List<TdApi.CallServer> filteredCallServers = new ArrayList<>();
for (TdApi.CallServer server : servers) {
if (filter != null && !filter.accept(server)) {
Expand All @@ -251,11 +260,50 @@ public static TdApi.CallServer[] modifyCallServers (TdApi.CallServer[] servers)
server = new TdApi.CallServer(server.id, "", server.ipv6Address, server.port, server.type);
}
validateModifiedCallServer(server);
switch (server.type.getConstructor()) {
case TdApi.CallServerTypeTelegramReflector.CONSTRUCTOR:
telegramReflectorCount++;
break;
case TdApi.CallServerTypeWebrtc.CONSTRUCTOR:
webrtcReflectorCount++;
break;
default:
Td.assertCallServerType_569fa9f7();
throw Td.unsupported(server.type);
}
filteredCallServers.add(server);
}
if (filteredCallServers.isEmpty()) {
throw new IllegalStateException();
}
if (testInvalidServers) {
int remainingWebrtcReflectors = webrtcReflectorCount;
int remainingTelegramReflectors = telegramReflectorCount;
for (int i = 0; i < filteredCallServers.size(); i++) {
TdApi.CallServer server = filteredCallServers.get(i);
boolean makeInvalid;
switch (server.type.getConstructor()) {
case TdApi.CallServerTypeTelegramReflector.CONSTRUCTOR:
makeInvalid = --remainingTelegramReflectors > 0;
break;
case TdApi.CallServerTypeWebrtc.CONSTRUCTOR:
makeInvalid = --remainingWebrtcReflectors > 0;
break;
default:
Td.assertCallServerType_569fa9f7();
throw Td.unsupported(server.type);
}
if (makeInvalid) {
server = new TdApi.CallServer(server.id,
"192.168.0.0",
"0:0:0:0:0:ffff:c0a8:0",
server.port,
server.type
);
filteredCallServers.set(i, server);
}
}
}
return filteredCallServers.toArray(new TdApi.CallServer[0]);
}

Expand Down

0 comments on commit fb0146a

Please sign in to comment.