mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: Reduce number of candidates when MEDIA_NODES_PUBLIC_IPS is defined
parent
9fd690559e
commit
3265bf401d
|
@ -17,8 +17,6 @@
|
||||||
|
|
||||||
package io.openvidu.server.kurento.endpoint;
|
package io.openvidu.server.kurento.endpoint;
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -576,16 +574,13 @@ public abstract class MediaEndpoint {
|
||||||
if (this.openviduConfig.areMediaNodesPublicIpsDefined()) {
|
if (this.openviduConfig.areMediaNodesPublicIpsDefined()) {
|
||||||
sendCandidatesWithConfiguredIp(senderPublicId, candidate);
|
sendCandidatesWithConfiguredIp(senderPublicId, candidate);
|
||||||
} else {
|
} else {
|
||||||
gatheredCandidateList.add(candidate);
|
sendCandidate(senderPublicId, candidate);
|
||||||
this.owner.logIceCandidate(new WebrtcDebugEvent(this.owner, this.streamId, WebrtcDebugEventIssuer.server,
|
|
||||||
this.getWebrtcDebugOperation(), WebrtcDebugEventType.iceCandidate,
|
|
||||||
gson.toJsonTree(candidate).toString()));
|
|
||||||
owner.sendIceCandidate(senderPublicId, endpointName, candidate);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendCandidatesWithConfiguredIp(String senderPublicId, IceCandidate candidate) {
|
private void sendCandidatesWithConfiguredIp(String senderPublicId, IceCandidate candidate) {
|
||||||
|
try {
|
||||||
// Get media node private IP
|
// Get media node private IP
|
||||||
String kurentoPrivateIp = this.owner.getSession().getKms().getIp();
|
String kurentoPrivateIp = this.owner.getSession().getKms().getIp();
|
||||||
|
|
||||||
|
@ -597,34 +592,41 @@ public abstract class MediaEndpoint {
|
||||||
// Create IceCandidateParser to modify original candidate information
|
// Create IceCandidateParser to modify original candidate information
|
||||||
IceCandidateDataParser candidateParser = new IceCandidateDataParser(candidate);
|
IceCandidateDataParser candidateParser = new IceCandidateDataParser(candidate);
|
||||||
|
|
||||||
// Only create host candidates to increase priority
|
// get original IP
|
||||||
if (candidateParser.getType() == IceCandidateType.host) {
|
String originalIp = candidateParser.getIp();
|
||||||
String originalIP = candidateParser.getIp();
|
|
||||||
// Send candidate with new configured IP
|
// Replace all candidates with with new configured IP
|
||||||
IceCandidate candidateMaxPriority = new IceCandidate(candidate.getCandidate(), candidate.getSdpMid(),
|
IceCandidate candidateMaxPriority = new IceCandidate(candidate.getCandidate(), candidate.getSdpMid(),
|
||||||
candidate.getSdpMLineIndex());
|
candidate.getSdpMLineIndex());
|
||||||
candidateParser.setIp(ipToReplace);
|
candidateParser.setIp(ipToReplace);
|
||||||
candidateParser.setMaxPriority(); // Set max priority for this candidate
|
candidateParser.setMaxPriority();
|
||||||
candidateMaxPriority.setCandidate(candidateParser.toString());
|
candidateMaxPriority.setCandidate(candidateParser.toString());
|
||||||
gatheredCandidateList.add(candidateMaxPriority);
|
sendCandidate(senderPublicId, candidateMaxPriority);
|
||||||
this.owner.logIceCandidate(new WebrtcDebugEvent(this.owner, this.streamId, WebrtcDebugEventIssuer.server,
|
|
||||||
this.getWebrtcDebugOperation(), WebrtcDebugEventType.iceCandidate,
|
|
||||||
gson.toJsonTree(candidateMaxPriority).toString()));
|
|
||||||
owner.sendIceCandidate(senderPublicId, endpointName, candidateMaxPriority);
|
|
||||||
|
|
||||||
// Send candidate with original IP
|
// Resend old public IP next to the new one
|
||||||
|
if (candidateParser.isType(IceCandidateType.srflx)) {
|
||||||
|
// Send candidate with private ip
|
||||||
IceCandidate candidateMinPriority = new IceCandidate(candidate.getCandidate(), candidate.getSdpMid(),
|
IceCandidate candidateMinPriority = new IceCandidate(candidate.getCandidate(), candidate.getSdpMid(),
|
||||||
candidate.getSdpMLineIndex());
|
candidate.getSdpMLineIndex());
|
||||||
candidateParser.setIp(originalIP);
|
candidateParser.setIp(originalIp);
|
||||||
candidateParser.setMinPriority(); // Set min priority for private IP
|
candidateParser.setMinPriority(); // Set min priority for original public IP
|
||||||
candidateMinPriority.setCandidate(candidateParser.toString());
|
candidateMinPriority.setCandidate(candidateParser.toString());
|
||||||
gatheredCandidateList.add(candidateMinPriority);
|
sendCandidate(senderPublicId, candidateMinPriority);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error on adding additional IP in candidates: {}", e.getMessage());
|
||||||
|
// On Exception, send candidate without any modification
|
||||||
|
sendCandidate(senderPublicId, candidate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendCandidate(String senderPublicId, IceCandidate candidate) {
|
||||||
|
gatheredCandidateList.add(candidate);
|
||||||
this.owner.logIceCandidate(new WebrtcDebugEvent(this.owner, this.streamId, WebrtcDebugEventIssuer.server,
|
this.owner.logIceCandidate(new WebrtcDebugEvent(this.owner, this.streamId, WebrtcDebugEventIssuer.server,
|
||||||
this.getWebrtcDebugOperation(), WebrtcDebugEventType.iceCandidate,
|
this.getWebrtcDebugOperation(), WebrtcDebugEventType.iceCandidate,
|
||||||
gson.toJsonTree(candidateMinPriority).toString()));
|
gson.toJsonTree(candidate).toString()));
|
||||||
owner.sendIceCandidate(senderPublicId, endpointName, candidateMinPriority);
|
owner.sendIceCandidate(senderPublicId, endpointName, candidate);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,7 +2,6 @@ package io.openvidu.server.utils.ice;
|
||||||
|
|
||||||
import org.kurento.client.IceCandidate;
|
import org.kurento.client.IceCandidate;
|
||||||
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,10 +13,11 @@ public class IceCandidateDataParser {
|
||||||
* Max priority and Min priority possible defined in rfc5245 15.1
|
* Max priority and Min priority possible defined in rfc5245 15.1
|
||||||
* "<priority>: is a positive integer between 1 and (2**31 - 1)"
|
* "<priority>: is a positive integer between 1 and (2**31 - 1)"
|
||||||
* MAX_PRIORITY = (2^24)*126 + (2^8)*65535 + 255
|
* MAX_PRIORITY = (2^24)*126 + (2^8)*65535 + 255
|
||||||
* MIN_PRIORITY = (2^24)*126 + (2^8)*1 + 255
|
* MIN_PRIORITY = (2^24)*1 + (2^8)*1 + 255
|
||||||
*/
|
*/
|
||||||
private final int MAX_PRIORITY = 2130706431;
|
private final int MAX_PRIORITY = 2130706431;
|
||||||
private final int MIN_PRIORITY = 511;
|
private final int MIN_PRIORITY = 16777727;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Full string with the candidate
|
* Full string with the candidate
|
||||||
|
@ -32,15 +32,6 @@ public class IceCandidateDataParser {
|
||||||
this.candidate = iceCandidate.split(" ");
|
this.candidate = iceCandidate.split(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Following rfc5245, section-15.1, the candidate foundation id is the 1 th element
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public void setRandomFoundation() {
|
|
||||||
String prefix = candidate[0].split(":")[0];
|
|
||||||
candidate[0] = prefix + ":" + new SecureRandom().nextInt(Integer.MAX_VALUE - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Following rfc5245, section-15.1, the priority is the 4th element
|
* Following rfc5245, section-15.1, the priority is the 4th element
|
||||||
* @return The priority of the candidate
|
* @return The priority of the candidate
|
||||||
|
|
Loading…
Reference in New Issue