Skip to content

Commit

Permalink
Fix for RPRO-8932
Browse files Browse the repository at this point in the history
  • Loading branch information
mondain committed Nov 8, 2021
1 parent 9c59546 commit bdd4ea0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<version>1.0</version>
</parent>
<artifactId>ice4j</artifactId>
<version>3.2.62</version>
<version>3.2.63</version>
<packaging>bundle</packaging>
<name>ice4j</name>
<url>https://github.com/Red5/ice4j</url>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/ice4j/ice/ConnectivityCheckClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ public void run() {
}
// Since we suspect that it is possible to startCheckForPair, processSuccessResponse and only then setStateInProgress, no synchronized
// since the CandidatePair#setState method is atomically enabled.
TransactionID transactionID = startCheckForPair(pairToCheck);
TransactionID transactionID = startCheckForPair(pairToCheck, 50, 500, 2); //100, 1600, 6
if (transactionID == null) {
logger.warn("Pair failed: {}", pairToCheck.toShortString());
pairToCheck.setStateFailed();
Expand Down
40 changes: 29 additions & 11 deletions src/main/java/org/ice4j/ice/harvest/HostCandidateHarvester.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import java.io.IOException;
import java.net.BindException;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
Expand Down Expand Up @@ -166,11 +167,13 @@ private static void initializeAddressFilters() {
allowedAddresses = new ArrayList<>();
}
allowedAddresses.add(address);
logger.debug("Allowed: {}", allowedAddresses);
}
}
String[] blockedAddressesStr = StackProperties.getStringArray(StackProperties.BLOCKED_ADDRESSES, ";");
// if allowed addresses is specified and blocked addresses are not, block all other addresses
if (allowedAddressesStr != null && blockedAddressesStr == null) {
boolean isIPv6Disabled = StackProperties.getBoolean(StackProperties.DISABLE_IPv6, true);
// create the blocked address holder if not done already
if (blockedAddresses == null) {
blockedAddresses = new ArrayList<>();
Expand All @@ -179,9 +182,20 @@ private static void initializeAddressFilters() {
availableHostAddresses.forEach(ref -> {
InetAddress addr = ref.getAddress();
if (!allowedAddresses.contains(addr)) {
blockedAddresses.add(addr);
if (addr instanceof Inet6Address) {
// dont automatically block ipv6 unless they are disabled
if (isIPv6Disabled) {
blockedAddresses.add(addr);
} else {
// ensure they are added to allowed, since they are bindable and not disabled
allowedAddresses.add(addr);
}
} else if (addr instanceof Inet4Address) {
blockedAddresses.add(addr);
}
}
});
logger.debug("Allowed: {} blocked: {}", allowedAddresses, blockedAddresses);
} else if (blockedAddressesStr != null) {
for (String addressStr : blockedAddressesStr) {
InetAddress address;
Expand All @@ -196,6 +210,7 @@ private static void initializeAddressFilters() {
}
blockedAddresses.add(address);
}
logger.debug("Blocked: {}", blockedAddresses);
}
}
}
Expand Down Expand Up @@ -419,17 +434,20 @@ static boolean isInterfaceAllowed(NetworkInterface iface) {
* @return true if address is allowed to be used by this HostCandidateHarvester.
*/
static boolean isAddressAllowed(InetAddress address) {
if (address.isLoopbackAddress()) {
return false;
}
logger.debug("isAddressAllowed: {}", address);
boolean ret = true;
List<InetAddress> allowed = getAllowedAddresses();
List<InetAddress> blocked = getBlockedAddresses();
if (allowed != null) {
ret = allowed.contains(address);
}
if (blocked != null) {
ret = ret && !blocked.contains(address);
if (!address.isLoopbackAddress()) {
List<InetAddress> allowed = getAllowedAddresses();
List<InetAddress> blocked = getBlockedAddresses();
if (allowed != null && allowed.size() > 0) {
ret = allowed.contains(address);
}
if (blocked != null && blocked.size() > 0) {
ret = ret && !blocked.contains(address);
}
} else {
// no loop back allowed
ret = false;
}
return ret;
}
Expand Down
9 changes: 6 additions & 3 deletions src/test/java/org/ice4j/MessageEventDispatchingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public class MessageEventDispatchingTest extends TestCase {
*/
PlainResponseCollector responseCollector;

//static String IPAddress = "fe80::995e:3662:2b68:2410";
static String IPAddress = "10.0.0.35";

/**
* junit setup method.
*
Expand All @@ -92,9 +95,9 @@ public class MessageEventDispatchingTest extends TestCase {
protected void setUp() throws Exception {
super.setUp();
logger.info("-------------------------------------------\nSettting up {}", getClass().getName());
clientAddress = new TransportAddress("127.0.0.1", PortUtil.getPort(), Transport.UDP);
serverAddress = new TransportAddress("127.0.0.1", PortUtil.getPort(), Transport.UDP);
serverAddress2 = new TransportAddress("127.0.0.1", PortUtil.getPort(), Transport.UDP);
clientAddress = new TransportAddress(IPAddress, PortUtil.getPort(), Transport.UDP);
serverAddress = new TransportAddress(IPAddress, PortUtil.getPort(), Transport.UDP);
serverAddress2 = new TransportAddress(IPAddress, PortUtil.getPort(), Transport.UDP);
stunStack = new StunStack();
// create the wrappers
clientSock = new IceUdpSocketWrapper(clientAddress);
Expand Down
14 changes: 6 additions & 8 deletions src/test/java/org/ice4j/stack/ShallowStackTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* See LICENSE.md for license information */
package org.ice4j.stack;

import java.io.IOException;
import java.net.DatagramPacket;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -14,7 +13,6 @@
import org.ice4j.AbstractResponseCollector;
import org.ice4j.BaseStunMessageEvent;
import org.ice4j.MsgFixture;
import org.ice4j.StunException;
import org.ice4j.StunFailureEvent;
import org.ice4j.StunMessageEvent;
import org.ice4j.StunResponseEvent;
Expand All @@ -34,11 +32,9 @@
import org.ice4j.message.MessageFactory;
import org.ice4j.message.Request;
import org.ice4j.message.Response;
import org.ice4j.security.CredentialsAuthority;
import org.ice4j.socket.IceSocketWrapper;
import org.ice4j.socket.IceTcpSocketWrapper;
import org.ice4j.socket.IceUdpSocketWrapper;
import org.ice4j.stunclient.ResponseSequenceServer;
import org.ice4j.util.Utils;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -75,7 +71,8 @@ public class ShallowStackTest extends TestCase {
* Transport type to be used for the test.
*/
static Transport selectedTransport = Transport.UDP;


//static String IPAddress = "fe80::995e:3662:2b68:2410";
static String IPAddress = "10.0.0.35";

/**
Expand All @@ -96,11 +93,12 @@ public ShallowStackTest(String name) {
protected void setUp() throws Exception {
super.setUp();
logger.info("--------------------------------------------------------------------------------------\nSettting up {}", getClass().getName());
System.setProperty("org.ice4j.TERMINATION_DELAY", "500");
System.setProperty("org.ice4j.BIND_RETRIES", "1");
System.setProperty("org.ice4j.ice.harvest.NAT_HARVESTER_LOCAL_ADDRESS", IPAddress);
System.setProperty("org.ice4j.ice.harvest.NAT_HARVESTER_PUBLIC_ADDRESS", IPAddress);
//System.setProperty("org.ice4j.ice.harvest.NAT_HARVESTER_LOCAL_ADDRESS", IPAddress);
//System.setProperty("org.ice4j.ice.harvest.NAT_HARVESTER_PUBLIC_ADDRESS", IPAddress);
System.setProperty("org.ice4j.ice.harvest.ALLOWED_ADDRESSES", IPAddress);
System.setProperty("org.ice4j.TERMINATION_DELAY", "500");
System.setProperty("org.ice4j.ipv6.DISABLED", "false");
// initializes the mapping harvesters
MappingCandidateHarvesters.getHarvesters();
//logger.info("setup");
Expand Down

0 comments on commit bdd4ea0

Please sign in to comment.