Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4426bc145b |
@ -1,17 +0,0 @@
|
|||||||
[*]
|
|
||||||
end_of_line = lf
|
|
||||||
insert_final_newline = true
|
|
||||||
charset = utf-8
|
|
||||||
|
|
||||||
[pom.xml]
|
|
||||||
indent_size = 2
|
|
||||||
indent_style = space
|
|
||||||
max_line_length = 120
|
|
||||||
|
|
||||||
[*.{kt,kts}]
|
|
||||||
max_line_length = 120
|
|
||||||
ktlint_code_style = intellij_idea
|
|
||||||
|
|
||||||
# I find trailing commas annoying
|
|
||||||
ktlint_standard_trailing-comma-on-call-site = disabled
|
|
||||||
ktlint_standard_trailing-comma-on-declaration-site = disabled
|
|
||||||
82
.github/workflows/maven.yml
vendored
82
.github/workflows/maven.yml
vendored
@ -1,82 +0,0 @@
|
|||||||
# This workflow will build a Java project with Maven
|
|
||||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
|
||||||
|
|
||||||
name: Java CI with Maven
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ master ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ master ]
|
|
||||||
|
|
||||||
env:
|
|
||||||
# Java version to use for the release
|
|
||||||
RELEASE_JAVA_VERSION: 11
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
java: [ 11, 17 ]
|
|
||||||
|
|
||||||
name: Java ${{ matrix.java }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Set up JDK ${{ matrix.java }}
|
|
||||||
uses: actions/setup-java@v3
|
|
||||||
with:
|
|
||||||
distribution: temurin
|
|
||||||
java-version: ${{ matrix.java }}
|
|
||||||
cache: maven
|
|
||||||
|
|
||||||
- name: Build and test with Maven
|
|
||||||
run: mvn -B -Dgpg.skip -Drelease=true -Pcoverage verify
|
|
||||||
|
|
||||||
- name: Upload coverage report
|
|
||||||
if: matrix.java == env.RELEASE_JAVA_VERSION
|
|
||||||
uses: codecov/codecov-action@v2
|
|
||||||
|
|
||||||
release:
|
|
||||||
if: github.ref == 'refs/heads/master'
|
|
||||||
needs: test
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Set up JDK
|
|
||||||
uses: actions/setup-java@v3
|
|
||||||
with:
|
|
||||||
distribution: temurin
|
|
||||||
java-version: ${{ env.RELEASE_JAVA_VERSION }}
|
|
||||||
cache: maven
|
|
||||||
server-id: ossrh
|
|
||||||
server-username: SONATYPE_USER
|
|
||||||
server-password: SONATYPE_PW
|
|
||||||
|
|
||||||
- name: Set version
|
|
||||||
run: |
|
|
||||||
VERSION=`git describe --match "v[0-9\.]*" --long --dirty --always`
|
|
||||||
mvn -B versions:set -DnewVersion=${VERSION:1} -DgenerateBackupPoms=false
|
|
||||||
|
|
||||||
- name: Release to Maven Central
|
|
||||||
env:
|
|
||||||
SONATYPE_USER: ${{ secrets.SONATYPE_USER }}
|
|
||||||
SONATYPE_PW: ${{ secrets.SONATYPE_PW }}
|
|
||||||
run: |
|
|
||||||
cat <(echo -e "${{ secrets.GPG_KEY }}") | gpg --batch --import
|
|
||||||
gpg --list-secret-keys --keyid-format LONG
|
|
||||||
mvn \
|
|
||||||
--no-transfer-progress \
|
|
||||||
--batch-mode \
|
|
||||||
-Dgpg.passphrase="${{ secrets.GPG_PW }}" \
|
|
||||||
-Drelease=true \
|
|
||||||
-DskipTests \
|
|
||||||
deploy
|
|
||||||
4
.gitignore
vendored
4
.gitignore
vendored
@ -7,7 +7,3 @@
|
|||||||
.project
|
.project
|
||||||
.settings/
|
.settings/
|
||||||
bin/
|
bin/
|
||||||
|
|
||||||
# Ignore IntelliJ IDEA files
|
|
||||||
.idea
|
|
||||||
*.iml
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ The Interactive Connectivity Establishment (ICE) protocol combines various NAT t
|
|||||||
|
|
||||||
This project provides a Java implementation of the ICE protocol that would be usable by both SIP and XMPP applications. The project also provides features such as socket sharing and support for Pseudo TCP.
|
This project provides a Java implementation of the ICE protocol that would be usable by both SIP and XMPP applications. The project also provides features such as socket sharing and support for Pseudo TCP.
|
||||||
|
|
||||||
ice4j is maintained by the [Jitsi](https://jitsi.org/) community. Use Jitsi's [community forum](https://community.jitsi.org) for questions and discussions.
|
ice4j is maintained by the [Jitsi](https://jitsi.org/) community. Use Jitsi's [dev mailing list](https://jitsi.org/Development/MailingLists) for questions and discussions.
|
||||||
|
|
||||||
Thanks
|
Thanks
|
||||||
------
|
------
|
||||||
|
|||||||
6
bnd.bnd
6
bnd.bnd
@ -1,6 +0,0 @@
|
|||||||
Export-Package: org.ice4j.*
|
|
||||||
Import-Package: *;version=!
|
|
||||||
Bundle-SymbolicName: org.jitsi.ice4j
|
|
||||||
-noextraheaders: true
|
|
||||||
-snapshot: SNAPSHOT
|
|
||||||
-removeheaders: Require-Capability, Bundle-SCM
|
|
||||||
306
build.xml
Normal file
306
build.xml
Normal file
@ -0,0 +1,306 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<project name="ice4j" basedir="." default="rebuild">
|
||||||
|
<property name="dest" value="classes"/>
|
||||||
|
<property name="dest-test" value="classes-test"/>
|
||||||
|
<property name="lib" value="lib"/>
|
||||||
|
<property name="JUnit.home" value="${lib}"/>
|
||||||
|
<property name="src" value="src/main/java"/>
|
||||||
|
<property name="src2" value="src/test/java"/>
|
||||||
|
<property name="junit.reports" value="junit-reports"/>
|
||||||
|
<property name="junit.html.reports" value="${junit.reports}/html"/>
|
||||||
|
<property name="ice4j.jar" value="ice4j.jar"/>
|
||||||
|
<property name="doc" value="doc"/>
|
||||||
|
<property name="java.doc" value="${doc}/api"/>
|
||||||
|
|
||||||
|
<path id="project.class.path">
|
||||||
|
<pathelement location="${dest}"/>
|
||||||
|
<pathelement location="${lib}/jain-sdp.jar"/>
|
||||||
|
<pathelement location="${lib}/weupnp-0.1.2-SNAPSHOT.jar"/>
|
||||||
|
</path>
|
||||||
|
<path id="test.class.path">
|
||||||
|
<path refid="project.class.path" />
|
||||||
|
<pathelement location="${dest-test}"/>
|
||||||
|
<pathelement location="${JUnit.home}/junit.jar"/>
|
||||||
|
</path>
|
||||||
|
|
||||||
|
<!--Patternset to exclude files from the output directory:-->
|
||||||
|
<patternset id="dest.exclude">
|
||||||
|
<exclude name="package cache/"/>
|
||||||
|
<exclude name="dependency cache/"/>
|
||||||
|
<exclude name="test/"/>
|
||||||
|
</patternset>
|
||||||
|
|
||||||
|
<!-- ANT TARGETS -->
|
||||||
|
|
||||||
|
<!-- compiles all classes -->
|
||||||
|
<target name="compile" depends="init">
|
||||||
|
<condition property="compile.javac.exclude.name" value="**/jdk8/**">
|
||||||
|
<not>
|
||||||
|
<matches string="${java.runtime.version}" pattern="^1\.8(\..*)?$"/>
|
||||||
|
</not>
|
||||||
|
</condition>
|
||||||
|
<javac classpathref="project.class.path"
|
||||||
|
debug="true"
|
||||||
|
deprecation="true"
|
||||||
|
destdir="${dest}"
|
||||||
|
includeantruntime="false"
|
||||||
|
nowarn="false"
|
||||||
|
optimize="true"
|
||||||
|
source="1.6"
|
||||||
|
target="1.6">
|
||||||
|
<compilerarg value="-Xlint"/>
|
||||||
|
<src path="${src}"/>
|
||||||
|
<exclude name="${compile.javac.exclude.name}"/>
|
||||||
|
</javac>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- compiles all tests -->
|
||||||
|
<target name="compile-tests" depends="init">
|
||||||
|
<javac classpathref="test.class.path"
|
||||||
|
debug="true"
|
||||||
|
deprecation="true"
|
||||||
|
destdir="${dest-test}"
|
||||||
|
nowarn="false"
|
||||||
|
optimize="true"
|
||||||
|
source="1.6"
|
||||||
|
target="1.6">
|
||||||
|
<src path="${src2}"/>
|
||||||
|
<compilerarg value="-Xlint"/>
|
||||||
|
</javac>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- copies ressource files if any to the classes directory -->
|
||||||
|
<target name="resource">
|
||||||
|
<copy todir="${dest}">
|
||||||
|
<fileset dir="${src}">
|
||||||
|
<include name="**/*.jpe"/>
|
||||||
|
<include name="**/*.jpeg"/>
|
||||||
|
<include name="**/*.rmf"/>
|
||||||
|
<include name="**/*.wav"/>
|
||||||
|
<include name="**/*.mid"/>
|
||||||
|
<include name="**/*.midi"/>
|
||||||
|
<include name="**/*.au"/>
|
||||||
|
<include name="**/*.gif"/>
|
||||||
|
<include name="**/*.png"/>
|
||||||
|
<include name="**/*.jpg"/>
|
||||||
|
<include name="**/*.aiff"/>
|
||||||
|
<include name="**/*.properties"/>
|
||||||
|
</fileset>
|
||||||
|
<fileset dir="${src2}">
|
||||||
|
<include name="**/*.jpe"/>
|
||||||
|
<include name="**/*.jpeg"/>
|
||||||
|
<include name="**/*.rmf"/>
|
||||||
|
<include name="**/*.wav"/>
|
||||||
|
<include name="**/*.mid"/>
|
||||||
|
<include name="**/*.midi"/>
|
||||||
|
<include name="**/*.au"/>
|
||||||
|
<include name="**/*.gif"/>
|
||||||
|
<include name="**/*.png"/>
|
||||||
|
<include name="**/*.jpg"/>
|
||||||
|
<include name="**/*.aiff"/>
|
||||||
|
<include name="**/*.properties"/>
|
||||||
|
</fileset>
|
||||||
|
</copy>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- creates the javadocs -->
|
||||||
|
<target name="javadoc">
|
||||||
|
<javadoc author="true" destdir="${java.doc}" package="true">
|
||||||
|
<fileset dir="${src}"/>
|
||||||
|
</javadoc>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- delete the contents of the classes directory-->
|
||||||
|
<target name="clean">
|
||||||
|
<delete failonerror="false" includeemptydirs="true">
|
||||||
|
<fileset dir="${dest}"/>
|
||||||
|
<fileset dir="${dest-test}"/>
|
||||||
|
<fileset dir="${junit.reports}"/>
|
||||||
|
<fileset dir="doc" />
|
||||||
|
</delete>
|
||||||
|
<delete file="${ice4j.jar}" failonerror="true" quiet="false"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- make everything -->
|
||||||
|
<target name="make" depends="compile,compile-tests,resource,jar"/>
|
||||||
|
|
||||||
|
<!-- clean and make everything -->
|
||||||
|
<target name="rebuild" depends="clean,make" />
|
||||||
|
|
||||||
|
<!-- make javadoc -->
|
||||||
|
<target name="doc" depends="make,javadoc" />
|
||||||
|
|
||||||
|
<!-- create needed subdirs-->
|
||||||
|
<target name="init">
|
||||||
|
<mkdir dir="${dest}"/>
|
||||||
|
<mkdir dir="${dest-test}"/>
|
||||||
|
<mkdir dir="${junit.reports}"/>
|
||||||
|
<mkdir dir="${junit.html.reports}"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- create jar file-->
|
||||||
|
<target name="jar" depends="compile">
|
||||||
|
<jar compress="true" destfile="${ice4j.jar}">
|
||||||
|
<fileset dir="${dest}">
|
||||||
|
<patternset refid="dest.exclude"/>
|
||||||
|
<include name="**/*.*"/>
|
||||||
|
</fileset>
|
||||||
|
</jar>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- We use this target from within the test target in order to generate
|
||||||
|
a human readable test report. We do not directly use the htmlreport
|
||||||
|
target because we need to include xalan in the classpath before we
|
||||||
|
do.-->
|
||||||
|
<target name="htmlreport">
|
||||||
|
<junitreport todir="${junit.reports}">
|
||||||
|
<fileset dir="${junit.reports}">
|
||||||
|
<include name="TEST-*.xml"/>
|
||||||
|
</fileset>
|
||||||
|
<report format="frames" todir="${junit.html.reports}"/>
|
||||||
|
</junitreport>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- Run the tests-->
|
||||||
|
<target name="test" depends="compile-tests">
|
||||||
|
<junit haltonfailure="true" fork="true" forkmode="once">
|
||||||
|
<formatter type="xml"/>
|
||||||
|
<formatter type="brief" usefile="false"/>
|
||||||
|
<test name="org.ice4j.StunTestSuite" todir="${junit.reports}"/>
|
||||||
|
<test name="org.ice4j.PseudoTcpTestSuite" todir="${junit.reports}"/>
|
||||||
|
<classpath refid="test.class.path"/>
|
||||||
|
</junit>
|
||||||
|
|
||||||
|
<!-- Generate the html report.
|
||||||
|
Run it quietly (i.e. redirect the output) because we don't won't to
|
||||||
|
see its "Build Successful" output line as users might confuse it
|
||||||
|
for a general build success while this might not be the case.-->
|
||||||
|
<echo message="Generating HTML test reports ..."/>
|
||||||
|
<java fork="true"
|
||||||
|
classname="org.apache.tools.ant.launch.Launcher"
|
||||||
|
classpath="${java.class.path}:${lib}/xalan-2.6.0.jar"
|
||||||
|
failonerror="true"
|
||||||
|
output="${junit.html.reports}/output.txt">
|
||||||
|
<arg value="htmlreport"/>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- runs our sample application -->
|
||||||
|
<target name="run-sample">
|
||||||
|
<java fork="true"
|
||||||
|
classname="test.Ice"
|
||||||
|
classpathref="test.class.path">
|
||||||
|
|
||||||
|
<!-- Tell java.util.logging about our logging preferences -->
|
||||||
|
<sysproperty key="java.util.logging.config.file"
|
||||||
|
value="lib/logging.properties"/>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- Run pseudotcp sample application -->
|
||||||
|
<target name="run-pseudotcp" depends="compile">
|
||||||
|
<java fork="true"
|
||||||
|
classname="test.IcePseudoTcp"
|
||||||
|
classpathref="test.class.path">
|
||||||
|
|
||||||
|
<!-- Tell java.util.logging about our logging preferences -->
|
||||||
|
<sysproperty key="java.util.logging.config.file"
|
||||||
|
value="lib/logging.properties"/>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- Debug pseudotcp example on port 5005 -->
|
||||||
|
<target name="debug-pseudotcp" depends="compile">
|
||||||
|
<java fork="true"
|
||||||
|
classname="test.IcePseudoTcp"
|
||||||
|
classpathref="test.class.path">
|
||||||
|
|
||||||
|
<!-- Tell java.util.logging about our logging preferences -->
|
||||||
|
<sysproperty key="java.util.logging.config.file"
|
||||||
|
value="lib/logging.properties"/>
|
||||||
|
<jvmarg value="-Xdebug" />
|
||||||
|
<jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005" />
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- Debug pseudotcp example with netbeans -->
|
||||||
|
<target name="nb-debug-pseudotcp" depends="compile">
|
||||||
|
<nbjpdastart addressproperty="jpda.address" name="ice4j" transport="dt_socket">
|
||||||
|
<classpath refid="test.class.path"/>
|
||||||
|
</nbjpdastart>
|
||||||
|
<java classname="test.IcePseudoTcp" fork="true">
|
||||||
|
<classpath refid="test.class.path"/>
|
||||||
|
<jvmarg value="-Xdebug"/>
|
||||||
|
<jvmarg value="-Xnoagent"/>
|
||||||
|
<jvmarg value="-Djava.compiler=none"/>
|
||||||
|
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
|
||||||
|
<!-- Tell java.util.logging about our logging preferences -->
|
||||||
|
<sysproperty key="java.util.logging.config.file"
|
||||||
|
value="lib/logging.properties"/>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- runs our sample distributed application -->
|
||||||
|
<target name="run-dist">
|
||||||
|
<java fork="true"
|
||||||
|
classname="test.IceDistributed"
|
||||||
|
classpathref="test.class.path">
|
||||||
|
|
||||||
|
<!-- Tell java.util.logging about our logging preferences -->
|
||||||
|
<sysproperty key="java.util.logging.config.file"
|
||||||
|
value="lib/logging.properties"/>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- runs our sample Trickle ICE application -->
|
||||||
|
<target name="run-trickle">
|
||||||
|
<java fork="true"
|
||||||
|
classname="test.TrickleIce"
|
||||||
|
classpathref="test.class.path">
|
||||||
|
|
||||||
|
<!-- Tell java.util.logging about our logging preferences -->
|
||||||
|
<sysproperty key="java.util.logging.config.file"
|
||||||
|
value="lib/logging.properties"/>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- runs our sample lite application -->
|
||||||
|
<target name="run-lite">
|
||||||
|
<java fork="true"
|
||||||
|
classname="test.IceLite"
|
||||||
|
classpathref="test.class.path">
|
||||||
|
|
||||||
|
<!-- Tell java.util.logging about our logging preferences -->
|
||||||
|
<sysproperty key="java.util.logging.config.file"
|
||||||
|
value="lib/logging.properties"/>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- runs our sample NAT mapping application -->
|
||||||
|
<target name="run-map">
|
||||||
|
<java fork="true"
|
||||||
|
classname="test.MappingTest"
|
||||||
|
classpathref="test.class.path">
|
||||||
|
|
||||||
|
<!-- Tell java.util.logging about our logging preferences -->
|
||||||
|
<sysproperty key="java.util.logging.config.file"
|
||||||
|
value="lib/logging.properties"/>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- runs our sample aws application -->
|
||||||
|
<target name="run-aws">
|
||||||
|
<java fork="true"
|
||||||
|
classname="test.AwsTest"
|
||||||
|
classpathref="test.class.path">
|
||||||
|
|
||||||
|
<!-- Tell java.util.logging about our logging preferences -->
|
||||||
|
<sysproperty key="java.util.logging.config.file"
|
||||||
|
value="lib/logging.properties"/>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<!-- Cruise Control Target-->
|
||||||
|
<target name="cc-buildloop" depends="rebuild,test"/>
|
||||||
|
</project>
|
||||||
@ -1,40 +0,0 @@
|
|||||||
<?xml version="1.0"?>
|
|
||||||
<!DOCTYPE module PUBLIC
|
|
||||||
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
|
|
||||||
"https://checkstyle.org/dtds/configuration_1_3.dtd">
|
|
||||||
|
|
||||||
<module name="Checker">
|
|
||||||
|
|
||||||
<module name="SuppressWithPlainTextCommentFilter"/>
|
|
||||||
|
|
||||||
<module name="LineLength">
|
|
||||||
<property name="fileExtensions" value="java"/>
|
|
||||||
<property name="max" value="120"/>
|
|
||||||
<property name="ignorePattern" value="http://|https://"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="TreeWalker">
|
|
||||||
<module name="LeftCurly">
|
|
||||||
<property name="option" value="nl"/>
|
|
||||||
<property name="tokens" value="LITERAL_CATCH"/>
|
|
||||||
<property name="tokens" value="LITERAL_ELSE"/>
|
|
||||||
<property name="tokens" value="LITERAL_FINALLY"/>
|
|
||||||
<property name="tokens" value="LITERAL_IF"/>
|
|
||||||
<property name="tokens" value="LITERAL_TRY"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<!-- Skips empty blocks {}, to not skip them: value="alone" -->
|
|
||||||
<module name="RightCurly">
|
|
||||||
<property name="option" value="alone_or_singleline"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="WhitespaceAfter">
|
|
||||||
<!-- Drops TYPECAST from default tokens -->
|
|
||||||
<property name="tokens" value="COMMA , SEMI , LITERAL_IF , LITERAL_ELSE , LITERAL_WHILE , LITERAL_DO , LITERAL_FOR , DO_WHILE"/>
|
|
||||||
</module>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="FileTabCharacter">
|
|
||||||
<property name="eachLine" value="true"/>
|
|
||||||
</module>
|
|
||||||
</module>
|
|
||||||
@ -1,87 +0,0 @@
|
|||||||
# General
|
|
||||||
This file describes some of the java properties which ```ice4j``` uses
|
|
||||||
to configure itself.
|
|
||||||
|
|
||||||
## Interfaces and IP addresses
|
|
||||||
|
|
||||||
### ```org.ice4j.ice.harvest.ALLOWED_INTERFACES```
|
|
||||||
Default: all interfaces are allowed.
|
|
||||||
|
|
||||||
This property can be used to specify a ";"-separated list of interfaces which are
|
|
||||||
allowed to be used for candidate allocations. If not specified, all interfaces are
|
|
||||||
considered allowed, unless they are explicitly blocked (see below).
|
|
||||||
|
|
||||||
### ```org.ice4j.ice.harvest.BLOCKED_INTERFACES```
|
|
||||||
Default: no interfaces are blocked.
|
|
||||||
|
|
||||||
This property can be used to specify a ";"-separated list of interfaces which are
|
|
||||||
not allowed to be used for candidate allocations.
|
|
||||||
|
|
||||||
### ```org.ice4j.ice.harvest.ALLOWED_ADDRESSES```
|
|
||||||
Default: all addresses are allowed.
|
|
||||||
|
|
||||||
This property can be used to specify a ";"-separated list of IP addresses which
|
|
||||||
are allowed to be used for candidate allocations. If not specified, all addresses
|
|
||||||
are considered allowed, unless they are explicitly blocked (see below).
|
|
||||||
|
|
||||||
### ```org.ice4j.ice.harvest.BLOCKED_ADDRESSES```
|
|
||||||
Default: no addresses are blocked.
|
|
||||||
|
|
||||||
This property can be used to specify a ";"-separated list of IP addresses which
|
|
||||||
are not allowed to be used for candidate allocations.
|
|
||||||
|
|
||||||
### ```org.ice4j.ipv6.DISABLED```
|
|
||||||
Type: boolean
|
|
||||||
|
|
||||||
Default: false
|
|
||||||
|
|
||||||
This property can be used to disable binding on IPv6 addresses.
|
|
||||||
|
|
||||||
|
|
||||||
## Mapping harvesters
|
|
||||||
Ice4j uses the concept of "mapping harvesters" to handle known IP address
|
|
||||||
mappings. A set of mapping harvesters is configured once when the library
|
|
||||||
initializes, and each of them contains a pair of IP addresses (local and public).
|
|
||||||
|
|
||||||
When an ICE Agent gathers candidates, it uses the set of mapping harvesters
|
|
||||||
to obtain ```srflx``` candidates without the use to e.g. a STUN server dynamically.
|
|
||||||
|
|
||||||
Mapping harvesters preserve the port number of the original candidate, so they should
|
|
||||||
only be used when port numbers are preserved.
|
|
||||||
|
|
||||||
Ice4j implements three types of mapping harvesters: one with a pre-configured pair of
|
|
||||||
addresses, one two which discover addresses dynamically using the AWS API and STUN.
|
|
||||||
|
|
||||||
|
|
||||||
### ```org.ice4j.ice.harvest.NAT_HARVESTER_LOCAL_ADDRESS```
|
|
||||||
### ```org.ice4j.ice.harvest.NAT_HARVESTER_PUBLIC_ADDRESS```
|
|
||||||
Default: none
|
|
||||||
|
|
||||||
Configures the addresses of the pre-configured mapping harvester.
|
|
||||||
|
|
||||||
### ```org.ice4j.ice.harvest.DISABLE_AWS_HARVESTER```
|
|
||||||
Default: false
|
|
||||||
|
|
||||||
Explicitly disables the AWS mapping harvester. By default the harvester
|
|
||||||
is enabled if ice4j detects that it is running in the AWS network.
|
|
||||||
|
|
||||||
### ```org.ice4j.ice.harvest.FORCE_AWS_HARVESTER```
|
|
||||||
Default: false
|
|
||||||
|
|
||||||
Force the use of the AWS mapping harvester, even if ice4j did not detect
|
|
||||||
that it is running in the AWS network.
|
|
||||||
|
|
||||||
### ```org.ice4j.ice.harvest.STUN_MAPPING_HARVESTER_ADDRESSES```
|
|
||||||
Default: none
|
|
||||||
|
|
||||||
A comma-separated list of STUN server addresses to use for mapping harvesters.
|
|
||||||
Each STUN server address is an ip_address:port pair.
|
|
||||||
Example: ```stun1.example.com:12345,stun2.example.com:23456```
|
|
||||||
|
|
||||||
## Single port UDP harvester
|
|
||||||
### ```org.ice4j.ice.harvest.AbstractUdpHarvester.SO_RCVBUF```
|
|
||||||
Configures the receive buffer size for the single port UDP harvester
|
|
||||||
(or other AbstractUdpListener implementations). If this is not set
|
|
||||||
the system default value will be used (the ```net.core.rmem_default```
|
|
||||||
sysctl parameter on linux). Note that the system maximum value may need to
|
|
||||||
be increased (```net.core.rmem_max``` on linux).
|
|
||||||
BIN
lib/junit.jar
Normal file
BIN
lib/junit.jar
Normal file
Binary file not shown.
@ -51,7 +51,6 @@ java.util.logging.ConsoleHandler.formatter = org.ice4j.util.Ice4jLogFormatter
|
|||||||
|
|
||||||
# Things coming from ice4j
|
# Things coming from ice4j
|
||||||
org.ice4j.level = INFO
|
org.ice4j.level = INFO
|
||||||
org.ice4j.pseudotcp.PseudoTCPBase.level = SEVERE
|
|
||||||
test.level = INFO
|
test.level = INFO
|
||||||
#org.ice4j.ice.checks.levell = FINEST
|
#org.ice4j.ice.checks.levell = FINEST
|
||||||
#org.ice4j.ice.ConnectivityCheckClient.level = FINER
|
#org.ice4j.ice.ConnectivityCheckClient.level = FINER
|
||||||
BIN
lib/weupnp-0.1.2-SNAPSHOT.jar
Normal file
BIN
lib/weupnp-0.1.2-SNAPSHOT.jar
Normal file
Binary file not shown.
BIN
lib/xalan-2.6.0.jar
Executable file
BIN
lib/xalan-2.6.0.jar
Executable file
Binary file not shown.
508
pom.xml
508
pom.xml
@ -1,542 +1,82 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
<groupId>org.jitsi</groupId>
|
<groupId>org.jitsi</groupId>
|
||||||
|
<artifactId>jitsi-universe-public</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
<artifactId>ice4j</artifactId>
|
<artifactId>ice4j</artifactId>
|
||||||
<version>3.0-SNAPSHOT</version>
|
<version>1.0.0</version>
|
||||||
|
<packaging>bundle</packaging>
|
||||||
|
|
||||||
<name>ice4j</name>
|
<name>ice4j</name>
|
||||||
<description>A Java implementation of the ICE protocol</description>
|
|
||||||
<url>https://github.com/jitsi/ice4j</url>
|
<url>https://github.com/jitsi/ice4j</url>
|
||||||
|
|
||||||
<organization>
|
|
||||||
<name>jitsi.org</name>
|
|
||||||
<url>https://jitsi.org</url>
|
|
||||||
</organization>
|
|
||||||
|
|
||||||
<developers>
|
|
||||||
<developer>
|
|
||||||
<id>org.jitsi</id>
|
|
||||||
<name>Jitsi Team</name>
|
|
||||||
<email>dev@jitsi.org</email>
|
|
||||||
</developer>
|
|
||||||
</developers>
|
|
||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
<url>https://github.com/jitsi/ice4j</url>
|
<url>https://github.com/jitsi/ice4j</url>
|
||||||
<connection>scm:git:https://github.com/jitsi/ice4j.git</connection>
|
<connection>scm:git:https://github.com/jitsi/ice4j.git</connection>
|
||||||
<developerConnection>scm:git:https://github.com/jitsi/ice4j.git</developerConnection>
|
<developerConnection>scm:git:https://github.com/jitsi/ice4j.git</developerConnection>
|
||||||
|
<tag>ice4j-1.0.0</tag>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<licenses>
|
|
||||||
<license>
|
|
||||||
<name>Apache-2.0</name>
|
|
||||||
<url>https://github.com/jitsi/ice4j/blob/master/LICENSE</url>
|
|
||||||
<distribution>repo</distribution>
|
|
||||||
</license>
|
|
||||||
</licenses>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<jicoco.version>1.1-127-gf49982f</jicoco.version>
|
|
||||||
<kotlin.version>1.9.10</kotlin.version>
|
|
||||||
<dokka.version>1.9.0</dokka.version>
|
|
||||||
<kotest.version>5.7.2</kotest.version>
|
|
||||||
<junit.version>5.10.0</junit.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.opentelecoms.sdp</groupId>
|
<groupId>org.opentelecoms.sdp</groupId>
|
||||||
<artifactId>java-sdp-nist-bridge</artifactId>
|
<artifactId>java-sdp-nist-bridge</artifactId>
|
||||||
<version>1.2</version>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jitsi</groupId>
|
||||||
|
<artifactId>jain-sip-ri-ossonly</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bitlet</groupId>
|
<groupId>org.bitlet</groupId>
|
||||||
<artifactId>weupnp</artifactId>
|
<artifactId>weupnp</artifactId>
|
||||||
<version>0.1.4</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>${project.groupId}</groupId>
|
|
||||||
<artifactId>jitsi-utils</artifactId>
|
|
||||||
<version>1.0-127-g6c65524</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>${project.groupId}</groupId>
|
|
||||||
<artifactId>jicoco-config</artifactId>
|
|
||||||
<version>${jicoco.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- test -->
|
<!-- test -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.platform</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit-platform-launcher</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>1.10.0</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.jupiter</groupId>
|
|
||||||
<artifactId>junit-jupiter-api</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.jupiter</groupId>
|
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.kotest</groupId>
|
|
||||||
<artifactId>kotest-assertions-core-jvm</artifactId>
|
|
||||||
<version>${kotest.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.kotest</groupId>
|
|
||||||
<artifactId>kotest-runner-junit5-jvm</artifactId>
|
|
||||||
<version>${kotest.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jitsi</groupId>
|
|
||||||
<artifactId>jicoco-test-kotlin</artifactId>
|
|
||||||
<version>${jicoco.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-core</artifactId>
|
|
||||||
<version>4.5.1</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.mockk</groupId>
|
|
||||||
<artifactId>mockk-jvm</artifactId>
|
|
||||||
<version>1.13.8</version>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
|
||||||
<artifactId>kotlin-maven-plugin</artifactId>
|
|
||||||
<version>${kotlin.version}</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>compile</id>
|
|
||||||
<phase>compile</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>compile</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<sourceDirs>
|
|
||||||
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
|
|
||||||
<sourceDir>${project.basedir}/src/main/java</sourceDir>
|
|
||||||
</sourceDirs>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<id>test-compile</id>
|
|
||||||
<phase>test-compile</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>test-compile</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<sourceDirs>
|
|
||||||
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
|
|
||||||
<sourceDir>${project.basedir}/src/test/java</sourceDir>
|
|
||||||
</sourceDirs>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<jvmTarget>11</jvmTarget>
|
|
||||||
<args>
|
|
||||||
<arg>-Xallow-result-return-type</arg>
|
|
||||||
</args>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.10.1</version>
|
|
||||||
<executions>
|
|
||||||
<!-- Replacing default-compile as it is treated specially by maven -->
|
|
||||||
<execution>
|
|
||||||
<id>default-compile</id>
|
|
||||||
<phase>none</phase>
|
|
||||||
</execution>
|
|
||||||
<!-- Replacing default-testCompile as it is treated specially by maven -->
|
|
||||||
<execution>
|
|
||||||
<id>default-testCompile</id>
|
|
||||||
<phase>none</phase>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<id>java-compile</id>
|
|
||||||
<phase>compile</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>compile</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<id>java-test-compile</id>
|
|
||||||
<phase>test-compile</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>testCompile</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<release>11</release>
|
|
||||||
<compilerArgs>
|
|
||||||
<arg>-Xlint:all</arg>
|
|
||||||
</compilerArgs>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
|
||||||
<version>3.1.2</version>
|
|
||||||
<configuration>
|
|
||||||
<configLocation>checkstyle.xml</configLocation>
|
|
||||||
</configuration>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.puppycrawl.tools</groupId>
|
|
||||||
<artifactId>checkstyle</artifactId>
|
|
||||||
<version>10.1</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>check</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>com.github.gantsign.maven</groupId>
|
|
||||||
<artifactId>ktlint-maven-plugin</artifactId>
|
|
||||||
<version>3.0.0</version>
|
|
||||||
<configuration>
|
|
||||||
<sourceRoots>
|
|
||||||
<sourceRoot>${project.basedir}/src/main/kotlin</sourceRoot>
|
|
||||||
</sourceRoots>
|
|
||||||
<testSourceRoots>
|
|
||||||
<testSourceRoot>${project.basedir}/src/test/kotlin</testSourceRoot>
|
|
||||||
</testSourceRoots>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>check</id>
|
|
||||||
<goals>
|
|
||||||
<goal>check</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>biz.aQute.bnd</groupId>
|
|
||||||
<artifactId>bnd-maven-plugin</artifactId>
|
|
||||||
<version>6.2.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>bnd-process</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
<version>3.2.2</version>
|
|
||||||
<configuration>
|
|
||||||
<archive>
|
|
||||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
|
||||||
</archive>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>3.0.0-M6</version>
|
|
||||||
<configuration>
|
<configuration>
|
||||||
<includes>**/*</includes>
|
<includes>
|
||||||
<systemPropertyVariables>
|
<include>**/*TestSuite.*</include>
|
||||||
<java.util.logging.config.file>${project.build.testSourceDirectory}/../resources/logging.properties</java.util.logging.config.file>
|
</includes>
|
||||||
</systemPropertyVariables>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.felix</groupId>
|
||||||
<artifactId>maven-deploy-plugin</artifactId>
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
<version>3.0.0-M2</version>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.sonatype.plugins</groupId>
|
|
||||||
<artifactId>nexus-staging-maven-plugin</artifactId>
|
|
||||||
<version>1.6.13</version>
|
|
||||||
<extensions>true</extensions>
|
|
||||||
<configuration>
|
|
||||||
<serverId>ossrh</serverId>
|
|
||||||
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
|
|
||||||
<autoReleaseAfterClose>true</autoReleaseAfterClose>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|
||||||
<pluginManagement>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>exec-maven-plugin</artifactId>
|
|
||||||
<version>3.0.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>java</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<classpathScope>test</classpathScope>
|
|
||||||
<systemProperties>
|
|
||||||
<systemProperty>
|
|
||||||
<key>java.util.logging.config.file</key>
|
|
||||||
<value>logging.properties</value>
|
|
||||||
</systemProperty>
|
|
||||||
</systemProperties>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</pluginManagement>
|
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
<profile>
|
<profile>
|
||||||
<id>coverage</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.jacoco</groupId>
|
|
||||||
<artifactId>jacoco-maven-plugin</artifactId>
|
|
||||||
<version>0.8.8</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>prepare-agent</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<id>report</id>
|
|
||||||
<phase>test</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>report</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
<profile>
|
|
||||||
<id>run-sample</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>exec-maven-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<mainClass>test.Ice</mainClass>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
|
|
||||||
<profile>
|
|
||||||
<id>run-pseudotcp</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>exec-maven-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<mainClass>test.IcePseudoTcp</mainClass>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
|
|
||||||
<profile>
|
|
||||||
<id>run-dist</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>exec-maven-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<mainClass>test.IceDistributed</mainClass>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
|
|
||||||
<profile>
|
|
||||||
<id>run-trickle</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>exec-maven-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<mainClass>test.TrickleIce</mainClass>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
|
|
||||||
<profile>
|
|
||||||
<id>run-lite</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>exec-maven-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<mainClass>test.IceLite</mainClass>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
|
|
||||||
<profile>
|
|
||||||
<id>run-map</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>exec-maven-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<mainClass>test.MappingTest</mainClass>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
|
|
||||||
<profile>
|
|
||||||
<id>run-aws</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>exec-maven-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<mainClass>test.AwsTest</mainClass>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
|
|
||||||
<profile>
|
|
||||||
<id>release</id>
|
|
||||||
<activation>
|
<activation>
|
||||||
<property>
|
<jdk>(,1.8)</jdk>
|
||||||
<name>release</name>
|
|
||||||
<value>true</value>
|
|
||||||
</property>
|
|
||||||
</activation>
|
</activation>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>build-helper-maven-plugin</artifactId>
|
|
||||||
<version>3.3.0</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>generate-sources</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>add-source</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<sources>
|
|
||||||
<source>src/main/kotlin</source>
|
|
||||||
</sources>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.2.1</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>attach-sources</id>
|
|
||||||
<phase>verify</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>jar-no-fork</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.jetbrains.dokka</groupId>
|
|
||||||
<artifactId>dokka-maven-plugin</artifactId>
|
|
||||||
<version>${dokka.version}</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>javadocJar</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-gpg-plugin</artifactId>
|
|
||||||
<version>3.0.1</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>sign-artifacts</id>
|
|
||||||
<phase>verify</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>sign</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
<configuration>
|
||||||
<gpgArguments>
|
<excludes>
|
||||||
<arg>--pinentry-mode</arg>
|
<exclude>**/jdk8/**</exclude>
|
||||||
<arg>loopback</arg>
|
</excludes>
|
||||||
</gpgArguments>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</profile>
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
|
|
||||||
<distributionManagement>
|
|
||||||
<snapshotRepository>
|
|
||||||
<id>ossrh</id>
|
|
||||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
|
||||||
</snapshotRepository>
|
|
||||||
<repository>
|
|
||||||
<id>ossrh</id>
|
|
||||||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
|
||||||
</repository>
|
|
||||||
</distributionManagement>
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -110,9 +110,6 @@ public class ChannelDataMessageEvent
|
|||||||
/**
|
/**
|
||||||
* Gets the <tt>TransportAddress</tt> which is local address on which this
|
* Gets the <tt>TransportAddress</tt> which is local address on which this
|
||||||
* event was received.
|
* event was received.
|
||||||
*
|
|
||||||
* @return the <tt>TransportAddress</tt> which is local address on which
|
|
||||||
* this event was received.
|
|
||||||
*/
|
*/
|
||||||
public TransportAddress getLocalAddress()
|
public TransportAddress getLocalAddress()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -17,8 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.ice4j;
|
package org.ice4j;
|
||||||
|
|
||||||
import org.ice4j.ice.*;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
|
|
||||||
@ -50,15 +48,6 @@ public class StackProperties
|
|||||||
*/
|
*/
|
||||||
public static final int BIND_RETRIES_DEFAULT_VALUE = 50;
|
public static final int BIND_RETRIES_DEFAULT_VALUE = 50;
|
||||||
|
|
||||||
/**
|
|
||||||
* The name of the property that tells if we should bind to the
|
|
||||||
* wildcard address instead of the (usually more specific) harvest candidate
|
|
||||||
* addresses.
|
|
||||||
*
|
|
||||||
* The wildcard is a special local IP address. It usually means "any".
|
|
||||||
*/
|
|
||||||
public static final String BIND_WILDCARD = "org.ice4j.BIND_WILDCARD";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of milliseconds a client transaction should wait before
|
* The number of milliseconds a client transaction should wait before
|
||||||
* retransmitting, after it has sent a request for the first time.
|
* retransmitting, after it has sent a request for the first time.
|
||||||
@ -86,6 +75,19 @@ public class StackProperties
|
|||||||
public static final String MAX_CTRAN_RETRANSMISSIONS
|
public static final String MAX_CTRAN_RETRANSMISSIONS
|
||||||
= "org.ice4j.MAX_RETRANSMISSIONS";
|
= "org.ice4j.MAX_RETRANSMISSIONS";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the System property that allows us to set a custom maximum
|
||||||
|
* for check list sizes.
|
||||||
|
*/
|
||||||
|
public static final String MAX_CHECK_LIST_SIZE
|
||||||
|
= "org.ice4j.MAX_CHECK_LIST_SIZE";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The value of the SOFTWARE attribute that ice4j should include in all
|
||||||
|
* outgoing messages.
|
||||||
|
*/
|
||||||
|
public static final String SOFTWARE = "org.ice4j.SOFTWARE";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the property that tells the stack whether or not it should
|
* The name of the property that tells the stack whether or not it should
|
||||||
* let the application see retransmissions of incoming requests.
|
* let the application see retransmissions of incoming requests.
|
||||||
@ -114,6 +116,14 @@ public class StackProperties
|
|||||||
public static final String REQUIRE_MESSAGE_INTEGRITY
|
public static final String REQUIRE_MESSAGE_INTEGRITY
|
||||||
= "org.ice4j.REQUIRE_MESSAGE_INTEGRITY";
|
= "org.ice4j.REQUIRE_MESSAGE_INTEGRITY";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the property that can be used to specify the number of
|
||||||
|
* milliseconds that we must wait after ICE processing enters a COMPLTED
|
||||||
|
* state and before we free candidates and move into the TERMINATED state.
|
||||||
|
*/
|
||||||
|
public static final String TERMINATION_DELAY
|
||||||
|
= "org.ice4j.TERMINATION_DELAY";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the property that can be used to disable STUN keep alives.
|
* The name of the property that can be used to disable STUN keep alives.
|
||||||
* Set to <tt>true</tt> to disable.
|
* Set to <tt>true</tt> to disable.
|
||||||
@ -132,6 +142,11 @@ public class StackProperties
|
|||||||
public static final String NOMINATION_TIMER
|
public static final String NOMINATION_TIMER
|
||||||
= "org.ice4j.NOMINATION_TIMER";
|
= "org.ice4j.NOMINATION_TIMER";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the property used to disabled IPv6 support.
|
||||||
|
*/
|
||||||
|
public static final String DISABLE_IPv6 = "org.ice4j.ipv6.DISABLED";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the allowed interfaces property which specifies the allowed
|
* The name of the allowed interfaces property which specifies the allowed
|
||||||
* interfaces for host candidate allocations.
|
* interfaces for host candidate allocations.
|
||||||
@ -156,6 +171,13 @@ public class StackProperties
|
|||||||
public static final String ALLOWED_ADDRESSES
|
public static final String ALLOWED_ADDRESSES
|
||||||
= "org.ice4j.ice.harvest.ALLOWED_ADDRESSES";
|
= "org.ice4j.ice.harvest.ALLOWED_ADDRESSES";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the property which, if set to true, specifies that IPv6
|
||||||
|
* link local addresses should not be used for candidate allocations.
|
||||||
|
*/
|
||||||
|
public static final String DISABLE_LINK_LOCAL_ADDRESSES
|
||||||
|
= "org.ice4j.ice.harvest.DISABLE_LINK_LOCAL_ADDRESSES";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the property which specifies a ";"-separated list of IP
|
* The name of the property which specifies a ";"-separated list of IP
|
||||||
* addresses that are not allowed to be used for host candidate allocations.
|
* addresses that are not allowed to be used for host candidate allocations.
|
||||||
@ -166,6 +188,13 @@ public class StackProperties
|
|||||||
public static final String BLOCKED_ADDRESSES
|
public static final String BLOCKED_ADDRESSES
|
||||||
= "org.ice4j.ice.harvest.BLOCKED_ADDRESSES";
|
= "org.ice4j.ice.harvest.BLOCKED_ADDRESSES";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the property which specifies whether the dynamic port UDP
|
||||||
|
* host harvester should be used by <tt>Agent</tt> instances.
|
||||||
|
*/
|
||||||
|
public static final String USE_DYNAMIC_HOST_HARVESTER
|
||||||
|
= "org.ice4j.ice.harvest.USE_DYNAMIC_HOST_HARVESTER";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the String value of the specified property (minus all
|
* Returns the String value of the specified property (minus all
|
||||||
* encompassing whitespaces)and null in case no property value was mapped
|
* encompassing whitespaces)and null in case no property value was mapped
|
||||||
|
|||||||
@ -99,22 +99,22 @@ public enum Transport
|
|||||||
public static Transport parse(String transportName)
|
public static Transport parse(String transportName)
|
||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (UDP.toString().equals(transportName))
|
if(UDP.toString().equals(transportName))
|
||||||
return UDP;
|
return UDP;
|
||||||
|
|
||||||
if (TCP.toString().equals(transportName))
|
if(TCP.toString().equals(transportName))
|
||||||
return TCP;
|
return TCP;
|
||||||
|
|
||||||
if (TLS.toString().equals(transportName))
|
if(TLS.toString().equals(transportName))
|
||||||
return TLS;
|
return TLS;
|
||||||
|
|
||||||
if (SCTP.toString().equals(transportName))
|
if(SCTP.toString().equals(transportName))
|
||||||
return SCTP;
|
return SCTP;
|
||||||
|
|
||||||
if (DTLS.toString().equals(transportName))
|
if(DTLS.toString().equals(transportName))
|
||||||
return DTLS;
|
return DTLS;
|
||||||
|
|
||||||
if (SSLTCP.toString().equals(transportName))
|
if(SSLTCP.toString().equals(transportName))
|
||||||
return SSLTCP;
|
return SSLTCP;
|
||||||
|
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
|||||||
@ -148,14 +148,14 @@ public class TransportAddress
|
|||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
String hostAddress = getHostAddress();
|
String hostAddress = getHostAddress();
|
||||||
if (hostAddress == null)
|
if(hostAddress == null)
|
||||||
{
|
{
|
||||||
hostAddress = getHostName();
|
hostAddress = getHostName();
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder bldr = new StringBuilder(hostAddress);
|
StringBuilder bldr = new StringBuilder(hostAddress);
|
||||||
|
|
||||||
if (isIPv6())
|
if(isIPv6())
|
||||||
bldr.insert(0, "[").append("]");
|
bldr.insert(0, "[").append("]");
|
||||||
|
|
||||||
bldr.append(":").append(getPort());
|
bldr.append(":").append(getPort());
|
||||||
@ -175,7 +175,7 @@ public class TransportAddress
|
|||||||
String addressStr
|
String addressStr
|
||||||
= addr != null ? addr.getHostAddress() : null;
|
= addr != null ? addr.getHostAddress() : null;
|
||||||
|
|
||||||
if (addr instanceof Inet6Address)
|
if(addr instanceof Inet6Address)
|
||||||
addressStr = NetworkUtils.stripScopeID(addressStr);
|
addressStr = NetworkUtils.stripScopeID(addressStr);
|
||||||
|
|
||||||
return addressStr;
|
return addressStr;
|
||||||
@ -216,7 +216,7 @@ public class TransportAddress
|
|||||||
* address if both the InetAddresses (or hostnames if it is unresolved),
|
* address if both the InetAddresses (or hostnames if it is unresolved),
|
||||||
* port numbers, and <tt>Transport</tt>s are equal.
|
* port numbers, and <tt>Transport</tt>s are equal.
|
||||||
*
|
*
|
||||||
* If both addresses are unresolved, then the hostname, the port and
|
* If both addresses are unresolved, then the hostname, the port & and
|
||||||
* the <tt>Transport</tt> are compared.
|
* the <tt>Transport</tt> are compared.
|
||||||
*
|
*
|
||||||
* @param obj the object to compare against.
|
* @param obj the object to compare against.
|
||||||
@ -258,7 +258,7 @@ public class TransportAddress
|
|||||||
*/
|
*/
|
||||||
public boolean canReach(TransportAddress dst)
|
public boolean canReach(TransportAddress dst)
|
||||||
{
|
{
|
||||||
if ( getTransport() != dst.getTransport() )
|
if( getTransport() != dst.getTransport() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (isIPv6() != dst.isIPv6())
|
if (isIPv6() != dst.isIPv6())
|
||||||
@ -269,7 +269,7 @@ public class TransportAddress
|
|||||||
Inet6Address srcAddr = (Inet6Address)getAddress();
|
Inet6Address srcAddr = (Inet6Address)getAddress();
|
||||||
Inet6Address dstAddr = (Inet6Address)dst.getAddress();
|
Inet6Address dstAddr = (Inet6Address)dst.getAddress();
|
||||||
|
|
||||||
if (srcAddr.isLinkLocalAddress() != dstAddr.isLinkLocalAddress())
|
if(srcAddr.isLinkLocalAddress() != dstAddr.isLinkLocalAddress())
|
||||||
{
|
{
|
||||||
//this one may actually work if for example we are contacting
|
//this one may actually work if for example we are contacting
|
||||||
//the public address of someone in our local network. however
|
//the public address of someone in our local network. however
|
||||||
|
|||||||
@ -24,32 +24,34 @@ import org.ice4j.*;
|
|||||||
/**
|
/**
|
||||||
* This class is used to represent Stun attributes that contain an address. Such
|
* This class is used to represent Stun attributes that contain an address. Such
|
||||||
* attributes are:
|
* attributes are:
|
||||||
*<ul>
|
*<p>
|
||||||
* <li>MAPPED-ADDRESS
|
* MAPPED-ADDRESS <br/>
|
||||||
* <li>RESPONSE-ADDRESS
|
* RESPONSE-ADDRESS <br/>
|
||||||
* <li>SOURCE-ADDRESS
|
* SOURCE-ADDRESS <br/>
|
||||||
* <li>CHANGED-ADDRESS
|
* CHANGED-ADDRESS <br/>
|
||||||
* <li>REFLECTED-FROM
|
* REFLECTED-FROM <br/>
|
||||||
* <li>ALTERNATE-SERVER
|
* ALTERNATE-SERVER <br/>
|
||||||
* <li>XOR-PEER-ADDRESS
|
* XOR-PEER-ADDRESS <br/>
|
||||||
* <li>XOR-RELAYED-ADDRESS
|
* XOR-RELAYED-ADDRESS <br/>
|
||||||
*</ul>
|
*</p>
|
||||||
*<p>
|
*<p>
|
||||||
* The different attributes are distinguished by the attributeType of
|
* The different attributes are distinguished by the attributeType of
|
||||||
* {@link Attribute}.
|
* org.ice4j.attribute.Attribute.
|
||||||
|
*</p>
|
||||||
*<p>
|
*<p>
|
||||||
* Address attributes indicate the mapped IP address and
|
* Address attributes indicate the mapped IP address and
|
||||||
* port. They consist of an eight bit address family, and a sixteen bit
|
* port. They consist of an eight bit address family, and a sixteen bit
|
||||||
* port, followed by a fixed length value representing the IP address.
|
* port, followed by a fixed length value representing the IP address.
|
||||||
*<pre>
|
*<code>
|
||||||
* 0 1 2 3
|
* 0 1 2 3 <br/>
|
||||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 <br/>
|
||||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ <br/>
|
||||||
* |x x x x x x x x| Family | Port |
|
* |x x x x x x x x| Family | Port | <br/>
|
||||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ <br/>
|
||||||
* | Address |
|
* | Address | <br/>
|
||||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ <br/>
|
||||||
* </pre>
|
* <br/>
|
||||||
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
* The port is a network byte ordered representation of the mapped port.
|
* The port is a network byte ordered representation of the mapped port.
|
||||||
* The address family is always 0x01, corresponding to IPv4. The first
|
* The address family is always 0x01, corresponding to IPv4. The first
|
||||||
@ -159,7 +161,8 @@ abstract class AddressAttribute extends Attribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof AddressAttribute))
|
if (! (obj instanceof AddressAttribute)
|
||||||
|
|| obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
@ -176,7 +179,7 @@ abstract class AddressAttribute extends Attribute
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
//addresses
|
//addresses
|
||||||
if ( att.getAddress() == null && getAddress() == null)
|
if( att.getAddress() == null && getAddress() == null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -221,12 +224,10 @@ abstract class AddressAttribute extends Attribute
|
|||||||
binValue[7] = (byte)(getPort() & 0x00FF);
|
binValue[7] = (byte)(getPort() & 0x00FF);
|
||||||
|
|
||||||
//address
|
//address
|
||||||
if (getFamily() == ADDRESS_FAMILY_IPV6)
|
if(getFamily() == ADDRESS_FAMILY_IPV6){
|
||||||
{
|
|
||||||
System.arraycopy(getAddressBytes(), 0, binValue, 8, 16);
|
System.arraycopy(getAddressBytes(), 0, binValue, 8, 16);
|
||||||
}
|
}
|
||||||
else
|
else{
|
||||||
{
|
|
||||||
System.arraycopy(getAddressBytes(), 0, binValue, 8, 4);
|
System.arraycopy(getAddressBytes(), 0, binValue, 8, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,7 +310,7 @@ abstract class AddressAttribute extends Attribute
|
|||||||
|
|
||||||
//address
|
//address
|
||||||
byte address[] = null;
|
byte address[] = null;
|
||||||
if (family == ADDRESS_FAMILY_IPV6)
|
if(family == ADDRESS_FAMILY_IPV6)
|
||||||
{
|
{
|
||||||
address = new byte[16];
|
address = new byte[16];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,53 +22,52 @@ import org.ice4j.*;
|
|||||||
/**
|
/**
|
||||||
* After the header are 0 or more attributes. Each attribute is TLV
|
* After the header are 0 or more attributes. Each attribute is TLV
|
||||||
* encoded, with a 16 bit type, 16 bit length, and variable value:
|
* encoded, with a 16 bit type, 16 bit length, and variable value:
|
||||||
*<pre>
|
|
||||||
* 0 1 2 3
|
|
||||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
||||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
||||||
* | Type | Length |
|
|
||||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
||||||
* | Value ....
|
|
||||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
||||||
*
|
*
|
||||||
* The following types are defined:
|
* 0 1 2 3 <br/>
|
||||||
|
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 <br/>
|
||||||
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ <br/>
|
||||||
|
* | Type | Length | <br/>
|
||||||
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ <br/>
|
||||||
|
* | Value .... <br/>
|
||||||
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ <br/>
|
||||||
|
*<br/>
|
||||||
|
* The following types are defined:<br/>
|
||||||
|
*<br/>
|
||||||
|
* STUN attributes:<br/>
|
||||||
|
* 0x0001: MAPPED-ADDRESS <br/>
|
||||||
|
* 0x0002: RESPONSE-ADDRESS <br/>
|
||||||
|
* 0x0003: CHANGE-REQUEST <br/>
|
||||||
|
* 0x0004: SOURCE-ADDRESS <br/>
|
||||||
|
* 0x0005: CHANGED-ADDRESS <br/>
|
||||||
|
* 0x0006: USERNAME <br/>
|
||||||
|
* 0x0007: PASSWORD <br/>
|
||||||
|
* 0x0008: MESSAGE-INTEGRITY <br/>
|
||||||
|
* 0x0009: ERROR-CODE <br/>
|
||||||
|
* 0x000a: UNKNOWN-ATTRIBUTES <br/>
|
||||||
|
* 0x000b: REFLECTED-FROM <br/>
|
||||||
|
* 0x0014: REALM <br/>
|
||||||
|
* 0x0015: NONCE <br/>
|
||||||
|
* 0x0020: XOR-MAPPED-ADDRESS <br/>
|
||||||
|
* 0x8022: SOFTWARE <br/>
|
||||||
|
* 0x8023: ALTERNATE-SERVER <br/>
|
||||||
|
* 0x8028: FINGERPRINT <br/>
|
||||||
|
* <br/>
|
||||||
|
* TURN attributes:<br/>
|
||||||
|
* 0x000C: CHANNEL-NUMBER <br/>
|
||||||
|
* 0x000D: LIFETIME <br/>
|
||||||
|
* 0x0012: XOR-PEER-ADDRESS <br/>
|
||||||
|
* 0x0013: DATA <br/>
|
||||||
|
* 0x0016: XOR-RELAYED-ADDRESS <br/>
|
||||||
|
* 0x0018: EVEN-PORT <br/>
|
||||||
|
* 0x0019: REQUESTED-TRANSPORT <br/>
|
||||||
|
* 0x001A: DONT-FRAGMENT <br/>
|
||||||
|
* 0x0022: RESERVATION-TOKEN <br/>
|
||||||
*
|
*
|
||||||
* STUN attributes:
|
* ICE attributes:<br/>
|
||||||
* 0x0001: MAPPED-ADDRESS
|
* 0x0024: PRIORITY <br/>
|
||||||
* 0x0002: RESPONSE-ADDRESS
|
* 0x0025: USE-CANDIDATE <br/>
|
||||||
* 0x0003: CHANGE-REQUEST
|
* 0x8029: ICE-CONTROLLED <br/>
|
||||||
* 0x0004: SOURCE-ADDRESS
|
* 0x802A: ICE-CONTROLLING <br/>
|
||||||
* 0x0005: CHANGED-ADDRESS
|
|
||||||
* 0x0006: USERNAME
|
|
||||||
* 0x0007: PASSWORD
|
|
||||||
* 0x0008: MESSAGE-INTEGRITY
|
|
||||||
* 0x0009: ERROR-CODE
|
|
||||||
* 0x000a: UNKNOWN-ATTRIBUTES
|
|
||||||
* 0x000b: REFLECTED-FROM
|
|
||||||
* 0x0014: REALM
|
|
||||||
* 0x0015: NONCE
|
|
||||||
* 0x0020: XOR-MAPPED-ADDRESS
|
|
||||||
* 0x8022: SOFTWARE
|
|
||||||
* 0x8023: ALTERNATE-SERVER
|
|
||||||
* 0x8028: FINGERPRINT
|
|
||||||
*
|
|
||||||
* TURN attributes:
|
|
||||||
* 0x000C: CHANNEL-NUMBER
|
|
||||||
* 0x000D: LIFETIME
|
|
||||||
* 0x0012: XOR-PEER-ADDRESS
|
|
||||||
* 0x0013: DATA
|
|
||||||
* 0x0016: XOR-RELAYED-ADDRESS
|
|
||||||
* 0x0018: EVEN-PORT
|
|
||||||
* 0x0019: REQUESTED-TRANSPORT
|
|
||||||
* 0x001A: DONT-FRAGMENT
|
|
||||||
* 0x0022: RESERVATION-TOKEN
|
|
||||||
*
|
|
||||||
* ICE attributes:
|
|
||||||
* 0x0024: PRIORITY
|
|
||||||
* 0x0025: USE-CANDIDATE
|
|
||||||
* 0x8029: ICE-CONTROLLED
|
|
||||||
* 0x802A: ICE-CONTROLLING
|
|
||||||
* </pre>
|
|
||||||
*
|
*
|
||||||
* @author Emil Ivov
|
* @author Emil Ivov
|
||||||
* @author Sebastien Vincent
|
* @author Sebastien Vincent
|
||||||
|
|||||||
@ -43,23 +43,23 @@ public class AttributeDecoder
|
|||||||
* @throws StunException if bytes is not a valid STUN attribute.
|
* @throws StunException if bytes is not a valid STUN attribute.
|
||||||
*/
|
*/
|
||||||
public static Attribute decode(byte[] bytes,
|
public static Attribute decode(byte[] bytes,
|
||||||
int offset,
|
char offset,
|
||||||
int length)
|
char length)
|
||||||
throws StunException
|
throws StunException
|
||||||
{
|
{
|
||||||
if (bytes == null || bytes.length < Attribute.HEADER_LENGTH)
|
if(bytes == null || bytes.length < Attribute.HEADER_LENGTH)
|
||||||
{
|
{
|
||||||
throw new StunException( StunException.ILLEGAL_ARGUMENT,
|
throw new StunException( StunException.ILLEGAL_ARGUMENT,
|
||||||
"Could not decode the specified binary array.");
|
"Could not decode the specified binary array.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Discover attribute type
|
//Discover attribute type
|
||||||
char attributeType = (char)
|
char attributeType = (char)((bytes[offset] << 8) | bytes[offset + 1]);
|
||||||
(((bytes[offset] & 0xFF) << 8) | (bytes[offset + 1] & 0xFF));
|
int len1 = bytes[offset + 2] & 0xff;
|
||||||
char attributeLength = (char)
|
int len2 = bytes[offset + 3] & 0xff;
|
||||||
(((bytes[offset + 2] & 0xFF) << 8) | (bytes[offset + 3] & 0xFF));
|
char attributeLength = (char)((len1 << 8) | len2);
|
||||||
|
|
||||||
if (attributeLength > bytes.length - offset )
|
if(attributeLength > bytes.length - offset )
|
||||||
throw new StunException( StunException.ILLEGAL_ARGUMENT,
|
throw new StunException( StunException.ILLEGAL_ARGUMENT,
|
||||||
"Could not decode the specified binary array.");
|
"Could not decode the specified binary array.");
|
||||||
|
|
||||||
|
|||||||
@ -544,8 +544,7 @@ public class AttributeFactory
|
|||||||
*
|
*
|
||||||
* @param priority the priority value
|
* @param priority the priority value
|
||||||
* @return the created PriorityAttribute
|
* @return the created PriorityAttribute
|
||||||
* @throws IllegalArgumentException if priority < 0 or priority >
|
* @throws IllegalArgumentException if priority < 0 or priority > (2^31 - 1)
|
||||||
* (2^31 - 1)
|
|
||||||
*/
|
*/
|
||||||
public static PriorityAttribute createPriorityAttribute(long priority)
|
public static PriorityAttribute createPriorityAttribute(long priority)
|
||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
@ -628,7 +627,7 @@ public class AttributeFactory
|
|||||||
= new RequestedAddressFamilyAttribute();
|
= new RequestedAddressFamilyAttribute();
|
||||||
|
|
||||||
boolean isSet = attribute.setFamily(family);
|
boolean isSet = attribute.setFamily(family);
|
||||||
if (!isSet)
|
if(!isSet)
|
||||||
{
|
{
|
||||||
attribute = null;
|
attribute = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,13 +24,13 @@ import org.ice4j.*;
|
|||||||
* attribute is used by the client to request that the server use a different
|
* attribute is used by the client to request that the server use a different
|
||||||
* address and/or port when sending the response. The attribute is 32 bits
|
* address and/or port when sending the response. The attribute is 32 bits
|
||||||
* long, although only two bits (A and B) are used:
|
* long, although only two bits (A and B) are used:
|
||||||
* <pre>
|
*
|
||||||
* 0 1 2 3
|
* 0 1 2 3 <br/>
|
||||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 <br/>
|
||||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ <br/>
|
||||||
* |0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A B 0|
|
* |0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A B 0| <br/>
|
||||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ <br/>
|
||||||
* </pre>
|
*
|
||||||
* The meaning of the flags is:
|
* The meaning of the flags is:
|
||||||
*
|
*
|
||||||
* A: This is the "change IP" flag. If true, it requests the server
|
* A: This is the "change IP" flag. If true, it requests the server
|
||||||
@ -100,7 +100,8 @@ public class ChangeRequestAttribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof ChangeRequestAttribute))
|
if (! (obj instanceof ChangeRequestAttribute)
|
||||||
|
|| obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
|
|||||||
@ -60,7 +60,8 @@ public class ChannelNumberAttribute extends Attribute
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof ChannelNumberAttribute))
|
if (! (obj instanceof ChannelNumberAttribute)
|
||||||
|
|| obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
@ -137,7 +138,7 @@ public class ChannelNumberAttribute extends Attribute
|
|||||||
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
||||||
throws StunException
|
throws StunException
|
||||||
{
|
{
|
||||||
if (length != 4)
|
if(length != 4)
|
||||||
{
|
{
|
||||||
throw new StunException("length invalid");
|
throw new StunException("length invalid");
|
||||||
}
|
}
|
||||||
@ -168,11 +169,11 @@ public class ChannelNumberAttribute extends Attribute
|
|||||||
/**
|
/**
|
||||||
* Determines if the channelNo is in valid range.
|
* Determines if the channelNo is in valid range.
|
||||||
* @param channelNo the channelNo to validate.
|
* @param channelNo the channelNo to validate.
|
||||||
* @return true if channnelNo is >= 0x4000.
|
* @return true if channnelNo is >= 0x4000.
|
||||||
*/
|
*/
|
||||||
public static boolean isValidRange(char channelNo)
|
public static boolean isValidRange(char channelNo)
|
||||||
{
|
{
|
||||||
if (channelNo >= 0x4000)
|
if(channelNo >= 0x4000)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -137,7 +137,7 @@ public class ConnectionIdAttribute
|
|||||||
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
||||||
throws StunException
|
throws StunException
|
||||||
{
|
{
|
||||||
if (length != DATA_LENGTH)
|
if(length != DATA_LENGTH)
|
||||||
{
|
{
|
||||||
throw new StunException("length invalid: " + length);
|
throw new StunException("length invalid: " + length);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,7 +52,7 @@ public class DataAttribute
|
|||||||
private final boolean padding;
|
private final boolean padding;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of this class with padding enabled.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
protected DataAttribute()
|
protected DataAttribute()
|
||||||
{
|
{
|
||||||
@ -60,9 +60,7 @@ public class DataAttribute
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of this class.
|
* Constructor.
|
||||||
* @param padding true to pad the data if the length is not on a word
|
|
||||||
* boundary.
|
|
||||||
*/
|
*/
|
||||||
protected DataAttribute(boolean padding)
|
protected DataAttribute(boolean padding)
|
||||||
{
|
{
|
||||||
@ -172,7 +170,8 @@ public class DataAttribute
|
|||||||
|
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof DataAttribute))
|
if (! (obj instanceof DataAttribute)
|
||||||
|
|| obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
|
|||||||
@ -54,8 +54,11 @@ public class DontFragmentAttribute extends Attribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof DontFragmentAttribute))
|
if (! (obj instanceof DontFragmentAttribute)
|
||||||
|
|| obj == null)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -112,7 +115,7 @@ public class DontFragmentAttribute extends Attribute
|
|||||||
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
||||||
throws StunException
|
throws StunException
|
||||||
{
|
{
|
||||||
if (length != 0)
|
if(length != 0)
|
||||||
{
|
{
|
||||||
throw new StunException("length invalid");
|
throw new StunException("length invalid");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -288,7 +288,7 @@ public class ErrorCodeAttribute extends Attribute
|
|||||||
public void setErrorClass(byte errorClass)
|
public void setErrorClass(byte errorClass)
|
||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (errorClass < 0 || errorClass > 99)
|
if(errorClass < 0 || errorClass > 99)
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
errorClass + " is not a valid error number!");
|
errorClass + " is not a valid error number!");
|
||||||
this.errorClass = errorClass;
|
this.errorClass = errorClass;
|
||||||
@ -415,7 +415,7 @@ public class ErrorCodeAttribute extends Attribute
|
|||||||
*/
|
*/
|
||||||
public String getReasonPhrase()
|
public String getReasonPhrase()
|
||||||
{
|
{
|
||||||
if (reasonPhrase == null)
|
if(reasonPhrase == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return new String(reasonPhrase);
|
return new String(reasonPhrase);
|
||||||
@ -472,7 +472,7 @@ public class ErrorCodeAttribute extends Attribute
|
|||||||
binValue[6] = getErrorClass();
|
binValue[6] = getErrorClass();
|
||||||
binValue[7] = getErrorNumber();
|
binValue[7] = getErrorNumber();
|
||||||
|
|
||||||
if (reasonPhrase != null)
|
if(reasonPhrase != null)
|
||||||
System.arraycopy(reasonPhrase, 0, binValue, 8, reasonPhrase.length);
|
System.arraycopy(reasonPhrase, 0, binValue, 8, reasonPhrase.length);
|
||||||
|
|
||||||
return binValue;
|
return binValue;
|
||||||
@ -488,7 +488,8 @@ public class ErrorCodeAttribute extends Attribute
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof ErrorCodeAttribute))
|
if (! (obj instanceof ErrorCodeAttribute)
|
||||||
|
|| obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
|
|||||||
@ -24,8 +24,8 @@ import org.ice4j.*;
|
|||||||
* server to allocate an even port and optionally allocate
|
* server to allocate an even port and optionally allocate
|
||||||
* the next higher port number.
|
* the next higher port number.
|
||||||
*
|
*
|
||||||
* There is one flag supported: <br>
|
* There are one flag supported : <br/>
|
||||||
* R : ask to reserve a second port.
|
* R : ask to reserve a second port.<br/>
|
||||||
*
|
*
|
||||||
* @author Sebastien Vincent
|
* @author Sebastien Vincent
|
||||||
*/
|
*/
|
||||||
@ -62,7 +62,8 @@ public class EvenPortAttribute extends Attribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof EvenPortAttribute))
|
if (! (obj instanceof EvenPortAttribute)
|
||||||
|
|| obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
@ -132,7 +133,7 @@ public class EvenPortAttribute extends Attribute
|
|||||||
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
||||||
throws StunException
|
throws StunException
|
||||||
{
|
{
|
||||||
if (length != 4)
|
if(length != 4)
|
||||||
{
|
{
|
||||||
throw new StunException("length invalid");
|
throw new StunException("length invalid");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -122,7 +122,7 @@ public class FingerprintAttribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof FingerprintAttribute))
|
if (! (obj instanceof FingerprintAttribute) || obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
@ -212,7 +212,7 @@ public class FingerprintAttribute
|
|||||||
char length)
|
char length)
|
||||||
throws StunException
|
throws StunException
|
||||||
{
|
{
|
||||||
if (length != 4)
|
if(length != 4)
|
||||||
{
|
{
|
||||||
throw new StunException("length invalid");
|
throw new StunException("length invalid");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -125,14 +125,15 @@ public abstract class IceControlAttribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (!(obj instanceof IceControlAttribute))
|
if(!(obj instanceof IceControlAttribute)
|
||||||
|
|| obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if(obj == this)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
IceControlAttribute iceControlAtt = (IceControlAttribute)obj;
|
IceControlAttribute iceControlAtt = (IceControlAttribute)obj;
|
||||||
if (iceControlAtt.getAttributeType() != getAttributeType()
|
if(iceControlAtt.getAttributeType() != getAttributeType()
|
||||||
|| iceControlAtt.isControlling != isControlling
|
|| iceControlAtt.isControlling != isControlling
|
||||||
|| iceControlAtt.getDataLength() != DATA_LENGTH_ICE_CONTROL
|
|| iceControlAtt.getDataLength() != DATA_LENGTH_ICE_CONTROL
|
||||||
|| getTieBreaker() != iceControlAtt.getTieBreaker())
|
|| getTieBreaker() != iceControlAtt.getTieBreaker())
|
||||||
|
|||||||
@ -61,7 +61,8 @@ public class LifetimeAttribute
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof LifetimeAttribute))
|
if (! (obj instanceof LifetimeAttribute)
|
||||||
|
|| obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
@ -138,7 +139,7 @@ public class LifetimeAttribute
|
|||||||
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
||||||
throws StunException
|
throws StunException
|
||||||
{
|
{
|
||||||
if (length != 4)
|
if(length != 4)
|
||||||
{
|
{
|
||||||
throw new StunException("length invalid");
|
throw new StunException("length invalid");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -83,7 +83,8 @@ public class MagicCookieAttribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof MagicCookieAttribute))
|
if (! (obj instanceof LifetimeAttribute)
|
||||||
|
|| obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
@ -138,7 +139,7 @@ public class MagicCookieAttribute
|
|||||||
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
||||||
throws StunException
|
throws StunException
|
||||||
{
|
{
|
||||||
if (length != 4)
|
if(length != 4)
|
||||||
{
|
{
|
||||||
throw new StunException("length invalid");
|
throw new StunException("length invalid");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,6 @@
|
|||||||
package org.ice4j.attribute;
|
package org.ice4j.attribute;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.*;
|
|
||||||
|
|
||||||
import javax.crypto.*;
|
import javax.crypto.*;
|
||||||
import javax.crypto.spec.*;
|
import javax.crypto.spec.*;
|
||||||
@ -38,6 +37,7 @@ import org.ice4j.stack.*;
|
|||||||
* The key for the HMAC depends on whether long-term or short-term
|
* The key for the HMAC depends on whether long-term or short-term
|
||||||
* credentials are in use. For long-term credentials, the key is 16
|
* credentials are in use. For long-term credentials, the key is 16
|
||||||
* bytes:
|
* bytes:
|
||||||
|
* <p>
|
||||||
* <pre>
|
* <pre>
|
||||||
* key = MD5(username ":" realm ":" SASLprep(password))
|
* key = MD5(username ":" realm ":" SASLprep(password))
|
||||||
* </pre>
|
* </pre>
|
||||||
@ -54,6 +54,7 @@ import org.ice4j.stack.*;
|
|||||||
* 0x8493fbc53ba582fb4c044c456bdc40eb.
|
* 0x8493fbc53ba582fb4c044c456bdc40eb.
|
||||||
* <p>
|
* <p>
|
||||||
* For short-term credentials:
|
* For short-term credentials:
|
||||||
|
* <p>
|
||||||
* <pre>
|
* <pre>
|
||||||
* key = SASLprep(password)
|
* key = SASLprep(password)
|
||||||
* </pre>
|
* </pre>
|
||||||
@ -87,13 +88,6 @@ public class MessageIntegrityAttribute
|
|||||||
extends Attribute
|
extends Attribute
|
||||||
implements ContentDependentAttribute
|
implements ContentDependentAttribute
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* The <tt>Logger</tt> used by the <tt>Message</tt> class and its instances
|
|
||||||
* for logging output.
|
|
||||||
*/
|
|
||||||
private static final Logger logger
|
|
||||||
= Logger.getLogger(MessageIntegrityAttribute.class.getName());
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attribute name.
|
* Attribute name.
|
||||||
*/
|
*/
|
||||||
@ -288,32 +282,26 @@ public class MessageIntegrityAttribute
|
|||||||
binValue[3] = (byte)(getDataLength() & 0x00FF);
|
binValue[3] = (byte)(getDataLength() & 0x00FF);
|
||||||
|
|
||||||
byte[] key = null;
|
byte[] key = null;
|
||||||
char msgType =
|
char msgType = (char)((content[0] << 8) + content[1]);
|
||||||
(char) (((content[0] & 0xFF) << 8) | (content[1] & 0xFF));
|
|
||||||
|
|
||||||
if (Message.isRequestType(msgType))
|
if(Message.isRequestType(msgType))
|
||||||
{
|
{
|
||||||
/* attribute part of a request, use the remote key */
|
/* attribute part of a request, use the remote key */
|
||||||
key
|
key = stunStack.getCredentialsManager().getRemoteKey(username,
|
||||||
= stunStack.getCredentialsManager()
|
media);
|
||||||
.getRemoteKey(username, media);
|
|
||||||
}
|
}
|
||||||
else if (Message.isResponseType(msgType))
|
else if(Message.isSuccessResponseType(msgType) ||
|
||||||
|
Message.isErrorResponseType(msgType))
|
||||||
{
|
{
|
||||||
/* attribute part of a response, use the local key */
|
/* attribute part of a response, use the local key */
|
||||||
key = stunStack.getCredentialsManager().getLocalKey(username);
|
key = stunStack.getCredentialsManager().getLocalKey(username);
|
||||||
}
|
}
|
||||||
else // msgType is Indication
|
|
||||||
{
|
|
||||||
logger.warning("Can not encode a message of type Indication.");
|
|
||||||
}
|
|
||||||
|
|
||||||
Objects.requireNonNull(key, "key=null; msgType=" + String.format("%04X", (int)msgType));
|
|
||||||
//now calculate the HMAC-SHA1
|
//now calculate the HMAC-SHA1
|
||||||
this.hmacSha1Content = calculateHmacSha1(content, offset, length, key);
|
this.hmacSha1Content = calculateHmacSha1(content, offset, length, key);
|
||||||
|
|
||||||
//username
|
//username
|
||||||
System.arraycopy(hmacSha1Content, 0, binValue, HEADER_LENGTH, getDataLength());
|
System.arraycopy(hmacSha1Content, 0, binValue, 4, getDataLength());
|
||||||
|
|
||||||
return binValue;
|
return binValue;
|
||||||
}
|
}
|
||||||
@ -347,7 +335,7 @@ public class MessageIntegrityAttribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof MessageIntegrityAttribute))
|
if (! (obj instanceof MessageIntegrityAttribute) || obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
|
|||||||
@ -134,7 +134,8 @@ public class OptionalAttribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof OptionalAttribute) )
|
if(obj == null
|
||||||
|
|| !(obj instanceof OptionalAttribute) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|||||||
@ -118,7 +118,8 @@ public class PriorityAttribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof PriorityAttribute))
|
if (! (obj instanceof PriorityAttribute)
|
||||||
|
|| obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
@ -174,7 +175,7 @@ public class PriorityAttribute
|
|||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
/* Priority must be between 1 and (2^31 - 1) */
|
/* Priority must be between 1 and (2^31 - 1) */
|
||||||
if (priority <= 0 || priority > 0x7FFFFFFFL)
|
if(priority <= 0 || priority > 0x7FFFFFFFL)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("Priority must be " +
|
throw new IllegalArgumentException("Priority must be " +
|
||||||
"between 0 and (2**31 - 1)");
|
"between 0 and (2**31 - 1)");
|
||||||
|
|||||||
@ -141,7 +141,7 @@ public class RealmAttribute extends Attribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof RealmAttribute))
|
if (! (obj instanceof RealmAttribute) || obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
|
|||||||
@ -144,14 +144,14 @@ public class RequestedAddressFamilyAttribute extends Attribute
|
|||||||
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
||||||
throws StunException
|
throws StunException
|
||||||
{
|
{
|
||||||
if (length != DATA_LENGTH)
|
if(length != DATA_LENGTH)
|
||||||
{
|
{
|
||||||
throw new StunException("length invalid: " + length);
|
throw new StunException("length invalid: " + length);
|
||||||
}
|
}
|
||||||
|
|
||||||
family = (char)(attributeValue[offset] & 0xff);
|
family = (char)(attributeValue[offset] & 0xff);
|
||||||
|
|
||||||
if (family != IPv4 && family != IPv6)
|
if(family != IPv4 && family != IPv6)
|
||||||
{
|
{
|
||||||
// instead throw TurnException
|
// instead throw TurnException
|
||||||
throw new StunException("invalid family value: " + family);
|
throw new StunException("invalid family value: " + family);
|
||||||
@ -174,7 +174,7 @@ public class RequestedAddressFamilyAttribute extends Attribute
|
|||||||
*/
|
*/
|
||||||
public boolean setFamily(char family)
|
public boolean setFamily(char family)
|
||||||
{
|
{
|
||||||
if (family == IPv4 || family == IPv6)
|
if(family == IPv4 || family == IPv6)
|
||||||
{
|
{
|
||||||
this.family = family;
|
this.family = family;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -70,7 +70,8 @@ public class RequestedTransportAttribute extends Attribute
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof RequestedTransportAttribute))
|
if (! (obj instanceof RequestedTransportAttribute)
|
||||||
|
|| obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
@ -147,7 +148,7 @@ public class RequestedTransportAttribute extends Attribute
|
|||||||
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
||||||
throws StunException
|
throws StunException
|
||||||
{
|
{
|
||||||
if (length != 4)
|
if(length != 4)
|
||||||
{
|
{
|
||||||
throw new StunException("length invalid");
|
throw new StunException("length invalid");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,7 +75,7 @@ public class ReservationTokenAttribute
|
|||||||
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
||||||
throws StunException
|
throws StunException
|
||||||
{
|
{
|
||||||
if (length != 8)
|
if(length != 8)
|
||||||
{
|
{
|
||||||
throw new StunException("Length mismatch!");
|
throw new StunException("Length mismatch!");
|
||||||
}
|
}
|
||||||
@ -189,12 +189,12 @@ public class ReservationTokenAttribute
|
|||||||
private static void generateReservationTokenAttribute(
|
private static void generateReservationTokenAttribute(
|
||||||
ReservationTokenAttribute token, int nb)
|
ReservationTokenAttribute token, int nb)
|
||||||
{
|
{
|
||||||
long left = System.currentTimeMillis(); // the first nb/2 bytes of the
|
long left = System.currentTimeMillis();// the first nb/2 bytes of the
|
||||||
// token
|
// token
|
||||||
long right = random.nextLong(); // the last nb/2 bytes of the token
|
long right = random.nextLong();// the last nb/2 bytes of the token
|
||||||
int b = nb / 2;
|
int b = nb / 2;
|
||||||
|
|
||||||
for (int i = 0; i < b; i++)
|
for(int i = 0; i < b; i++)
|
||||||
{
|
{
|
||||||
token.reservationToken[i] = (byte)((left >> (i * 8)) & 0xFFL);
|
token.reservationToken[i] = (byte)((left >> (i * 8)) & 0xFFL);
|
||||||
token.reservationToken[i + b] = (byte)((right >> (i * 8)) & 0xFFL);
|
token.reservationToken[i + b] = (byte)((right >> (i * 8)) & 0xFFL);
|
||||||
@ -216,7 +216,8 @@ public class ReservationTokenAttribute
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof ReservationTokenAttribute))
|
if (! (obj instanceof ReservationTokenAttribute)
|
||||||
|
|| obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
|
|||||||
@ -151,7 +151,8 @@ public class SoftwareAttribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof SoftwareAttribute))
|
if (! (obj instanceof SoftwareAttribute)
|
||||||
|
|| obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
|
|||||||
@ -84,7 +84,7 @@ public class UnknownAttributesAttribute extends Attribute
|
|||||||
{
|
{
|
||||||
char len = (char)unknownAttributes.size();
|
char len = (char)unknownAttributes.size();
|
||||||
|
|
||||||
if ( (len % 2 ) != 0 )
|
if( (len % 2 ) != 0 )
|
||||||
len++;
|
len++;
|
||||||
|
|
||||||
return (char)(len * 2);
|
return (char)(len * 2);
|
||||||
@ -99,7 +99,7 @@ public class UnknownAttributesAttribute extends Attribute
|
|||||||
{
|
{
|
||||||
//some attributes may be repeated for padding
|
//some attributes may be repeated for padding
|
||||||
//(packet length should be divisable by 4)
|
//(packet length should be divisable by 4)
|
||||||
if (!contains(attributeID))
|
if(!contains(attributeID))
|
||||||
unknownAttributes.add(attributeID);
|
unknownAttributes.add(attributeID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ public class UnknownAttributesAttribute extends Attribute
|
|||||||
// If the number of unknown attributes is an odd number, one of the
|
// If the number of unknown attributes is an odd number, one of the
|
||||||
// attributes MUST be repeated in the list, so that the total length of
|
// attributes MUST be repeated in the list, so that the total length of
|
||||||
// the list is a multiple of 4 bytes.
|
// the list is a multiple of 4 bytes.
|
||||||
if (offset < binValue.length)
|
if(offset < binValue.length)
|
||||||
{
|
{
|
||||||
char att = getAttribute(0);
|
char att = getAttribute(0);
|
||||||
binValue[offset++] = (byte) (att >> 8);
|
binValue[offset++] = (byte) (att >> 8);
|
||||||
@ -191,7 +191,8 @@ public class UnknownAttributesAttribute extends Attribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof UnknownAttributesAttribute))
|
if (! (obj instanceof UnknownAttributesAttribute)
|
||||||
|
|| obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
@ -221,15 +222,15 @@ public class UnknownAttributesAttribute extends Attribute
|
|||||||
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
||||||
throws StunException
|
throws StunException
|
||||||
{
|
{
|
||||||
if ( (length % 2 ) != 0)
|
if( (length % 2 ) != 0)
|
||||||
throw new StunException("Attribute IDs are 2 bytes long and the "
|
throw new StunException("Attribute IDs are 2 bytes long and the "
|
||||||
+ "passed binary array has an odd length " +
|
+ "passed binary array has an odd length " +
|
||||||
"value.");
|
"value.");
|
||||||
char originalOffset = offset;
|
char originalOffset = offset;
|
||||||
for (int i = offset; i < originalOffset + length; i += 2)
|
for(int i = offset; i < originalOffset + length; i += 2)
|
||||||
{
|
{
|
||||||
char attributeID = (char) (((attributeValue[offset++] & 0xFF) << 8)
|
char attributeID = (char)( (attributeValue[offset++] << 8) |
|
||||||
| (attributeValue[offset++] & 0xFF));
|
(attributeValue[offset++]) );
|
||||||
addAttributeID(attributeID);
|
addAttributeID(attributeID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -89,14 +89,15 @@ public class UseCandidateAttribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (!(obj instanceof UseCandidateAttribute))
|
if(!(obj instanceof UseCandidateAttribute)
|
||||||
|
|| obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if(obj == this)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
UseCandidateAttribute useCandidateAtt = (UseCandidateAttribute)obj;
|
UseCandidateAttribute useCandidateAtt = (UseCandidateAttribute)obj;
|
||||||
if (useCandidateAtt.getAttributeType() != getAttributeType()
|
if(useCandidateAtt.getAttributeType() != getAttributeType()
|
||||||
|| useCandidateAtt.getDataLength() != getDataLength())
|
|| useCandidateAtt.getDataLength() != getDataLength())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@ -56,7 +56,6 @@ public class UsernameAttribute extends Attribute
|
|||||||
* offset is equal to the index of the first byte after length)
|
* offset is equal to the index of the first byte after length)
|
||||||
* @param length the length of the binary array.
|
* @param length the length of the binary array.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
||||||
{
|
{
|
||||||
username = new byte[length];
|
username = new byte[length];
|
||||||
@ -148,7 +147,7 @@ public class UsernameAttribute extends Attribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof UsernameAttribute))
|
if (! (obj instanceof UsernameAttribute) || obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
|
|||||||
@ -102,7 +102,7 @@ public class XorMappedAddressAttribute
|
|||||||
|
|
||||||
port ^= portModifier;
|
port ^= portModifier;
|
||||||
|
|
||||||
for (int i = 0; i < addressBytes.length; i++)
|
for(int i = 0; i < addressBytes.length; i++)
|
||||||
addressBytes[i] ^= transactionID[i];
|
addressBytes[i] ^= transactionID[i];
|
||||||
|
|
||||||
TransportAddress xoredAdd;
|
TransportAddress xoredAdd;
|
||||||
|
|||||||
@ -111,7 +111,8 @@ public class XorOnlyAttribute
|
|||||||
|
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof XorOnlyAttribute))
|
if (! (obj instanceof XorOnlyAttribute)
|
||||||
|
|| obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -438,17 +438,17 @@ public abstract class Candidate<T extends Candidate<?>>
|
|||||||
/* Google Talk priority is in range 0 - 1, we multiply this by 1000
|
/* Google Talk priority is in range 0 - 1, we multiply this by 1000
|
||||||
* to have a long rather than float
|
* to have a long rather than float
|
||||||
*/
|
*/
|
||||||
if (candidateType == CandidateType.HOST_CANDIDATE)
|
if(candidateType == CandidateType.HOST_CANDIDATE)
|
||||||
{
|
{
|
||||||
priority += 0.95 * 1000 -
|
priority += 0.95 * 1000 -
|
||||||
(this.getBase().getTransport() == Transport.TCP ? 200 : 0);
|
(this.getBase().getTransport() == Transport.TCP ? 200 : 0);
|
||||||
}
|
}
|
||||||
else if (candidateType == CandidateType.PEER_REFLEXIVE_CANDIDATE)
|
else if(candidateType == CandidateType.PEER_REFLEXIVE_CANDIDATE)
|
||||||
{
|
{
|
||||||
priority += (long)(0.9 * 1000) -
|
priority += (long)(0.9 * 1000) -
|
||||||
(this.getBase().getTransport() == Transport.TCP ? 200 : 0);
|
(this.getBase().getTransport() == Transport.TCP ? 200 : 0);
|
||||||
}
|
}
|
||||||
else if (candidateType == CandidateType.SERVER_REFLEXIVE_CANDIDATE)
|
else if(candidateType == CandidateType.SERVER_REFLEXIVE_CANDIDATE)
|
||||||
{
|
{
|
||||||
priority += (long)(0.9 * 1000);
|
priority += (long)(0.9 * 1000);
|
||||||
}
|
}
|
||||||
@ -462,9 +462,9 @@ public abstract class Candidate<T extends Candidate<?>>
|
|||||||
InetAddress addr = getTransportAddress().getAddress();
|
InetAddress addr = getTransportAddress().getAddress();
|
||||||
|
|
||||||
// IPv6 has better priority than IPv4
|
// IPv6 has better priority than IPv4
|
||||||
if (addr instanceof Inet6Address)
|
if(addr instanceof Inet6Address)
|
||||||
{
|
{
|
||||||
if (addr.isLinkLocalAddress())
|
if(addr.isLinkLocalAddress())
|
||||||
{
|
{
|
||||||
priority += 40;
|
priority += 40;
|
||||||
}
|
}
|
||||||
@ -499,15 +499,15 @@ public abstract class Candidate<T extends Candidate<?>>
|
|||||||
{
|
{
|
||||||
int typePreference;
|
int typePreference;
|
||||||
|
|
||||||
if (candidateType == CandidateType.HOST_CANDIDATE)
|
if(candidateType == CandidateType.HOST_CANDIDATE)
|
||||||
{
|
{
|
||||||
typePreference = MAX_TYPE_PREFERENCE; // 126
|
typePreference = MAX_TYPE_PREFERENCE; // 126
|
||||||
}
|
}
|
||||||
else if (candidateType == CandidateType.PEER_REFLEXIVE_CANDIDATE)
|
else if(candidateType == CandidateType.PEER_REFLEXIVE_CANDIDATE)
|
||||||
{
|
{
|
||||||
typePreference = 110;
|
typePreference = 110;
|
||||||
}
|
}
|
||||||
else if (candidateType == CandidateType.SERVER_REFLEXIVE_CANDIDATE)
|
else if(candidateType == CandidateType.SERVER_REFLEXIVE_CANDIDATE)
|
||||||
{
|
{
|
||||||
typePreference = 100;
|
typePreference = 100;
|
||||||
}
|
}
|
||||||
@ -540,13 +540,13 @@ public abstract class Candidate<T extends Candidate<?>>
|
|||||||
{
|
{
|
||||||
//The ICE spec says: When there is only a single IP address, this value
|
//The ICE spec says: When there is only a single IP address, this value
|
||||||
//SHOULD be set to.
|
//SHOULD be set to.
|
||||||
if (getParentComponent().countLocalHostCandidates() < 2)
|
if(getParentComponent().countLocalHostCandidates() < 2)
|
||||||
return MAX_LOCAL_PREFERENCE;
|
return MAX_LOCAL_PREFERENCE;
|
||||||
|
|
||||||
//The ICE spec also says: Furthermore, if an agent is multi-homed and
|
//The ICE spec also says: Furthermore, if an agent is multi-homed and
|
||||||
//has multiple IP addresses, the local preference for host candidates
|
//has multiple IP addresses, the local preference for host candidates
|
||||||
//from a VPN interface SHOULD have a priority of 0.
|
//from a VPN interface SHOULD have a priority of 0.
|
||||||
if (isVirtual())
|
if(isVirtual())
|
||||||
return MIN_LOCAL_PREFERENCE;
|
return MIN_LOCAL_PREFERENCE;
|
||||||
|
|
||||||
InetAddress addr = getTransportAddress().getAddress();
|
InetAddress addr = getTransportAddress().getAddress();
|
||||||
@ -556,10 +556,10 @@ public abstract class Candidate<T extends Candidate<?>>
|
|||||||
//Johnnie seems to think.
|
//Johnnie seems to think.
|
||||||
|
|
||||||
//prefer IPv6 to IPv4
|
//prefer IPv6 to IPv4
|
||||||
if (addr instanceof Inet6Address)
|
if(addr instanceof Inet6Address)
|
||||||
{
|
{
|
||||||
//prefer link local addresses to global ones
|
//prefer link local addresses to global ones
|
||||||
if (addr.isLinkLocalAddress())
|
if(addr.isLinkLocalAddress())
|
||||||
return 30;
|
return 30;
|
||||||
else
|
else
|
||||||
return 40;
|
return 40;
|
||||||
@ -719,7 +719,7 @@ public abstract class Candidate<T extends Candidate<?>>
|
|||||||
*/
|
*/
|
||||||
public TransportAddress getRelatedAddress()
|
public TransportAddress getRelatedAddress()
|
||||||
{
|
{
|
||||||
if (getRelatedCandidate() != null)
|
if(getRelatedCandidate() != null)
|
||||||
{
|
{
|
||||||
return getRelatedCandidate().getTransportAddress();
|
return getRelatedCandidate().getTransportAddress();
|
||||||
}
|
}
|
||||||
@ -770,7 +770,7 @@ public abstract class Candidate<T extends Candidate<?>>
|
|||||||
|
|
||||||
TransportAddress relAddr = getRelatedAddress();
|
TransportAddress relAddr = getRelatedAddress();
|
||||||
|
|
||||||
if (relAddr != null)
|
if(relAddr != null)
|
||||||
{
|
{
|
||||||
buff.append(" raddr ").append(relAddr.getHostAddress());
|
buff.append(" raddr ").append(relAddr.getHostAddress());
|
||||||
buff.append(" rport ").append(relAddr.getPort());
|
buff.append(" rport ").append(relAddr.getPort());
|
||||||
@ -873,19 +873,19 @@ public abstract class Candidate<T extends Candidate<?>>
|
|||||||
switch (getType())
|
switch (getType())
|
||||||
{
|
{
|
||||||
case SERVER_REFLEXIVE_CANDIDATE:
|
case SERVER_REFLEXIVE_CANDIDATE:
|
||||||
if (getBase() != null)
|
if(getBase() != null)
|
||||||
{
|
{
|
||||||
return getBase().getHostAddress();
|
return getBase().getHostAddress();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PEER_REFLEXIVE_CANDIDATE:
|
case PEER_REFLEXIVE_CANDIDATE:
|
||||||
if (getBase() != null)
|
if(getBase() != null)
|
||||||
{
|
{
|
||||||
return getBase().getHostAddress();
|
return getBase().getHostAddress();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RELAYED_CANDIDATE:
|
case RELAYED_CANDIDATE:
|
||||||
if (getRelatedCandidate() != null)
|
if(getRelatedCandidate() != null)
|
||||||
{
|
{
|
||||||
return getRelatedCandidate().getHostAddress();
|
return getRelatedCandidate().getHostAddress();
|
||||||
}
|
}
|
||||||
@ -912,7 +912,7 @@ public abstract class Candidate<T extends Candidate<?>>
|
|||||||
return getTransportAddress();
|
return getTransportAddress();
|
||||||
case RELAYED_CANDIDATE:
|
case RELAYED_CANDIDATE:
|
||||||
// Corresponding to getMappedAddress();
|
// Corresponding to getMappedAddress();
|
||||||
if (getRelatedCandidate() != null)
|
if(getRelatedCandidate() != null)
|
||||||
{
|
{
|
||||||
return getRelatedCandidate().getReflexiveAddress();
|
return getRelatedCandidate().getReflexiveAddress();
|
||||||
}
|
}
|
||||||
@ -965,19 +965,19 @@ public abstract class Candidate<T extends Candidate<?>>
|
|||||||
*/
|
*/
|
||||||
public T getRelatedCandidate()
|
public T getRelatedCandidate()
|
||||||
{
|
{
|
||||||
if (this.relatedCandidate == null)
|
if(this.relatedCandidate == null)
|
||||||
{
|
{
|
||||||
TransportAddress relatedAddress = null;
|
TransportAddress relatedAddress = null;
|
||||||
switch (getType())
|
switch (getType())
|
||||||
{
|
{
|
||||||
case SERVER_REFLEXIVE_CANDIDATE:
|
case SERVER_REFLEXIVE_CANDIDATE:
|
||||||
if (getBase() != null)
|
if(getBase() != null)
|
||||||
{
|
{
|
||||||
relatedAddress = getBase().getTransportAddress();
|
relatedAddress = getBase().getTransportAddress();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PEER_REFLEXIVE_CANDIDATE:
|
case PEER_REFLEXIVE_CANDIDATE:
|
||||||
if (getBase() != null)
|
if(getBase() != null)
|
||||||
{
|
{
|
||||||
relatedAddress = getBase().getTransportAddress();
|
relatedAddress = getBase().getTransportAddress();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -122,25 +122,25 @@ public enum CandidateExtendedType
|
|||||||
public static CandidateExtendedType parse(String extendedTypeName)
|
public static CandidateExtendedType parse(String extendedTypeName)
|
||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (HOST_CANDIDATE.toString().equals(extendedTypeName))
|
if(HOST_CANDIDATE.toString().equals(extendedTypeName))
|
||||||
return HOST_CANDIDATE;
|
return HOST_CANDIDATE;
|
||||||
else if (UPNP_CANDIDATE.toString().equals(extendedTypeName))
|
else if(UPNP_CANDIDATE.toString().equals(extendedTypeName))
|
||||||
return UPNP_CANDIDATE;
|
return UPNP_CANDIDATE;
|
||||||
else if (STUN_PEER_REFLEXIVE_CANDIDATE.toString().equals(
|
else if(STUN_PEER_REFLEXIVE_CANDIDATE.toString().equals(
|
||||||
extendedTypeName))
|
extendedTypeName))
|
||||||
return STUN_PEER_REFLEXIVE_CANDIDATE;
|
return STUN_PEER_REFLEXIVE_CANDIDATE;
|
||||||
else if (STUN_SERVER_REFLEXIVE_CANDIDATE.toString().equals(
|
else if(STUN_SERVER_REFLEXIVE_CANDIDATE.toString().equals(
|
||||||
extendedTypeName))
|
extendedTypeName))
|
||||||
return STUN_SERVER_REFLEXIVE_CANDIDATE;
|
return STUN_SERVER_REFLEXIVE_CANDIDATE;
|
||||||
else if (TURN_RELAYED_CANDIDATE.toString().equals(extendedTypeName))
|
else if(TURN_RELAYED_CANDIDATE.toString().equals(extendedTypeName))
|
||||||
return TURN_RELAYED_CANDIDATE;
|
return TURN_RELAYED_CANDIDATE;
|
||||||
else if (GOOGLE_TURN_RELAYED_CANDIDATE.toString().equals(
|
else if(GOOGLE_TURN_RELAYED_CANDIDATE.toString().equals(
|
||||||
extendedTypeName))
|
extendedTypeName))
|
||||||
return GOOGLE_TURN_RELAYED_CANDIDATE;
|
return GOOGLE_TURN_RELAYED_CANDIDATE;
|
||||||
else if (GOOGLE_TCP_TURN_RELAYED_CANDIDATE.toString().equals(
|
else if(GOOGLE_TCP_TURN_RELAYED_CANDIDATE.toString().equals(
|
||||||
extendedTypeName))
|
extendedTypeName))
|
||||||
return GOOGLE_TCP_TURN_RELAYED_CANDIDATE;
|
return GOOGLE_TCP_TURN_RELAYED_CANDIDATE;
|
||||||
else if (JINGLE_NODE_CANDIDATE.toString().equals(extendedTypeName))
|
else if(JINGLE_NODE_CANDIDATE.toString().equals(extendedTypeName))
|
||||||
return JINGLE_NODE_CANDIDATE;
|
return JINGLE_NODE_CANDIDATE;
|
||||||
|
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
|||||||
@ -111,8 +111,8 @@ public class CandidatePair
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link TransactionID} of the client transaction for a connectivity
|
* The {@link TransactionID} of the client transaction for a connectivity
|
||||||
* check over this pair in case it is in the
|
* check over this pair in case it is in the {@link CandidatePairState#
|
||||||
* {@link CandidatePairState#IN_PROGRESS} state.
|
* IN_PROGRESS} state.
|
||||||
*/
|
*/
|
||||||
private TransactionID connCheckTranID = null;
|
private TransactionID connCheckTranID = null;
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ public class CandidatePair
|
|||||||
* @param localCnd the local <tt>Candidate</tt> of this
|
* @param localCnd the local <tt>Candidate</tt> of this
|
||||||
* <tt>CandidatePair</tt>.
|
* <tt>CandidatePair</tt>.
|
||||||
*/
|
*/
|
||||||
protected void setLocalCandidate(LocalCandidate localCnd)
|
protected void setLocalCandidate( LocalCandidate localCnd)
|
||||||
{
|
{
|
||||||
this.localCandidate = localCnd;
|
this.localCandidate = localCnd;
|
||||||
}
|
}
|
||||||
@ -290,13 +290,13 @@ public class CandidatePair
|
|||||||
|
|
||||||
this.state = newState;
|
this.state = newState;
|
||||||
|
|
||||||
if (newState == CandidatePairState.IN_PROGRESS)
|
if(newState == CandidatePairState.IN_PROGRESS)
|
||||||
{
|
{
|
||||||
if (tranID == null)
|
if (tranID == null)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Putting a pair into the In-Progress state MUST be"
|
"Putting a pair into the In-Progress state MUST be"
|
||||||
+ " accompanied with the TransactionID of the"
|
+ " accomapnied with the TransactionID of the"
|
||||||
+ " connectivity check.");
|
+ " connectivity check.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -367,7 +367,7 @@ public class CandidatePair
|
|||||||
* agent. Let D be the priority for the candidate provided by the
|
* agent. Let D be the priority for the candidate provided by the
|
||||||
* controlled agent. The priority for a pair is computed as:
|
* controlled agent. The priority for a pair is computed as:
|
||||||
* <p>
|
* <p>
|
||||||
* <i>pair priority = 2^32*MIN(G,D) + 2*MAX(G,D) + (G>D?1:0)</i>
|
* <i>pair priority = 2^32*MIN(G,D) + 2*MAX(G,D) + (G>D?1:0)</i>
|
||||||
* <p>
|
* <p>
|
||||||
* This formula ensures a unique priority for each pair. Once the priority
|
* This formula ensures a unique priority for each pair. Once the priority
|
||||||
* is assigned, the agent sorts the candidate pairs in decreasing order of
|
* is assigned, the agent sorts the candidate pairs in decreasing order of
|
||||||
@ -443,7 +443,7 @@ public class CandidatePair
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof CandidatePair))
|
if ((obj == null) || !(obj instanceof CandidatePair))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
CandidatePair candidatePair = (CandidatePair) obj;
|
CandidatePair candidatePair = (CandidatePair) obj;
|
||||||
@ -723,7 +723,6 @@ public class CandidatePair
|
|||||||
* @return the UDP <tt>DatagramSocket</tt> (if any) for this
|
* @return the UDP <tt>DatagramSocket</tt> (if any) for this
|
||||||
* <tt>CandidatePair</tt>.
|
* <tt>CandidatePair</tt>.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public DatagramSocket getDatagramSocket()
|
public DatagramSocket getDatagramSocket()
|
||||||
{
|
{
|
||||||
IceSocketWrapper wrapper = getIceSocketWrapper();
|
IceSocketWrapper wrapper = getIceSocketWrapper();
|
||||||
@ -734,28 +733,18 @@ public class CandidatePair
|
|||||||
* Returns the TCP <tt>Socket</tt> (if any) for this <tt>CandidatePair</tt>.
|
* Returns the TCP <tt>Socket</tt> (if any) for this <tt>CandidatePair</tt>.
|
||||||
* @return the TCP <tt>Socket</tt> (if any) for this <tt>CandidatePair</tt>.
|
* @return the TCP <tt>Socket</tt> (if any) for this <tt>CandidatePair</tt>.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public Socket getSocket()
|
public Socket getSocket()
|
||||||
{
|
{
|
||||||
return null;
|
IceSocketWrapper wrapper = getIceSocketWrapper();
|
||||||
|
return wrapper == null ? null : wrapper.getTCPSocket();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the <tt>IceSocketWrapper</tt> for this <tt>CandidatePair</tt>.
|
* Returns the <tt>IceSocketWrapper</tt> for this <tt>CandidatePair</tt>.
|
||||||
* @return the <tt>IceSocketWrapper</tt> for this <tt>CandidatePair</tt>.
|
* @return the <tt>IceSocketWrapper</tt> for this <tt>CandidatePair</tt>.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public IceSocketWrapper getIceSocketWrapper()
|
public IceSocketWrapper getIceSocketWrapper()
|
||||||
{
|
{
|
||||||
IceSocketWrapper componentSocket
|
|
||||||
= getParentComponent().getSocketWrapper();
|
|
||||||
// If the merging socket is used, all candidate pairs just refer to the
|
|
||||||
// component.
|
|
||||||
if (componentSocket != null)
|
|
||||||
{
|
|
||||||
return getParentComponent().getSocketWrapper();
|
|
||||||
}
|
|
||||||
|
|
||||||
LocalCandidate localCandidate = getLocalCandidate();
|
LocalCandidate localCandidate = getLocalCandidate();
|
||||||
if (localCandidate == null)
|
if (localCandidate == null)
|
||||||
{
|
{
|
||||||
@ -764,9 +753,7 @@ public class CandidatePair
|
|||||||
|
|
||||||
LocalCandidate base = localCandidate.getBase();
|
LocalCandidate base = localCandidate.getBase();
|
||||||
if (base != null)
|
if (base != null)
|
||||||
{
|
|
||||||
localCandidate = base;
|
localCandidate = base;
|
||||||
}
|
|
||||||
|
|
||||||
RemoteCandidate remoteCandidate = getRemoteCandidate();
|
RemoteCandidate remoteCandidate = getRemoteCandidate();
|
||||||
if (remoteCandidate != null)
|
if (remoteCandidate != null)
|
||||||
@ -774,11 +761,9 @@ public class CandidatePair
|
|||||||
SocketAddress remoteAddress
|
SocketAddress remoteAddress
|
||||||
= remoteCandidate.getTransportAddress();
|
= remoteCandidate.getTransportAddress();
|
||||||
if (remoteAddress != null)
|
if (remoteAddress != null)
|
||||||
{
|
return localCandidate.getIceSocketWrapper(remoteAddress);
|
||||||
return localCandidate.getCandidateIceSocketWrapper(remoteAddress);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return localCandidate.getCandidateIceSocketWrapper();
|
return localCandidate.getIceSocketWrapper();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,12 +79,11 @@ class CandidatePrioritizer
|
|||||||
* <code>comp1.equals(comp2)</code> implies that
|
* <code>comp1.equals(comp2)</code> implies that
|
||||||
* <tt>sgn(comp1.compare(o1, o2))==sgn(comp2.compare(o1, o2))</tt> for
|
* <tt>sgn(comp1.compare(o1, o2))==sgn(comp2.compare(o1, o2))</tt> for
|
||||||
* every object reference <tt>o1</tt> and <tt>o2</tt>.<p>
|
* every object reference <tt>o1</tt> and <tt>o2</tt>.<p>
|
||||||
* <p>
|
* <p/>
|
||||||
* Note that it is <i>always</i> safe <i>not</i> to override
|
* Note that it is <i>always</i> safe <i>not</i> to override
|
||||||
* <tt>Object.equals(Object)</tt>. However, overriding this method may,
|
* <tt>Object.equals(Object)</tt>. However, overriding this method may,
|
||||||
* in some cases, improve performance by allowing programs to determine
|
* in some cases, improve performance by allowing programs to determine
|
||||||
* that two distinct Comparators impose the same order.
|
* that two distinct Comparators impose the same order.
|
||||||
* </p>
|
|
||||||
*
|
*
|
||||||
* @param obj the reference object with which to compare.
|
* @param obj the reference object with which to compare.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -74,8 +74,6 @@ public enum CandidateTcpType
|
|||||||
* Parses the string <tt>candidateTcpTypeName</tt> and return the
|
* Parses the string <tt>candidateTcpTypeName</tt> and return the
|
||||||
* corresponding <tt>CandidateTcpType</tt> instance.
|
* corresponding <tt>CandidateTcpType</tt> instance.
|
||||||
*
|
*
|
||||||
* @param candidateTcpTypeName the string to parse
|
|
||||||
* @return candidateTcpTypeName as an Enum
|
|
||||||
* @throws IllegalArgumentException in case <tt>candidateTcpTypeName</tt> is
|
* @throws IllegalArgumentException in case <tt>candidateTcpTypeName</tt> is
|
||||||
* not a valid or currently supported candidate TCP type.
|
* not a valid or currently supported candidate TCP type.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -123,23 +123,23 @@ public enum CandidateType
|
|||||||
public static CandidateType parse(String candidateTypeName)
|
public static CandidateType parse(String candidateTypeName)
|
||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (PEER_REFLEXIVE_CANDIDATE.toString().equals(candidateTypeName))
|
if(PEER_REFLEXIVE_CANDIDATE.toString().equals(candidateTypeName))
|
||||||
return PEER_REFLEXIVE_CANDIDATE;
|
return PEER_REFLEXIVE_CANDIDATE;
|
||||||
|
|
||||||
if (SERVER_REFLEXIVE_CANDIDATE.toString().equals(candidateTypeName))
|
if(SERVER_REFLEXIVE_CANDIDATE.toString().equals(candidateTypeName))
|
||||||
return SERVER_REFLEXIVE_CANDIDATE;
|
return SERVER_REFLEXIVE_CANDIDATE;
|
||||||
|
|
||||||
if (RELAYED_CANDIDATE.toString().equals(candidateTypeName))
|
if(RELAYED_CANDIDATE.toString().equals(candidateTypeName))
|
||||||
return RELAYED_CANDIDATE;
|
return RELAYED_CANDIDATE;
|
||||||
|
|
||||||
if (HOST_CANDIDATE.toString().equals(candidateTypeName))
|
if(HOST_CANDIDATE.toString().equals(candidateTypeName))
|
||||||
return HOST_CANDIDATE;
|
return HOST_CANDIDATE;
|
||||||
|
|
||||||
// old name but returns the standard name
|
// old name but returns the standard name
|
||||||
if (STUN_CANDIDATE.toString().equals(candidateTypeName))
|
if(STUN_CANDIDATE.toString().equals(candidateTypeName))
|
||||||
return SERVER_REFLEXIVE_CANDIDATE;
|
return SERVER_REFLEXIVE_CANDIDATE;
|
||||||
|
|
||||||
if (LOCAL_CANDIDATE.toString().equals(candidateTypeName))
|
if(LOCAL_CANDIDATE.toString().equals(candidateTypeName))
|
||||||
return HOST_CANDIDATE;
|
return HOST_CANDIDATE;
|
||||||
|
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
|||||||
@ -17,10 +17,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.ice4j.ice;
|
package org.ice4j.ice;
|
||||||
|
|
||||||
import org.jitsi.utils.logging2.*;
|
|
||||||
|
|
||||||
import java.beans.*;
|
import java.beans.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.logging.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A check list is a list of <tt>CandidatePair</tt>s with a state (i.e. a
|
* A check list is a list of <tt>CandidatePair</tt>s with a state (i.e. a
|
||||||
@ -35,23 +34,17 @@ import java.util.*;
|
|||||||
public class CheckList
|
public class CheckList
|
||||||
extends Vector<CandidatePair>
|
extends Vector<CandidatePair>
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* The logger.
|
||||||
|
*/
|
||||||
|
private static final Logger logger =
|
||||||
|
Logger.getLogger(CheckList.class.getName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A dummy serialization id.
|
* A dummy serialization id.
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
|
||||||
* The name of the {@link PropertyChangeEvent} that we use to deliver
|
|
||||||
* changes on the state of this check list.
|
|
||||||
*/
|
|
||||||
public static final String PROPERTY_CHECK_LIST_STATE = "CheckListState";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The name of the {@link PropertyChangeEvent} that we use to deliver
|
|
||||||
* changes on the end of checks of this check list.
|
|
||||||
*/
|
|
||||||
public static final String PROPERTY_CHECK_LIST_CHECKS = "CheckListChecks";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The state of this check list.
|
* The state of this check list.
|
||||||
*/
|
*/
|
||||||
@ -85,9 +78,16 @@ public class CheckList
|
|||||||
= new LinkedList<>();
|
= new LinkedList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link Logger} used by {@link CheckList} instances.
|
* The name of the {@link PropertyChangeEvent} that we use to deliver
|
||||||
|
* changes on the state of this check list.
|
||||||
*/
|
*/
|
||||||
private Logger logger;
|
public static final String PROPERTY_CHECK_LIST_STATE = "CheckListState";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the {@link PropertyChangeEvent} that we use to deliver
|
||||||
|
* changes on the end of checks of this check list.
|
||||||
|
*/
|
||||||
|
public static final String PROPERTY_CHECK_LIST_CHECKS = "CheckListChecks";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a check list with the specified name.
|
* Creates a check list with the specified name.
|
||||||
@ -98,7 +98,6 @@ public class CheckList
|
|||||||
protected CheckList(IceMediaStream parentStream)
|
protected CheckList(IceMediaStream parentStream)
|
||||||
{
|
{
|
||||||
this.parentStream = parentStream;
|
this.parentStream = parentStream;
|
||||||
logger = parentStream.getLogger().createChildLogger(this.getClass().getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -135,7 +134,7 @@ public class CheckList
|
|||||||
{
|
{
|
||||||
synchronized(triggeredCheckQueue)
|
synchronized(triggeredCheckQueue)
|
||||||
{
|
{
|
||||||
if (!triggeredCheckQueue.contains(pair))
|
if(!triggeredCheckQueue.contains(pair))
|
||||||
{
|
{
|
||||||
triggeredCheckQueue.add(pair);
|
triggeredCheckQueue.add(pair);
|
||||||
pair.setStateWaiting();
|
pair.setStateWaiting();
|
||||||
@ -154,7 +153,7 @@ public class CheckList
|
|||||||
{
|
{
|
||||||
synchronized(triggeredCheckQueue)
|
synchronized(triggeredCheckQueue)
|
||||||
{
|
{
|
||||||
if (triggeredCheckQueue.size() > 0)
|
if(triggeredCheckQueue.size() > 0)
|
||||||
return triggeredCheckQueue.remove(0);
|
return triggeredCheckQueue.remove(0);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -182,7 +181,7 @@ public class CheckList
|
|||||||
{
|
{
|
||||||
if (pair.getState() == CandidatePairState.WAITING)
|
if (pair.getState() == CandidatePairState.WAITING)
|
||||||
{
|
{
|
||||||
if (highestPriorityPair == null
|
if(highestPriorityPair == null
|
||||||
|| pair.getPriority() > highestPriorityPair.getPriority())
|
|| pair.getPriority() > highestPriorityPair.getPriority())
|
||||||
{
|
{
|
||||||
highestPriorityPair = pair;
|
highestPriorityPair = pair;
|
||||||
@ -190,14 +189,14 @@ public class CheckList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (highestPriorityPair != null)
|
if(highestPriorityPair != null)
|
||||||
return highestPriorityPair;
|
return highestPriorityPair;
|
||||||
|
|
||||||
for (CandidatePair pair : this)
|
for (CandidatePair pair : this)
|
||||||
{
|
{
|
||||||
if (pair.getState() == CandidatePairState.FROZEN)
|
if (pair.getState() == CandidatePairState.FROZEN)
|
||||||
{
|
{
|
||||||
if (highestPriorityPair == null
|
if(highestPriorityPair == null
|
||||||
|| pair.getPriority() > highestPriorityPair.getPriority())
|
|| pair.getPriority() > highestPriorityPair.getPriority())
|
||||||
{
|
{
|
||||||
highestPriorityPair = pair;
|
highestPriorityPair = pair;
|
||||||
@ -209,25 +208,6 @@ public class CheckList
|
|||||||
return highestPriorityPair; //return even if null
|
return highestPriorityPair; //return even if null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a pair which matches the specified local and remote candidates'
|
|
||||||
* transport addresses, if any, otherwise null.
|
|
||||||
*/
|
|
||||||
public synchronized CandidatePair findPairMatching(LocalCandidate local, RemoteCandidate remote)
|
|
||||||
{
|
|
||||||
for (CandidatePair pair : this)
|
|
||||||
{
|
|
||||||
if (pair.getLocalCandidate() == local ||
|
|
||||||
pair.getLocalCandidate().getTransportAddress().equals(local.getTransportAddress()))
|
|
||||||
{
|
|
||||||
if (pair.getRemoteCandidate() == remote ||
|
|
||||||
pair.getRemoteCandidate().getTransportAddress().equals(remote.getTransportAddress()))
|
|
||||||
return pair;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether this <tt>CheckList</tt> can be considered active.
|
* Determines whether this <tt>CheckList</tt> can be considered active.
|
||||||
* RFC 5245 says: A check list with at least one pair that is Waiting is
|
* RFC 5245 says: A check list with at least one pair that is Waiting is
|
||||||
@ -319,14 +299,14 @@ public class CheckList
|
|||||||
Map<String, CandidatePair> pairsToWait = new Hashtable<>();
|
Map<String, CandidatePair> pairsToWait = new Hashtable<>();
|
||||||
|
|
||||||
//first, determine the pairs that we'd need to put in the waiting state.
|
//first, determine the pairs that we'd need to put in the waiting state.
|
||||||
for (CandidatePair pair : this)
|
for(CandidatePair pair : this)
|
||||||
{
|
{
|
||||||
//we need to check whether the pair is already in the wait list. if
|
//we need to check whether the pair is already in the wait list. if
|
||||||
//so we'll compare it with this one and determine which of the two
|
//so we'll compare it with this one and determine which of the two
|
||||||
//needs to stay.
|
//needs to stay.
|
||||||
CandidatePair prevPair = pairsToWait.get(pair.getFoundation());
|
CandidatePair prevPair = pairsToWait.get(pair.getFoundation());
|
||||||
|
|
||||||
if (prevPair == null)
|
if(prevPair == null)
|
||||||
{
|
{
|
||||||
//first pair with this foundation.
|
//first pair with this foundation.
|
||||||
pairsToWait.put(pair.getFoundation(), pair);
|
pairsToWait.put(pair.getFoundation(), pair);
|
||||||
@ -336,9 +316,9 @@ public class CheckList
|
|||||||
//we already have a pair with the same foundation. determine which
|
//we already have a pair with the same foundation. determine which
|
||||||
//of the two has the lower component id and higher priority and
|
//of the two has the lower component id and higher priority and
|
||||||
//keep that one in the list.
|
//keep that one in the list.
|
||||||
if ( prevPair.getParentComponent() == pair.getParentComponent())
|
if( prevPair.getParentComponent() == pair.getParentComponent())
|
||||||
{
|
{
|
||||||
if (pair.getPriority() > prevPair.getPriority())
|
if(pair.getPriority() > prevPair.getPriority())
|
||||||
{
|
{
|
||||||
//need to replace the pair in the list.
|
//need to replace the pair in the list.
|
||||||
pairsToWait.put(pair.getFoundation(), pair);
|
pairsToWait.put(pair.getFoundation(), pair);
|
||||||
@ -346,7 +326,7 @@ public class CheckList
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (pair.getParentComponent().getComponentID()
|
if(pair.getParentComponent().getComponentID()
|
||||||
< prevPair.getParentComponent().getComponentID())
|
< prevPair.getParentComponent().getComponentID())
|
||||||
{
|
{
|
||||||
//need to replace the pair in the list.
|
//need to replace the pair in the list.
|
||||||
@ -368,7 +348,7 @@ public class CheckList
|
|||||||
protected synchronized void recomputePairPriorities()
|
protected synchronized void recomputePairPriorities()
|
||||||
{
|
{
|
||||||
//first, determine the pairs that we'd need to put in the waiting state.
|
//first, determine the pairs that we'd need to put in the waiting state.
|
||||||
for (CandidatePair pair : this)
|
for(CandidatePair pair : this)
|
||||||
pair.computePriority();
|
pair.computePriority();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,7 +378,7 @@ public class CheckList
|
|||||||
{
|
{
|
||||||
Component cmp = nominatedPair.getParentComponent();
|
Component cmp = nominatedPair.getParentComponent();
|
||||||
|
|
||||||
if (cmp.getSelectedPair() != null)
|
if(cmp.getSelectedPair() != null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -410,7 +390,7 @@ public class CheckList
|
|||||||
cmp.setSelectedPair(nominatedPair);
|
cmp.setSelectedPair(nominatedPair);
|
||||||
|
|
||||||
Iterator<CandidatePair> pairsIter = iterator();
|
Iterator<CandidatePair> pairsIter = iterator();
|
||||||
while (pairsIter.hasNext())
|
while(pairsIter.hasNext())
|
||||||
{
|
{
|
||||||
CandidatePair pair = pairsIter.next();
|
CandidatePair pair = pairsIter.next();
|
||||||
if (pair.getParentComponent() == cmp
|
if (pair.getParentComponent() == cmp
|
||||||
@ -427,7 +407,7 @@ public class CheckList
|
|||||||
{
|
{
|
||||||
Iterator<CandidatePair> triggeredPairsIter
|
Iterator<CandidatePair> triggeredPairsIter
|
||||||
= triggeredCheckQueue.iterator();
|
= triggeredCheckQueue.iterator();
|
||||||
while (triggeredPairsIter.hasNext())
|
while(triggeredPairsIter.hasNext())
|
||||||
{
|
{
|
||||||
CandidatePair pair = triggeredPairsIter.next();
|
CandidatePair pair = triggeredPairsIter.next();
|
||||||
if (pair.getParentComponent() == cmp
|
if (pair.getParentComponent() == cmp
|
||||||
@ -493,7 +473,7 @@ public class CheckList
|
|||||||
{
|
{
|
||||||
synchronized(stateListeners)
|
synchronized(stateListeners)
|
||||||
{
|
{
|
||||||
if (!stateListeners.contains(l))
|
if(!stateListeners.contains(l))
|
||||||
this.stateListeners.add(l);
|
this.stateListeners.add(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -532,7 +512,7 @@ public class CheckList
|
|||||||
PropertyChangeEvent evt = new PropertyChangeEvent(
|
PropertyChangeEvent evt = new PropertyChangeEvent(
|
||||||
this, PROPERTY_CHECK_LIST_STATE, oldState, newState);
|
this, PROPERTY_CHECK_LIST_STATE, oldState, newState);
|
||||||
|
|
||||||
for (PropertyChangeListener l : listenersCopy)
|
for(PropertyChangeListener l : listenersCopy)
|
||||||
{
|
{
|
||||||
l.propertyChange(evt);
|
l.propertyChange(evt);
|
||||||
}
|
}
|
||||||
@ -548,7 +528,7 @@ public class CheckList
|
|||||||
{
|
{
|
||||||
synchronized(checkListeners)
|
synchronized(checkListeners)
|
||||||
{
|
{
|
||||||
if (!checkListeners.contains(l))
|
if(!checkListeners.contains(l))
|
||||||
{
|
{
|
||||||
checkListeners.add(l);
|
checkListeners.add(l);
|
||||||
}
|
}
|
||||||
@ -564,7 +544,7 @@ public class CheckList
|
|||||||
{
|
{
|
||||||
synchronized(checkListeners)
|
synchronized(checkListeners)
|
||||||
{
|
{
|
||||||
if (checkListeners.contains(l))
|
if(checkListeners.contains(l))
|
||||||
{
|
{
|
||||||
checkListeners.remove(l);
|
checkListeners.remove(l);
|
||||||
}
|
}
|
||||||
@ -587,7 +567,7 @@ public class CheckList
|
|||||||
PropertyChangeEvent evt = new PropertyChangeEvent(
|
PropertyChangeEvent evt = new PropertyChangeEvent(
|
||||||
this, PROPERTY_CHECK_LIST_CHECKS, false, true);
|
this, PROPERTY_CHECK_LIST_CHECKS, false, true);
|
||||||
|
|
||||||
for (PropertyChangeListener l : listenersCopy)
|
for(PropertyChangeListener l : listenersCopy)
|
||||||
{
|
{
|
||||||
l.propertyChange(evt);
|
l.propertyChange(evt);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,17 +20,17 @@ package org.ice4j.ice;
|
|||||||
/**
|
/**
|
||||||
* Everty <tt>CheckList</tt> is associated with a state, which captures the
|
* Everty <tt>CheckList</tt> is associated with a state, which captures the
|
||||||
* state of ICE checks for that media stream. There are three states:
|
* state of ICE checks for that media stream. There are three states:
|
||||||
* <br>
|
* <p/>
|
||||||
* Running: In this state, ICE checks are still in progress for this
|
* Running: In this state, ICE checks are still in progress for this
|
||||||
* media stream.
|
* media stream.
|
||||||
* <br>
|
* <p/>
|
||||||
* Completed: In this state, ICE checks have produced nominated pairs
|
* Completed: In this state, ICE checks have produced nominated pairs
|
||||||
* for each component of the media stream. Consequently, ICE has succeeded and
|
* for each component of the media stream. Consequently, ICE has succeeded and
|
||||||
* media can be sent.
|
* media can be sent.
|
||||||
* <br>
|
* <p/>
|
||||||
* Failed: In this state, the ICE checks have not completed successfully for
|
* Failed: In this state, the ICE checks have not completed successfully for
|
||||||
* this media stream.
|
* this media stream.
|
||||||
* <br>
|
* <p/>
|
||||||
* When a check list is first constructed as the consequence of an offer/answer
|
* When a check list is first constructed as the consequence of an offer/answer
|
||||||
* exchange, it is placed in the Running state.
|
* exchange, it is placed in the Running state.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -17,14 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.ice4j.ice;
|
package org.ice4j.ice;
|
||||||
|
|
||||||
import java.beans.*;
|
|
||||||
import java.net.*;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.logging.*;
|
||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
import org.ice4j.socket.*;
|
|
||||||
import org.jitsi.utils.logging2.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A component is a piece of a media stream requiring a single transport
|
* A component is a piece of a media stream requiring a single transport
|
||||||
@ -39,8 +35,13 @@ import org.jitsi.utils.logging2.*;
|
|||||||
* @author Boris Grozev
|
* @author Boris Grozev
|
||||||
*/
|
*/
|
||||||
public class Component
|
public class Component
|
||||||
implements PropertyChangeListener
|
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Our class logger.
|
||||||
|
*/
|
||||||
|
private static final Logger logger
|
||||||
|
= Logger.getLogger(Component.class.getName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The component ID to use with RTP streams.
|
* The component ID to use with RTP streams.
|
||||||
*/
|
*/
|
||||||
@ -111,48 +112,6 @@ public class Component
|
|||||||
*/
|
*/
|
||||||
private Candidate<?> defaultRemoteCandidate = null;
|
private Candidate<?> defaultRemoteCandidate = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link Logger} used by {@link Component} instances.
|
|
||||||
*/
|
|
||||||
private final Logger logger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link ComponentSocket} instance which, if enabled, will serve as the
|
|
||||||
* single socket instance for this {@link Component}, merging received
|
|
||||||
* packets from all of its candidates.
|
|
||||||
*/
|
|
||||||
private final ComponentSocket componentSocket;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The public view of {@link #componentSocket}, wrapped in a
|
|
||||||
* {@link MultiplexingDatagramSocket} for the convenience of users of the
|
|
||||||
* library.
|
|
||||||
* This is the instance which should be used by applications for
|
|
||||||
* reading/writing application data.
|
|
||||||
*/
|
|
||||||
private final MultiplexingDatagramSocket socket;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A wrapper around {@link #socket}, kept only to help preserve the old
|
|
||||||
* API (see {@link LocalCandidate#getIceSocketWrapper()} and
|
|
||||||
* {@link CandidatePair#getIceSocketWrapper()})
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private final IceSocketWrapper socketWrapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link KeepAliveStrategy} used by this component to select which
|
|
||||||
* pairs are to be kept alive.
|
|
||||||
*/
|
|
||||||
private final KeepAliveStrategy keepAliveStrategy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The set of pairs which this component wants to keep alive.
|
|
||||||
*/
|
|
||||||
private final Set<CandidatePair> keepAlivePairs
|
|
||||||
= Collections.newSetFromMap(
|
|
||||||
new ConcurrentHashMap<CandidatePair, Boolean>());
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new <tt>Component</tt> with the specified <tt>componentID</tt>
|
* Creates a new <tt>Component</tt> with the specified <tt>componentID</tt>
|
||||||
* as a child of the specified <tt>IceMediaStream</tt>.
|
* as a child of the specified <tt>IceMediaStream</tt>.
|
||||||
@ -160,62 +119,13 @@ public class Component
|
|||||||
* @param componentID the id of this component.
|
* @param componentID the id of this component.
|
||||||
* @param mediaStream the {@link IceMediaStream} instance that would be the
|
* @param mediaStream the {@link IceMediaStream} instance that would be the
|
||||||
* parent of this component.
|
* parent of this component.
|
||||||
* @deprecated
|
|
||||||
*/
|
*/
|
||||||
protected Component(int componentID,
|
protected Component(int componentID,
|
||||||
IceMediaStream mediaStream,
|
IceMediaStream mediaStream)
|
||||||
KeepAliveStrategy keepAliveStrategy,
|
|
||||||
Logger parentLogger)
|
|
||||||
{
|
|
||||||
this(componentID, mediaStream, keepAliveStrategy, true, parentLogger);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new <tt>Component</tt> with the specified <tt>componentID</tt>
|
|
||||||
* as a child of the specified <tt>IceMediaStream</tt>.
|
|
||||||
*
|
|
||||||
* @param componentID the id of this component.
|
|
||||||
* @param mediaStream the {@link IceMediaStream} instance that would be the
|
|
||||||
* parent of this component.
|
|
||||||
* @param useComponentSocket whether the component socket should be used.
|
|
||||||
*/
|
|
||||||
protected Component(int componentID,
|
|
||||||
IceMediaStream mediaStream,
|
|
||||||
KeepAliveStrategy keepAliveStrategy,
|
|
||||||
boolean useComponentSocket,
|
|
||||||
Logger parentLogger)
|
|
||||||
{
|
{
|
||||||
// the max value for componentID is 256
|
// the max value for componentID is 256
|
||||||
this.componentID = componentID;
|
this.componentID = componentID;
|
||||||
this.parentStream = mediaStream;
|
this.parentStream = mediaStream;
|
||||||
this.keepAliveStrategy
|
|
||||||
= Objects.requireNonNull(keepAliveStrategy, "keepAliveStrategy");
|
|
||||||
this.logger = parentLogger.createChildLogger(
|
|
||||||
this.getClass().getName(),
|
|
||||||
Collections.singletonMap("componentId", Integer.toString(componentID))
|
|
||||||
);
|
|
||||||
|
|
||||||
if (useComponentSocket)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
componentSocket = new ComponentSocket(this, logger);
|
|
||||||
socket = new MultiplexingDatagramSocket(componentSocket);
|
|
||||||
socketWrapper = new IceUdpSocketWrapper(socket);
|
|
||||||
}
|
|
||||||
catch (SocketException se)
|
|
||||||
{
|
|
||||||
throw new RuntimeException(se);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
componentSocket = null;
|
|
||||||
socket = null;
|
|
||||||
socketWrapper = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
mediaStream.addPairChangeListener(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -289,7 +199,7 @@ public class Component
|
|||||||
synchronized(localCandidates)
|
synchronized(localCandidates)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (Candidate<?> cand : localCandidates)
|
for(Candidate<?> cand : localCandidates)
|
||||||
{
|
{
|
||||||
if ((cand.getType() == CandidateType.HOST_CANDIDATE)
|
if ((cand.getType() == CandidateType.HOST_CANDIDATE)
|
||||||
&& !cand.isVirtual())
|
&& !cand.isVirtual())
|
||||||
@ -384,7 +294,7 @@ public class Component
|
|||||||
|
|
||||||
synchronized(remoteUpdateCandidates)
|
synchronized(remoteUpdateCandidates)
|
||||||
{
|
{
|
||||||
if (remoteUpdateCandidates.size() == 0)
|
if(remoteUpdateCandidates.size() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
newRemoteCandidates = new LinkedList<>(remoteUpdateCandidates);
|
newRemoteCandidates = new LinkedList<>(remoteUpdateCandidates);
|
||||||
@ -393,9 +303,9 @@ public class Component
|
|||||||
|
|
||||||
// remove UPnP base from local candidate
|
// remove UPnP base from local candidate
|
||||||
LocalCandidate upnpBase = null;
|
LocalCandidate upnpBase = null;
|
||||||
for (LocalCandidate lc : localCnds)
|
for(LocalCandidate lc : localCnds)
|
||||||
{
|
{
|
||||||
if (lc instanceof UPNPCandidate)
|
if(lc instanceof UPNPCandidate)
|
||||||
{
|
{
|
||||||
upnpBase = lc.getBase();
|
upnpBase = lc.getBase();
|
||||||
}
|
}
|
||||||
@ -403,26 +313,26 @@ public class Component
|
|||||||
|
|
||||||
checkList = new Vector<>();
|
checkList = new Vector<>();
|
||||||
|
|
||||||
for (LocalCandidate localCnd : localCnds)
|
for(LocalCandidate localCnd : localCnds)
|
||||||
{
|
{
|
||||||
if (localCnd == upnpBase)
|
if(localCnd == upnpBase)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
//pair each of the new remote candidates with each of our locals
|
//pair each of the new remote candidates with each of our locals
|
||||||
for (RemoteCandidate remoteCnd : remoteUpdateCandidates)
|
for(RemoteCandidate remoteCnd : remoteUpdateCandidates)
|
||||||
{
|
{
|
||||||
if (localCnd.canReach(remoteCnd)
|
if(localCnd.canReach(remoteCnd)
|
||||||
&& remoteCnd.getTransportAddress().getPort() != 0)
|
&& remoteCnd.getTransportAddress().getPort() != 0)
|
||||||
{
|
{
|
||||||
// A single LocalCandidate might be/become connected
|
// A single LocalCandidate might be/become connected
|
||||||
// to more more than one remote address, and that's ok
|
// to more more than one remote address, and that's ok
|
||||||
// (that is, we need to form pairs with them all).
|
// (that is, we need to form pairs with them all).
|
||||||
/*
|
/*
|
||||||
if (localCnd.getTransport() == Transport.TCP &&
|
if(localCnd.getTransport() == Transport.TCP &&
|
||||||
localCnd.getIceSocketWrapper().getTCPSocket().
|
localCnd.getIceSocketWrapper().getTCPSocket().
|
||||||
isConnected())
|
isConnected())
|
||||||
{
|
{
|
||||||
if (!localCnd.getIceSocketWrapper().getTCPSocket().
|
if(!localCnd.getIceSocketWrapper().getTCPSocket().
|
||||||
getRemoteSocketAddress().equals(
|
getRemoteSocketAddress().equals(
|
||||||
remoteCnd.getTransportAddress()))
|
remoteCnd.getTransportAddress()))
|
||||||
{
|
{
|
||||||
@ -435,6 +345,7 @@ public class Component
|
|||||||
= getParentStream()
|
= getParentStream()
|
||||||
.getParentAgent()
|
.getParentAgent()
|
||||||
.createCandidatePair(localCnd, remoteCnd);
|
.createCandidatePair(localCnd, remoteCnd);
|
||||||
|
logger.info("new Pair added: " + pair.toShortString());
|
||||||
checkList.add(pair);
|
checkList.add(pair);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -451,7 +362,7 @@ public class Component
|
|||||||
Collections.sort(checkList, CandidatePair.comparator);
|
Collections.sort(checkList, CandidatePair.comparator);
|
||||||
parentStream.pruneCheckList(checkList);
|
parentStream.pruneCheckList(checkList);
|
||||||
|
|
||||||
if (parentStream.getCheckList().getState().equals(
|
if(parentStream.getCheckList().getState().equals(
|
||||||
CheckListState.RUNNING))
|
CheckListState.RUNNING))
|
||||||
{
|
{
|
||||||
//add the updated CandidatePair list to the currently running
|
//add the updated CandidatePair list to the currently running
|
||||||
@ -459,29 +370,9 @@ public class Component
|
|||||||
CheckList streamCheckList = parentStream.getCheckList();
|
CheckList streamCheckList = parentStream.getCheckList();
|
||||||
synchronized(streamCheckList)
|
synchronized(streamCheckList)
|
||||||
{
|
{
|
||||||
for (CandidatePair pair : checkList)
|
for(CandidatePair pair : checkList)
|
||||||
{
|
|
||||||
/* Check whether the pair is already in the check list.
|
|
||||||
* (This can happen for pairs with remote peer-reflexive candidates,
|
|
||||||
* since those candidates aren't added to the candidate list even
|
|
||||||
* though the pair is added to the check list).
|
|
||||||
*/
|
|
||||||
CandidatePair existingPair
|
|
||||||
= streamCheckList.findPairMatching(pair.getLocalCandidate(), pair.getRemoteCandidate());
|
|
||||||
if (existingPair != null)
|
|
||||||
{
|
|
||||||
logger.info("existing Pair updated: " +
|
|
||||||
existingPair.toShortString() +
|
|
||||||
" to " + pair.toShortString() + ".");
|
|
||||||
existingPair.setRemoteCandidate(pair.getRemoteCandidate());
|
|
||||||
existingPair.computePriority();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
streamCheckList.add(pair);
|
streamCheckList.add(pair);
|
||||||
logger.info("new Pair added: " + pair.toShortString()
|
|
||||||
+ ".");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -571,7 +462,7 @@ public class Component
|
|||||||
//local candidates
|
//local candidates
|
||||||
int localCandidatesCount = getLocalCandidateCount();
|
int localCandidatesCount = getLocalCandidateCount();
|
||||||
|
|
||||||
if (localCandidatesCount > 0)
|
if(localCandidatesCount > 0)
|
||||||
{
|
{
|
||||||
buff.append("\n")
|
buff.append("\n")
|
||||||
.append(localCandidatesCount)
|
.append(localCandidatesCount)
|
||||||
@ -594,7 +485,7 @@ public class Component
|
|||||||
//remote candidates
|
//remote candidates
|
||||||
int remoteCandidatesCount = getRemoteCandidateCount();
|
int remoteCandidatesCount = getRemoteCandidateCount();
|
||||||
|
|
||||||
if (remoteCandidatesCount > 0)
|
if(remoteCandidatesCount > 0)
|
||||||
{
|
{
|
||||||
buff.append("\n")
|
buff.append("\n")
|
||||||
.append(remoteCandidatesCount)
|
.append(remoteCandidatesCount)
|
||||||
@ -703,7 +594,11 @@ public class Component
|
|||||||
&& (cand.getPriority() >= cand2.getPriority()))
|
&& (cand.getPriority() >= cand2.getPriority()))
|
||||||
{
|
{
|
||||||
localCandidates.remove(j);
|
localCandidates.remove(j);
|
||||||
logger.trace(() -> "eliminating redundant cand: "+ cand2);
|
if(logger.isLoggable(Level.FINEST))
|
||||||
|
{
|
||||||
|
logger.finest(
|
||||||
|
"eliminating redundant cand: "+ cand2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
j++;
|
j++;
|
||||||
@ -870,17 +765,6 @@ public class Component
|
|||||||
localCandidateIter.remove();
|
localCandidateIter.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getParentStream().removePairStateChangeListener(this);
|
|
||||||
keepAlivePairs.clear();
|
|
||||||
if (componentSocket != null)
|
|
||||||
{
|
|
||||||
componentSocket.close();
|
|
||||||
}
|
|
||||||
if (socket != null)
|
|
||||||
{
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -904,7 +788,12 @@ public class Component
|
|||||||
*/
|
*/
|
||||||
if (t instanceof ThreadDeath)
|
if (t instanceof ThreadDeath)
|
||||||
throw (ThreadDeath) t;
|
throw (ThreadDeath) t;
|
||||||
logger.info(() -> "Failed to free LocalCandidate: " + localCandidate);
|
if (logger.isLoggable(Level.INFO))
|
||||||
|
{
|
||||||
|
logger.log(
|
||||||
|
Level.INFO,
|
||||||
|
"Failed to free LocalCandidate: " + localCandidate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -921,47 +810,10 @@ public class Component
|
|||||||
*/
|
*/
|
||||||
public LocalCandidate findLocalCandidate(TransportAddress localAddress)
|
public LocalCandidate findLocalCandidate(TransportAddress localAddress)
|
||||||
{
|
{
|
||||||
return findLocalCandidate(localAddress, null);
|
for (LocalCandidate localCnd : localCandidates)
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the local <tt>LocalCandidate</tt> with the specified
|
|
||||||
* <tt>address</tt> if it belongs to this component or <tt>null</tt>
|
|
||||||
* if it doesn't. If {@code base} is also specified, tries to find a
|
|
||||||
* candidate whose base matches {@code base}.
|
|
||||||
*
|
|
||||||
* @param address the {@link TransportAddress} we are looking for.
|
|
||||||
* @param base an optional base to match.
|
|
||||||
*
|
|
||||||
* @return the local <tt>LocalCandidate</tt> with the specified
|
|
||||||
* <tt>address</tt> if it belongs to this component or <tt>null</tt>
|
|
||||||
* if it doesn't.
|
|
||||||
*/
|
|
||||||
public LocalCandidate findLocalCandidate(TransportAddress address, LocalCandidate base)
|
|
||||||
{
|
{
|
||||||
for (LocalCandidate localCandidate : localCandidates)
|
if (localCnd.getTransportAddress().equals(localAddress))
|
||||||
{
|
return localCnd;
|
||||||
if (localCandidate.getTransportAddress().equals(address))
|
|
||||||
{
|
|
||||||
if (base == null || base.equals(localCandidate.getBase()))
|
|
||||||
{
|
|
||||||
return localCandidate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// In case the above loop failed to find a result because `base` was
|
|
||||||
// specified, fallback to the original behavior and return the first
|
|
||||||
// candidate matching `address` regardless of `base`.
|
|
||||||
for (LocalCandidate localCandidate : localCandidates)
|
|
||||||
{
|
|
||||||
if (localCandidate.getTransportAddress().equals(address))
|
|
||||||
{
|
|
||||||
logger.warn("Returning a candidate matching the address, "
|
|
||||||
+ "while no candidates match both address ("
|
|
||||||
+ address + ") and base (" + base +"): " + localCandidate
|
|
||||||
+ " with base " + localCandidate.getBase());
|
|
||||||
return localCandidate;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -980,13 +832,11 @@ public class Component
|
|||||||
*/
|
*/
|
||||||
public RemoteCandidate findRemoteCandidate(TransportAddress remoteAddress)
|
public RemoteCandidate findRemoteCandidate(TransportAddress remoteAddress)
|
||||||
{
|
{
|
||||||
for (RemoteCandidate remoteCnd : remoteCandidates)
|
for(RemoteCandidate remoteCnd : remoteCandidates)
|
||||||
{
|
|
||||||
if (remoteCnd.getTransportAddress().equals(remoteAddress))
|
|
||||||
{
|
{
|
||||||
|
if(remoteCnd.getTransportAddress().equals(remoteAddress))
|
||||||
return remoteCnd;
|
return remoteCnd;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -999,12 +849,6 @@ public class Component
|
|||||||
*/
|
*/
|
||||||
protected void setSelectedPair(CandidatePair pair)
|
protected void setSelectedPair(CandidatePair pair)
|
||||||
{
|
{
|
||||||
if (keepAliveStrategy == KeepAliveStrategy.SELECTED_ONLY)
|
|
||||||
{
|
|
||||||
keepAlivePairs.clear();
|
|
||||||
}
|
|
||||||
keepAlivePairs.add(pair);
|
|
||||||
|
|
||||||
this.selectedPair = pair;
|
this.selectedPair = pair;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1032,18 +876,12 @@ public class Component
|
|||||||
public String getName()
|
public String getName()
|
||||||
{
|
{
|
||||||
if (componentID == RTP)
|
if (componentID == RTP)
|
||||||
{
|
|
||||||
return "RTP";
|
return "RTP";
|
||||||
}
|
else if(componentID == RTCP)
|
||||||
else if (componentID == RTCP)
|
|
||||||
{
|
|
||||||
return "RTCP";
|
return "RTCP";
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
return Integer.toString(componentID);
|
return Integer.toString(componentID);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use builder pattern to allow creation of immutable Component instances,
|
* Use builder pattern to allow creation of immutable Component instances,
|
||||||
@ -1054,129 +892,9 @@ public class Component
|
|||||||
* parent of this component.
|
* parent of this component.
|
||||||
* @return Component
|
* @return Component
|
||||||
*/
|
*/
|
||||||
public static Component build(int componentID, IceMediaStream mediaStream, Logger parentLogger)
|
public static Component build(int componentID, IceMediaStream mediaStream)
|
||||||
{
|
{
|
||||||
return
|
return new Component(componentID, mediaStream);
|
||||||
new Component(
|
|
||||||
componentID,
|
|
||||||
mediaStream,
|
|
||||||
KeepAliveStrategy.SELECTED_ONLY,
|
|
||||||
AgentConfig.config.getUseComponentSocket(),
|
|
||||||
parentLogger
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the single socket for this {@link Component} which should be
|
|
||||||
* used for reading and writing data, if the component socket is enabled
|
|
||||||
* and {@code null} if it is not enabled.
|
|
||||||
* </p>
|
|
||||||
* This is for ice4j internal use only! For reading/writing application
|
|
||||||
* data, use {@link #getSocket()}.
|
|
||||||
*/
|
|
||||||
public ComponentSocket getComponentSocket()
|
|
||||||
{
|
|
||||||
return componentSocket;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the socket for this {@link Component}, which should be used for
|
|
||||||
* reading/writing application data. If the component socket is not enabled,
|
|
||||||
* this returns {@code null} and users of the library should use the socket
|
|
||||||
* instance from the desired candidate pair instead.
|
|
||||||
*/
|
|
||||||
public MultiplexingDatagramSocket getSocket()
|
|
||||||
{
|
|
||||||
return socket;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return an {@link IceSocketWrapper} instance wrapping the socket for this
|
|
||||||
* candidate (see {@link #getSocket()}).
|
|
||||||
* @deprecated Use {@link #getSocket()} directly. This is only introduced
|
|
||||||
* to ease the transition of applications which are already written to use
|
|
||||||
* a {@link IceSocketWrapper} instance.
|
|
||||||
*/
|
|
||||||
public IceSocketWrapper getSocketWrapper()
|
|
||||||
{
|
|
||||||
return socketWrapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the set of candidate pairs which are to be kept alive.
|
|
||||||
*/
|
|
||||||
Set<CandidatePair> getKeepAlivePairs()
|
|
||||||
{
|
|
||||||
return keepAlivePairs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
* </p>
|
|
||||||
* Handles events coming from candidate pairs.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void propertyChange(PropertyChangeEvent event)
|
|
||||||
{
|
|
||||||
String propertyName = event.getPropertyName();
|
|
||||||
if (!(event.getSource() instanceof CandidatePair))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CandidatePair pair = (CandidatePair) event.getSource();
|
|
||||||
if (!equals(pair.getParentComponent()))
|
|
||||||
{
|
|
||||||
// Events are fired by the IceMediaStream, which might have
|
|
||||||
// multiple components. Make sure that we only handle events for
|
|
||||||
// this component.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean addToKeepAlive = false;
|
|
||||||
|
|
||||||
// We handle this case in setSelectedPair
|
|
||||||
if (keepAliveStrategy == KeepAliveStrategy.SELECTED_ONLY)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (IceMediaStream.PROPERTY_PAIR_STATE_CHANGED.equals(propertyName))
|
|
||||||
{
|
|
||||||
CandidatePairState newState
|
|
||||||
= (CandidatePairState) event.getNewValue();
|
|
||||||
|
|
||||||
if (CandidatePairState.SUCCEEDED.equals(newState))
|
|
||||||
{
|
|
||||||
if (keepAliveStrategy == KeepAliveStrategy.ALL_SUCCEEDED)
|
|
||||||
{
|
|
||||||
addToKeepAlive = true;
|
|
||||||
}
|
|
||||||
else if (keepAliveStrategy == KeepAliveStrategy.SELECTED_AND_TCP)
|
|
||||||
{
|
|
||||||
Transport transport
|
|
||||||
= pair.getLocalCandidate().getTransport();
|
|
||||||
addToKeepAlive = transport == Transport.TCP
|
|
||||||
|| transport == Transport.SSLTCP;
|
|
||||||
|
|
||||||
// Pairs with a remote TCP port 9 cannot be checked.
|
|
||||||
// Instead, the corresponding pair with the peer reflexive
|
|
||||||
// candidate needs to be checked. However, we observe
|
|
||||||
// such pairs transitioning into the SUCCEEDED state.
|
|
||||||
// Ignore them.
|
|
||||||
addToKeepAlive
|
|
||||||
&= pair.getRemoteCandidate()
|
|
||||||
.getTransportAddress().getPort() != 9;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (addToKeepAlive && !keepAlivePairs.contains(pair))
|
|
||||||
{
|
|
||||||
keepAlivePairs.add(pair);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Logger getLogger()
|
|
||||||
{
|
|
||||||
return logger;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,202 +0,0 @@
|
|||||||
/*
|
|
||||||
* ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
|
|
||||||
*
|
|
||||||
* Copyright @ 2015-2016 Atlassian Pty Ltd
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.ice4j.ice;
|
|
||||||
|
|
||||||
import org.ice4j.*;
|
|
||||||
import org.ice4j.socket.*;
|
|
||||||
|
|
||||||
import java.beans.*;
|
|
||||||
import java.net.*;
|
|
||||||
import java.util.*;
|
|
||||||
import org.ice4j.util.*; //Disambiguation
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extends {@link MergingDatagramSocket} with functionality specific to
|
|
||||||
* an ICE {@link Component}.
|
|
||||||
*/
|
|
||||||
public class ComponentSocket
|
|
||||||
extends MergingDatagramSocket
|
|
||||||
implements PropertyChangeListener
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Controls access to {@link #authorizedAddresses}.
|
|
||||||
*/
|
|
||||||
private final Object authorizedAddressesSyncRoot = new Object();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The set of remote addresses, which this socket is allowed to receive
|
|
||||||
* from. These should be the addresses which we have confirmed (e.g. by
|
|
||||||
* having received a STUN message with correct authentication fields).
|
|
||||||
*/
|
|
||||||
private Set<SocketAddress> authorizedAddresses = new HashSet<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The owning {@link Component}.
|
|
||||||
*/
|
|
||||||
private Component component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether we have invoked {@link #initializeActive}.
|
|
||||||
*/
|
|
||||||
private boolean initializedActive = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to synchronize access to {@link #initializedActive}.
|
|
||||||
*/
|
|
||||||
private final Object initializedActiveSyncRoot = new Object();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes a new {@link MergingDatagramSocket} instance.
|
|
||||||
* @throws SocketException
|
|
||||||
*/
|
|
||||||
ComponentSocket(Component component, org.jitsi.utils.logging2.Logger parentLogger)
|
|
||||||
throws SocketException
|
|
||||||
{
|
|
||||||
super(parentLogger);
|
|
||||||
|
|
||||||
this.component = component;
|
|
||||||
component.getParentStream().addPairChangeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
* </p>
|
|
||||||
* Verifies that the source of the packet is an authorized remote address.
|
|
||||||
*/
|
|
||||||
protected boolean accept(DatagramPacket p)
|
|
||||||
{
|
|
||||||
return authorizedAddresses.contains(p.getSocketAddress());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a specific address to the list of authorized remote addresses.
|
|
||||||
* @param address the address to add.
|
|
||||||
*/
|
|
||||||
private void addAuthorizedAddress(SocketAddress address)
|
|
||||||
{
|
|
||||||
synchronized (authorizedAddressesSyncRoot)
|
|
||||||
{
|
|
||||||
if (authorizedAddresses.contains(address))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Adding allowed address: " + address);
|
|
||||||
|
|
||||||
Set<SocketAddress> newSet = new HashSet<>();
|
|
||||||
newSet.addAll(authorizedAddresses);
|
|
||||||
newSet.add(address);
|
|
||||||
|
|
||||||
authorizedAddresses = newSet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
* </p>
|
|
||||||
* Handles property change events coming from ICE pairs.
|
|
||||||
* @param event
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void propertyChange(PropertyChangeEvent event)
|
|
||||||
{
|
|
||||||
if (!(event.getSource() instanceof CandidatePair))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CandidatePair pair = (CandidatePair) event.getSource();
|
|
||||||
if (!pair.getParentComponent().equals(component))
|
|
||||||
{
|
|
||||||
// Events are fired by the IceMediaStream, which might have
|
|
||||||
// multiple components. Make sure that we only handle events for
|
|
||||||
// our own component.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String propertyName = event.getPropertyName();
|
|
||||||
if (IceMediaStream.PROPERTY_PAIR_STATE_CHANGED.equals(propertyName))
|
|
||||||
{
|
|
||||||
CandidatePairState newState
|
|
||||||
= (CandidatePairState) event.getNewValue();
|
|
||||||
|
|
||||||
if (CandidatePairState.SUCCEEDED.equals(newState))
|
|
||||||
{
|
|
||||||
addAuthorizedAddress(
|
|
||||||
pair.getRemoteCandidate().getTransportAddress());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (IceMediaStream.PROPERTY_PAIR_NOMINATED.equals(propertyName))
|
|
||||||
{
|
|
||||||
synchronized (initializedActiveSyncRoot)
|
|
||||||
{
|
|
||||||
if (initializedActive)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the remote address and the correct socket to be used by
|
|
||||||
// the pair.
|
|
||||||
LocalCandidate localCandidate = pair.getLocalCandidate();
|
|
||||||
LocalCandidate base = localCandidate.getBase();
|
|
||||||
if (base != null)
|
|
||||||
{
|
|
||||||
localCandidate = base;
|
|
||||||
}
|
|
||||||
|
|
||||||
TransportAddress remoteAddress = null;
|
|
||||||
RemoteCandidate remoteCandidate = pair.getRemoteCandidate();
|
|
||||||
if (remoteCandidate != null)
|
|
||||||
{
|
|
||||||
remoteAddress = remoteCandidate.getTransportAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
// The local candidate may have more than one associated socket.
|
|
||||||
// Make sure we get the one for the remote address that we are
|
|
||||||
// going to use.
|
|
||||||
IceSocketWrapper socketWrapper
|
|
||||||
= localCandidate
|
|
||||||
.getCandidateIceSocketWrapper(remoteAddress);
|
|
||||||
|
|
||||||
initializeActive(socketWrapper, remoteAddress);
|
|
||||||
initializedActive = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void close()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
super.close();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Component component = this.component;
|
|
||||||
if (component != null)
|
|
||||||
{
|
|
||||||
component.getParentStream().removePairStateChangeListener(this);
|
|
||||||
this.component = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -18,17 +18,14 @@
|
|||||||
package org.ice4j.ice;
|
package org.ice4j.ice;
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.time.*;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.logging.*;
|
||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
import org.ice4j.attribute.*;
|
import org.ice4j.attribute.*;
|
||||||
import org.ice4j.message.*;
|
import org.ice4j.message.*;
|
||||||
import org.ice4j.socket.*;
|
import org.ice4j.socket.*;
|
||||||
import org.ice4j.stack.*;
|
import org.ice4j.stack.*;
|
||||||
import org.ice4j.util.*;
|
|
||||||
import org.jitsi.utils.logging2.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class that will be generating our outgoing connectivity checks and that
|
* The class that will be generating our outgoing connectivity checks and that
|
||||||
@ -40,21 +37,18 @@ import org.jitsi.utils.logging2.Logger;
|
|||||||
class ConnectivityCheckClient
|
class ConnectivityCheckClient
|
||||||
implements ResponseCollector
|
implements ResponseCollector
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* The <tt>Logger</tt> used by the <tt>ConnectivityCheckClient</tt>
|
||||||
|
* class and its instances for logging output.
|
||||||
|
*/
|
||||||
|
private static final Logger logger
|
||||||
|
= Logger.getLogger(ConnectivityCheckClient.class.getName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The agent that created us.
|
* The agent that created us.
|
||||||
*/
|
*/
|
||||||
private final Agent parentAgent;
|
private final Agent parentAgent;
|
||||||
|
|
||||||
/**
|
|
||||||
* A scheduled executor service to perform periodic tasks of the client
|
|
||||||
*/
|
|
||||||
private final ScheduledExecutorService scheduledExecutorService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An executor service to perform background tasks of the client
|
|
||||||
*/
|
|
||||||
private final ExecutorService executorService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <tt>StunStack</tt> that we will use for connectivity checks.
|
* The <tt>StunStack</tt> that we will use for connectivity checks.
|
||||||
*/
|
*/
|
||||||
@ -63,52 +57,29 @@ class ConnectivityCheckClient
|
|||||||
/**
|
/**
|
||||||
* The {@link PaceMaker}s that are currently running checks in this client.
|
* The {@link PaceMaker}s that are currently running checks in this client.
|
||||||
*/
|
*/
|
||||||
private final Queue<PaceMaker> paceMakers
|
private final List<PaceMaker> paceMakers = new LinkedList<>();
|
||||||
= new ConcurrentLinkedQueue<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether this {@link ConnectivityCheckClient} has been stopped.
|
|
||||||
* Synchronized by {@link #paceMakers}.
|
|
||||||
*/
|
|
||||||
private boolean stopped = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Timer that is used to let some seconds before a CheckList is considered
|
* Timer that is used to let some seconds before a CheckList is considered
|
||||||
* as FAILED.
|
* as FAILED.
|
||||||
*/
|
*/
|
||||||
private ConcurrentMap<String, ScheduledFuture<?>>
|
private Map<String, Timer> timers = new HashMap<>();
|
||||||
checkListCompletionCheckers = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A flag that determines whether we have received a STUN response or not.
|
* A flag that determines whether we have received a STUN response or not.
|
||||||
*/
|
*/
|
||||||
private boolean alive = false;
|
private boolean alive = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link Logger} used by {@link ConnectivityCheckClient} instances.
|
|
||||||
*/
|
|
||||||
private Logger logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new <tt>ConnectivityCheckClient</tt> setting
|
* Creates a new <tt>ConnectivityCheckClient</tt> setting
|
||||||
* <tt>parentAgent</tt> as the agent that will be used for retrieving
|
* <tt>parentAgent</tt> as the agent that will be used for retrieving
|
||||||
* information such as user fragments for example.
|
* information such as user fragments for example.
|
||||||
*
|
*
|
||||||
* @param parentAgent the <tt>Agent</tt> that is creating this instance.
|
* @param parentAgent the <tt>Agent</tt> that is creating this instance.
|
||||||
* @param scheduledExecutorService the <tt>ScheduledExecutorService</tt>
|
|
||||||
* to execute clients tasks
|
|
||||||
* @param executorService the <tt>ExecutorService</tt> to execute
|
|
||||||
* background tasks of connectivity check client
|
|
||||||
*/
|
*/
|
||||||
public ConnectivityCheckClient(
|
public ConnectivityCheckClient(Agent parentAgent)
|
||||||
Agent parentAgent,
|
|
||||||
ScheduledExecutorService scheduledExecutorService,
|
|
||||||
ExecutorService executorService)
|
|
||||||
{
|
{
|
||||||
this.parentAgent = parentAgent;
|
this.parentAgent = parentAgent;
|
||||||
this.scheduledExecutorService = scheduledExecutorService;
|
|
||||||
this.executorService = executorService;
|
|
||||||
logger = parentAgent.getLogger().createChildLogger(this.getClass().getName());
|
|
||||||
|
|
||||||
stunStack = this.parentAgent.getStunStack();
|
stunStack = this.parentAgent.getStunStack();
|
||||||
}
|
}
|
||||||
@ -144,7 +115,7 @@ class ConnectivityCheckClient
|
|||||||
|
|
||||||
if (streamsWithPendingConnectivityEstablishment.size() > 0)
|
if (streamsWithPendingConnectivityEstablishment.size() > 0)
|
||||||
{
|
{
|
||||||
logger.info("Start connectivity checks.");
|
logger.info("Start connectivity checks!");
|
||||||
startChecks(
|
startChecks(
|
||||||
streamsWithPendingConnectivityEstablishment
|
streamsWithPendingConnectivityEstablishment
|
||||||
.get(0).getCheckList());
|
.get(0).getCheckList());
|
||||||
@ -165,16 +136,13 @@ class ConnectivityCheckClient
|
|||||||
*/
|
*/
|
||||||
public void startChecks(CheckList checkList)
|
public void startChecks(CheckList checkList)
|
||||||
{
|
{
|
||||||
|
PaceMaker paceMaker = new PaceMaker(checkList);
|
||||||
|
|
||||||
synchronized (paceMakers)
|
synchronized (paceMakers)
|
||||||
{
|
{
|
||||||
if (stopped)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
PaceMaker paceMaker = new PaceMaker(checkList);
|
|
||||||
paceMakers.add(paceMaker);
|
paceMakers.add(paceMaker);
|
||||||
paceMaker.schedule();
|
|
||||||
}
|
}
|
||||||
|
paceMaker.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -195,18 +163,23 @@ class ConnectivityCheckClient
|
|||||||
indication,
|
indication,
|
||||||
candidatePair.getRemoteCandidate().getTransportAddress(),
|
candidatePair.getRemoteCandidate().getTransportAddress(),
|
||||||
localCandidate.getBase().getTransportAddress());
|
localCandidate.getBase().getTransportAddress());
|
||||||
logger.trace(() ->
|
if(logger.isLoggable(Level.FINEST))
|
||||||
|
{
|
||||||
|
logger.finest(
|
||||||
"sending binding indication to pair " + candidatePair);
|
"sending binding indication to pair " + candidatePair);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
IceSocketWrapper stunSocket = localCandidate.getStunSocket(null);
|
IceSocketWrapper stunSocket = localCandidate.getStunSocket(null);
|
||||||
|
|
||||||
if (stunSocket != null)
|
if(stunSocket != null)
|
||||||
{
|
{
|
||||||
logger.info("Failed to send " + indication + " through "
|
logger.log(
|
||||||
+ stunSocket.getLocalSocketAddress() + "\n" +
|
Level.INFO,
|
||||||
ex.toString());
|
"Failed to send " + indication + " through "
|
||||||
|
+ stunSocket.getLocalSocketAddress(),
|
||||||
|
ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -277,7 +250,7 @@ class ConnectivityCheckClient
|
|||||||
//nominated pairs.
|
//nominated pairs.
|
||||||
if (candidatePair.isNominated())
|
if (candidatePair.isNominated())
|
||||||
{
|
{
|
||||||
logger.debug(() ->
|
logger.fine(
|
||||||
"Add USE-CANDIDATE in check for: "
|
"Add USE-CANDIDATE in check for: "
|
||||||
+ candidatePair.toShortString());
|
+ candidatePair.toShortString());
|
||||||
request.putAttribute(
|
request.putAttribute(
|
||||||
@ -297,7 +270,7 @@ class ConnectivityCheckClient
|
|||||||
.getParentComponent().getParentStream().getName();
|
.getParentComponent().getParentStream().getName();
|
||||||
String localUserName = parentAgent.generateLocalUserName(media);
|
String localUserName = parentAgent.generateLocalUserName(media);
|
||||||
|
|
||||||
if (localUserName == null)
|
if(localUserName == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
UsernameAttribute unameAttr
|
UsernameAttribute unameAttr
|
||||||
@ -321,12 +294,9 @@ class ConnectivityCheckClient
|
|||||||
|
|
||||||
tran.setApplicationData(candidatePair);
|
tran.setApplicationData(candidatePair);
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
logger.fine(
|
||||||
{
|
|
||||||
logger.debug(
|
|
||||||
"start check for " + candidatePair.toShortString() + " tid "
|
"start check for " + candidatePair.toShortString() + " tid "
|
||||||
+ tran);
|
+ tran);
|
||||||
}
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
tran
|
tran
|
||||||
@ -340,39 +310,32 @@ class ConnectivityCheckClient
|
|||||||
originalWaitInterval,
|
originalWaitInterval,
|
||||||
maxWaitInterval,
|
maxWaitInterval,
|
||||||
maxRetransmissions);
|
maxRetransmissions);
|
||||||
if (logger.isTraceEnabled())
|
if(logger.isLoggable(Level.FINEST))
|
||||||
{
|
{
|
||||||
logger.trace("checking pair " + candidatePair + " tid " + tran);
|
logger.finest(
|
||||||
|
"checking pair " + candidatePair + " tid " + tran);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (NetAccessManager.SocketNotFoundException e)
|
|
||||||
{
|
|
||||||
logger.info("Could not start connectivity check: " + e.getMessage());
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
tran = null;
|
tran = null;
|
||||||
|
|
||||||
IceSocketWrapper stunSocket = localCandidate.getStunSocket(null);
|
IceSocketWrapper stunSocket = localCandidate.getStunSocket(null);
|
||||||
|
|
||||||
if (stunSocket != null)
|
if(stunSocket != null)
|
||||||
{
|
{
|
||||||
String msg
|
String msg
|
||||||
= "Failed to send " + request + " through "
|
= "Failed to send " + request + " through "
|
||||||
+ stunSocket.getLocalSocketAddress() + ".";
|
+ stunSocket.getLocalSocketAddress() + ".";
|
||||||
|
|
||||||
if ((ex instanceof NoRouteToHostException)
|
if((ex instanceof NoRouteToHostException)
|
||||||
|| (ex.getMessage() != null
|
|| (ex.getMessage() != null
|
||||||
&& ex.getMessage().equals("No route to host")))
|
&& ex.getMessage().equals("No route to host")))
|
||||||
{
|
{
|
||||||
msg += " No route to host.";
|
msg += " No route to host.";
|
||||||
ex = null;
|
ex = null;
|
||||||
}
|
}
|
||||||
logger.info(msg + (ex == null ? "" : "\n" + ex.toString()));
|
logger.log(Level.INFO, msg, ex);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.warn("Failed to send " + request, ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,18 +371,18 @@ class ConnectivityCheckClient
|
|||||||
char messageType = response.getMessageType();
|
char messageType = response.getMessageType();
|
||||||
|
|
||||||
//handle error responses.
|
//handle error responses.
|
||||||
if (messageType == Response.BINDING_ERROR_RESPONSE)
|
if(messageType == Response.BINDING_ERROR_RESPONSE)
|
||||||
{
|
{
|
||||||
if (!response.containsAttribute(Attribute.ERROR_CODE))
|
if(!response.containsAttribute(Attribute.ERROR_CODE))
|
||||||
{
|
{
|
||||||
logger.debug(() -> "Received a malformed error response.");
|
logger.fine("Received a malformed error response.");
|
||||||
return; //malformed error response
|
return; //malformed error response
|
||||||
}
|
}
|
||||||
|
|
||||||
processErrorResponse(ev);
|
processErrorResponse(ev);
|
||||||
}
|
}
|
||||||
//handle success responses.
|
//handle success responses.
|
||||||
else if (messageType == Response.BINDING_SUCCESS_RESPONSE)
|
else if(messageType == Response.BINDING_SUCCESS_RESPONSE)
|
||||||
{
|
{
|
||||||
processSuccessResponse(ev);
|
processSuccessResponse(ev);
|
||||||
}
|
}
|
||||||
@ -444,29 +407,31 @@ class ConnectivityCheckClient
|
|||||||
= checkedPair.getParentComponent().getParentStream();
|
= checkedPair.getParentComponent().getParentStream();
|
||||||
final CheckList checkList = stream.getCheckList();
|
final CheckList checkList = stream.getCheckList();
|
||||||
|
|
||||||
if (stream.getParentAgent().getState().isEstablished())
|
if(stream.getParentAgent().getState().isEstablished())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//If all of the pairs in the check list are now either in the Failed or
|
//If all of the pairs in the check list are now either in the Failed or
|
||||||
//Succeeded state:
|
//Succeeded state:
|
||||||
if (checkList.allChecksCompleted())
|
if(checkList.allChecksCompleted())
|
||||||
{
|
{
|
||||||
//If there is not a pair in the valid list for each component of the
|
//If there is not a pair in the valid list for each component of the
|
||||||
//media stream, the state of the check list is set to Failed.
|
//media stream, the state of the check list is set to Failed.
|
||||||
if ( !stream.validListContainsAllComponents())
|
if ( !stream.validListContainsAllComponents())
|
||||||
{
|
{
|
||||||
final String streamName = stream.getName();
|
final String streamName = stream.getName();
|
||||||
if (!checkListCompletionCheckers.containsKey(streamName))
|
Timer timer = timers.get(streamName);
|
||||||
{
|
|
||||||
logger.info("CheckList will failed in a few seconds" +
|
|
||||||
" if no succeeded checks come");
|
|
||||||
|
|
||||||
Runnable checkLickCompletedChecker = new Runnable()
|
if(timer == null)
|
||||||
|
{
|
||||||
|
logger.info("CheckList will failed in a few seconds if no" +
|
||||||
|
"succeeded checks come");
|
||||||
|
|
||||||
|
TimerTask task = new TimerTask()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
if (checkList.getState() != CheckListState.COMPLETED)
|
if(checkList.getState() != CheckListState.COMPLETED)
|
||||||
{
|
{
|
||||||
logger.info("CheckList for stream " +
|
logger.info("CheckList for stream " +
|
||||||
streamName + " FAILED");
|
streamName + " FAILED");
|
||||||
@ -476,20 +441,9 @@ class ConnectivityCheckClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
timer = new Timer();
|
||||||
final ScheduledFuture<?> scheduledCheckerFuture
|
timers.put(streamName, timer);
|
||||||
= scheduledExecutorService.schedule(
|
timer.schedule(task, 5000);
|
||||||
checkLickCompletedChecker,
|
|
||||||
5000,
|
|
||||||
TimeUnit.MILLISECONDS);
|
|
||||||
|
|
||||||
final ScheduledFuture<?> existingCheckerFuture
|
|
||||||
= checkListCompletionCheckers
|
|
||||||
.putIfAbsent(streamName, scheduledCheckerFuture);
|
|
||||||
if (existingCheckerFuture != null)
|
|
||||||
{
|
|
||||||
scheduledCheckerFuture.cancel(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,7 +459,7 @@ class ConnectivityCheckClient
|
|||||||
{
|
{
|
||||||
CheckList anotherCheckList = anotherStream.getCheckList();
|
CheckList anotherCheckList = anotherStream.getCheckList();
|
||||||
|
|
||||||
if (anotherCheckList.isFrozen())
|
if(anotherCheckList.isFrozen())
|
||||||
{
|
{
|
||||||
anotherCheckList.computeInitialCheckListPairStates();
|
anotherCheckList.computeInitialCheckListPairStates();
|
||||||
startChecks(anotherCheckList);
|
startChecks(anotherCheckList);
|
||||||
@ -533,10 +487,10 @@ class ConnectivityCheckClient
|
|||||||
|
|
||||||
if (!response.containsAttribute(Attribute.XOR_MAPPED_ADDRESS))
|
if (!response.containsAttribute(Attribute.XOR_MAPPED_ADDRESS))
|
||||||
{
|
{
|
||||||
logger.debug(() -> "Received a success response with no "
|
logger.fine("Received a success response with no "
|
||||||
+ "XOR_MAPPED_ADDRESS attribute.");
|
+ "XOR_MAPPED_ADDRESS attribute.");
|
||||||
logger.info("Pair failed (no XOR-MAPPED-ADDRESS): "
|
logger.info("Pair failed (no XOR-MAPPED-ADDRESS): "
|
||||||
+ checkedPair.toShortString() + ".");
|
+ checkedPair.toShortString());
|
||||||
checkedPair.setStateFailed();
|
checkedPair.setStateFailed();
|
||||||
return; //malformed error response
|
return; //malformed error response
|
||||||
}
|
}
|
||||||
@ -558,12 +512,9 @@ class ConnectivityCheckClient
|
|||||||
Transport.TCP);
|
Transport.TCP);
|
||||||
}
|
}
|
||||||
|
|
||||||
// In some situations we may have more than one local candidate matching
|
LocalCandidate validLocalCandidate = null;
|
||||||
// the mapped address. In this case we want to find the that matches
|
|
||||||
// the socket we received the response on.
|
validLocalCandidate = parentAgent.findLocalCandidate(mappedAddress);
|
||||||
LocalCandidate base = checkedPair.getLocalCandidate().getBase();
|
|
||||||
LocalCandidate validLocalCandidate
|
|
||||||
= parentAgent.findLocalCandidate(mappedAddress, base);
|
|
||||||
|
|
||||||
RemoteCandidate validRemoteCandidate = checkedPair.getRemoteCandidate();
|
RemoteCandidate validRemoteCandidate = checkedPair.getRemoteCandidate();
|
||||||
|
|
||||||
@ -607,9 +558,9 @@ class ConnectivityCheckClient
|
|||||||
|
|
||||||
if (checkedPair.getParentComponent().getSelectedPair() == null)
|
if (checkedPair.getParentComponent().getSelectedPair() == null)
|
||||||
{
|
{
|
||||||
logger.info("Receive a peer-reflexive candidate: "
|
logger.info(
|
||||||
+ peerReflexiveCandidate.getTransportAddress()
|
"Receive a peer-reflexive candidate: "
|
||||||
+ ".");
|
+ peerReflexiveCandidate.getTransportAddress());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -645,18 +596,14 @@ class ConnectivityCheckClient
|
|||||||
//Succeeded. Note that, the pair which *generated* the check may be
|
//Succeeded. Note that, the pair which *generated* the check may be
|
||||||
//different than the valid pair constructed above
|
//different than the valid pair constructed above
|
||||||
if (checkedPair.getParentComponent().getSelectedPair() == null)
|
if (checkedPair.getParentComponent().getSelectedPair() == null)
|
||||||
{
|
logger.info("Pair succeeded: " + checkedPair.toShortString());
|
||||||
logger.info("Pair succeeded: " + checkedPair.toShortString()
|
|
||||||
+ ".");
|
|
||||||
}
|
|
||||||
checkedPair.setStateSucceeded();
|
checkedPair.setStateSucceeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!validPair.isValid())
|
if (!validPair.isValid())
|
||||||
{
|
{
|
||||||
if (validPair.getParentComponent().getSelectedPair() == null)
|
if (validPair.getParentComponent().getSelectedPair() == null)
|
||||||
logger.info("Pair validated: " + validPair.toShortString()
|
logger.info("Pair validated: " + validPair.toShortString());
|
||||||
+ ".");
|
|
||||||
parentAgent.validatePair(validPair);
|
parentAgent.validatePair(validPair);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -665,12 +612,12 @@ class ConnectivityCheckClient
|
|||||||
IceMediaStream parentStream
|
IceMediaStream parentStream
|
||||||
= checkedPair.getParentComponent().getParentStream();
|
= checkedPair.getParentComponent().getParentStream();
|
||||||
|
|
||||||
synchronized (this)
|
synchronized(this)
|
||||||
{
|
{
|
||||||
Vector<CandidatePair> parentCheckList
|
Vector<CandidatePair> parentCheckList
|
||||||
= new Vector<>(parentStream.getCheckList());
|
= new Vector<>(parentStream.getCheckList());
|
||||||
|
|
||||||
for (CandidatePair pair : parentCheckList)
|
for(CandidatePair pair : parentCheckList)
|
||||||
{
|
{
|
||||||
if (pair.getState() == CandidatePairState.FROZEN
|
if (pair.getState() == CandidatePairState.FROZEN
|
||||||
&& checkedPair.getFoundation().equals(
|
&& checkedPair.getFoundation().equals(
|
||||||
@ -727,8 +674,7 @@ class ConnectivityCheckClient
|
|||||||
logger.info("IsControlling: " + parentAgent.isControlling() +
|
logger.info("IsControlling: " + parentAgent.isControlling() +
|
||||||
" USE-CANDIDATE:" +
|
" USE-CANDIDATE:" +
|
||||||
(request.containsAttribute(Attribute.USE_CANDIDATE) ||
|
(request.containsAttribute(Attribute.USE_CANDIDATE) ||
|
||||||
checkedPair.useCandidateSent())
|
checkedPair.useCandidateSent()));
|
||||||
+ ".");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//If the agent was a controlling agent, and it had included a USE-
|
//If the agent was a controlling agent, and it had included a USE-
|
||||||
@ -737,16 +683,16 @@ class ConnectivityCheckClient
|
|||||||
if (parentAgent.isControlling()
|
if (parentAgent.isControlling()
|
||||||
&& request.containsAttribute(Attribute.USE_CANDIDATE))
|
&& request.containsAttribute(Attribute.USE_CANDIDATE))
|
||||||
{
|
{
|
||||||
if (validPair.getParentComponent().getSelectedPair() == null)
|
if(validPair.getParentComponent().getSelectedPair() == null)
|
||||||
{
|
{
|
||||||
logger.info("Nomination confirmed for pair: "
|
logger.info(
|
||||||
+ validPair.toShortString()
|
"Nomination confirmed for pair: "
|
||||||
+ ".");
|
+ validPair.toShortString());
|
||||||
parentAgent.nominationConfirmed( validPair );
|
parentAgent.nominationConfirmed( validPair );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger.debug(() ->
|
logger.fine(
|
||||||
"Keep alive for pair: " + validPair.toShortString());
|
"Keep alive for pair: " + validPair.toShortString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -759,7 +705,7 @@ class ConnectivityCheckClient
|
|||||||
&& checkedPair.useCandidateReceived()
|
&& checkedPair.useCandidateReceived()
|
||||||
&& !checkedPair.isNominated())
|
&& !checkedPair.isNominated())
|
||||||
{
|
{
|
||||||
if (checkedPair.getParentComponent().getSelectedPair() == null)
|
if(checkedPair.getParentComponent().getSelectedPair() == null)
|
||||||
{
|
{
|
||||||
logger.info(
|
logger.info(
|
||||||
"Nomination confirmed for pair: "
|
"Nomination confirmed for pair: "
|
||||||
@ -768,18 +714,15 @@ class ConnectivityCheckClient
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger.debug(() ->
|
logger.fine(
|
||||||
"Keep alive for pair: " + validPair.toShortString());
|
"Keep alive for pair: " + validPair.toShortString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Selected pairs get their consent freshness confirmed.
|
// Selected pairs get their consent freshness confirmed.
|
||||||
// XXX Should we also confirm consent freshness for non-selected pairs?
|
if (checkedPair == checkedPair.getParentComponent().getSelectedPair())
|
||||||
if (checkedPair.equals(checkedPair.getParentComponent().getSelectedPair()))
|
|
||||||
{
|
|
||||||
checkedPair.setConsentFreshness();
|
checkedPair.setConsentFreshness();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns <tt>true</tt> if the {@link Response} in <tt>evt</tt> had a
|
* Returns <tt>true</tt> if the {@link Response} in <tt>evt</tt> had a
|
||||||
@ -838,15 +781,15 @@ class ConnectivityCheckClient
|
|||||||
CandidatePair pair
|
CandidatePair pair
|
||||||
= (CandidatePair) ev.getTransactionID().getApplicationData();
|
= (CandidatePair) ev.getTransactionID().getApplicationData();
|
||||||
|
|
||||||
logger.trace(() -> "Received error code " + ((int) errorCode));
|
logger.finer("Received error code " + ((int) errorCode));
|
||||||
|
|
||||||
//RESOLVE ROLE_CONFLICTS
|
//RESOLVE ROLE_CONFLICTS
|
||||||
if (errorCode == ErrorCodeAttribute.ROLE_CONFLICT)
|
if(errorCode == ErrorCodeAttribute.ROLE_CONFLICT)
|
||||||
{
|
{
|
||||||
boolean wasControlling
|
boolean wasControlling
|
||||||
= originalRequest.containsAttribute(Attribute.ICE_CONTROLLING);
|
= originalRequest.containsAttribute(Attribute.ICE_CONTROLLING);
|
||||||
|
|
||||||
logger.trace(() -> "Switching to isControlling=" + !wasControlling);
|
logger.finer("Swithing to isControlling=" + !wasControlling);
|
||||||
parentAgent.setControlling(!wasControlling);
|
parentAgent.setControlling(!wasControlling);
|
||||||
|
|
||||||
pair.getParentComponent().getParentStream().getCheckList()
|
pair.getParentComponent().getParentStream().getCheckList()
|
||||||
@ -855,12 +798,10 @@ class ConnectivityCheckClient
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
int code = cl * 100 + co;
|
int code = cl * 100 + co;
|
||||||
String reason = errorAttr.getReasonPhrase();
|
|
||||||
String trimmedReason = reason != null ? reason.trim() : null;
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"Error response for pair: " + pair.toShortString() +
|
"Error response for pair: " + pair.toShortString() +
|
||||||
", failing. Code = " + code +
|
", failing. Code = " + code +
|
||||||
"(class=" + cl + "; number=" + co + "): " + trimmedReason);
|
"(class=" + cl + "; number=" + co + ")");
|
||||||
pair.setStateFailed();
|
pair.setStateFailed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -884,11 +825,17 @@ class ConnectivityCheckClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class to control periodically scheduled runnable that actually sends
|
* The thread that actually sends the checks for a particular check list
|
||||||
* the checks for a particular check list in the pace defined in RFC 5245.
|
* in the pace defined in RFC 5245.
|
||||||
*/
|
*/
|
||||||
private final class PaceMaker extends PeriodicRunnable
|
private class PaceMaker
|
||||||
|
extends Thread
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Indicates whether this <tt>Thread</tt> should still be running.
|
||||||
|
*/
|
||||||
|
boolean running = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link CheckList} that this <tt>PaceMaker</tt> will be running
|
* The {@link CheckList} that this <tt>PaceMaker</tt> will be running
|
||||||
* checks for.
|
* checks for.
|
||||||
@ -904,8 +851,39 @@ class ConnectivityCheckClient
|
|||||||
*/
|
*/
|
||||||
public PaceMaker(CheckList checkList)
|
public PaceMaker(CheckList checkList)
|
||||||
{
|
{
|
||||||
super(scheduledExecutorService, executorService);
|
super("ICE PaceMaker: " + parentAgent.getLocalUfrag());
|
||||||
|
|
||||||
this.checkList = checkList;
|
this.checkList = checkList;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Because PaceMaker does not seem to be a daemon at least on Ubuntu
|
||||||
|
* in the run-sample target and it looks like it should be from the
|
||||||
|
* standpoint of the application, explicitly tell it to be a daemon.
|
||||||
|
* Otherwise, it could prevent the application from exiting because
|
||||||
|
* of a problem in the ICE implementation.
|
||||||
|
*/
|
||||||
|
setDaemon(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number milliseconds to wait before we send the next
|
||||||
|
* check.
|
||||||
|
*
|
||||||
|
* @return the number milliseconds to wait before we send the next
|
||||||
|
* check.
|
||||||
|
*/
|
||||||
|
private long getNextWaitInterval()
|
||||||
|
{
|
||||||
|
int activeCheckLists = parentAgent.getActiveCheckListCount();
|
||||||
|
|
||||||
|
if (activeCheckLists < 1)
|
||||||
|
{
|
||||||
|
//don't multiply by 0. even when we no longer have active check
|
||||||
|
//lists we may still have nomination checks to
|
||||||
|
activeCheckLists = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parentAgent.calculateTa() * activeCheckLists;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -914,17 +892,41 @@ class ConnectivityCheckClient
|
|||||||
* or the regular check lists.
|
* or the regular check lists.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void run()
|
public synchronized void run()
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
while(running)
|
||||||
|
{
|
||||||
|
long waitFor = getNextWaitInterval();
|
||||||
|
|
||||||
|
if(waitFor > 0)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* waitFor will be 0 for the first check since we won't
|
||||||
|
* have any active check lists at that point yet.
|
||||||
|
*/
|
||||||
|
try
|
||||||
|
{
|
||||||
|
wait(waitFor);
|
||||||
|
}
|
||||||
|
catch (InterruptedException e)
|
||||||
|
{
|
||||||
|
logger.log(Level.FINER, "PaceMaker got interrupted",
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!running)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
CandidatePair pairToCheck = checkList.popTriggeredCheck();
|
CandidatePair pairToCheck = checkList.popTriggeredCheck();
|
||||||
|
|
||||||
//if there are no triggered checks, go for an ordinary one.
|
//if there are no triggered checks, go for an ordinary one.
|
||||||
if (pairToCheck == null)
|
if(pairToCheck == null)
|
||||||
{
|
|
||||||
pairToCheck = checkList.getNextOrdinaryPairToCheck();
|
pairToCheck = checkList.getNextOrdinaryPairToCheck();
|
||||||
}
|
|
||||||
|
|
||||||
if (pairToCheck != null)
|
if(pairToCheck != null)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Since we suspect that it is possible to
|
* Since we suspect that it is possible to
|
||||||
@ -938,7 +940,7 @@ class ConnectivityCheckClient
|
|||||||
TransactionID transactionID
|
TransactionID transactionID
|
||||||
= startCheckForPair(pairToCheck);
|
= startCheckForPair(pairToCheck);
|
||||||
|
|
||||||
if (transactionID == null)
|
if(transactionID == null)
|
||||||
{
|
{
|
||||||
logger.info(
|
logger.info(
|
||||||
"Pair failed: "
|
"Pair failed: "
|
||||||
@ -946,11 +948,9 @@ class ConnectivityCheckClient
|
|||||||
pairToCheck.setStateFailed();
|
pairToCheck.setStateFailed();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
pairToCheck.setStateInProgress(transactionID);
|
pairToCheck.setStateInProgress(transactionID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -958,30 +958,21 @@ class ConnectivityCheckClient
|
|||||||
* its final state in either the processResponse(),
|
* its final state in either the processResponse(),
|
||||||
* processTimeout() or processFailure() method.
|
* processTimeout() or processFailure() method.
|
||||||
*/
|
*/
|
||||||
logger.trace(() -> "will skip a check beat.");
|
logger.finest("will skip a check beat.");
|
||||||
checkList.fireEndOfOrdinaryChecks();
|
checkList.fireEndOfOrdinaryChecks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the number milliseconds to wait before we send the next
|
|
||||||
* check.
|
|
||||||
*
|
|
||||||
* @return the number milliseconds to wait before we send the next
|
|
||||||
* check.
|
|
||||||
*/
|
|
||||||
protected Duration getDelayUntilNextRun()
|
|
||||||
{
|
|
||||||
int activeCheckLists = parentAgent.getActiveCheckListCount();
|
|
||||||
|
|
||||||
if (activeCheckLists < 1)
|
|
||||||
{
|
|
||||||
//don't multiply by 0. even when we no longer have active check
|
|
||||||
//lists we may still have nomination checks to
|
|
||||||
activeCheckLists = 1;
|
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
return Duration.ofMillis(parentAgent.calculateTa() * activeCheckLists);
|
{
|
||||||
|
synchronized (paceMakers)
|
||||||
|
{
|
||||||
|
synchronized(this)
|
||||||
|
{
|
||||||
|
paceMakers.remove(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -992,15 +983,19 @@ class ConnectivityCheckClient
|
|||||||
{
|
{
|
||||||
synchronized (paceMakers)
|
synchronized (paceMakers)
|
||||||
{
|
{
|
||||||
stopped = true;
|
Iterator<PaceMaker> paceMakersIter = paceMakers.iterator();
|
||||||
while (true)
|
|
||||||
|
while(paceMakersIter.hasNext())
|
||||||
{
|
{
|
||||||
final PaceMaker paceMaker = paceMakers.poll();
|
PaceMaker paceMaker = paceMakersIter.next();
|
||||||
if (paceMaker == null)
|
|
||||||
|
synchronized(paceMaker)
|
||||||
{
|
{
|
||||||
break;
|
paceMaker.running = false;
|
||||||
|
paceMaker.notify();
|
||||||
}
|
}
|
||||||
paceMaker.cancel();
|
|
||||||
|
paceMakersIter.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,12 +17,13 @@
|
|||||||
*/
|
*/
|
||||||
package org.ice4j.ice;
|
package org.ice4j.ice;
|
||||||
|
|
||||||
|
import java.util.logging.*;
|
||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
import org.ice4j.attribute.*;
|
import org.ice4j.attribute.*;
|
||||||
import org.ice4j.message.*;
|
import org.ice4j.message.*;
|
||||||
import org.ice4j.security.*;
|
import org.ice4j.security.*;
|
||||||
import org.ice4j.stack.*;
|
import org.ice4j.stack.*;
|
||||||
import org.jitsi.utils.logging2.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class that would be handling and responding to incoming connectivity
|
* The class that would be handling and responding to incoming connectivity
|
||||||
@ -35,6 +36,30 @@ class ConnectivityCheckServer
|
|||||||
implements RequestListener,
|
implements RequestListener,
|
||||||
CredentialsAuthority
|
CredentialsAuthority
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* The <tt>Logger</tt> used by the <tt>ConnectivityCheckServer</tt>
|
||||||
|
* class and its instances for logging output.
|
||||||
|
*/
|
||||||
|
private static final Logger logger
|
||||||
|
= Logger.getLogger(ConnectivityCheckServer.class.getName());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares <tt>a</tt> and <tt>b</tt> as unsigned long values. Serves the
|
||||||
|
* same purpose as the <tt>Long.compareUnsigned</tt> method available in
|
||||||
|
* Java 1.8.
|
||||||
|
* @return <tt>-1</tt> if <tt>a</tt> is less than <tt>b</tt>, <tt>0</tt> if
|
||||||
|
* they are equal and <tt>1</tt> if <tt>a</tt> is bigger.
|
||||||
|
*/
|
||||||
|
private static int compareUnsignedLong(long a, long b)
|
||||||
|
{
|
||||||
|
if (a == b)
|
||||||
|
return 0;
|
||||||
|
else if ((a + Long.MIN_VALUE) < (b + Long.MIN_VALUE))
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The agent that created us.
|
* The agent that created us.
|
||||||
*/
|
*/
|
||||||
@ -56,11 +81,6 @@ class ConnectivityCheckServer
|
|||||||
*/
|
*/
|
||||||
private boolean alive = false;
|
private boolean alive = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link Logger} used by {@link ConnectivityCheckServer} instances.
|
|
||||||
*/
|
|
||||||
private Logger logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new <tt>ConnectivityCheckServer</tt> setting
|
* Creates a new <tt>ConnectivityCheckServer</tt> setting
|
||||||
* <tt>parentAgent</tt> as the agent that will be used for retrieving
|
* <tt>parentAgent</tt> as the agent that will be used for retrieving
|
||||||
@ -71,7 +91,6 @@ class ConnectivityCheckServer
|
|||||||
public ConnectivityCheckServer(Agent parentAgent)
|
public ConnectivityCheckServer(Agent parentAgent)
|
||||||
{
|
{
|
||||||
this.parentAgent = parentAgent;
|
this.parentAgent = parentAgent;
|
||||||
logger = parentAgent.getLogger().createChildLogger(this.getClass().getName());
|
|
||||||
|
|
||||||
stunStack = this.parentAgent.getStunStack();
|
stunStack = this.parentAgent.getStunStack();
|
||||||
stunStack.getCredentialsManager().registerAuthority(this);
|
stunStack.getCredentialsManager().registerAuthority(this);
|
||||||
@ -111,7 +130,8 @@ class ConnectivityCheckServer
|
|||||||
public void processRequest(StunMessageEvent evt)
|
public void processRequest(StunMessageEvent evt)
|
||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
logger.trace(() -> "Received request " + evt);
|
if(logger.isLoggable(Level.FINER))
|
||||||
|
logger.finer("Received request " + evt);
|
||||||
|
|
||||||
alive = true;
|
alive = true;
|
||||||
|
|
||||||
@ -124,14 +144,14 @@ class ConnectivityCheckServer
|
|||||||
UsernameAttribute uname = (UsernameAttribute)request
|
UsernameAttribute uname = (UsernameAttribute)request
|
||||||
.getAttribute(Attribute.USERNAME);
|
.getAttribute(Attribute.USERNAME);
|
||||||
|
|
||||||
if ( uname == null
|
if( uname == null
|
||||||
|| !checkLocalUserName(new String(uname.getUsername())))
|
|| !checkLocalUserName(new String(uname.getUsername())))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//detect role conflicts
|
//detect role conflicts
|
||||||
if ( ( parentAgent.isControlling()
|
if( ( parentAgent.isControlling()
|
||||||
&& request.containsAttribute(Attribute.ICE_CONTROLLING))
|
&& request.containsAttribute(Attribute.ICE_CONTROLLING))
|
||||||
|| ( ! parentAgent.isControlling()
|
|| ( ! parentAgent.isControlling()
|
||||||
&& request.containsAttribute(Attribute.ICE_CONTROLLED)))
|
&& request.containsAttribute(Attribute.ICE_CONTROLLED)))
|
||||||
@ -181,9 +201,11 @@ class ConnectivityCheckServer
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
logger.info("Failed to send " + response
|
logger.log(
|
||||||
+ " through " + evt.getLocalAddress() + "\n" +
|
Level.INFO,
|
||||||
e.toString());
|
"Failed to send " + response
|
||||||
|
+ " through " + evt.getLocalAddress(),
|
||||||
|
e);
|
||||||
//try to trigger a 500 response although if this one failed,
|
//try to trigger a 500 response although if this one failed,
|
||||||
//then chances are the 500 will fail too.
|
//then chances are the 500 will fail too.
|
||||||
throw new RuntimeException("Failed to send a response", e);
|
throw new RuntimeException("Failed to send a response", e);
|
||||||
@ -214,10 +236,13 @@ class ConnectivityCheckServer
|
|||||||
//apply tie-breaking
|
//apply tie-breaking
|
||||||
|
|
||||||
//extract priority
|
//extract priority
|
||||||
if (priorityAttr == null)
|
if(priorityAttr == null)
|
||||||
{
|
{
|
||||||
logger.debug(() -> "Received a connectivity check with"
|
if(logger.isLoggable(Level.FINE))
|
||||||
|
{
|
||||||
|
logger.log(Level.FINE, "Received a connectivity check with"
|
||||||
+ "no PRIORITY attribute. Discarding.");
|
+ "no PRIORITY attribute. Discarding.");
|
||||||
|
}
|
||||||
|
|
||||||
throw new IllegalArgumentException("Missing PRIORITY attribute!");
|
throw new IllegalArgumentException("Missing PRIORITY attribute!");
|
||||||
}
|
}
|
||||||
@ -242,51 +267,29 @@ class ConnectivityCheckServer
|
|||||||
*/
|
*/
|
||||||
private boolean repairRoleConflict(StunMessageEvent evt)
|
private boolean repairRoleConflict(StunMessageEvent evt)
|
||||||
{
|
{
|
||||||
final Message req = evt.getMessage();
|
Message req = evt.getMessage();
|
||||||
final boolean selfIceControlling = parentAgent.isControlling();
|
long ourTieBreaker = parentAgent.getTieBreaker();
|
||||||
|
|
||||||
|
|
||||||
// If the agent is in the controlling role, and the
|
// If the agent is in the controlling role, and the
|
||||||
// ICE-CONTROLLING attribute is present in the request:
|
// ICE-CONTROLLING attribute is present in the request:
|
||||||
final boolean bothControllingConflict = selfIceControlling &&
|
if(parentAgent.isControlling()
|
||||||
req.containsAttribute(Attribute.ICE_CONTROLLING);
|
&& req.containsAttribute(Attribute.ICE_CONTROLLING))
|
||||||
|
|
||||||
// If the agent is in the controlled role, and the ICE-CONTROLLED
|
|
||||||
// attribute is present in the request:
|
|
||||||
final boolean bothControlledConflict = !selfIceControlling &&
|
|
||||||
req.containsAttribute(Attribute.ICE_CONTROLLED);
|
|
||||||
|
|
||||||
if (!(bothControllingConflict || bothControlledConflict))
|
|
||||||
{
|
{
|
||||||
// we don't have a role conflict
|
IceControllingAttribute controlling = (IceControllingAttribute)
|
||||||
return true;
|
req.getAttribute(Attribute.ICE_CONTROLLING);
|
||||||
}
|
|
||||||
|
|
||||||
final long selfTieBreaker = parentAgent.getTieBreaker();
|
long theirTieBreaker = controlling.getTieBreaker();
|
||||||
|
|
||||||
final IceControlAttribute theirIceControl = bothControllingConflict
|
|
||||||
? (IceControlAttribute)req.getAttribute(Attribute.ICE_CONTROLLING)
|
|
||||||
: (IceControlAttribute)req.getAttribute(Attribute.ICE_CONTROLLED);
|
|
||||||
|
|
||||||
final long theirTieBreaker = theirIceControl.getTieBreaker();
|
|
||||||
|
|
||||||
// If the agent's tie-breaker is larger than or equal to the
|
// If the agent's tie-breaker is larger than or equal to the
|
||||||
// contents of the ICE control attribute, the agent generates
|
// contents of the ICE-CONTROLLING attribute, the agent generates
|
||||||
// a Binding error response and includes an ERROR-CODE attribute
|
// a Binding error response and includes an ERROR-CODE attribute
|
||||||
// with a value of 487 (Role Conflict) but retains its role.
|
// with a value of 487 (Role Conflict) but retains its role.
|
||||||
if (Long.compareUnsigned(selfTieBreaker, theirTieBreaker) >= 0)
|
if(compareUnsignedLong(ourTieBreaker, theirTieBreaker) >= 0)
|
||||||
{
|
{
|
||||||
final UsernameAttribute requestUserName = (UsernameAttribute)req
|
Response response = MessageFactory.createBindingErrorResponse(
|
||||||
.getAttribute(Attribute.USERNAME);
|
|
||||||
|
|
||||||
final Response response =
|
|
||||||
MessageFactory.createBindingErrorResponse(
|
|
||||||
ErrorCodeAttribute.ROLE_CONFLICT);
|
ErrorCodeAttribute.ROLE_CONFLICT);
|
||||||
|
|
||||||
final Attribute messageIntegrityAttribute =
|
|
||||||
AttributeFactory.createMessageIntegrityAttribute(
|
|
||||||
new String(requestUserName.getUsername()));
|
|
||||||
response.putAttribute(messageIntegrityAttribute);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
stunStack.sendResponse(
|
stunStack.sendResponse(
|
||||||
@ -294,6 +297,7 @@ class ConnectivityCheckServer
|
|||||||
response,
|
response,
|
||||||
evt.getLocalAddress(),
|
evt.getLocalAddress(),
|
||||||
evt.getRemoteAddress());
|
evt.getRemoteAddress());
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
catch(Exception exc)
|
catch(Exception exc)
|
||||||
@ -303,19 +307,68 @@ class ConnectivityCheckServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//If the agent's tie-breaker is less than the contents of the
|
//If the agent's tie-breaker is less than the contents of the
|
||||||
//ICE control attribute, the agent toggles its ICE control role.
|
//ICE-CONTROLLING attribute, the agent switches to the controlled
|
||||||
|
//role.
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
final String selfNextControlState
|
logger.finer(
|
||||||
= selfIceControlling ? "controlled" : "controlling";
|
"Switching to controlled because theirTieBreaker="
|
||||||
logger.trace(() ->
|
+ theirTieBreaker + " and ourTieBreaker="
|
||||||
"Switching to " + selfNextControlState + " because " +
|
+ ourTieBreaker);
|
||||||
" theirTieBreaker= " + theirTieBreaker + " and " +
|
parentAgent.setControlling(false);
|
||||||
"selfTieBreaker= " + selfTieBreaker);
|
|
||||||
parentAgent.setControlling(!selfIceControlling);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// If the agent is in the controlled role, and the ICE-CONTROLLED
|
||||||
|
// attribute is present in the request:
|
||||||
|
else if(!parentAgent.isControlling()
|
||||||
|
&& req.containsAttribute(Attribute.ICE_CONTROLLED))
|
||||||
|
{
|
||||||
|
IceControlledAttribute controlled = (IceControlledAttribute)
|
||||||
|
req.getAttribute(Attribute.ICE_CONTROLLED);
|
||||||
|
|
||||||
|
long theirTieBreaker = controlled.getTieBreaker();
|
||||||
|
|
||||||
|
//If the agent's tie-breaker is larger than or equal to the
|
||||||
|
//contents of the ICE-CONTROLLED attribute, the agent switches to
|
||||||
|
//the controlling role.
|
||||||
|
if(compareUnsignedLong(ourTieBreaker, theirTieBreaker) >= 0)
|
||||||
|
{
|
||||||
|
logger.finer(
|
||||||
|
"Switching to controlling because theirTieBreaker="
|
||||||
|
+ theirTieBreaker + " and ourTieBreaker="
|
||||||
|
+ ourTieBreaker);
|
||||||
|
parentAgent.setControlling(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// If the agent's tie-breaker is less than the contents of the
|
||||||
|
// ICE-CONTROLLED attribute, the agent generates a Binding error
|
||||||
|
// response and includes an ERROR-CODE attribute with a value of
|
||||||
|
// 487 (Role Conflict) but retains its role.
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Response response = MessageFactory.createBindingErrorResponse(
|
||||||
|
ErrorCodeAttribute.ROLE_CONFLICT);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
stunStack.sendResponse(
|
||||||
|
evt.getTransactionID().getBytes(),
|
||||||
|
response,
|
||||||
|
evt.getLocalAddress(),
|
||||||
|
evt.getRemoteAddress());
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch(Exception exc)
|
||||||
|
{
|
||||||
|
//rethrow so that we would send a 500 response instead.
|
||||||
|
throw new RuntimeException("Failed to send a 487", exc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true; // we don't have a role conflict
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies whether <tt>username</tt> is currently known to this server
|
* Verifies whether <tt>username</tt> is currently known to this server
|
||||||
@ -380,7 +433,7 @@ class ConnectivityCheckServer
|
|||||||
public byte[] getRemoteKey(String username, String media)
|
public byte[] getRemoteKey(String username, String media)
|
||||||
{
|
{
|
||||||
IceMediaStream stream = parentAgent.getStream(media);
|
IceMediaStream stream = parentAgent.getStream(media);
|
||||||
if (stream == null)
|
if(stream == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -400,7 +453,7 @@ class ConnectivityCheckServer
|
|||||||
//caller gave us the entire username.
|
//caller gave us the entire username.
|
||||||
if (username.equals(parentAgent.generateLocalUserName(media)))
|
if (username.equals(parentAgent.generateLocalUserName(media)))
|
||||||
{
|
{
|
||||||
if (stream.getRemotePassword() != null)
|
if(stream.getRemotePassword() != null)
|
||||||
return stream.getRemotePassword().getBytes();
|
return stream.getRemotePassword().getBytes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,10 +17,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.ice4j.ice;
|
package org.ice4j.ice;
|
||||||
|
|
||||||
import org.jitsi.utils.logging2.*;
|
|
||||||
|
|
||||||
import java.beans.*;
|
import java.beans.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.logging.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements ice4j internal nomination strategies.
|
* Implements ice4j internal nomination strategies.
|
||||||
@ -30,6 +29,12 @@ import java.util.*;
|
|||||||
public class DefaultNominator
|
public class DefaultNominator
|
||||||
implements PropertyChangeListener
|
implements PropertyChangeListener
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* The logger.
|
||||||
|
*/
|
||||||
|
private static final Logger logger
|
||||||
|
= Logger.getLogger(DefaultNominator.class.getName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Agent that created us.
|
* The Agent that created us.
|
||||||
*/
|
*/
|
||||||
@ -43,15 +48,10 @@ public class DefaultNominator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Map that will remember association between validated relayed candidate
|
* Map that will remember association between validated relayed candidate
|
||||||
* and a timer. It is used with the NOMINATE_FIRST_HIGHEST_VALID strategy.
|
* and a timer. It is use with the NOMINATE_FIRST_HIGHEST_VALID strategy.
|
||||||
*/
|
*/
|
||||||
private final Map<String, TimerTask> validatedCandidates = new HashMap<>();
|
private final Map<String, TimerTask> validatedCandidates = new HashMap<>();
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link Logger} used by {@link DefaultNominator} instances.
|
|
||||||
*/
|
|
||||||
private Logger logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of this nominator using <tt>parentAgent</tt> as
|
* Creates a new instance of this nominator using <tt>parentAgent</tt> as
|
||||||
* a reference to the <tt>Agent</tt> instance that we should use to
|
* a reference to the <tt>Agent</tt> instance that we should use to
|
||||||
@ -62,7 +62,6 @@ public class DefaultNominator
|
|||||||
public DefaultNominator(Agent parentAgent)
|
public DefaultNominator(Agent parentAgent)
|
||||||
{
|
{
|
||||||
this.parentAgent = parentAgent;
|
this.parentAgent = parentAgent;
|
||||||
logger = parentAgent.getLogger().createChildLogger(this.getClass().getName());
|
|
||||||
parentAgent.addStateChangeListener(this);
|
parentAgent.addStateChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,12 +76,12 @@ public class DefaultNominator
|
|||||||
{
|
{
|
||||||
String propertyName = ev.getPropertyName();
|
String propertyName = ev.getPropertyName();
|
||||||
|
|
||||||
if (Agent.PROPERTY_ICE_PROCESSING_STATE.equals(propertyName))
|
if(Agent.PROPERTY_ICE_PROCESSING_STATE.equals(propertyName))
|
||||||
{
|
{
|
||||||
if (ev.getNewValue() != IceProcessingState.RUNNING)
|
if(ev.getNewValue() != IceProcessingState.RUNNING)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (IceMediaStream stream : parentAgent.getStreams())
|
for(IceMediaStream stream : parentAgent.getStreams())
|
||||||
{
|
{
|
||||||
stream.addPairChangeListener(this);
|
stream.addPairChangeListener(this);
|
||||||
stream.getCheckList().addStateChangeListener(this);
|
stream.getCheckList().addStateChangeListener(this);
|
||||||
@ -95,23 +94,20 @@ public class DefaultNominator
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ev.getSource() instanceof CandidatePair)
|
if(ev.getSource() instanceof CandidatePair)
|
||||||
{
|
{
|
||||||
// STUN Usage for Consent Freshness is of no concern here.
|
// STUN Usage for Consent Freshness is of no concern here.
|
||||||
if (IceMediaStream.PROPERTY_PAIR_CONSENT_FRESHNESS_CHANGED.equals(propertyName))
|
if (IceMediaStream.PROPERTY_PAIR_CONSENT_FRESHNESS_CHANGED.equals(
|
||||||
{
|
propertyName))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
CandidatePair validPair = (CandidatePair) ev.getSource();
|
CandidatePair validPair = (CandidatePair) ev.getSource();
|
||||||
Component parentComponent = validPair.getParentComponent();
|
|
||||||
IceMediaStream parentStream = parentComponent.getParentStream();
|
|
||||||
|
|
||||||
// do not nominate pair if there is currently a nominated pair for
|
// do not nominate pair if there is currently a selected pair for
|
||||||
// the component
|
// the component
|
||||||
if (parentStream.validListContainsNomineeForComponent(parentComponent))
|
if(validPair.getParentComponent().getSelectedPair() != null)
|
||||||
{
|
{
|
||||||
logger.debug(() ->
|
logger.fine(
|
||||||
"Keep-alive for pair: " + validPair.toShortString());
|
"Keep-alive for pair: " + validPair.toShortString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -135,13 +131,11 @@ public class DefaultNominator
|
|||||||
*/
|
*/
|
||||||
private void strategyNominateFirstValid(PropertyChangeEvent evt)
|
private void strategyNominateFirstValid(PropertyChangeEvent evt)
|
||||||
{
|
{
|
||||||
if (IceMediaStream.PROPERTY_PAIR_VALIDATED
|
if(IceMediaStream.PROPERTY_PAIR_VALIDATED.equals(evt.getPropertyName()))
|
||||||
.equals(evt.getPropertyName()))
|
|
||||||
{
|
{
|
||||||
CandidatePair validPair = (CandidatePair)evt.getSource();
|
CandidatePair validPair = (CandidatePair)evt.getSource();
|
||||||
|
|
||||||
logger.info("Nominate (first valid): " + validPair.toShortString()
|
logger.info("Nominate (first valid): " + validPair.toShortString());
|
||||||
+ ".");
|
|
||||||
parentAgent.nominate(validPair);
|
parentAgent.nominate(validPair);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -158,7 +152,7 @@ public class DefaultNominator
|
|||||||
{
|
{
|
||||||
String pname = ev.getPropertyName();
|
String pname = ev.getPropertyName();
|
||||||
|
|
||||||
if (IceMediaStream.PROPERTY_PAIR_VALIDATED.equals(pname)
|
if(IceMediaStream.PROPERTY_PAIR_VALIDATED.equals(pname)
|
||||||
|| (IceMediaStream.PROPERTY_PAIR_STATE_CHANGED.equals(pname)
|
|| (IceMediaStream.PROPERTY_PAIR_STATE_CHANGED.equals(pname)
|
||||||
&& (ev.getNewValue() == CandidatePairState.FAILED)))
|
&& (ev.getNewValue() == CandidatePairState.FAILED)))
|
||||||
{
|
{
|
||||||
@ -167,14 +161,14 @@ public class DefaultNominator
|
|||||||
IceMediaStream parentStream = parentComponent.getParentStream();
|
IceMediaStream parentStream = parentComponent.getParentStream();
|
||||||
CheckList parentCheckList = parentStream.getCheckList();
|
CheckList parentCheckList = parentStream.getCheckList();
|
||||||
|
|
||||||
if (!parentCheckList.allChecksCompleted())
|
if(!parentCheckList.allChecksCompleted())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (Component component : parentStream.getComponents())
|
for(Component component : parentStream.getComponents())
|
||||||
{
|
{
|
||||||
CandidatePair pair = parentStream.getValidPair(component);
|
CandidatePair pair = parentStream.getValidPair(component);
|
||||||
|
|
||||||
if (pair != null)
|
if(pair != null)
|
||||||
{
|
{
|
||||||
logger.info(
|
logger.info(
|
||||||
"Nominate (highest priority): "
|
"Nominate (highest priority): "
|
||||||
@ -185,18 +179,6 @@ public class DefaultNominator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link NominationStrategy} that this nominator is using when
|
|
||||||
* deciding whether or not a valid {@link CandidatePair} is suitable for
|
|
||||||
* nomination.
|
|
||||||
*
|
|
||||||
* @return the {@link NominationStrategy} we are using.
|
|
||||||
*/
|
|
||||||
public NominationStrategy getStrategy()
|
|
||||||
{
|
|
||||||
return strategy;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link NominationStrategy} that this nominator should use when
|
* The {@link NominationStrategy} that this nominator should use when
|
||||||
* deciding whether or not a valid {@link CandidatePair} is suitable for
|
* deciding whether or not a valid {@link CandidatePair} is suitable for
|
||||||
@ -222,7 +204,7 @@ public class DefaultNominator
|
|||||||
private void strategyNominateFirstHostOrReflexiveValid(
|
private void strategyNominateFirstHostOrReflexiveValid(
|
||||||
PropertyChangeEvent evt)
|
PropertyChangeEvent evt)
|
||||||
{
|
{
|
||||||
if (IceMediaStream.PROPERTY_PAIR_VALIDATED.equals(evt.getPropertyName()))
|
if(IceMediaStream.PROPERTY_PAIR_VALIDATED.equals(evt.getPropertyName()))
|
||||||
{
|
{
|
||||||
CandidatePair validPair = (CandidatePair) evt.getSource();
|
CandidatePair validPair = (CandidatePair) evt.getSource();
|
||||||
|
|
||||||
@ -236,12 +218,12 @@ public class DefaultNominator
|
|||||||
CandidateType.RELAYED_CANDIDATE);
|
CandidateType.RELAYED_CANDIDATE);
|
||||||
boolean nominate = false;
|
boolean nominate = false;
|
||||||
|
|
||||||
synchronized (validatedCandidates)
|
synchronized(validatedCandidates)
|
||||||
{
|
{
|
||||||
TimerTask task
|
TimerTask task
|
||||||
= validatedCandidates.get(component.toShortString());
|
= validatedCandidates.get(component.toShortString());
|
||||||
|
|
||||||
if (isRelayed && task == null)
|
if(isRelayed && task == null)
|
||||||
{
|
{
|
||||||
/* armed a timer and see if a host or server reflexive pair
|
/* armed a timer and see if a host or server reflexive pair
|
||||||
* gets nominated. Otherwise nominate the relayed candidate
|
* gets nominated. Otherwise nominate the relayed candidate
|
||||||
@ -254,10 +236,10 @@ public class DefaultNominator
|
|||||||
timer.schedule(task, 0);
|
timer.schedule(task, 0);
|
||||||
validatedCandidates.put(component.toShortString(), task);
|
validatedCandidates.put(component.toShortString(), task);
|
||||||
}
|
}
|
||||||
else if (!isRelayed)
|
else if(!isRelayed)
|
||||||
{
|
{
|
||||||
// host or server reflexive candidate pair
|
// host or server reflexive candidate pair
|
||||||
if (task != null)
|
if(task != null)
|
||||||
{
|
{
|
||||||
task.cancel();
|
task.cancel();
|
||||||
logger.info(
|
logger.info(
|
||||||
@ -272,7 +254,7 @@ public class DefaultNominator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nominate)
|
if(nominate)
|
||||||
parentAgent.nominate(validPair);
|
parentAgent.nominate(validPair);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -321,24 +303,18 @@ public class DefaultNominator
|
|||||||
*/
|
*/
|
||||||
public void propertyChange(PropertyChangeEvent evt)
|
public void propertyChange(PropertyChangeEvent evt)
|
||||||
{
|
{
|
||||||
// Make it clear that PROPERTY_CHECK_LIST_CHECKS is in use here.
|
/* check list has running out of ordinary checks, see if all other
|
||||||
if (!CheckList.PROPERTY_CHECK_LIST_CHECKS.equals(
|
* candidates are FAILED, in which case we nominate immediately
|
||||||
evt.getPropertyName()))
|
* the relayed candidate
|
||||||
{
|
*/
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check list has run out of ordinary checks, see if all other
|
|
||||||
// candidates are FAILED, in which case we nominate immediately
|
|
||||||
// the relayed candidate
|
|
||||||
CheckList checkList = (CheckList)evt.getSource();
|
CheckList checkList = (CheckList)evt.getSource();
|
||||||
boolean allFailed = true;
|
boolean allFailed = true;
|
||||||
|
|
||||||
synchronized (checkList)
|
synchronized(checkList)
|
||||||
{
|
{
|
||||||
for (CandidatePair c : checkList)
|
for(CandidatePair c : checkList)
|
||||||
{
|
{
|
||||||
if (c != pair && c.getState() != CandidatePairState.FAILED)
|
if(c != pair && c.getState() != CandidatePairState.FAILED)
|
||||||
{
|
{
|
||||||
allFailed = false;
|
allFailed = false;
|
||||||
break;
|
break;
|
||||||
@ -378,7 +354,7 @@ public class DefaultNominator
|
|||||||
{
|
{
|
||||||
Thread.sleep(WAIT_TIME);
|
Thread.sleep(WAIT_TIME);
|
||||||
}
|
}
|
||||||
catch (InterruptedException e)
|
catch(InterruptedException e)
|
||||||
{
|
{
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
}
|
}
|
||||||
@ -389,7 +365,7 @@ public class DefaultNominator
|
|||||||
this);
|
this);
|
||||||
validatedCandidates.remove(component.toShortString());
|
validatedCandidates.remove(component.toShortString());
|
||||||
|
|
||||||
if (cancelled)
|
if(cancelled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
|
|||||||
@ -83,7 +83,7 @@ public class FoundationsRegistry
|
|||||||
|
|
||||||
StringBuffer foundationStringBuff = new StringBuffer(type);
|
StringBuffer foundationStringBuff = new StringBuffer(type);
|
||||||
foundationStringBuff.append(base);
|
foundationStringBuff.append(base);
|
||||||
if (server != null)
|
if(server != null)
|
||||||
foundationStringBuff.append(server);
|
foundationStringBuff.append(server);
|
||||||
|
|
||||||
foundationStringBuff.append(transport);
|
foundationStringBuff.append(transport);
|
||||||
@ -97,7 +97,7 @@ public class FoundationsRegistry
|
|||||||
|
|
||||||
//obtain a new foundation number if we don't have one for this kind
|
//obtain a new foundation number if we don't have one for this kind
|
||||||
//of candidates.
|
//of candidates.
|
||||||
if (foundationValue == null)
|
if(foundationValue == null)
|
||||||
{
|
{
|
||||||
foundationValue = Integer.toString(++lastAssignedFoundation);
|
foundationValue = Integer.toString(++lastAssignedFoundation);
|
||||||
foundations.put(foundationString, foundationValue);
|
foundations.put(foundationString, foundationValue);
|
||||||
|
|||||||
@ -103,7 +103,7 @@ public class GoogleRelayedCandidate
|
|||||||
turnCandidateHarvest.hostCandidate.getParentComponent()
|
turnCandidateHarvest.hostCandidate.getParentComponent()
|
||||||
.findLocalCandidate(mappedAddress));
|
.findLocalCandidate(mappedAddress));
|
||||||
|
|
||||||
if (transportAddress.getTransport() == Transport.TCP)
|
if(transportAddress.getTransport() == Transport.TCP)
|
||||||
{
|
{
|
||||||
super.setExtendedType(
|
super.setExtendedType(
|
||||||
CandidateExtendedType.GOOGLE_TCP_TURN_RELAYED_CANDIDATE);
|
CandidateExtendedType.GOOGLE_TCP_TURN_RELAYED_CANDIDATE);
|
||||||
@ -191,22 +191,21 @@ public class GoogleRelayedCandidate
|
|||||||
*
|
*
|
||||||
* @return the <tt>DatagramSocket</tt> associated with this
|
* @return the <tt>DatagramSocket</tt> associated with this
|
||||||
* <tt>Candidate</tt>
|
* <tt>Candidate</tt>
|
||||||
* @see LocalCandidate#getCandidateIceSocketWrapper()
|
* @see LocalCandidate#getIceSocketWrapper()
|
||||||
*/
|
*/
|
||||||
@Override
|
public synchronized IceSocketWrapper getIceSocketWrapper()
|
||||||
public synchronized IceSocketWrapper getCandidateIceSocketWrapper()
|
|
||||||
{
|
{
|
||||||
if (socket == null)
|
if (socket == null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (getTransport() == Transport.UDP)
|
if(getTransport() == Transport.UDP)
|
||||||
{
|
{
|
||||||
socket
|
socket
|
||||||
= new IceUdpSocketWrapper(new MultiplexingDatagramSocket(
|
= new IceUdpSocketWrapper(new MultiplexingDatagramSocket(
|
||||||
getRelayedCandidateDatagramSocket()));
|
getRelayedCandidateDatagramSocket()));
|
||||||
}
|
}
|
||||||
else if (getTransport() == Transport.TCP)
|
else if(getTransport() == Transport.TCP)
|
||||||
{
|
{
|
||||||
final Socket s = getRelayedCandidateSocket();
|
final Socket s = getRelayedCandidateSocket();
|
||||||
socket = new IceTcpSocketWrapper(new MultiplexingSocket(s));
|
socket = new IceTcpSocketWrapper(new MultiplexingSocket(s));
|
||||||
|
|||||||
@ -131,12 +131,13 @@ public class HostCandidate extends LocalCandidate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* Gets the <tt>DatagramSocket</tt> associated with this <tt>Candidate</tt>.
|
||||||
* SHOULD NOT be used outside ice4j. Only exposed for use in the
|
*
|
||||||
* org.ice4j.socket package.
|
* @return the <tt>DatagramSocket</tt> associated with this
|
||||||
|
* <tt>Candidate</tt>
|
||||||
|
* @see LocalCandidate#getIceSocketWrapper()
|
||||||
*/
|
*/
|
||||||
@Override
|
public IceSocketWrapper getIceSocketWrapper()
|
||||||
public IceSocketWrapper getCandidateIceSocketWrapper()
|
|
||||||
{
|
{
|
||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,12 +19,9 @@ package org.ice4j.ice;
|
|||||||
|
|
||||||
import java.beans.*;
|
import java.beans.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.logging.*;
|
||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
import org.jitsi.utils.collections.*;
|
|
||||||
import org.jitsi.utils.logging2.*;
|
|
||||||
|
|
||||||
import static org.ice4j.ice.AgentConfig.config;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class represents a media stream from the ICE perspective, i.e. a
|
* The class represents a media stream from the ICE perspective, i.e. a
|
||||||
@ -35,6 +32,12 @@ import static org.ice4j.ice.AgentConfig.config;
|
|||||||
*/
|
*/
|
||||||
public class IceMediaStream
|
public class IceMediaStream
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Our class logger.
|
||||||
|
*/
|
||||||
|
private static final Logger logger =
|
||||||
|
Logger.getLogger(IceMediaStream.class.getName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The property name that we use when delivering events notifying listeners
|
* The property name that we use when delivering events notifying listeners
|
||||||
* that the consent freshness of a pair has changed.
|
* that the consent freshness of a pair has changed.
|
||||||
@ -60,19 +63,6 @@ public class IceMediaStream
|
|||||||
*/
|
*/
|
||||||
public static final String PROPERTY_PAIR_VALIDATED = "PairValidated";
|
public static final String PROPERTY_PAIR_VALIDATED = "PairValidated";
|
||||||
|
|
||||||
/**
|
|
||||||
* Use builder pattern to provide an immutable IceMediaStream instance.
|
|
||||||
*
|
|
||||||
* @param name the name of the media stream
|
|
||||||
* @param parentAgent the agent that is handling the session that this
|
|
||||||
* media stream is a part of
|
|
||||||
* @return IceMediaStream
|
|
||||||
*/
|
|
||||||
public static IceMediaStream build(Agent parentAgent, String name)
|
|
||||||
{
|
|
||||||
return new IceMediaStream(parentAgent, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of this media stream. The name is equal to the value specified
|
* The name of this media stream. The name is equal to the value specified
|
||||||
* in the SDP description.
|
* in the SDP description.
|
||||||
@ -129,7 +119,7 @@ public class IceMediaStream
|
|||||||
* across all check lists to a specific value, adn this value MUST be
|
* across all check lists to a specific value, adn this value MUST be
|
||||||
* configurable. A default of 100 is RECOMMENDED.
|
* configurable. A default of 100 is RECOMMENDED.
|
||||||
*/
|
*/
|
||||||
private int maxCheckListSize = config.getMaxCheckListSize();
|
private int maxCheckListSize = Agent.DEFAULT_MAX_CHECK_LIST_SIZE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user fragment that we received from the remote party.
|
* The user fragment that we received from the remote party.
|
||||||
@ -141,11 +131,6 @@ public class IceMediaStream
|
|||||||
*/
|
*/
|
||||||
private String remotePassword = null;
|
private String remotePassword = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link Logger} used by {@link IceMediaStream} instances.
|
|
||||||
*/
|
|
||||||
private Logger logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a new <tt>IceMediaStream</tt> object.
|
* Initializes a new <tt>IceMediaStream</tt> object.
|
||||||
*
|
*
|
||||||
@ -155,9 +140,6 @@ public class IceMediaStream
|
|||||||
*/
|
*/
|
||||||
protected IceMediaStream(Agent parentAgent, String name)
|
protected IceMediaStream(Agent parentAgent, String name)
|
||||||
{
|
{
|
||||||
logger = parentAgent.getLogger().createChildLogger(
|
|
||||||
IceMediaStream.class.getName(),
|
|
||||||
Collections.singletonMap("name", name));
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.parentAgent = parentAgent;
|
this.parentAgent = parentAgent;
|
||||||
checkList = new CheckList(this);
|
checkList = new CheckList(this);
|
||||||
@ -169,29 +151,16 @@ public class IceMediaStream
|
|||||||
* when creating the component so make sure you keep that in mind in case
|
* when creating the component so make sure you keep that in mind in case
|
||||||
* assigning a specific component ID is important to you.
|
* assigning a specific component ID is important to you.
|
||||||
*
|
*
|
||||||
* @param keepAliveStrategy the keep-alive strategy, which dictates which
|
|
||||||
* candidates pairs are going to be kept alive.
|
|
||||||
* @param useComponentSocket whether the "component socket" should be used
|
|
||||||
* or not. See {@link AgentConfig#getUseComponentSocket()}.
|
|
||||||
*
|
|
||||||
* @return the newly created stream <tt>Component</tt> after adding it to
|
* @return the newly created stream <tt>Component</tt> after adding it to
|
||||||
* the stream first.
|
* the stream first.
|
||||||
*/
|
*/
|
||||||
protected Component createComponent(
|
protected Component createComponent()
|
||||||
KeepAliveStrategy keepAliveStrategy,
|
|
||||||
boolean useComponentSocket)
|
|
||||||
{
|
{
|
||||||
Component component;
|
Component component;
|
||||||
|
|
||||||
synchronized (components)
|
synchronized (components)
|
||||||
{
|
{
|
||||||
component
|
component = new Component(++lastComponentID, this);
|
||||||
= new Component(
|
|
||||||
++lastComponentID,
|
|
||||||
this,
|
|
||||||
keepAliveStrategy,
|
|
||||||
useComponentSocket,
|
|
||||||
logger);
|
|
||||||
components.put(component.getComponentID(), component);
|
components.put(component.getComponentID(), component);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,6 +261,18 @@ public class IceMediaStream
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of <tt>Component</tt>s currently registered with this
|
||||||
|
* stream.
|
||||||
|
*
|
||||||
|
* @return the number of <tt>Component</tt>s currently registered with this
|
||||||
|
* stream.
|
||||||
|
*/
|
||||||
|
public int getStreamCount()
|
||||||
|
{
|
||||||
|
return getComponentCount();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a reference to the <tt>Agent</tt> that this stream belongs to.
|
* Returns a reference to the <tt>Agent</tt> that this stream belongs to.
|
||||||
*
|
*
|
||||||
@ -364,7 +345,7 @@ public class IceMediaStream
|
|||||||
|
|
||||||
orderCheckList();
|
orderCheckList();
|
||||||
pruneCheckList(checkList);
|
pruneCheckList(checkList);
|
||||||
logger.trace(() -> "Checklist initialized.");
|
logger.finest("Checklist initialized.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,7 +357,7 @@ public class IceMediaStream
|
|||||||
*/
|
*/
|
||||||
protected void createCheckList(List<CandidatePair> checkList)
|
protected void createCheckList(List<CandidatePair> checkList)
|
||||||
{
|
{
|
||||||
for (Component cmp : getComponents())
|
for(Component cmp : getComponents())
|
||||||
createCheckList(cmp, checkList);
|
createCheckList(cmp, checkList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,22 +376,22 @@ public class IceMediaStream
|
|||||||
List<RemoteCandidate> remoteCnds = component.getRemoteCandidates();
|
List<RemoteCandidate> remoteCnds = component.getRemoteCandidates();
|
||||||
LocalCandidate upnpBase = null;
|
LocalCandidate upnpBase = null;
|
||||||
|
|
||||||
for (LocalCandidate lc : localCnds)
|
for(LocalCandidate lc : localCnds)
|
||||||
{
|
{
|
||||||
// XXX do we assume a single UPNPCandidate here?
|
// XXX do we assume a single UPNPCandidate here?
|
||||||
if (lc instanceof UPNPCandidate)
|
if(lc instanceof UPNPCandidate)
|
||||||
upnpBase = lc.getBase();
|
upnpBase = lc.getBase();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (LocalCandidate localCnd : localCnds)
|
for(LocalCandidate localCnd : localCnds)
|
||||||
{
|
{
|
||||||
// Don't take into consideration UPnP base candidate
|
// Don't take into consideration UPnP base candidate
|
||||||
if (localCnd == upnpBase)
|
if(localCnd == upnpBase)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (RemoteCandidate remoteCnd : remoteCnds)
|
for(RemoteCandidate remoteCnd : remoteCnds)
|
||||||
{
|
{
|
||||||
if (localCnd.canReach(remoteCnd)
|
if(localCnd.canReach(remoteCnd)
|
||||||
&& remoteCnd.getTransportAddress().getPort() != 0)
|
&& remoteCnd.getTransportAddress().getPort() != 0)
|
||||||
{
|
{
|
||||||
CandidatePair pair
|
CandidatePair pair
|
||||||
@ -441,7 +422,7 @@ public class IceMediaStream
|
|||||||
* candidate with its base. Once this has been done, we remove each pair
|
* candidate with its base. Once this has been done, we remove each pair
|
||||||
* where the local and remote candidates are identical to the local and
|
* where the local and remote candidates are identical to the local and
|
||||||
* remote candidates of a pair higher up on the priority list.
|
* remote candidates of a pair higher up on the priority list.
|
||||||
* <br>
|
* <p/>
|
||||||
* In addition, in order to limit the attacks described in Section 18.5.2
|
* In addition, in order to limit the attacks described in Section 18.5.2
|
||||||
* of the ICE spec, we limit the total number of pairs and hence
|
* of the ICE spec, we limit the total number of pairs and hence
|
||||||
* (connectivity checks) to a specific value, (a total of 100 by default).
|
* (connectivity checks) to a specific value, (a total of 100 by default).
|
||||||
@ -456,12 +437,12 @@ public class IceMediaStream
|
|||||||
|
|
||||||
Iterator<CandidatePair> ckListIter = checkList.iterator();
|
Iterator<CandidatePair> ckListIter = checkList.iterator();
|
||||||
|
|
||||||
while (ckListIter.hasNext())
|
while(ckListIter.hasNext())
|
||||||
{
|
{
|
||||||
CandidatePair pair = ckListIter.next();
|
CandidatePair pair = ckListIter.next();
|
||||||
|
|
||||||
//drop all pairs above MAX_CHECK_LIST_SIZE.
|
//drop all pairs above MAX_CHECK_LIST_SIZE.
|
||||||
if (tmpCheckList.size() > maxCheckListSize)
|
if(tmpCheckList.size() > maxCheckListSize)
|
||||||
{
|
{
|
||||||
ckListIter.remove();
|
ckListIter.remove();
|
||||||
continue;
|
continue;
|
||||||
@ -469,14 +450,14 @@ public class IceMediaStream
|
|||||||
|
|
||||||
//replace local server reflexive candidates with their base.
|
//replace local server reflexive candidates with their base.
|
||||||
LocalCandidate localCnd = pair.getLocalCandidate();
|
LocalCandidate localCnd = pair.getLocalCandidate();
|
||||||
if ( localCnd.getType()
|
if( localCnd.getType()
|
||||||
== CandidateType.SERVER_REFLEXIVE_CANDIDATE)
|
== CandidateType.SERVER_REFLEXIVE_CANDIDATE)
|
||||||
{
|
{
|
||||||
pair.setLocalCandidate(localCnd.getBase());
|
pair.setLocalCandidate(localCnd.getBase());
|
||||||
|
|
||||||
//if the new pair corresponds to another one with a higher
|
//if the new pair corresponds to another one with a higher
|
||||||
//priority, then remove it.
|
//priority, then remove it.
|
||||||
if (tmpCheckList.contains(pair))
|
if(tmpCheckList.contains(pair))
|
||||||
{
|
{
|
||||||
ckListIter.remove();
|
ckListIter.remove();
|
||||||
continue;
|
continue;
|
||||||
@ -511,28 +492,23 @@ public class IceMediaStream
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the local <tt>LocalCandidate</tt> with the specified
|
* Returns the local <tt>LocalCandidate</tt> with the specified
|
||||||
* <tt>address</tt> if it belongs to any of this stream's components
|
* <tt>localAddress</tt> if it belongs to any of this stream's components
|
||||||
* or <tt>null</tt> otherwise. If {@code base} is also specified, tries to
|
* or <tt>null</tt> otherwise.
|
||||||
* find a candidate whose base matches {@code base}.
|
|
||||||
*
|
*
|
||||||
* @param address the {@link TransportAddress} we are looking for.
|
* @param localAddress the {@link TransportAddress} we are looking for.
|
||||||
* @param base an optional base to match.
|
|
||||||
*
|
*
|
||||||
* @return the local <tt>LocalCandidate</tt> with the specified
|
* @return the local <tt>LocalCandidate</tt> with the specified
|
||||||
* <tt>address</tt> if it belongs to any of this stream's components
|
* <tt>localAddress</tt> if it belongs to any of this stream's components
|
||||||
* or <tt>null</tt> otherwise.
|
* or <tt>null</tt> otherwise.
|
||||||
*/
|
*/
|
||||||
public LocalCandidate findLocalCandidate(TransportAddress address, LocalCandidate base)
|
public LocalCandidate findLocalCandidate(TransportAddress localAddress)
|
||||||
{
|
{
|
||||||
for (Component component : components.values())
|
for( Component cmp : components.values())
|
||||||
{
|
{
|
||||||
LocalCandidate localCandidate
|
LocalCandidate cnd = cmp.findLocalCandidate(localAddress);
|
||||||
= component.findLocalCandidate(address, base);
|
|
||||||
|
|
||||||
if (localCandidate != null)
|
if(cnd != null)
|
||||||
{
|
return cnd;
|
||||||
return localCandidate;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -552,11 +528,11 @@ public class IceMediaStream
|
|||||||
*/
|
*/
|
||||||
public RemoteCandidate findRemoteCandidate(TransportAddress remoteAddress)
|
public RemoteCandidate findRemoteCandidate(TransportAddress remoteAddress)
|
||||||
{
|
{
|
||||||
for ( Component cmp : components.values())
|
for( Component cmp : components.values())
|
||||||
{
|
{
|
||||||
RemoteCandidate cnd = cmp.findRemoteCandidate(remoteAddress);
|
RemoteCandidate cnd = cmp.findRemoteCandidate(remoteAddress);
|
||||||
|
|
||||||
if (cnd != null)
|
if(cnd != null)
|
||||||
return cnd;
|
return cnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -582,12 +558,12 @@ public class IceMediaStream
|
|||||||
{
|
{
|
||||||
synchronized(checkList)
|
synchronized(checkList)
|
||||||
{
|
{
|
||||||
for (CandidatePair pair : checkList)
|
for( CandidatePair pair : checkList)
|
||||||
{
|
{
|
||||||
if (pair.getLocalCandidate().getTransportAddress()
|
if( pair.getLocalCandidate().getTransportAddress()
|
||||||
.equals(localAddress)
|
.equals(localAddress)
|
||||||
&& pair.getRemoteCandidate().getTransportAddress()
|
&& pair.getRemoteCandidate().getTransportAddress()
|
||||||
.equals(remoteAddress))
|
.equals(remoteAddress) )
|
||||||
{
|
{
|
||||||
return pair;
|
return pair;
|
||||||
}
|
}
|
||||||
@ -612,12 +588,12 @@ public class IceMediaStream
|
|||||||
{
|
{
|
||||||
synchronized(checkList)
|
synchronized(checkList)
|
||||||
{
|
{
|
||||||
for (CandidatePair pair : checkList)
|
for( CandidatePair pair : checkList)
|
||||||
{
|
{
|
||||||
LocalCandidate local = pair.getLocalCandidate();
|
LocalCandidate local = pair.getLocalCandidate();
|
||||||
RemoteCandidate remote = pair.getRemoteCandidate();
|
RemoteCandidate remote = pair.getRemoteCandidate();
|
||||||
|
|
||||||
if (local.getUfrag().equals(remoteUFrag)
|
if(local.getUfrag().equals(remoteUFrag)
|
||||||
&& remote.getUfrag().equals(localUFrag))
|
&& remote.getUfrag().equals(localUFrag))
|
||||||
{
|
{
|
||||||
return pair;
|
return pair;
|
||||||
@ -638,7 +614,7 @@ public class IceMediaStream
|
|||||||
|
|
||||||
synchronized (components)
|
synchronized (components)
|
||||||
{
|
{
|
||||||
for (Component cmp : components.values())
|
for(Component cmp : components.values())
|
||||||
num += cmp.countLocalHostCandidates();
|
num += cmp.countLocalHostCandidates();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -670,7 +646,7 @@ public class IceMediaStream
|
|||||||
{
|
{
|
||||||
synchronized (validList)
|
synchronized (validList)
|
||||||
{
|
{
|
||||||
if (!validList.contains(pair))
|
if(!validList.contains(pair))
|
||||||
validList.add(pair);
|
validList.add(pair);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -691,7 +667,7 @@ public class IceMediaStream
|
|||||||
{
|
{
|
||||||
synchronized(validList)
|
synchronized(validList)
|
||||||
{
|
{
|
||||||
for (CandidatePair pair : validList)
|
for(CandidatePair pair : validList)
|
||||||
{
|
{
|
||||||
if (pair.getFoundation().equals(foundation))
|
if (pair.getFoundation().equals(foundation))
|
||||||
return true;
|
return true;
|
||||||
@ -739,7 +715,7 @@ public class IceMediaStream
|
|||||||
*/
|
*/
|
||||||
protected boolean validListContainsAllComponents()
|
protected boolean validListContainsAllComponents()
|
||||||
{
|
{
|
||||||
for (Component cmp : getComponents())
|
for(Component cmp : getComponents())
|
||||||
{
|
{
|
||||||
if (getValidPair(cmp) == null)
|
if (getValidPair(cmp) == null)
|
||||||
{
|
{
|
||||||
@ -787,9 +763,9 @@ public class IceMediaStream
|
|||||||
*/
|
*/
|
||||||
protected boolean allComponentsHaveSelected()
|
protected boolean allComponentsHaveSelected()
|
||||||
{
|
{
|
||||||
for (Component component : getComponents())
|
for(Component component : getComponents())
|
||||||
{
|
{
|
||||||
if (component.getSelectedPair() == null)
|
if(component.getSelectedPair() == null)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -807,11 +783,11 @@ public class IceMediaStream
|
|||||||
*/
|
*/
|
||||||
protected CandidatePair getValidPair(Component component)
|
protected CandidatePair getValidPair(Component component)
|
||||||
{
|
{
|
||||||
synchronized (validList)
|
synchronized(validList)
|
||||||
{
|
{
|
||||||
for (CandidatePair pair : validList)
|
for(CandidatePair pair : validList)
|
||||||
{
|
{
|
||||||
if (pair.getParentComponent() == component)
|
if(pair.getParentComponent() == component)
|
||||||
return pair;
|
return pair;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -828,9 +804,9 @@ public class IceMediaStream
|
|||||||
*/
|
*/
|
||||||
public void addPairChangeListener(PropertyChangeListener l)
|
public void addPairChangeListener(PropertyChangeListener l)
|
||||||
{
|
{
|
||||||
synchronized (streamListeners)
|
synchronized(streamListeners)
|
||||||
{
|
{
|
||||||
if (!streamListeners.contains(l))
|
if(!streamListeners.contains(l))
|
||||||
streamListeners.add(l);
|
streamListeners.add(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -843,7 +819,7 @@ public class IceMediaStream
|
|||||||
*/
|
*/
|
||||||
public void removePairStateChangeListener(PropertyChangeListener l)
|
public void removePairStateChangeListener(PropertyChangeListener l)
|
||||||
{
|
{
|
||||||
synchronized (streamListeners)
|
synchronized(streamListeners)
|
||||||
{
|
{
|
||||||
streamListeners.remove(l);
|
streamListeners.remove(l);
|
||||||
}
|
}
|
||||||
@ -865,7 +841,7 @@ public class IceMediaStream
|
|||||||
{
|
{
|
||||||
PropertyChangeListener[] ls;
|
PropertyChangeListener[] ls;
|
||||||
|
|
||||||
synchronized (streamListeners)
|
synchronized(streamListeners)
|
||||||
{
|
{
|
||||||
ls
|
ls
|
||||||
= streamListeners.toArray(
|
= streamListeners.toArray(
|
||||||
@ -875,7 +851,7 @@ public class IceMediaStream
|
|||||||
PropertyChangeEvent ev
|
PropertyChangeEvent ev
|
||||||
= new PropertyChangeEvent(source, propertyName, oldValue, newValue);
|
= new PropertyChangeEvent(source, propertyName, oldValue, newValue);
|
||||||
|
|
||||||
for (PropertyChangeListener l : ls)
|
for(PropertyChangeListener l : ls)
|
||||||
l.propertyChange(ev);
|
l.propertyChange(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -924,8 +900,17 @@ public class IceMediaStream
|
|||||||
return remotePassword;
|
return remotePassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Logger getLogger()
|
/**
|
||||||
|
* Use builder pattern to provide an immutable IceMediaStream instance.
|
||||||
|
*
|
||||||
|
* @param name the name of the media stream
|
||||||
|
* @param parentAgent the agent that is handling the session that this
|
||||||
|
* media stream is a part of
|
||||||
|
* @return IceMediaStream
|
||||||
|
*/
|
||||||
|
public static IceMediaStream build(Agent parentAgent, String name)
|
||||||
{
|
{
|
||||||
return logger;
|
return new IceMediaStream(parentAgent, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
|
|
||||||
*
|
|
||||||
* Copyright @ 2015 Atlassian Pty Ltd
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.ice4j.ice;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An enumeration of strategies for selecting which candidate pairs to
|
|
||||||
* keep alive.
|
|
||||||
*/
|
|
||||||
public enum KeepAliveStrategy
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Only keep alive the selected pair.
|
|
||||||
*/
|
|
||||||
SELECTED_ONLY("selected_only"),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Keep alive the selected pair and any TCP pairs.
|
|
||||||
*/
|
|
||||||
SELECTED_AND_TCP("selected_and_tcp"),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Keep alive all succeeded pairs.
|
|
||||||
*/
|
|
||||||
ALL_SUCCEEDED("all_succeeded");
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
KeepAliveStrategy(String name)
|
|
||||||
{
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the {@link KeepAliveStrategy} with name equal to the given
|
|
||||||
* string, or {@code null} if there is no such strategy.
|
|
||||||
* @param string the name of the strategy.
|
|
||||||
*/
|
|
||||||
public static KeepAliveStrategy fromString(String string)
|
|
||||||
{
|
|
||||||
for (KeepAliveStrategy strategy : KeepAliveStrategy.values())
|
|
||||||
{
|
|
||||||
if (strategy.name.equals(string))
|
|
||||||
return strategy;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -19,11 +19,11 @@ package org.ice4j.ice;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
|
import java.util.logging.*;
|
||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
import org.ice4j.socket.*;
|
import org.ice4j.socket.*;
|
||||||
import org.ice4j.stack.*;
|
import org.ice4j.stack.*;
|
||||||
import org.jitsi.utils.logging2.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <tt>LocalCandidate</tt>s are obtained by an agent for every stream component
|
* <tt>LocalCandidate</tt>s are obtained by an agent for every stream component
|
||||||
@ -35,16 +35,6 @@ import org.jitsi.utils.logging2.*;
|
|||||||
public abstract class LocalCandidate
|
public abstract class LocalCandidate
|
||||||
extends Candidate<LocalCandidate>
|
extends Candidate<LocalCandidate>
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* The <tt>Logger</tt> used by the <tt>LocalCandidate</tt> class for logging
|
|
||||||
* output.
|
|
||||||
* Note that this shouldn't be used directly by instances of
|
|
||||||
* {@link DefaultNominator}, because it doesn't take into account the
|
|
||||||
* per-instance log level. Instances should use {@link #logger} instead.
|
|
||||||
*/
|
|
||||||
private static final java.util.logging.Logger classLogger
|
|
||||||
= java.util.logging.Logger.getLogger(HostCandidate.class.getName());
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of method used to discover this candidate ("host", "upnp", "stun
|
* The type of method used to discover this candidate ("host", "upnp", "stun
|
||||||
* peer reflexive", "stun server reflexive", "turn relayed", "google turn
|
* peer reflexive", "stun server reflexive", "turn relayed", "google turn
|
||||||
@ -63,9 +53,11 @@ public abstract class LocalCandidate
|
|||||||
private boolean isSSL = false;
|
private boolean isSSL = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link Logger} used by {@link LocalCandidate} instances.
|
* The <tt>Logger</tt> used by the <tt>LocalCandidate</tt> class and its
|
||||||
|
* instances for logging output.
|
||||||
*/
|
*/
|
||||||
private final Logger logger;
|
private static final Logger logger
|
||||||
|
= Logger.getLogger(HostCandidate.class.getName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a <tt>LocalCandidate</tt> instance for the specified transport
|
* Creates a <tt>LocalCandidate</tt> instance for the specified transport
|
||||||
@ -90,10 +82,8 @@ public abstract class LocalCandidate
|
|||||||
CandidateType type,
|
CandidateType type,
|
||||||
CandidateExtendedType extendedType,
|
CandidateExtendedType extendedType,
|
||||||
LocalCandidate relatedCandidate)
|
LocalCandidate relatedCandidate)
|
||||||
|
|
||||||
{
|
{
|
||||||
super(transportAddress, parentComponent, type, relatedCandidate);
|
super(transportAddress, parentComponent, type, relatedCandidate);
|
||||||
logger = parentComponent.getLogger().createChildLogger(this.getClass().getName());
|
|
||||||
this.extendedType = extendedType;
|
this.extendedType = extendedType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +95,8 @@ public abstract class LocalCandidate
|
|||||||
* <tt>Candidate</tt>
|
* <tt>Candidate</tt>
|
||||||
*
|
*
|
||||||
* @deprecated This should be used by the library only. Users of ice4j
|
* @deprecated This should be used by the library only. Users of ice4j
|
||||||
* should use {@link org.ice4j.ice.Component#getSocket()} instead.
|
* should use {@link org.ice4j.ice.CandidatePair#getDatagramSocket()}
|
||||||
|
* on the appropriate <tt>CandidatePair</tt> instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public DatagramSocket getDatagramSocket()
|
public DatagramSocket getDatagramSocket()
|
||||||
@ -122,47 +113,37 @@ public abstract class LocalCandidate
|
|||||||
* <tt>Candidate</tt>
|
* <tt>Candidate</tt>
|
||||||
*
|
*
|
||||||
* @deprecated This should be used by the library only. Users of ice4j
|
* @deprecated This should be used by the library only. Users of ice4j
|
||||||
* should use {@link org.ice4j.ice.Component#getSocket()} instead.
|
* should use {@link org.ice4j.ice.CandidatePair#getSocket()} on the
|
||||||
|
* appropriate <tt>CandidatePair</tt> instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Socket getSocket()
|
public Socket getSocket()
|
||||||
{
|
{
|
||||||
return null;
|
IceSocketWrapper wrapper = getIceSocketWrapper();
|
||||||
|
return wrapper == null ? null : wrapper.getTCPSocket();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the {@link IceSocketWrapper} instance of the {@link Component}
|
* Gets the <tt>IceSocketWrapper</tt> associated with this
|
||||||
* which owns this {@link LocalCandidate}. Note that this IS NOT an
|
* <tt>Candidate</tt>.
|
||||||
* instance specific to this {@link LocalCandidate}. See
|
*
|
||||||
* {@link #getCandidateIceSocketWrapper()}.
|
* @return the <tt>IceSocketWrapper</tt> associated with this
|
||||||
|
* <tt>Candidate</tt>
|
||||||
*/
|
*/
|
||||||
protected IceSocketWrapper getIceSocketWrapper()
|
protected abstract IceSocketWrapper getIceSocketWrapper();
|
||||||
{
|
|
||||||
return getParentComponent().getSocketWrapper();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the {@link IceSocketWrapper} instance, if any, associated with
|
* Gets the <tt>IceSocketWrapper</tt> associated with this
|
||||||
* this candidate. Note that this IS NOT the instance which should be used
|
* <tt>Candidate</tt> which is to be used for a specific remote address.
|
||||||
* for reading and writing by the application, and SHOULD NOT be used from
|
* This default implementation ignores the remote address.
|
||||||
* outside ice4j (even if a subclass exposes it as public). Also see
|
*
|
||||||
* {@link #getIceSocketWrapper()}.
|
* @param remoteAddress the remote address for which to get a socket.
|
||||||
|
* @return the <tt>IceSocketWrapper</tt> associated with this
|
||||||
|
* <tt>Candidate</tt> which is to be used for a specific remote address.
|
||||||
*/
|
*/
|
||||||
protected abstract IceSocketWrapper getCandidateIceSocketWrapper();
|
protected IceSocketWrapper getIceSocketWrapper(SocketAddress remoteAddress)
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the {@link IceSocketWrapper} instance for this candidate,
|
|
||||||
* associated with a particular remote address.
|
|
||||||
* @param remoteAddress the remote address for which to return an
|
|
||||||
* associated socket.
|
|
||||||
*/
|
|
||||||
protected IceSocketWrapper getCandidateIceSocketWrapper(
|
|
||||||
SocketAddress remoteAddress)
|
|
||||||
{
|
{
|
||||||
// The default implementation just refers to the method which doesn't
|
return getIceSocketWrapper();
|
||||||
// involve a remove address. Extenders which support multiple instances
|
|
||||||
// mapped by remote address should override.
|
|
||||||
return getCandidateIceSocketWrapper();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -180,7 +161,7 @@ public abstract class LocalCandidate
|
|||||||
*/
|
*/
|
||||||
public IceSocketWrapper getStunSocket(TransportAddress serverAddress)
|
public IceSocketWrapper getStunSocket(TransportAddress serverAddress)
|
||||||
{
|
{
|
||||||
IceSocketWrapper hostSocket = getCandidateIceSocketWrapper();
|
IceSocketWrapper hostSocket = getIceSocketWrapper();
|
||||||
|
|
||||||
if (hostSocket != null
|
if (hostSocket != null
|
||||||
&& hostSocket.getTCPSocket() != null)
|
&& hostSocket.getTCPSocket() != null)
|
||||||
@ -202,7 +183,8 @@ public abstract class LocalCandidate
|
|||||||
}
|
}
|
||||||
catch (SocketException sex) //don't u just luv da name? ;)
|
catch (SocketException sex) //don't u just luv da name? ;)
|
||||||
{
|
{
|
||||||
logger.error("Failed to acquire Socket"
|
logger.log(Level.SEVERE,
|
||||||
|
"Failed to acquire Socket"
|
||||||
+ " specific to STUN communication.",
|
+ " specific to STUN communication.",
|
||||||
sex);
|
sex);
|
||||||
exception = sex;
|
exception = sex;
|
||||||
@ -258,7 +240,8 @@ public abstract class LocalCandidate
|
|||||||
}
|
}
|
||||||
catch (SocketException sex) //don't u just luv da name? ;)
|
catch (SocketException sex) //don't u just luv da name? ;)
|
||||||
{
|
{
|
||||||
logger.error("Failed to acquire DatagramSocket"
|
logger.log(Level.SEVERE,
|
||||||
|
"Failed to acquire DatagramSocket"
|
||||||
+ " specific to STUN communication.",
|
+ " specific to STUN communication.",
|
||||||
sex);
|
sex);
|
||||||
exception = sex;
|
exception = sex;
|
||||||
@ -327,7 +310,7 @@ public abstract class LocalCandidate
|
|||||||
protected void free()
|
protected void free()
|
||||||
{
|
{
|
||||||
// Close the socket associated with this LocalCandidate.
|
// Close the socket associated with this LocalCandidate.
|
||||||
IceSocketWrapper socket = getCandidateIceSocketWrapper();
|
IceSocketWrapper socket = getIceSocketWrapper();
|
||||||
|
|
||||||
if (socket != null)
|
if (socket != null)
|
||||||
{
|
{
|
||||||
@ -335,7 +318,7 @@ public abstract class LocalCandidate
|
|||||||
|
|
||||||
if ((base == null)
|
if ((base == null)
|
||||||
|| (base == this)
|
|| (base == this)
|
||||||
|| (base.getCandidateIceSocketWrapper() != socket))
|
|| (base.getIceSocketWrapper() != socket))
|
||||||
{
|
{
|
||||||
//remove our socket from the stack.
|
//remove our socket from the stack.
|
||||||
getStunStack().removeSocket(getTransportAddress());
|
getStunStack().removeSocket(getTransportAddress());
|
||||||
|
|||||||
@ -98,6 +98,35 @@ public class NetworkUtils
|
|||||||
&& (add.getAddress()[1] & 0xFF) == 254;
|
&& (add.getAddress()[1] & 0xFF) == 254;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the address is an IPv4 link local address. IPv4 link
|
||||||
|
* local addresses are those in the following networks:
|
||||||
|
*
|
||||||
|
* 10.0.0.0 to 10.255.255.255
|
||||||
|
* 172.16.0.0 to 172.31.255.255
|
||||||
|
* 192.168.0.0 to 192.168.255.255
|
||||||
|
*
|
||||||
|
* @param add the address to inspect
|
||||||
|
* @return true if add is a link local ipv4 address and false if not.
|
||||||
|
*/
|
||||||
|
public static boolean isLinkLocalIPv4Address(InetAddress add)
|
||||||
|
{
|
||||||
|
if (add instanceof Inet4Address)
|
||||||
|
{
|
||||||
|
byte address[] = add.getAddress();
|
||||||
|
if ( (address[0] & 0xFF) == 10)
|
||||||
|
return true;
|
||||||
|
if ( (address[0] & 0xFF) == 172
|
||||||
|
&& (address[1] & 0xFF) >= 16 && address[1] <= 31)
|
||||||
|
return true;
|
||||||
|
if ( (address[0] & 0xFF) == 192
|
||||||
|
&& (address[1] & 0xFF) == 168)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a random local port number that user applications could bind to.
|
* Returns a random local port number that user applications could bind to.
|
||||||
* (i.e. above 1024).
|
* (i.e. above 1024).
|
||||||
@ -109,16 +138,44 @@ public class NetworkUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a random local port number in the interval [min, max].
|
* Returns a random local port number, greater than min and lower than max.
|
||||||
*
|
*
|
||||||
* @param min the minimum allowed value for the returned port number.
|
* @param min the minimum allowed value for the returned port number.
|
||||||
* @param max the maximum allowed value for the returned port number.
|
* @param max the maximum allowed value for the returned port number.
|
||||||
*
|
*
|
||||||
* @return a random int in the interval [min, max].
|
* @return a random int located between greater than min and lower than max.
|
||||||
*/
|
*/
|
||||||
public static int getRandomPortNumber(int min, int max)
|
public static int getRandomPortNumber(int min, int max)
|
||||||
{
|
{
|
||||||
return portNumberGenerator.nextInt(max - min + 1) + min;
|
return portNumberGenerator.nextInt(max - min) + min;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a random local port number, greater than min and lower than max.
|
||||||
|
* If the pair flag is set to true, then the returned port number is
|
||||||
|
* guaranteed to be pair. This is useful for protocols that require this
|
||||||
|
* such as RTP
|
||||||
|
*
|
||||||
|
* @param min the minimum allowed value for the returned port number.
|
||||||
|
* @param max the maximum allowed value for the returned port number.
|
||||||
|
* @param pair specifies whether the caller would like the returned port to
|
||||||
|
* be pair.
|
||||||
|
*
|
||||||
|
* @return a random int located between greater than min and lower than max.
|
||||||
|
*/
|
||||||
|
public static int getRandomPortNumber(int min, int max, boolean pair)
|
||||||
|
{
|
||||||
|
if(pair)
|
||||||
|
{
|
||||||
|
int delta = max - min;
|
||||||
|
delta /= 2;
|
||||||
|
int port = getRandomPortNumber(min, min + delta);
|
||||||
|
return port * 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return getRandomPortNumber(min, max);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -342,15 +399,6 @@ public class NetworkUtils
|
|||||||
|
|
||||||
colonIndex = -1;
|
colonIndex = -1;
|
||||||
int i = 0, j = 0;
|
int i = 0, j = 0;
|
||||||
|
|
||||||
// Can be wrapped in []
|
|
||||||
if (addrBuff[i] == '[')
|
|
||||||
{
|
|
||||||
++i;
|
|
||||||
if (scopeID == -1)
|
|
||||||
--srcb_length;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Starting : mean we need to have at least one more.
|
// Starting : mean we need to have at least one more.
|
||||||
if (addrBuff[i] == ':')
|
if (addrBuff[i] == ':')
|
||||||
if (addrBuff[++i] != ':')
|
if (addrBuff[++i] != ':')
|
||||||
@ -482,7 +530,7 @@ public class NetworkUtils
|
|||||||
if (isMappedIPv4Addr(addr))
|
if (isMappedIPv4Addr(addr))
|
||||||
{
|
{
|
||||||
byte[] newAddr = new byte[IN4_ADDR_SIZE];
|
byte[] newAddr = new byte[IN4_ADDR_SIZE];
|
||||||
System.arraycopy(addr, 12, newAddr, 0, IN4_ADDR_SIZE);
|
System.arraycopy(addr, 12, newAddr, 0, IN6_ADDR_SIZE);
|
||||||
return newAddr;
|
return newAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -614,13 +662,13 @@ public class NetworkUtils
|
|||||||
return IN4_ADDR_ANY;
|
return IN4_ADDR_ANY;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (ifaces.hasMoreElements())
|
while(ifaces.hasMoreElements())
|
||||||
{
|
{
|
||||||
Enumeration<InetAddress> addrs
|
Enumeration<InetAddress> addrs
|
||||||
= ifaces.nextElement().getInetAddresses();
|
= ifaces.nextElement().getInetAddresses();
|
||||||
while (addrs.hasMoreElements())
|
while (addrs.hasMoreElements())
|
||||||
{
|
{
|
||||||
if (addrs.nextElement() instanceof Inet6Address)
|
if(addrs.nextElement() instanceof Inet6Address)
|
||||||
return IN6_ADDR_ANY;
|
return IN6_ADDR_ANY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -635,11 +683,11 @@ public class NetworkUtils
|
|||||||
* @param port the port number that we'd like verified.
|
* @param port the port number that we'd like verified.
|
||||||
*
|
*
|
||||||
* @return <tt>true</tt> if port is a valid and bindable port number and
|
* @return <tt>true</tt> if port is a valid and bindable port number and
|
||||||
* <tt>false</tt> otherwise.
|
* <tt>alse</tt> otherwise.
|
||||||
*/
|
*/
|
||||||
public static boolean isValidPortNumber(int port)
|
public static boolean isValidPortNumber(int port)
|
||||||
{
|
{
|
||||||
return MIN_PORT_NUMBER <= port && port <= MAX_PORT_NUMBER;
|
return MIN_PORT_NUMBER < port && port < MAX_PORT_NUMBER;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -752,7 +800,7 @@ public class NetworkUtils
|
|||||||
|
|
||||||
//in case this was an IPv6 literal and we remove the closing bracket,
|
//in case this was an IPv6 literal and we remove the closing bracket,
|
||||||
//put it back in now.
|
//put it back in now.
|
||||||
if (ipv6Address.charAt(0) == '['
|
if(ipv6Address.charAt(0) == '['
|
||||||
&& ipv6Address.charAt(ipv6Address.length()-1) != ']')
|
&& ipv6Address.charAt(ipv6Address.length()-1) != ']')
|
||||||
{
|
{
|
||||||
ipv6Address += ']';
|
ipv6Address += ']';
|
||||||
|
|||||||
@ -44,11 +44,8 @@ public enum NominationStrategy
|
|||||||
NOMINATE_FIRST_VALID("NominateFirstValid"),
|
NOMINATE_FIRST_VALID("NominateFirstValid"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The strategy consists in nominating the highest priority valid pair.
|
* The strategy consists in nominating the highest priority valid pair once
|
||||||
* Once a pair is validated, if no higher-priority pairs remain outstanding,
|
* all checks in a list have completed.
|
||||||
* it is nominated; otherwise, a timer is armed, and if higher-priority
|
|
||||||
* pairs are still outstanding after the timeout, the highest-priority validated
|
|
||||||
* pair is nominated.
|
|
||||||
*/
|
*/
|
||||||
NOMINATE_HIGHEST_PRIO("NominateHighestPriority"),
|
NOMINATE_HIGHEST_PRIO("NominateHighestPriority"),
|
||||||
|
|
||||||
@ -93,19 +90,4 @@ public enum NominationStrategy
|
|||||||
{
|
{
|
||||||
return strategyName;
|
return strategyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the {@link NominationStrategy} with name equal to the given
|
|
||||||
* string, or {@code null} if there is no such strategy.
|
|
||||||
* @param string the name of the strategy.
|
|
||||||
*/
|
|
||||||
public static NominationStrategy fromString(String string)
|
|
||||||
{
|
|
||||||
for (NominationStrategy strategy : NominationStrategy.values())
|
|
||||||
{
|
|
||||||
if (strategy.strategyName.equals(string))
|
|
||||||
return strategy;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,15 +61,18 @@ public class PeerReflexiveCandidate
|
|||||||
base);
|
base);
|
||||||
super.setBase(base);
|
super.setBase(base);
|
||||||
super.priority = priority;
|
super.priority = priority;
|
||||||
super.setTcpType(base.getTcpType());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* Returns the <tt>DatagramSocket</tt> associated with this
|
||||||
|
* <tt>Candidate</tt>.
|
||||||
|
*
|
||||||
|
* @return the <tt>DatagramSocket</tt> associated with this
|
||||||
|
* <tt>Candidate</tt>
|
||||||
|
* @see LocalCandidate#getIceSocketWrapper()
|
||||||
*/
|
*/
|
||||||
@Override
|
public IceSocketWrapper getIceSocketWrapper()
|
||||||
public IceSocketWrapper getCandidateIceSocketWrapper()
|
|
||||||
{
|
{
|
||||||
return getBase().getCandidateIceSocketWrapper();
|
return getBase().getIceSocketWrapper();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -101,7 +101,7 @@ public class RelayedCandidate
|
|||||||
* @return the <tt>RelayedCandidateDatagramSocket</tt> of this
|
* @return the <tt>RelayedCandidateDatagramSocket</tt> of this
|
||||||
* <tt>RelayedCandidate</tt>
|
* <tt>RelayedCandidate</tt>
|
||||||
*/
|
*/
|
||||||
private synchronized RelayedCandidateDatagramSocket
|
public synchronized RelayedCandidateDatagramSocket
|
||||||
getRelayedCandidateDatagramSocket()
|
getRelayedCandidateDatagramSocket()
|
||||||
{
|
{
|
||||||
if (relayedCandidateDatagramSocket == null)
|
if (relayedCandidateDatagramSocket == null)
|
||||||
@ -127,9 +127,9 @@ public class RelayedCandidate
|
|||||||
*
|
*
|
||||||
* @return the <tt>DatagramSocket</tt> associated with this
|
* @return the <tt>DatagramSocket</tt> associated with this
|
||||||
* <tt>Candidate</tt>
|
* <tt>Candidate</tt>
|
||||||
|
* @see LocalCandidate#getIceSocketWrapper()
|
||||||
*/
|
*/
|
||||||
@Override
|
public synchronized IceSocketWrapper getIceSocketWrapper()
|
||||||
public synchronized IceSocketWrapper getCandidateIceSocketWrapper()
|
|
||||||
{
|
{
|
||||||
if (socket == null)
|
if (socket == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -104,12 +104,16 @@ public class ServerReflexiveCandidate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* Gets the <tt>DatagramSocket</tt> associated with this <tt>Candidate</tt>.
|
||||||
|
*
|
||||||
|
* @return the <tt>DatagramSocket</tt> associated with this
|
||||||
|
* <tt>Candidate</tt>
|
||||||
|
* @see LocalCandidate#getIceSocketWrapper()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public IceSocketWrapper getCandidateIceSocketWrapper()
|
public IceSocketWrapper getIceSocketWrapper()
|
||||||
{
|
{
|
||||||
return getBase().getCandidateIceSocketWrapper();
|
return getBase().getIceSocketWrapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -123,7 +127,7 @@ public class ServerReflexiveCandidate
|
|||||||
{
|
{
|
||||||
super.free();
|
super.free();
|
||||||
|
|
||||||
if (stunHarvest != null)
|
if(stunHarvest != null)
|
||||||
stunHarvest.close();
|
stunHarvest.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,23 +54,6 @@ public class TcpHostCandidate
|
|||||||
super(transportAddress, parentComponent);
|
super(transportAddress, parentComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected IceSocketWrapper getCandidateIceSocketWrapper(
|
|
||||||
SocketAddress remoteAddress)
|
|
||||||
{
|
|
||||||
for (IceSocketWrapper socket : sockets)
|
|
||||||
{
|
|
||||||
if (socket.getTCPSocket().getRemoteSocketAddress()
|
|
||||||
.equals(remoteAddress))
|
|
||||||
return socket;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addSocket(IceSocketWrapper socket)
|
public void addSocket(IceSocketWrapper socket)
|
||||||
{
|
{
|
||||||
sockets.add(socket);
|
sockets.add(socket);
|
||||||
@ -100,4 +83,16 @@ public class TcpHostCandidate
|
|||||||
super.free();
|
super.free();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IceSocketWrapper getIceSocketWrapper(SocketAddress remoteAddress)
|
||||||
|
{
|
||||||
|
for (IceSocketWrapper socket : sockets)
|
||||||
|
{
|
||||||
|
if (socket.getTCPSocket().getRemoteSocketAddress()
|
||||||
|
.equals(remoteAddress))
|
||||||
|
return socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,8 +79,8 @@ public class UPNPCandidate
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
IceSocketWrapper socket = getCandidateIceSocketWrapper();
|
IceSocketWrapper socket = getIceSocketWrapper();
|
||||||
if (socket != null)
|
if(socket != null)
|
||||||
{
|
{
|
||||||
socket.close();
|
socket.close();
|
||||||
}
|
}
|
||||||
@ -89,19 +89,13 @@ public class UPNPCandidate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* Gets the <tt>DatagramSocket</tt> associated with this <tt>Candidate</tt>.
|
||||||
|
*
|
||||||
|
* @return the <tt>DatagramSocket</tt> associated with this
|
||||||
|
* <tt>Candidate</tt>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public IceSocketWrapper getCandidateIceSocketWrapper()
|
public IceSocketWrapper getIceSocketWrapper()
|
||||||
{
|
|
||||||
return getBase().getCandidateIceSocketWrapper();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected IceSocketWrapper getIceSocketWrapper()
|
|
||||||
{
|
{
|
||||||
return getBase().getIceSocketWrapper();
|
return getBase().getIceSocketWrapper();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
|
|
||||||
*
|
|
||||||
* Copyright @ 2015 Atlassian Pty Ltd
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.ice4j.ice.harvest;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An abstract partial implementation of {@link CandidateHarvester}.
|
|
||||||
*
|
|
||||||
* @author Emil Ivov
|
|
||||||
* @author Lyubomir Marinov
|
|
||||||
* @author Boris Grozev
|
|
||||||
*/
|
|
||||||
public abstract class AbstractCandidateHarvester
|
|
||||||
implements CandidateHarvester
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Manages statistics about harvesting time.
|
|
||||||
*/
|
|
||||||
private HarvestStatistics harvestStatistics = new HarvestStatistics();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public HarvestStatistics getHarvestStatistics()
|
|
||||||
{
|
|
||||||
return harvestStatistics;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean isHostHarvester()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,703 +0,0 @@
|
|||||||
/*
|
|
||||||
* ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
|
|
||||||
*
|
|
||||||
* Copyright @ 2015 Atlassian Pty Ltd
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.ice4j.ice.harvest;
|
|
||||||
|
|
||||||
import org.ice4j.*;
|
|
||||||
import org.ice4j.attribute.*;
|
|
||||||
import org.ice4j.message.*;
|
|
||||||
import org.jitsi.utils.queue.*;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.*;
|
|
||||||
import java.time.*;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.*;
|
|
||||||
import java.util.logging.*;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import static org.ice4j.ice.harvest.HarvestConfig.config;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A class which holds a {@link DatagramSocket} and runs a thread
|
|
||||||
* ({@link #thread}) which perpetually reads from it.
|
|
||||||
*
|
|
||||||
* When a datagram from an unknown source is received, it is parsed as a STUN
|
|
||||||
* Binding Request, and if it has a USERNAME attribute, its ufrag is extracted.
|
|
||||||
* At this point, an implementing class may choose to create a mapping for
|
|
||||||
* the remote address of the datagram, which will be used for further packets
|
|
||||||
* from this address.
|
|
||||||
*
|
|
||||||
* @author Boris Grozev
|
|
||||||
*/
|
|
||||||
public abstract class AbstractUdpListener
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Our class logger.
|
|
||||||
*/
|
|
||||||
private static final Logger logger
|
|
||||||
= Logger.getLogger(AbstractUdpListener.class.getName());
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The size for newly allocated <tt>Buffer</tt> instances. This limits the
|
|
||||||
* maximum size of datagrams we can receive.
|
|
||||||
*
|
|
||||||
* XXX should we increase this in case of other MTUs, or set it dynamically
|
|
||||||
* according to the available network interfaces?
|
|
||||||
*/
|
|
||||||
private static final int BUFFER_SIZE
|
|
||||||
= /* assumed MTU */ 1500 - /* IPv4 header */ 20 - /* UDP header */ 8;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The number of <tt>Buffer</tt> instances to keep in {@link #pool}.
|
|
||||||
*/
|
|
||||||
private static final int POOL_SIZE = 256;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the list of {@link TransportAddress}es, one for each allowed IP
|
|
||||||
* address found on each allowed network interface, with the given port.
|
|
||||||
*
|
|
||||||
* @param port the UDP port number.
|
|
||||||
* @return the list of allowed transport addresses.
|
|
||||||
*/
|
|
||||||
public static List<TransportAddress> getAllowedAddresses(int port)
|
|
||||||
{
|
|
||||||
List<TransportAddress> addresses = new LinkedList<>();
|
|
||||||
for (InetAddress address
|
|
||||||
: HostCandidateHarvester.getAllAllowedAddresses())
|
|
||||||
{
|
|
||||||
addresses.add(new TransportAddress(address, port, Transport.UDP));
|
|
||||||
}
|
|
||||||
|
|
||||||
return addresses;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to parse the bytes in <tt>buf</tt> at offset <tt>off</tt> (and
|
|
||||||
* length <tt>len</tt>) as a STUN Binding Request message. If successful,
|
|
||||||
* looks for a USERNAME attribute and returns the local username fragment
|
|
||||||
* part (see RFC5245 Section 7.1.2.3).
|
|
||||||
* In case of any failure returns <tt>null</tt>.
|
|
||||||
*
|
|
||||||
* @param buf the bytes.
|
|
||||||
* @param off the offset.
|
|
||||||
* @param len the length.
|
|
||||||
* @return the local ufrag from the USERNAME attribute of the STUN message
|
|
||||||
* contained in <tt>buf</tt>, or <tt>null</tt>.
|
|
||||||
*/
|
|
||||||
static String getUfrag(byte[] buf, int off, int len)
|
|
||||||
{
|
|
||||||
// RFC5389, Section 6:
|
|
||||||
// All STUN messages MUST start with a 20-byte header followed by zero
|
|
||||||
// or more Attributes.
|
|
||||||
if (buf == null || buf.length < off + len || len < 20)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// RFC5389, Section 6:
|
|
||||||
// The magic cookie field MUST contain the fixed value 0x2112A442 in
|
|
||||||
// network byte order.
|
|
||||||
if ( !( (buf[off + 4] & 0xFF) == 0x21 &&
|
|
||||||
(buf[off + 5] & 0xFF) == 0x12 &&
|
|
||||||
(buf[off + 6] & 0xFF) == 0xA4 &&
|
|
||||||
(buf[off + 7] & 0xFF) == 0x42))
|
|
||||||
{
|
|
||||||
if (logger.isLoggable(Level.FINE))
|
|
||||||
{
|
|
||||||
logger.fine("Not a STUN packet, magic cookie not found.");
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Message stunMessage = Message.decode(buf, off, len);
|
|
||||||
|
|
||||||
if (stunMessage.getMessageType()
|
|
||||||
!= Message.BINDING_REQUEST)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
UsernameAttribute usernameAttribute
|
|
||||||
= (UsernameAttribute)
|
|
||||||
stunMessage.getAttribute(Attribute.USERNAME);
|
|
||||||
if (usernameAttribute == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
String usernameString
|
|
||||||
= new String(usernameAttribute.getUsername());
|
|
||||||
return usernameString.split(":")[0];
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
// Catch everything. We are going to log, and then drop the packet
|
|
||||||
// anyway.
|
|
||||||
if (logger.isLoggable(Level.FINE))
|
|
||||||
{
|
|
||||||
logger.fine("Failed to extract local ufrag: " + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The map which keeps the known remote addresses and their associated
|
|
||||||
* candidateSockets.
|
|
||||||
* {@link #thread} is the only thread which adds new entries, while
|
|
||||||
* other threads remove entries when candidates are freed.
|
|
||||||
*/
|
|
||||||
private final Map<SocketAddress, MySocket> sockets
|
|
||||||
= new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A pool of <tt>Buffer</tt> instances used to avoid creating of new java
|
|
||||||
* objects.
|
|
||||||
*/
|
|
||||||
private final ArrayBlockingQueue<Buffer> pool
|
|
||||||
= new ArrayBlockingQueue<>(POOL_SIZE);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The local address that this harvester is bound to.
|
|
||||||
*/
|
|
||||||
protected final TransportAddress localAddress;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The "main" socket that this harvester reads from.
|
|
||||||
*/
|
|
||||||
private final DatagramSocket socket;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The thread reading from {@link #socket}.
|
|
||||||
*/
|
|
||||||
private final Thread thread;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggers the termination of the threads of this instance.
|
|
||||||
*/
|
|
||||||
private boolean close = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes a new <tt>SinglePortUdpHarvester</tt> instance which is to
|
|
||||||
* bind on the specified local address.
|
|
||||||
* @param localAddress the address to bind to. If the port is 0 an ephemeral port will be chosen by the OS and the
|
|
||||||
* AbstractUdpListener.localAddress will reflect the allocated port.
|
|
||||||
* @throws IOException if initialization fails.
|
|
||||||
*/
|
|
||||||
protected AbstractUdpListener(TransportAddress localAddress)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
TransportAddress tempAddress = localAddress;
|
|
||||||
|
|
||||||
boolean bindWildcard = StackProperties.getBoolean(
|
|
||||||
StackProperties.BIND_WILDCARD,
|
|
||||||
false);
|
|
||||||
|
|
||||||
if (bindWildcard)
|
|
||||||
{
|
|
||||||
tempAddress = new TransportAddress(
|
|
||||||
(InetAddress) null,
|
|
||||||
localAddress.getPort(),
|
|
||||||
localAddress.getTransport()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
socket = new DatagramSocket( tempAddress );
|
|
||||||
|
|
||||||
Integer receiveBufferSize = config.udpReceiveBufferSize();
|
|
||||||
if (receiveBufferSize != null)
|
|
||||||
{
|
|
||||||
socket.setReceiveBufferSize(receiveBufferSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Update the port number if needed. */
|
|
||||||
if (localAddress.getPort() == 0)
|
|
||||||
{
|
|
||||||
tempAddress = new TransportAddress(
|
|
||||||
tempAddress.getAddress(),
|
|
||||||
socket.getLocalPort(),
|
|
||||||
tempAddress.getTransport()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
this.localAddress = tempAddress;
|
|
||||||
|
|
||||||
String logMessage
|
|
||||||
= "Initialized AbstractUdpListener with address " + this.localAddress;
|
|
||||||
logMessage += ". Receive buffer size " + socket.getReceiveBufferSize();
|
|
||||||
if (receiveBufferSize != null)
|
|
||||||
{
|
|
||||||
logMessage += " (asked for " + receiveBufferSize + ")";
|
|
||||||
}
|
|
||||||
logger.info(logMessage);
|
|
||||||
|
|
||||||
thread = new Thread()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
AbstractUdpListener.this.runInHarvesterThread();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
thread.setName(AbstractUdpListener.class.getName() + " thread for " + this.localAddress);
|
|
||||||
thread.setDaemon(true);
|
|
||||||
thread.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TransportAddress getLocalAddress()
|
|
||||||
{
|
|
||||||
return localAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggers the termination of the threads of this instance.
|
|
||||||
*/
|
|
||||||
public void close()
|
|
||||||
{
|
|
||||||
close = true;
|
|
||||||
socket.close(); // causes socket#receive to stop blocking.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Perpetually reads datagrams from {@link #socket} and handles them
|
|
||||||
* accordingly.
|
|
||||||
*
|
|
||||||
* It is important that this blocks are little as possible (except on
|
|
||||||
* socket.receive(), of course), because it could potentially delay the
|
|
||||||
* reception of both ICE and media packets for the whole application.
|
|
||||||
*/
|
|
||||||
private void runInHarvesterThread()
|
|
||||||
{
|
|
||||||
Buffer buf;
|
|
||||||
DatagramPacket pkt = null;
|
|
||||||
MySocket destinationSocket;
|
|
||||||
InetSocketAddress remoteAddress;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
if (close)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
buf = getFreeBuffer();
|
|
||||||
|
|
||||||
if (pkt == null)
|
|
||||||
pkt = new DatagramPacket(buf.buffer, 0, buf.buffer.length);
|
|
||||||
else
|
|
||||||
pkt.setData(buf.buffer, 0, buf.buffer.length);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
socket.receive(pkt);
|
|
||||||
}
|
|
||||||
catch (IOException ioe)
|
|
||||||
{
|
|
||||||
if (!close)
|
|
||||||
{
|
|
||||||
logger.severe("Failed to receive from socket: " + ioe);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
buf.len = pkt.getLength();
|
|
||||||
|
|
||||||
|
|
||||||
remoteAddress = (InetSocketAddress) pkt.getSocketAddress();
|
|
||||||
destinationSocket = sockets.get(remoteAddress);
|
|
||||||
if (destinationSocket != null)
|
|
||||||
{
|
|
||||||
//make 'pkt' available for reading through destinationSocket
|
|
||||||
destinationSocket.addBuffer(buf);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Packet from an unknown source. Is it a STUN Binding Request?
|
|
||||||
String ufrag = getUfrag(buf.buffer, 0, buf.len);
|
|
||||||
if (ufrag == null)
|
|
||||||
{
|
|
||||||
// Not a STUN Binding Request or doesn't have a valid
|
|
||||||
// USERNAME attribute. Drop it.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
maybeAcceptNewSession(buf, remoteAddress, ufrag);
|
|
||||||
// Maybe add to #sockets here in the base class?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (true);
|
|
||||||
|
|
||||||
// now clean up and exit
|
|
||||||
for (MySocket candidateSocket : new ArrayList<>(sockets.values()))
|
|
||||||
{
|
|
||||||
candidateSocket.close();
|
|
||||||
}
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles the reception of a STUN Binding Request with a valid USERNAME
|
|
||||||
* attribute, from a "new" remote address (one which is not in
|
|
||||||
* {@link #sockets}).
|
|
||||||
* Implementations may choose to e.g. create a socket and pass it to their
|
|
||||||
* ICE stack.
|
|
||||||
*
|
|
||||||
* Note that this is meant to only be executed by
|
|
||||||
* {@link AbstractUdpListener}'s read thread, and should not be called from
|
|
||||||
* implementing classes.
|
|
||||||
*
|
|
||||||
* @param buf the UDP payload of the first datagram received on the newly
|
|
||||||
* accepted socket.
|
|
||||||
* @param remoteAddress the remote address from which the datagram was
|
|
||||||
* received.
|
|
||||||
* @param ufrag the local ICE username fragment of the received STUN Binding
|
|
||||||
* Request.
|
|
||||||
*/
|
|
||||||
protected abstract void maybeAcceptNewSession(
|
|
||||||
Buffer buf,
|
|
||||||
InetSocketAddress remoteAddress,
|
|
||||||
String ufrag);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets an unused <tt>Buffer</tt> instance, creating it if necessary.
|
|
||||||
* @return an unused <tt>Buffer</tt> instance, creating it if necessary.
|
|
||||||
*/
|
|
||||||
private Buffer getFreeBuffer()
|
|
||||||
{
|
|
||||||
Buffer buf = pool.poll();
|
|
||||||
if (buf == null)
|
|
||||||
{
|
|
||||||
buf = new Buffer(new byte[BUFFER_SIZE], 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new {@link MySocket} instance and associates it with the given
|
|
||||||
* remote address. Returns the created instance.
|
|
||||||
*
|
|
||||||
* Note that this is meant to only execute in {@link AbstractUdpListener}'s
|
|
||||||
* read thread.
|
|
||||||
*
|
|
||||||
* @param remoteAddress the remote address with which to associate the new
|
|
||||||
* socket instance.
|
|
||||||
* @param ufrag The username fragment associated with the socket.
|
|
||||||
* @return the created socket instance.
|
|
||||||
*/
|
|
||||||
protected MySocket addSocket(InetSocketAddress remoteAddress, String ufrag)
|
|
||||||
throws SocketException
|
|
||||||
{
|
|
||||||
MySocket newSocket = new MySocket(remoteAddress, ufrag);
|
|
||||||
sockets.put(remoteAddress, newSocket);
|
|
||||||
return newSocket;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements a <tt>DatagramSocket</tt> for the purposes of a specific
|
|
||||||
* <tt>MyCandidate</tt>.
|
|
||||||
*
|
|
||||||
* It is not bound to a specific port, but shares the same local address
|
|
||||||
* as the bound socket held by the harvester.
|
|
||||||
*/
|
|
||||||
protected class MySocket
|
|
||||||
extends DatagramSocket
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The size of {@link #queue}.
|
|
||||||
*/
|
|
||||||
private static final int QUEUE_SIZE = 128;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The FIFO which acts as a buffer for this socket.
|
|
||||||
*/
|
|
||||||
private final ArrayBlockingQueue<Buffer> queue
|
|
||||||
= new ArrayBlockingQueue<>(QUEUE_SIZE);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link QueueStatistics} instance optionally used to collect and
|
|
||||||
* print detailed statistics about {@link #queue}.
|
|
||||||
*/
|
|
||||||
private final QueueStatistics queueStatistics;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The remote address that is associated with this socket.
|
|
||||||
*/
|
|
||||||
private InetSocketAddress remoteAddress;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The flag which indicates that this <tt>DatagramSocket</tt> has been
|
|
||||||
* closed.
|
|
||||||
*/
|
|
||||||
private boolean closed = false;
|
|
||||||
|
|
||||||
private final String ufrag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes a new <tt>MySocket</tt> instance with the given
|
|
||||||
* remote address.
|
|
||||||
* @param remoteAddress the remote address to be associated with the
|
|
||||||
* new instance.
|
|
||||||
* @throws SocketException
|
|
||||||
*/
|
|
||||||
MySocket(InetSocketAddress remoteAddress, String ufrag)
|
|
||||||
throws SocketException
|
|
||||||
{
|
|
||||||
// unbound
|
|
||||||
super((SocketAddress)null);
|
|
||||||
|
|
||||||
this.ufrag = ufrag;
|
|
||||||
this.remoteAddress = remoteAddress;
|
|
||||||
if (logger.isLoggable(Level.FINEST))
|
|
||||||
{
|
|
||||||
queueStatistics = new QueueStatistics(QUEUE_SIZE, Clock.systemUTC());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
queueStatistics = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds pkt to this socket. If the queue is full, drops a packet. Does
|
|
||||||
* not block.
|
|
||||||
*/
|
|
||||||
public void addBuffer(Buffer buf)
|
|
||||||
{
|
|
||||||
synchronized (queue)
|
|
||||||
{
|
|
||||||
// Drop the first rather than the current packet, so that
|
|
||||||
// receivers can notice the loss earlier.
|
|
||||||
if (queue.size() == QUEUE_SIZE)
|
|
||||||
{
|
|
||||||
logger.info(
|
|
||||||
"Dropping a packet because the queue is full. Remote address = "
|
|
||||||
+ remoteAddress + " ufrag=" + ufrag);
|
|
||||||
if (queueStatistics != null)
|
|
||||||
{
|
|
||||||
queueStatistics.dropped();
|
|
||||||
}
|
|
||||||
queue.poll();
|
|
||||||
}
|
|
||||||
|
|
||||||
queue.offer(buf);
|
|
||||||
if (queueStatistics != null)
|
|
||||||
{
|
|
||||||
queueStatistics.added();
|
|
||||||
}
|
|
||||||
|
|
||||||
queue.notify();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* Delegates to the actual socket of the harvester.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public InetAddress getLocalAddress()
|
|
||||||
{
|
|
||||||
return localAddress.getAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* Delegates to the actual socket of the harvester.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int getLocalPort()
|
|
||||||
{
|
|
||||||
return localAddress.getPort();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* Delegates to the actual socket of the harvester.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public SocketAddress getLocalSocketAddress()
|
|
||||||
{
|
|
||||||
return localAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
* </p>
|
|
||||||
* This {@link DatagramSocket} will only allow packets from the
|
|
||||||
* remote address that it has, so we consider it connected to this
|
|
||||||
* address.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public SocketAddress getRemoteSocketAddress()
|
|
||||||
{
|
|
||||||
return remoteAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
* </p>
|
|
||||||
* This {@link DatagramSocket} will only allow packets from the
|
|
||||||
* remote address that it has, so we consider it connected to this
|
|
||||||
* address.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public InetAddress getInetAddress()
|
|
||||||
{
|
|
||||||
return remoteAddress.getAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
* </p>
|
|
||||||
* This {@link DatagramSocket} will only allow packets from the
|
|
||||||
* remote address that it has, so we consider it connected to this
|
|
||||||
* address.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int getPort()
|
|
||||||
{
|
|
||||||
return remoteAddress.getPort();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* Removes the association of the remote address with this socket from
|
|
||||||
* the harvester's map.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void close()
|
|
||||||
{
|
|
||||||
synchronized (queue)
|
|
||||||
{
|
|
||||||
closed = true;
|
|
||||||
|
|
||||||
// Wake up any threads still in receive()
|
|
||||||
queue.notifyAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
// We could be called by the super-class constructor, in which
|
|
||||||
// case this.removeAddress is not initialized yet.
|
|
||||||
if (remoteAddress != null)
|
|
||||||
{
|
|
||||||
AbstractUdpListener.this.sockets.remove(remoteAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads the data from the first element of {@link #queue} into
|
|
||||||
* <tt>p</tt>. Blocks until {@link #queue} has an element.
|
|
||||||
* @param p
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void receive(DatagramPacket p)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
Buffer buf = null;
|
|
||||||
|
|
||||||
while (buf == null)
|
|
||||||
{
|
|
||||||
synchronized (queue)
|
|
||||||
{
|
|
||||||
if (closed)
|
|
||||||
{
|
|
||||||
throw new SocketException("Socket closed");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (queue.isEmpty())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
queue.wait();
|
|
||||||
}
|
|
||||||
catch (InterruptedException ie)
|
|
||||||
{}
|
|
||||||
}
|
|
||||||
|
|
||||||
buf = queue.poll();
|
|
||||||
if (buf != null && queueStatistics != null)
|
|
||||||
{
|
|
||||||
queueStatistics.removed(queue.size(), null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] pData = p.getData();
|
|
||||||
|
|
||||||
// XXX Should we use p.setData() here with a buffer of our own?
|
|
||||||
if (pData == null || pData.length < buf.len)
|
|
||||||
{
|
|
||||||
throw new IOException("packet buffer not available");
|
|
||||||
}
|
|
||||||
|
|
||||||
System.arraycopy(buf.buffer, 0, pData, 0, buf.len);
|
|
||||||
p.setLength(buf.len);
|
|
||||||
p.setSocketAddress(remoteAddress);
|
|
||||||
|
|
||||||
pool.offer(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* Delegates to the actual socket of the harvester.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void send(DatagramPacket p)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
socket.send(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a buffer for the purposes of <tt>SinglePortUdpHarvester</tt>.
|
|
||||||
* Wraps a byte[] and adds a length field specifying the number of elements
|
|
||||||
* actually used.
|
|
||||||
*/
|
|
||||||
protected class Buffer
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The actual data.
|
|
||||||
*/
|
|
||||||
byte[] buffer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The number of elements of {@link #buffer} actually used.
|
|
||||||
*/
|
|
||||||
int len;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes a new <tt>Buffer</tt> instance.
|
|
||||||
* @param buffer the data.
|
|
||||||
* @param len the length.
|
|
||||||
*/
|
|
||||||
private Buffer(byte[] buffer, int len)
|
|
||||||
{
|
|
||||||
this.buffer = buffer;
|
|
||||||
this.len = len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -83,7 +83,7 @@ public class AwsCandidateHarvester
|
|||||||
*/
|
*/
|
||||||
public AwsCandidateHarvester()
|
public AwsCandidateHarvester()
|
||||||
{
|
{
|
||||||
super("aws");
|
super(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -130,7 +130,6 @@ public class AwsCandidateHarvester
|
|||||||
* Returns the public (mask) address, or null.
|
* Returns the public (mask) address, or null.
|
||||||
* @return the public (mask) address, or null.
|
* @return the public (mask) address, or null.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public TransportAddress getMask()
|
public TransportAddress getMask()
|
||||||
{
|
{
|
||||||
if (smellsLikeAnEC2())
|
if (smellsLikeAnEC2())
|
||||||
@ -145,7 +144,6 @@ public class AwsCandidateHarvester
|
|||||||
* Returns the local (face) address, or null.
|
* Returns the local (face) address, or null.
|
||||||
* @return the local (face) address, or null.
|
* @return the local (face) address, or null.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public TransportAddress getFace()
|
public TransportAddress getFace()
|
||||||
{
|
{
|
||||||
if (smellsLikeAnEC2())
|
if (smellsLikeAnEC2())
|
||||||
|
|||||||
@ -28,10 +28,14 @@ import org.ice4j.ice.*;
|
|||||||
*
|
*
|
||||||
* @author Emil Ivov
|
* @author Emil Ivov
|
||||||
* @author Lyubomir Marinov
|
* @author Lyubomir Marinov
|
||||||
* @author Boris Grozev
|
|
||||||
*/
|
*/
|
||||||
public interface CandidateHarvester
|
public abstract class CandidateHarvester
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Manages statistics about harvesting time.
|
||||||
|
*/
|
||||||
|
private HarvestStatistics harvestStatistics = new HarvestStatistics();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gathers all candidate addresses of the type that this
|
* Gathers all candidate addresses of the type that this
|
||||||
* <tt>CandidateHarvester</tt> supports. The gathered candidate addresses
|
* <tt>CandidateHarvester</tt> supports. The gathered candidate addresses
|
||||||
@ -48,7 +52,7 @@ public interface CandidateHarvester
|
|||||||
* as they are discovered, they should also be returned in order to make
|
* as they are discovered, they should also be returned in order to make
|
||||||
* sure that the gathering will be considered successful.
|
* sure that the gathering will be considered successful.
|
||||||
*/
|
*/
|
||||||
Collection<LocalCandidate> harvest(Component component);
|
public abstract Collection<LocalCandidate> harvest(Component component);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the statistics describing how well the various harvests of this
|
* Returns the statistics describing how well the various harvests of this
|
||||||
@ -57,7 +61,10 @@ public interface CandidateHarvester
|
|||||||
* @return The {@link HarvestStatistics} describing this harvester's
|
* @return The {@link HarvestStatistics} describing this harvester's
|
||||||
* harvests.
|
* harvests.
|
||||||
*/
|
*/
|
||||||
HarvestStatistics getHarvestStatistics();
|
public HarvestStatistics getHarvestStatistics()
|
||||||
|
{
|
||||||
|
return harvestStatistics;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns <tt>true</tt> if this <tt>CandidateHarvester</tt> is to be
|
* Returns <tt>true</tt> if this <tt>CandidateHarvester</tt> is to be
|
||||||
@ -70,5 +77,8 @@ public interface CandidateHarvester
|
|||||||
* @return <tt>true</tt> if this <tt>CandidateHarvester</tt> is a harvester
|
* @return <tt>true</tt> if this <tt>CandidateHarvester</tt> is a harvester
|
||||||
* for host candidates.
|
* for host candidates.
|
||||||
*/
|
*/
|
||||||
boolean isHostHarvester();
|
public boolean isHostHarvester()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,6 @@ import java.util.*;
|
|||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
|
|
||||||
import org.ice4j.*;
|
|
||||||
import org.ice4j.ice.*;
|
import org.ice4j.ice.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -198,17 +197,7 @@ public class CandidateHarvesterSet
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
future.get(HarvestConfig.config.timeout().toMillis(), TimeUnit.MILLISECONDS);
|
future.get();
|
||||||
break;
|
|
||||||
}
|
|
||||||
catch (TimeoutException te)
|
|
||||||
{
|
|
||||||
CandidateHarvesterSetElement harvester = task.getKey().getHarvester();
|
|
||||||
if (harvester != null)
|
|
||||||
{
|
|
||||||
harvester.setEnabled(false);
|
|
||||||
}
|
|
||||||
logger.warning("timed out while harvesting from " + harvester);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
catch (CancellationException ce)
|
catch (CancellationException ce)
|
||||||
|
|||||||
@ -96,7 +96,7 @@ class CandidateHarvesterSetElement
|
|||||||
{
|
{
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
}
|
}
|
||||||
else if (trickleCallback != null)
|
else if(trickleCallback != null)
|
||||||
{
|
{
|
||||||
trickleCallback.onIceCandidates(candidates);
|
trickleCallback.onIceCandidates(candidates);
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@ class CandidateHarvesterSetElement
|
|||||||
*/
|
*/
|
||||||
public void setEnabled(boolean enabled)
|
public void setEnabled(boolean enabled)
|
||||||
{
|
{
|
||||||
logger.fine((enabled ? "Enabling: " : "Disabling: ") + harvester);
|
logger.info((enabled ? "Enabling: " : "Disabling: ") + harvester);
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -105,7 +105,7 @@ public class GoogleTurnCandidateHarvest
|
|||||||
Attribute attribute
|
Attribute attribute
|
||||||
= response.getAttribute(Attribute.MAPPED_ADDRESS);
|
= response.getAttribute(Attribute.MAPPED_ADDRESS);
|
||||||
|
|
||||||
if (attribute != null)
|
if(attribute != null)
|
||||||
{
|
{
|
||||||
TransportAddress relayedAddress
|
TransportAddress relayedAddress
|
||||||
= ((MappedAddressAttribute) attribute).getAddress();
|
= ((MappedAddressAttribute) attribute).getAddress();
|
||||||
@ -133,18 +133,6 @@ public class GoogleTurnCandidateHarvest
|
|||||||
harvester.getStunStack().addSocket(
|
harvester.getStunStack().addSocket(
|
||||||
relayedCandidate.getStunSocket(null));
|
relayedCandidate.getStunSocket(null));
|
||||||
|
|
||||||
// Make the relayed candidate's socket available for reading
|
|
||||||
// by the component.
|
|
||||||
IceSocketWrapper candidateSocket
|
|
||||||
= relayedCandidate.getCandidateIceSocketWrapper();
|
|
||||||
|
|
||||||
ComponentSocket componentSocket
|
|
||||||
= relayedCandidate.getParentComponent().getComponentSocket();
|
|
||||||
if (componentSocket != null)
|
|
||||||
{
|
|
||||||
componentSocket.add(candidateSocket);
|
|
||||||
}
|
|
||||||
|
|
||||||
addCandidate(relayedCandidate);
|
addCandidate(relayedCandidate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,109 +29,43 @@ import org.ice4j.socket.*;
|
|||||||
* Implements a <tt>CandidateHarvester</tt> which gathers Google TURN SSLTCP
|
* Implements a <tt>CandidateHarvester</tt> which gathers Google TURN SSLTCP
|
||||||
* dialect <tt>Candidate</tt>s for a specified {@link Component}.
|
* dialect <tt>Candidate</tt>s for a specified {@link Component}.
|
||||||
*
|
*
|
||||||
* This dialect exchanges a SSL v2.0 client-hello answered by a TLS v1.0
|
|
||||||
* server-hello, before TURN data is exchanged. The data is SSL-spec compliant,
|
|
||||||
* but use hard-coded values for data that typically aught to be generated
|
|
||||||
* (for example: challenge, session-id and random fields).
|
|
||||||
*
|
|
||||||
* @author Sebastien Vincent
|
* @author Sebastien Vincent
|
||||||
*/
|
*/
|
||||||
public class GoogleTurnSSLCandidateHarvester
|
public class GoogleTurnSSLCandidateHarvester
|
||||||
extends GoogleTurnCandidateHarvester
|
extends GoogleTurnCandidateHarvester
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Data for the SSL message sent by the server ('server-hello').
|
* Data for the SSL message sent by the server.
|
||||||
*/
|
*/
|
||||||
static final byte SSL_SERVER_HANDSHAKE[] =
|
static final byte SSL_SERVER_HANDSHAKE[] =
|
||||||
{
|
{
|
||||||
// Content type: Handshake
|
0x16, 0x03, 0x01, 0x00, 0x4a, 0x02, 0x00, 0x00,
|
||||||
0x16,
|
0x46, 0x03, 0x01, 0x42, (byte)0x85, 0x45, (byte)0xa7, 0x27,
|
||||||
|
(byte)0xa9, 0x5d, (byte)0xa0, (byte)0xb3, (byte)0xc5, (byte)0xe7, 0x53,
|
||||||
// Version: TLS 1.0
|
(byte)0xda,
|
||||||
0x03, 0x01,
|
0x48, 0x2b, 0x3f, (byte)0xc6, 0x5a, (byte)0xca, (byte)0x89, (byte)0xc1,
|
||||||
|
0x58, 0x52, (byte)0xa1, 0x78, 0x3c, 0x5b, 0x17, 0x46,
|
||||||
// Length: 74
|
0x00, (byte)0x85, 0x3f, 0x20, 0x0e, (byte)0xd3, 0x06, 0x72,
|
||||||
0x00, 0x4a,
|
0x5b, 0x5b, 0x1b, 0x5f, 0x15, (byte)0xac, 0x13, (byte)0xf9,
|
||||||
|
(byte)0x88, 0x53, (byte)0x9d, (byte)0x9b, (byte)0xe8, 0x3d, 0x7b, 0x0c,
|
||||||
// Handshake Layer starts here
|
|
||||||
|
|
||||||
// Handshake type: Server Hello
|
|
||||||
0x02,
|
|
||||||
|
|
||||||
// Length: 70
|
|
||||||
0x00, 0x00, 0x46,
|
|
||||||
|
|
||||||
// Version: TLS 1.0
|
|
||||||
0x03, 0x01,
|
|
||||||
|
|
||||||
// 32 bytes random (well, obviously hardcoded here)
|
|
||||||
0x42, (byte)0x85, 0x45, (byte)0xa7, 0x27, (byte)0xa9,
|
|
||||||
0x5d, (byte)0xa0, (byte)0xb3, (byte)0xc5, (byte)0xe7,
|
|
||||||
0x53, (byte)0xda, 0x48, 0x2b, 0x3f, (byte)0xc6, 0x5a,
|
|
||||||
(byte)0xca, (byte)0x89, (byte)0xc1, 0x58, 0x52,
|
|
||||||
(byte)0xa1, 0x78, 0x3c, 0x5b, 0x17, 0x46, 0x00,
|
|
||||||
(byte)0x85, 0x3f,
|
|
||||||
|
|
||||||
// Session-ID length: 32
|
|
||||||
0x20,
|
|
||||||
|
|
||||||
// Session-ID
|
|
||||||
0x0e, (byte)0xd3, 0x06, 0x72, 0x5b, 0x5b, 0x1b, 0x5f,
|
|
||||||
0x15, (byte)0xac, 0x13, (byte)0xf9, (byte)0x88, 0x53,
|
|
||||||
(byte)0x9d, (byte)0x9b, (byte)0xe8, 0x3d, 0x7b, 0x0c,
|
|
||||||
0x30, 0x32, 0x6e, 0x38, 0x4d, (byte)0xa2, 0x75, 0x57,
|
0x30, 0x32, 0x6e, 0x38, 0x4d, (byte)0xa2, 0x75, 0x57,
|
||||||
0x41, 0x6c, 0x34, 0x5c,
|
0x41, 0x6c, 0x34, 0x5c, 0x00, 0x04, 0x00
|
||||||
|
|
||||||
// Selected Cipher suite
|
|
||||||
0x00, 0x04, // TLS_RSA_WITH_RC4_128_MD5
|
|
||||||
|
|
||||||
// Compression method: null
|
|
||||||
0x00
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data for the SSL message sent by the client (client-hello).
|
* Data for the SSL message sent by the client.
|
||||||
*/
|
*/
|
||||||
public static final byte SSL_CLIENT_HANDSHAKE[] =
|
public static final byte SSL_CLIENT_HANDSHAKE[] =
|
||||||
{
|
{
|
||||||
// Version: SSL 2.0 (0x0002) and length: 70
|
(byte)0x80, 0x46, 0x01, 0x03, 0x01, 0x00, 0x2d, 0x00,
|
||||||
(byte)0x80, 0x46,
|
0x00, 0x00, 0x10, 0x01, 0x00, (byte)0x80, 0x03, 0x00,
|
||||||
|
(byte)0x80, 0x07, 0x00, (byte)0xc0, 0x06, 0x00, 0x40, 0x02,
|
||||||
// Handshake message type: Client Hello
|
0x00, (byte)0x80, 0x04, 0x00, (byte)0x80, 0x00, 0x00, 0x04,
|
||||||
0x01,
|
0x00, (byte)0xfe, (byte)0xff, 0x00, 0x00, 0x0a, 0x00, (byte)0xfe,
|
||||||
|
(byte)0xfe, 0x00, 0x00, 0x09, 0x00, 0x00, 0x64, 0x00,
|
||||||
// Version TLS 1.0
|
0x00, 0x62, 0x00, 0x00, 0x03, 0x00, 0x00, 0x06,
|
||||||
0x03, 0x01,
|
0x1f, 0x17, 0x0c, (byte)0xa6, 0x2f, 0x00, 0x78, (byte)0xfc,
|
||||||
|
0x46, 0x55, 0x2e, (byte)0xb1, (byte)0x83, 0x39, (byte)0xf1, (byte)0xea
|
||||||
// Cipher Spec Length: 45
|
|
||||||
0x00, 0x2d,
|
|
||||||
|
|
||||||
// Session ID: 0
|
|
||||||
0x00, 0x00,
|
|
||||||
|
|
||||||
// Challenge length: 16
|
|
||||||
0x00, 0x10,
|
|
||||||
|
|
||||||
// Cipher spec (15 cyphers)
|
|
||||||
0x01, 0x00, (byte)0x80, // SSL2_RC4_128_WITH_MD5
|
|
||||||
0x03, 0x00, (byte)0x80, // SSL2_rc2_128_CBC_WITH_MD5
|
|
||||||
0x07, 0x00, (byte)0xc0, // SSL2_DES_192_EDE3_CBC_WITH_MD5
|
|
||||||
0x06, 0x00, 0x40, // SSL2_DES_64_CBC_WITH_MD5
|
|
||||||
0x02, 0x00, (byte)0x80, // SSL2_RC4_128_EXPORT40_WITH_MD5
|
|
||||||
0x04, 0x00, (byte)0x80, // SSL2_RC2_128_CBC_EXPORT40_WITH_MD5
|
|
||||||
0x00, 0x00, 0x04, // TLS_RSA_WITH_RC4_128_MD5
|
|
||||||
0x00, (byte)0xfe, (byte)0xff, // SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA
|
|
||||||
0x00, 0x00, 0x0a, // TLS_RSA_WITH_3DES_EDE_CBC_SHA
|
|
||||||
0x00, (byte)0xfe, (byte)0xfe, // SSL_RSA_FIPS_WITH_DES_CBC_SHA
|
|
||||||
0x00, 0x00, 0x09, // TLS_RSA_WITH_DES_CBC_SHA
|
|
||||||
0x00, 0x00, 0x64, // TLS_RSA_EXPORT1024_WITH_RC4_56_SHA
|
|
||||||
0x00, 0x00, 0x62, // TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA
|
|
||||||
0x00, 0x00, 0x03, // TLS_RSA_EXPORT_WITH_RC4_40_MD5
|
|
||||||
0x00, 0x00, 0x06, // TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5
|
|
||||||
|
|
||||||
// Challenge
|
|
||||||
0x1f, 0x17, 0x0c, (byte)0xa6, 0x2f, 0x00, 0x78, (byte)0xfc, 0x46,
|
|
||||||
0x55, 0x2e, (byte)0xb1, (byte)0x83, 0x39, (byte)0xf1, (byte)0xea
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -187,7 +121,7 @@ public class GoogleTurnSSLCandidateHarvester
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the host candidate.
|
* Returns the host candidate.
|
||||||
* For UDP it simply returns the candidate passed as parameter
|
* For UDP it simply returns the candidate passed as paramter
|
||||||
*
|
*
|
||||||
* However for TCP, we cannot return the same hostCandidate because in Java
|
* However for TCP, we cannot return the same hostCandidate because in Java
|
||||||
* a "server" socket cannot connect to a destination with the same local
|
* a "server" socket cannot connect to a destination with the same local
|
||||||
@ -209,14 +143,14 @@ public class GoogleTurnSSLCandidateHarvester
|
|||||||
OutputStream outputStream = sock.getOutputStream();
|
OutputStream outputStream = sock.getOutputStream();
|
||||||
InputStream inputStream = sock.getInputStream();
|
InputStream inputStream = sock.getInputStream();
|
||||||
|
|
||||||
if (sslHandshake(inputStream, outputStream))
|
if(sslHandshake(inputStream, outputStream))
|
||||||
{
|
{
|
||||||
Component parentComponent = hostCand.getParentComponent();
|
Component parentComponent = hostCand.getParentComponent();
|
||||||
MultiplexingSocket multiplexing = new MultiplexingSocket(sock);
|
|
||||||
|
|
||||||
cand
|
cand
|
||||||
= new HostCandidate(
|
= new HostCandidate(
|
||||||
new IceTcpSocketWrapper(multiplexing),
|
new IceTcpSocketWrapper(
|
||||||
|
new MultiplexingSocket(sock)),
|
||||||
parentComponent,
|
parentComponent,
|
||||||
Transport.TCP);
|
Transport.TCP);
|
||||||
parentComponent
|
parentComponent
|
||||||
@ -224,12 +158,6 @@ public class GoogleTurnSSLCandidateHarvester
|
|||||||
.getParentAgent()
|
.getParentAgent()
|
||||||
.getStunStack()
|
.getStunStack()
|
||||||
.addSocket(cand.getStunSocket(null));
|
.addSocket(cand.getStunSocket(null));
|
||||||
ComponentSocket componentSocket
|
|
||||||
= parentComponent.getComponentSocket();
|
|
||||||
if (componentSocket != null)
|
|
||||||
{
|
|
||||||
componentSocket.add(multiplexing);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -259,12 +187,12 @@ public class GoogleTurnSSLCandidateHarvester
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Do the SSL handshake (send client certificate and wait for receive server
|
* Do the SSL handshake (send client certificate and wait for receive server
|
||||||
* certificate). We explicitly need <tt>InputStream</tt> and
|
* certificate). We explicitely need <tt>InputStream</tt> and
|
||||||
* <tt>OutputStream</tt> because some <tt>Socket</tt> may redefine
|
* <tt>OutputStream</tt> because some <tt>Socket</tt> may redefine
|
||||||
* getInputStream()/getOutputStream() and we need the original stream.
|
* getInputStream()/getOutputStream() and we need the original stream.
|
||||||
*
|
*
|
||||||
* @param inputStream <tt>InputStream</tt> of the socket
|
* @param inputStream <tt>InputStream</tt> of the socket
|
||||||
* @param outputStream <tt>OutputStream</tt> of the socket
|
* @param outputStream <tt>OuputStream</tt> of the socket
|
||||||
* @return true if the SSL handshake is done
|
* @return true if the SSL handshake is done
|
||||||
* @throws IOException if something goes wrong
|
* @throws IOException if something goes wrong
|
||||||
*/
|
*/
|
||||||
@ -279,7 +207,7 @@ public class GoogleTurnSSLCandidateHarvester
|
|||||||
outputStream = null;
|
outputStream = null;
|
||||||
inputStream = null;
|
inputStream = null;
|
||||||
|
|
||||||
if (Arrays.equals(data, SSL_SERVER_HANDSHAKE))
|
if(Arrays.equals(data, SSL_SERVER_HANDSHAKE))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,7 +75,7 @@ public class HarvestStatistics
|
|||||||
protected void stopHarvestTiming(Collection<LocalCandidate> harvest)
|
protected void stopHarvestTiming(Collection<LocalCandidate> harvest)
|
||||||
{
|
{
|
||||||
//count total candidates
|
//count total candidates
|
||||||
if (harvest != null)
|
if(harvest != null)
|
||||||
stopHarvestTiming(harvest.size());
|
stopHarvestTiming(harvest.size());
|
||||||
else
|
else
|
||||||
stopHarvestTiming(0);
|
stopHarvestTiming(0);
|
||||||
@ -108,13 +108,13 @@ public class HarvestStatistics
|
|||||||
*/
|
*/
|
||||||
public long getHarvestDuration()
|
public long getHarvestDuration()
|
||||||
{
|
{
|
||||||
if (this.lastStartHarvestingTime != -1)
|
if(this.lastStartHarvestingTime != -1)
|
||||||
{
|
{
|
||||||
long currentHarvestingTime
|
long currentHarvestingTime
|
||||||
= System.currentTimeMillis() - lastStartHarvestingTime;
|
= System.currentTimeMillis() - lastStartHarvestingTime;
|
||||||
// Retest here, while the harvesting may be end while computing the
|
// Retest here, while the harvesting may be end while computing the
|
||||||
// harvesting time.
|
// harvesting time.
|
||||||
if (this.lastStartHarvestingTime != -1)
|
if(this.lastStartHarvestingTime != -1)
|
||||||
{
|
{
|
||||||
return this.lastHarvestingTime + currentHarvestingTime;
|
return this.lastHarvestingTime + currentHarvestingTime;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,8 +26,6 @@ import org.ice4j.*;
|
|||||||
import org.ice4j.ice.*;
|
import org.ice4j.ice.*;
|
||||||
import org.ice4j.socket.*;
|
import org.ice4j.socket.*;
|
||||||
|
|
||||||
import static org.ice4j.ice.harvest.HarvestConfig.config;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A <tt>HostCandidateHarvester</tt> gathers host <tt>Candidate</tt>s for a
|
* A <tt>HostCandidateHarvester</tt> gathers host <tt>Candidate</tt>s for a
|
||||||
* specified {@link org.ice4j.ice.Component}. Most <tt>CandidateHarvester</tt>s
|
* specified {@link org.ice4j.ice.Component}. Most <tt>CandidateHarvester</tt>s
|
||||||
@ -131,17 +129,18 @@ public class HostCandidateHarvester
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the list of addresses which have been explicitly allowed via
|
* Gets the list of explicitly allowed addresses.
|
||||||
* configuration properties. To get the list of all allowed addresses,
|
|
||||||
* use {@link #getAllAllowedAddresses()}.
|
|
||||||
* @return the list of explicitly allowed addresses.
|
* @return the list of explicitly allowed addresses.
|
||||||
*/
|
*/
|
||||||
public static synchronized List<InetAddress> getAllowedAddresses()
|
public static List<InetAddress> getAllowedAddresses()
|
||||||
|
{
|
||||||
|
synchronized (HostCandidateHarvester.class)
|
||||||
{
|
{
|
||||||
if (!addressFiltersInitialized)
|
if (!addressFiltersInitialized)
|
||||||
{
|
{
|
||||||
initializeAddressFilters();
|
initializeAddressFilters();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return allowedAddresses;
|
return allowedAddresses;
|
||||||
}
|
}
|
||||||
@ -150,12 +149,15 @@ public class HostCandidateHarvester
|
|||||||
* Gets the list of blocked addresses.
|
* Gets the list of blocked addresses.
|
||||||
* @return the list of blocked addresses.
|
* @return the list of blocked addresses.
|
||||||
*/
|
*/
|
||||||
public static synchronized List<InetAddress> getBlockedAddresses()
|
public static List<InetAddress> getBlockedAddresses()
|
||||||
|
{
|
||||||
|
synchronized (HostCandidateHarvester.class)
|
||||||
{
|
{
|
||||||
if (!addressFiltersInitialized)
|
if (!addressFiltersInitialized)
|
||||||
{
|
{
|
||||||
initializeAddressFilters();
|
initializeAddressFilters();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return blockedAddresses;
|
return blockedAddresses;
|
||||||
}
|
}
|
||||||
@ -164,11 +166,12 @@ public class HostCandidateHarvester
|
|||||||
* Initializes the lists of allowed and blocked addresses according to the
|
* Initializes the lists of allowed and blocked addresses according to the
|
||||||
* configuration properties.
|
* configuration properties.
|
||||||
*/
|
*/
|
||||||
private static synchronized void initializeAddressFilters()
|
private static void initializeAddressFilters()
|
||||||
|
{
|
||||||
|
synchronized (HostCandidateHarvester.class)
|
||||||
{
|
{
|
||||||
if (addressFiltersInitialized)
|
if (addressFiltersInitialized)
|
||||||
return;
|
return;
|
||||||
addressFiltersInitialized = true;
|
|
||||||
|
|
||||||
String[] allowedAddressesStr
|
String[] allowedAddressesStr
|
||||||
= StackProperties.getStringArray(
|
= StackProperties.getStringArray(
|
||||||
@ -222,51 +225,9 @@ public class HostCandidateHarvester
|
|||||||
blockedAddresses.add(address);
|
blockedAddresses.add(address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
addressFiltersInitialized = true;
|
||||||
* @return the list of all local IP addresses from all allowed network
|
|
||||||
* interfaces, which are allowed addresses.
|
|
||||||
*/
|
|
||||||
public static List<InetAddress> getAllAllowedAddresses()
|
|
||||||
{
|
|
||||||
List<InetAddress> addresses = new LinkedList<>();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
for (NetworkInterface iface
|
|
||||||
: Collections.list(NetworkInterface.getNetworkInterfaces()))
|
|
||||||
{
|
|
||||||
if (NetworkUtils.isInterfaceLoopback(iface)
|
|
||||||
|| !NetworkUtils.isInterfaceUp(iface)
|
|
||||||
|| !isInterfaceAllowed(iface))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Enumeration<InetAddress> ifaceAddresses
|
|
||||||
= iface.getInetAddresses();
|
|
||||||
while (ifaceAddresses.hasMoreElements())
|
|
||||||
{
|
|
||||||
InetAddress address = ifaceAddresses.nextElement();
|
|
||||||
|
|
||||||
if (!isAddressAllowed(address))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!config.useIpv6() && address instanceof Inet6Address)
|
|
||||||
continue;
|
|
||||||
if (!config.useLinkLocalAddresses() && address.isLinkLocalAddress())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
addresses.add(address);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (SocketException se)
|
|
||||||
{
|
|
||||||
logger.info("Failed to get network interfaces: " + se);
|
|
||||||
}
|
|
||||||
|
|
||||||
return addresses;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -276,8 +237,6 @@ public class HostCandidateHarvester
|
|||||||
* If that fails we will move through all ports between <tt>minPort</tt> and
|
* If that fails we will move through all ports between <tt>minPort</tt> and
|
||||||
* <tt>maxPort</tt> and give up if still can't find a free port.
|
* <tt>maxPort</tt> and give up if still can't find a free port.
|
||||||
*
|
*
|
||||||
* If 0, 0, 0 are specified for preferred, min and max port, an ephemeral port will be used instead.
|
|
||||||
*
|
|
||||||
* @param component the {@link Component} that we'd like to gather candidate
|
* @param component the {@link Component} that we'd like to gather candidate
|
||||||
* addresses for.
|
* addresses for.
|
||||||
* @param preferredPort the port number that should be tried first when
|
* @param preferredPort the port number that should be tried first when
|
||||||
@ -289,7 +248,7 @@ public class HostCandidateHarvester
|
|||||||
* @param transport transport protocol used
|
* @param transport transport protocol used
|
||||||
*
|
*
|
||||||
* @throws IllegalArgumentException if either <tt>minPort</tt> or
|
* @throws IllegalArgumentException if either <tt>minPort</tt> or
|
||||||
* <tt>maxPort</tt> is not a valid port number, <tt>minPort >
|
* <tt>maxPort</tt> is not a valid port number, <tt>minPort >
|
||||||
* maxPort</tt> or if transport is not supported.
|
* maxPort</tt> or if transport is not supported.
|
||||||
* @throws IOException if an error occurs while the underlying resolver lib
|
* @throws IOException if an error occurs while the underlying resolver lib
|
||||||
* is using sockets.
|
* is using sockets.
|
||||||
@ -304,16 +263,24 @@ public class HostCandidateHarvester
|
|||||||
{
|
{
|
||||||
harvestStatistics.startHarvestTiming();
|
harvestStatistics.startHarvestTiming();
|
||||||
|
|
||||||
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
|
Enumeration<NetworkInterface> interfaces
|
||||||
|
= NetworkInterface.getNetworkInterfaces();
|
||||||
|
|
||||||
if (transport != Transport.UDP && transport != Transport.TCP)
|
boolean isIPv6Disabled = StackProperties.getBoolean(
|
||||||
|
StackProperties.DISABLE_IPv6,
|
||||||
|
false);
|
||||||
|
|
||||||
|
boolean isIPv6LinkLocalDisabled = StackProperties.getBoolean(
|
||||||
|
StackProperties.DISABLE_LINK_LOCAL_ADDRESSES,
|
||||||
|
false);
|
||||||
|
|
||||||
|
if(transport != Transport.UDP && transport != Transport.TCP)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("Transport protocol not supported: " + transport);
|
throw new IllegalArgumentException(
|
||||||
|
"Transport protocol not supported: " + transport);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean boundAtLeastOneSocket = false;
|
boolean boundAtLeastOneSocket = false;
|
||||||
boolean foundAtLeastOneUsableInterface = false;
|
|
||||||
boolean foundAtLeastOneUsableAddress = false;
|
|
||||||
while (interfaces.hasMoreElements())
|
while (interfaces.hasMoreElements())
|
||||||
{
|
{
|
||||||
NetworkInterface iface = interfaces.nextElement();
|
NetworkInterface iface = interfaces.nextElement();
|
||||||
@ -325,11 +292,10 @@ public class HostCandidateHarvester
|
|||||||
//this one is obviously not going to do
|
//this one is obviously not going to do
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
foundAtLeastOneUsableInterface = true;
|
|
||||||
|
|
||||||
Enumeration<InetAddress> addresses = iface.getInetAddresses();
|
Enumeration<InetAddress> addresses = iface.getInetAddresses();
|
||||||
|
|
||||||
while (addresses.hasMoreElements())
|
while(addresses.hasMoreElements())
|
||||||
{
|
{
|
||||||
InetAddress addr = addresses.nextElement();
|
InetAddress addr = addresses.nextElement();
|
||||||
|
|
||||||
@ -338,25 +304,27 @@ public class HostCandidateHarvester
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config.useLinkLocalAddresses() && addr.isLinkLocalAddress())
|
if (isIPv6LinkLocalDisabled
|
||||||
|
&& (addr instanceof Inet6Address)
|
||||||
|
&& addr.isLinkLocalAddress())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
foundAtLeastOneUsableAddress = true;
|
|
||||||
|
|
||||||
if ((addr instanceof Inet4Address) || config.useIpv6())
|
if((addr instanceof Inet4Address) || !isIPv6Disabled)
|
||||||
{
|
{
|
||||||
IceSocketWrapper sock = null;
|
IceSocketWrapper sock = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (transport == Transport.UDP)
|
if(transport == Transport.UDP)
|
||||||
{
|
{
|
||||||
sock = createDatagramSocket(addr, preferredPort, minPort, maxPort);
|
sock = createDatagramSocket(
|
||||||
|
addr, preferredPort, minPort, maxPort);
|
||||||
boundAtLeastOneSocket = true;
|
boundAtLeastOneSocket = true;
|
||||||
}
|
}
|
||||||
else if (transport == Transport.TCP)
|
else if(transport == Transport.TCP)
|
||||||
{
|
{
|
||||||
if (addr instanceof Inet6Address)
|
if(addr instanceof Inet6Address)
|
||||||
continue;
|
continue;
|
||||||
sock = createServerSocket(
|
sock = createServerSocket(
|
||||||
addr,
|
addr,
|
||||||
@ -386,11 +354,13 @@ public class HostCandidateHarvester
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
HostCandidate candidate = new HostCandidate(sock, component, transport);
|
HostCandidate candidate
|
||||||
candidate.setVirtual(NetworkUtils.isInterfaceVirtual(iface));
|
= new HostCandidate(sock, component, transport);
|
||||||
|
candidate.setVirtual(
|
||||||
|
NetworkUtils.isInterfaceVirtual(iface));
|
||||||
component.addLocalCandidate(candidate);
|
component.addLocalCandidate(candidate);
|
||||||
|
|
||||||
if (transport == Transport.TCP)
|
if(transport == Transport.TCP)
|
||||||
{
|
{
|
||||||
// have to wait a client connection to add a STUN socket
|
// have to wait a client connection to add a STUN socket
|
||||||
// to the StunStack
|
// to the StunStack
|
||||||
@ -402,31 +372,22 @@ public class HostCandidateHarvester
|
|||||||
// checks. In case we have enabled STUN, we are going to use
|
// checks. In case we have enabled STUN, we are going to use
|
||||||
// them as well while harvesting reflexive candidates.
|
// them as well while harvesting reflexive candidates.
|
||||||
createAndRegisterStunSocket(candidate);
|
createAndRegisterStunSocket(candidate);
|
||||||
|
|
||||||
ComponentSocket componentSocket = component.getComponentSocket();
|
|
||||||
if (componentSocket != null)
|
|
||||||
{
|
|
||||||
componentSocket.add(sock);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!boundAtLeastOneSocket)
|
if(!boundAtLeastOneSocket)
|
||||||
{
|
{
|
||||||
throw new IOException(
|
throw new IOException(
|
||||||
"Failed to bind even a single host candidate for component:"
|
"Failed to bind even a single host candidate for component:"
|
||||||
+ component
|
+ component
|
||||||
+ " preferredPort=" + preferredPort
|
+ " preferredPort=" + preferredPort
|
||||||
+ " minPort=" + minPort
|
+ " minPort=" + minPort
|
||||||
+ " maxPort=" + maxPort
|
+ " maxPort=" + maxPort);
|
||||||
+ " foundAtLeastOneUsableInterface="
|
|
||||||
+ foundAtLeastOneUsableInterface
|
|
||||||
+ " foundAtLeastOneUsableAddress="
|
|
||||||
+ foundAtLeastOneUsableAddress);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.harvestStatistics.stopHarvestTiming(component.getLocalCandidateCount());
|
this.harvestStatistics
|
||||||
|
.stopHarvestTiming(component.getLocalCandidateCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -441,7 +402,7 @@ public class HostCandidateHarvester
|
|||||||
* <tt>org.ice4j.ice.harvest.BLOCKED_INTERFACES</tt> list. It returns
|
* <tt>org.ice4j.ice.harvest.BLOCKED_INTERFACES</tt> list. It returns
|
||||||
* <tt>false</tt> otherwise.
|
* <tt>false</tt> otherwise.
|
||||||
*/
|
*/
|
||||||
public static boolean isInterfaceAllowed(NetworkInterface iface)
|
static boolean isInterfaceAllowed(NetworkInterface iface)
|
||||||
{
|
{
|
||||||
if (iface == null)
|
if (iface == null)
|
||||||
throw new IllegalArgumentException("iface cannot be null");
|
throw new IllegalArgumentException("iface cannot be null");
|
||||||
@ -521,8 +482,6 @@ public class HostCandidateHarvester
|
|||||||
* <tt>localAddress</tt> and a port in the range specified by the
|
* <tt>localAddress</tt> and a port in the range specified by the
|
||||||
* <tt>minPort</tt> and <tt>maxPort</tt> parameters.
|
* <tt>minPort</tt> and <tt>maxPort</tt> parameters.
|
||||||
*
|
*
|
||||||
* If 0, 0, 0 are specified for preferred, min and max port, an ephemeral port will be used instead.
|
|
||||||
*
|
|
||||||
* @param laddr the address that we'd like to bind the socket on.
|
* @param laddr the address that we'd like to bind the socket on.
|
||||||
* @param preferredPort the port number that we should try to bind to first.
|
* @param preferredPort the port number that we should try to bind to first.
|
||||||
* @param minPort the port number where we should first try to bind before
|
* @param minPort the port number where we should first try to bind before
|
||||||
@ -533,7 +492,7 @@ public class HostCandidateHarvester
|
|||||||
* @return the newly created <tt>DatagramSocket</tt>.
|
* @return the newly created <tt>DatagramSocket</tt>.
|
||||||
*
|
*
|
||||||
* @throws IllegalArgumentException if either <tt>minPort</tt> or
|
* @throws IllegalArgumentException if either <tt>minPort</tt> or
|
||||||
* <tt>maxPort</tt> is not a valid port number or if <tt>minPort >
|
* <tt>maxPort</tt> is not a valid port number or if <tt>minPort >
|
||||||
* maxPort</tt>.
|
* maxPort</tt>.
|
||||||
* @throws IOException if an error occurs while the underlying resolver lib
|
* @throws IOException if an error occurs while the underlying resolver lib
|
||||||
* is using sockets.
|
* is using sockets.
|
||||||
@ -549,18 +508,7 @@ public class HostCandidateHarvester
|
|||||||
BindException
|
BindException
|
||||||
{
|
{
|
||||||
// make sure port numbers are valid
|
// make sure port numbers are valid
|
||||||
boolean ephemeral = checkPorts(preferredPort, minPort, maxPort);
|
this.checkPorts(preferredPort, minPort, maxPort);
|
||||||
if (ephemeral)
|
|
||||||
{
|
|
||||||
ServerSocket socket = new ServerSocket();
|
|
||||||
socket.setReuseAddress(true);
|
|
||||||
socket.bind(new InetSocketAddress(laddr, 0));
|
|
||||||
if (logger.isLoggable(Level.FINEST))
|
|
||||||
{
|
|
||||||
logger.finest("Bound using an ephemeral port to " + socket.getLocalSocketAddress());
|
|
||||||
}
|
|
||||||
return new IceTcpServerSocketWrapper(new DelegatingServerSocket(socket), component);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bindRetries = StackProperties.getInt(
|
int bindRetries = StackProperties.getInt(
|
||||||
StackProperties.BIND_RETRIES,
|
StackProperties.BIND_RETRIES,
|
||||||
@ -575,11 +523,10 @@ public class HostCandidateHarvester
|
|||||||
sock.setReuseAddress(true);
|
sock.setReuseAddress(true);
|
||||||
sock.bind(new InetSocketAddress(laddr, port));
|
sock.bind(new InetSocketAddress(laddr, port));
|
||||||
IceSocketWrapper socket
|
IceSocketWrapper socket
|
||||||
= new IceTcpServerSocketWrapper(
|
= new IceTcpServerSocketWrapper(sock,
|
||||||
new DelegatingServerSocket(sock),
|
|
||||||
component);
|
component);
|
||||||
|
|
||||||
if (logger.isLoggable(Level.FINEST))
|
if(logger.isLoggable(Level.FINEST))
|
||||||
{
|
{
|
||||||
logger.log(
|
logger.log(
|
||||||
Level.FINEST,
|
Level.FINEST,
|
||||||
@ -604,7 +551,8 @@ public class HostCandidateHarvester
|
|||||||
port = minPort;
|
port = minPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new BindException("Could not bind to any port between " + minPort + " and " + (port - 1));
|
throw new BindException("Could not bind to any port between "
|
||||||
|
+ minPort + " and " + (port - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -619,8 +567,6 @@ public class HostCandidateHarvester
|
|||||||
* start over again at <tt>minPort</tt> and keep going until we run out of
|
* start over again at <tt>minPort</tt> and keep going until we run out of
|
||||||
* retries.
|
* retries.
|
||||||
*
|
*
|
||||||
* If 0, 0, 0 are specified for preferred, min and max port, an ephemeral port will be used instead.
|
|
||||||
*
|
|
||||||
* @param laddr the address that we'd like to bind the socket on.
|
* @param laddr the address that we'd like to bind the socket on.
|
||||||
* @param preferredPort the port number that we should try to bind to first.
|
* @param preferredPort the port number that we should try to bind to first.
|
||||||
* @param minPort the port number where we should first try to bind before
|
* @param minPort the port number where we should first try to bind before
|
||||||
@ -631,7 +577,7 @@ public class HostCandidateHarvester
|
|||||||
* @return the newly created <tt>DatagramSocket</tt>.
|
* @return the newly created <tt>DatagramSocket</tt>.
|
||||||
*
|
*
|
||||||
* @throws IllegalArgumentException if either <tt>minPort</tt> or
|
* @throws IllegalArgumentException if either <tt>minPort</tt> or
|
||||||
* <tt>maxPort</tt> is not a valid port number or if <tt>minPort >
|
* <tt>maxPort</tt> is not a valid port number or if <tt>minPort >
|
||||||
* maxPort</tt>.
|
* maxPort</tt>.
|
||||||
* @throws IOException if an error occurs while the underlying resolver lib
|
* @throws IOException if an error occurs while the underlying resolver lib
|
||||||
* is using sockets.
|
* is using sockets.
|
||||||
@ -648,16 +594,7 @@ public class HostCandidateHarvester
|
|||||||
BindException
|
BindException
|
||||||
{
|
{
|
||||||
// make sure port numbers are valid.
|
// make sure port numbers are valid.
|
||||||
boolean ephemeral = checkPorts(preferredPort, minPort, maxPort);
|
this.checkPorts(preferredPort, minPort, maxPort);
|
||||||
if (ephemeral)
|
|
||||||
{
|
|
||||||
DatagramSocket socket = new MultiplexingDatagramSocket(0, laddr);
|
|
||||||
if (logger.isLoggable(Level.FINEST))
|
|
||||||
{
|
|
||||||
logger.finest("Bound using ephemeral port to " + socket.getLocalSocketAddress());
|
|
||||||
}
|
|
||||||
return new IceUdpSocketWrapper(socket);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bindRetries = StackProperties.getInt(
|
int bindRetries = StackProperties.getInt(
|
||||||
StackProperties.BIND_RETRIES,
|
StackProperties.BIND_RETRIES,
|
||||||
@ -672,7 +609,7 @@ public class HostCandidateHarvester
|
|||||||
= new IceUdpSocketWrapper(new
|
= new IceUdpSocketWrapper(new
|
||||||
MultiplexingDatagramSocket(port, laddr));
|
MultiplexingDatagramSocket(port, laddr));
|
||||||
|
|
||||||
if (logger.isLoggable(Level.FINEST))
|
if(logger.isLoggable(Level.FINEST))
|
||||||
{
|
{
|
||||||
logger.log(
|
logger.log(
|
||||||
Level.FINEST,
|
Level.FINEST,
|
||||||
@ -719,10 +656,8 @@ public class HostCandidateHarvester
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the different ports are correctly set. If not, throws {@link IllegalArgumentException}. The
|
* Checks if the different ports are correctly set. If not, throws an
|
||||||
* special values 0, 0, 0 for the parameters are interpreted as "use an ephemeral port".
|
* IllegalArgumentException.
|
||||||
*
|
|
||||||
* @return {@code true} if the params specify that an ephemeral port should be used, and {@code false} otherwise.
|
|
||||||
*
|
*
|
||||||
* @param preferredPort the port number that we should try to bind to first.
|
* @param preferredPort the port number that we should try to bind to first.
|
||||||
* @param minPort the port number where we should first try to bind before
|
* @param minPort the port number where we should first try to bind before
|
||||||
@ -734,14 +669,9 @@ public class HostCandidateHarvester
|
|||||||
* <tt>maxPort</tt> is not a valid port number or if <tt>minPort</tt> is
|
* <tt>maxPort</tt> is not a valid port number or if <tt>minPort</tt> is
|
||||||
* greater than <tt>maxPort</tt>.
|
* greater than <tt>maxPort</tt>.
|
||||||
*/
|
*/
|
||||||
private static boolean checkPorts(int preferredPort, int minPort, int maxPort)
|
private void checkPorts(int preferredPort, int minPort, int maxPort)
|
||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (preferredPort == 0 && minPort == 0 && maxPort == 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// make sure port numbers are valid
|
// make sure port numbers are valid
|
||||||
if (!NetworkUtils.isValidPortNumber(minPort)
|
if (!NetworkUtils.isValidPortNumber(minPort)
|
||||||
|| !NetworkUtils.isValidPortNumber(maxPort))
|
|| !NetworkUtils.isValidPortNumber(maxPort))
|
||||||
@ -766,8 +696,6 @@ public class HostCandidateHarvester
|
|||||||
+") must be between minPort (" + minPort
|
+") must be between minPort (" + minPort
|
||||||
+ ") and maxPort (" + maxPort + ")");
|
+ ") and maxPort (" + maxPort + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -790,13 +718,19 @@ public class HostCandidateHarvester
|
|||||||
* @throws java.lang.IllegalStateException if there were errors during host
|
* @throws java.lang.IllegalStateException if there were errors during host
|
||||||
* candidate interface filters initialization.
|
* candidate interface filters initialization.
|
||||||
*/
|
*/
|
||||||
public static synchronized void initializeInterfaceFilters()
|
public static void initializeInterfaceFilters()
|
||||||
|
{
|
||||||
|
synchronized (HostCandidateHarvester.class)
|
||||||
{
|
{
|
||||||
// We want this method to run only once.
|
// We want this method to run only once.
|
||||||
if (interfaceFiltersInitialized)
|
if (interfaceFiltersInitialized)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
interfaceFiltersInitialized = true;
|
interfaceFiltersInitialized = true;
|
||||||
|
|
||||||
|
// Should we hold this lock until we are done modifying the fields?
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize the allowed interfaces array.
|
// Initialize the allowed interfaces array.
|
||||||
allowedInterfaces = StackProperties.getStringArray(
|
allowedInterfaces = StackProperties.getStringArray(
|
||||||
StackProperties.ALLOWED_INTERFACES, ";");
|
StackProperties.ALLOWED_INTERFACES, ";");
|
||||||
|
|||||||
@ -0,0 +1,143 @@
|
|||||||
|
/*
|
||||||
|
* ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
|
||||||
|
*
|
||||||
|
* Copyright @ 2015 Atlassian Pty Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.ice4j.ice.harvest;
|
||||||
|
|
||||||
|
import org.ice4j.*;
|
||||||
|
import org.ice4j.ice.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses a list of addresses as a predefined static mask in order to generate
|
||||||
|
* {@link TransportAddress}es. This harvester is meant for use in situations
|
||||||
|
* where servers are deployed behind a NAT or in a DMZ with static port mapping.
|
||||||
|
* <p>
|
||||||
|
* Every time the {@link #harvest(Component)} method is called, the mapping
|
||||||
|
* harvester will return a list of candidates that provide masked alternatives
|
||||||
|
* for every host candidate in the component. Kind of like a STUN server.
|
||||||
|
* <p>
|
||||||
|
* Example: You run this on a server with address 192.168.0.1, that is behind
|
||||||
|
* a NAT with public IP: 93.184.216.119. You allocate a host candidate
|
||||||
|
* 192.168.0.1/UDP/5000. This harvester is going to then generate an address
|
||||||
|
* 93.184.216.119/UDP/5000
|
||||||
|
* <p>
|
||||||
|
* This harvester is instant and does not introduce any harvesting latency.
|
||||||
|
*
|
||||||
|
* @author Emil Ivov
|
||||||
|
*/
|
||||||
|
public class MappingCandidateHarvester
|
||||||
|
extends CandidateHarvester
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The addresses that we will use as a mask
|
||||||
|
*/
|
||||||
|
protected TransportAddress mask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The addresses that we will be masking
|
||||||
|
*/
|
||||||
|
protected TransportAddress face;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a mapping harvester with the specified <tt>mask</tt>
|
||||||
|
*
|
||||||
|
* @param mask the <tt>TransportAddress</tt>es that would be used as a mask.
|
||||||
|
* @param face the <tt>TransportAddress</tt>es that we will be masking.
|
||||||
|
*/
|
||||||
|
public MappingCandidateHarvester(TransportAddress mask,
|
||||||
|
TransportAddress face)
|
||||||
|
{
|
||||||
|
this.mask = mask;
|
||||||
|
this.face = face;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps all candidates to this harvester's mask and adds them to
|
||||||
|
* <tt>component</tt>.
|
||||||
|
*
|
||||||
|
* @param component the {@link Component} that we'd like to map candidates
|
||||||
|
* to.
|
||||||
|
* @return the <tt>LocalCandidate</tt>s gathered by this
|
||||||
|
* <tt>CandidateHarvester</tt> or <tt>null</tt> if no mask is specified.
|
||||||
|
*/
|
||||||
|
public Collection<LocalCandidate> harvest(Component component)
|
||||||
|
{
|
||||||
|
if (getMask() == null || getFace() == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Report the LocalCandidates gathered by this CandidateHarvester so
|
||||||
|
* that the harvest is sure to be considered successful.
|
||||||
|
*/
|
||||||
|
Collection<LocalCandidate> candidates = new HashSet<>();
|
||||||
|
|
||||||
|
for (Candidate<?> cand : component.getLocalCandidates())
|
||||||
|
{
|
||||||
|
if (!(cand instanceof HostCandidate)
|
||||||
|
|| !cand.getTransportAddress().getHostAddress()
|
||||||
|
.equals(getFace().getHostAddress())
|
||||||
|
|| cand.getTransport() != getFace().getTransport())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
HostCandidate hostCandidate = (HostCandidate) cand;
|
||||||
|
TransportAddress mappedAddress = new TransportAddress(
|
||||||
|
getMask().getHostAddress(),
|
||||||
|
hostCandidate.getHostAddress().getPort(),
|
||||||
|
hostCandidate.getHostAddress().getTransport());
|
||||||
|
|
||||||
|
ServerReflexiveCandidate mappedCandidate
|
||||||
|
= new ServerReflexiveCandidate(
|
||||||
|
mappedAddress,
|
||||||
|
hostCandidate,
|
||||||
|
hostCandidate.getStunServerAddress(),
|
||||||
|
CandidateExtendedType.STATICALLY_MAPPED_CANDIDATE);
|
||||||
|
if (hostCandidate.isSSL())
|
||||||
|
mappedCandidate.setSSL(true);
|
||||||
|
|
||||||
|
//try to add the candidate to the component and then
|
||||||
|
//only add it to the harvest not redundant
|
||||||
|
if( !candidates.contains(mappedCandidate)
|
||||||
|
&& component.addLocalCandidate(mappedCandidate))
|
||||||
|
{
|
||||||
|
candidates.add(mappedCandidate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return candidates;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the public (mask) address, or null.
|
||||||
|
* @return the public (mask) address, or null.
|
||||||
|
*/
|
||||||
|
public TransportAddress getMask()
|
||||||
|
{
|
||||||
|
return this.mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the local (face) address, or null.
|
||||||
|
* @return the local (face) address, or null.
|
||||||
|
*/
|
||||||
|
public TransportAddress getFace()
|
||||||
|
{
|
||||||
|
return this.face;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,334 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright @ 2015-2016 Atlassian Pty Ltd
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.ice4j.ice.harvest;
|
|
||||||
|
|
||||||
import org.ice4j.*;
|
|
||||||
import org.jetbrains.annotations.*;
|
|
||||||
import org.jitsi.utils.concurrent.*;
|
|
||||||
|
|
||||||
import java.net.*;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.*;
|
|
||||||
import java.util.logging.*;
|
|
||||||
|
|
||||||
import static org.ice4j.ice.harvest.HarvestConfig.config;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Manages a static list of {@link MappingCandidateHarvester} instances, created
|
|
||||||
* according to configuration provided as system properties.
|
|
||||||
*
|
|
||||||
* The instances in the set are safe to use by any {@code Agent}s.
|
|
||||||
*
|
|
||||||
* @author Damian Minkov
|
|
||||||
* @author Boris Grozev
|
|
||||||
*/
|
|
||||||
public class MappingCandidateHarvesters
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The {@link Logger} used by the {@link MappingCandidateHarvesters}
|
|
||||||
* class for logging output.
|
|
||||||
*/
|
|
||||||
private static final Logger logger = Logger.getLogger(MappingCandidateHarvesters.class.getName());
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether {@link #harvesters} has been initialized.
|
|
||||||
*/
|
|
||||||
private static boolean initialized = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The list of already configured harvesters.
|
|
||||||
*/
|
|
||||||
private static MappingCandidateHarvester[] harvesters
|
|
||||||
= new MappingCandidateHarvester[0];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether the discovery of a public address via STUN has failed.
|
|
||||||
* It is considered failed if the configuration included at least one STUN
|
|
||||||
* server, but we failed to receive at least one valid response.
|
|
||||||
* Note that this defaults to false and is only raised after we are certain
|
|
||||||
* we failed (i.e. after our STUN transactions timeout).
|
|
||||||
*/
|
|
||||||
public static boolean stunDiscoveryFailed = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the list of configured harvesters.
|
|
||||||
*/
|
|
||||||
public static MappingCandidateHarvester[] getHarvesters()
|
|
||||||
{
|
|
||||||
initialize();
|
|
||||||
return harvesters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the (first) mapping harvester which matches a given public address, or {@code null} if none match it.
|
|
||||||
*/
|
|
||||||
public static MappingCandidateHarvester findHarvesterForAddress(TransportAddress publicAddress)
|
|
||||||
{
|
|
||||||
for (MappingCandidateHarvester harvester : harvesters)
|
|
||||||
{
|
|
||||||
if (harvester.publicAddressMatches(publicAddress))
|
|
||||||
{
|
|
||||||
return harvester;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes {@link #harvesters}.
|
|
||||||
* First it reads the configuration and instantiates harvesters accordingly,
|
|
||||||
* waiting for their initialization (which may include network communication
|
|
||||||
* and thus take a long time). Then it removes harvesters which failed to
|
|
||||||
* initialize properly and remove any harvesters with duplicate addresses.
|
|
||||||
*
|
|
||||||
* Three types of mapping harvesters are supported: NAT (with
|
|
||||||
* pre-configured addresses), AWS and STUN.
|
|
||||||
*/
|
|
||||||
public static synchronized void initialize()
|
|
||||||
{
|
|
||||||
if (initialized)
|
|
||||||
return;
|
|
||||||
initialized = true;
|
|
||||||
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
List<MappingCandidateHarvester> harvesterList = new LinkedList<>();
|
|
||||||
|
|
||||||
for (HarvestConfig.StaticMapping staticMapping : config.getStaticMappings())
|
|
||||||
{
|
|
||||||
logger.info("Adding a static mapping: " + staticMapping);
|
|
||||||
// If the configuration has no port, then the port value is not used in any way. We put 9 (for "discard")
|
|
||||||
// as a filler.
|
|
||||||
int localPort = staticMapping.getLocalPort() != null ? staticMapping.getLocalPort() : 9;
|
|
||||||
int publicPort = staticMapping.getPublicPort() != null ? staticMapping.getPublicPort() : 9;
|
|
||||||
TransportAddress localAddress
|
|
||||||
= new TransportAddress(staticMapping.getLocalAddress(), localPort, Transport.UDP);
|
|
||||||
TransportAddress publicAddress
|
|
||||||
= new TransportAddress(staticMapping.getPublicAddress(), publicPort, Transport.UDP);
|
|
||||||
|
|
||||||
harvesterList.add(new StaticMappingCandidateHarvester(
|
|
||||||
publicAddress,
|
|
||||||
localAddress,
|
|
||||||
staticMapping.getName(),
|
|
||||||
staticMapping.getLocalPort() != null));
|
|
||||||
}
|
|
||||||
|
|
||||||
// AWS harvester
|
|
||||||
boolean enableAwsHarvester = config.enableAwsHarvester();
|
|
||||||
if (enableAwsHarvester && (config.forceAwsHarvester() || AwsCandidateHarvester.smellsLikeAnEC2()))
|
|
||||||
{
|
|
||||||
logger.info("Using AwsCandidateHarvester.");
|
|
||||||
harvesterList.add(new AwsCandidateHarvester());
|
|
||||||
}
|
|
||||||
|
|
||||||
// STUN harvesters
|
|
||||||
List<String> stunServers = config.stunMappingCandidateHarvesterAddresses();
|
|
||||||
if (!stunServers.isEmpty())
|
|
||||||
{
|
|
||||||
// Create STUN harvesters (and wait for all of their discovery to finish).
|
|
||||||
List<StunMappingCandidateHarvester> stunHarvesters = createStunHarvesters(stunServers);
|
|
||||||
|
|
||||||
// We have STUN servers configured, so flag failure if none of them were able to discover an address.
|
|
||||||
stunDiscoveryFailed = stunHarvesters.isEmpty();
|
|
||||||
|
|
||||||
harvesterList.addAll(stunHarvesters);
|
|
||||||
}
|
|
||||||
|
|
||||||
harvesterList = prune(harvesterList);
|
|
||||||
harvesters = harvesterList.toArray(new MappingCandidateHarvester[harvesterList.size()]);
|
|
||||||
|
|
||||||
for (MappingCandidateHarvester harvester : harvesters)
|
|
||||||
{
|
|
||||||
logger.info("Using " + harvester);
|
|
||||||
}
|
|
||||||
logger.info("Initialized mapping harvesters (delay="
|
|
||||||
+ (System.currentTimeMillis() - start) + "ms). "
|
|
||||||
+ " stunDiscoveryFailed=" + stunDiscoveryFailed);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prunes a list of mapping harvesters, removing the ones without valid
|
|
||||||
* addresses and those with duplicate addresses.
|
|
||||||
* @param harvesters the list of harvesters.
|
|
||||||
* @return the pruned list.
|
|
||||||
*/
|
|
||||||
private static List<MappingCandidateHarvester> prune(
|
|
||||||
List<MappingCandidateHarvester> harvesters)
|
|
||||||
{
|
|
||||||
List<MappingCandidateHarvester> pruned = new LinkedList<>();
|
|
||||||
for (MappingCandidateHarvester harvester : harvesters)
|
|
||||||
{
|
|
||||||
maybeAdd(harvester, pruned);
|
|
||||||
}
|
|
||||||
return pruned;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds {@code harvester} to {@code harvesters}, if it has valid addresses
|
|
||||||
* and {@code harvesters} doesn't already contain a harvester with the same
|
|
||||||
* addresses.
|
|
||||||
* @param harvester the harvester to add.
|
|
||||||
* @param harvesters the list to add to.
|
|
||||||
*/
|
|
||||||
private static void maybeAdd(
|
|
||||||
MappingCandidateHarvester harvester,
|
|
||||||
List<MappingCandidateHarvester> harvesters)
|
|
||||||
{
|
|
||||||
TransportAddress face = harvester.getFace();
|
|
||||||
TransportAddress mask = harvester.getMask();
|
|
||||||
if (face == null || mask == null || face.equals(mask))
|
|
||||||
{
|
|
||||||
logger.info("Discarding a mapping harvester: " + harvester);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (MappingCandidateHarvester h : harvesters)
|
|
||||||
{
|
|
||||||
if (face.getAddress().equals(h.getFace().getAddress())
|
|
||||||
&& mask.getAddress().equals(h.getMask().getAddress()))
|
|
||||||
{
|
|
||||||
logger.info("Discarding a mapping harvester with duplicate addresses: " + harvester + ". Kept: " + h);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
harvesters.add(harvester);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates STUN mapping harvesters for each of the given STUN servers, and
|
|
||||||
* waits for address discovery to finish for all of them.
|
|
||||||
* @param stunServers an array of STUN server addresses (ip_address:port
|
|
||||||
* pairs).
|
|
||||||
* @return the list of those who were successful in discovering an address.
|
|
||||||
*/
|
|
||||||
private static List<StunMappingCandidateHarvester> createStunHarvesters(@NotNull List<String> stunServers)
|
|
||||||
{
|
|
||||||
List<StunMappingCandidateHarvester> stunHarvesters = new LinkedList<>();
|
|
||||||
|
|
||||||
List<Callable<StunMappingCandidateHarvester>> tasks = new LinkedList<>();
|
|
||||||
|
|
||||||
// Create a StunMappingCandidateHarvester for each local:remote address pair.
|
|
||||||
List<InetAddress> localAddresses = HostCandidateHarvester.getAllAllowedAddresses();
|
|
||||||
for (String stunServer : stunServers)
|
|
||||||
{
|
|
||||||
String[] addressAndPort = stunServer.split(":");
|
|
||||||
if (addressAndPort.length < 2)
|
|
||||||
{
|
|
||||||
logger.severe("Failed to parse STUN server address: " + stunServer);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int port;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
port = Integer.parseInt(addressAndPort[1]);
|
|
||||||
}
|
|
||||||
catch (NumberFormatException nfe)
|
|
||||||
{
|
|
||||||
logger.severe("Invalid STUN server port: " + addressAndPort[1]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
TransportAddress remoteAddress
|
|
||||||
= new TransportAddress(
|
|
||||||
addressAndPort[0],
|
|
||||||
port,
|
|
||||||
Transport.UDP);
|
|
||||||
|
|
||||||
for (InetAddress localInetAddress : localAddresses)
|
|
||||||
{
|
|
||||||
if (localInetAddress instanceof Inet6Address)
|
|
||||||
{
|
|
||||||
// This is disabled, because it is broken for an unknown
|
|
||||||
// reason and it is not currently needed.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
TransportAddress localAddress = new TransportAddress(localInetAddress, 0, Transport.UDP);
|
|
||||||
|
|
||||||
logger.info("Using " + remoteAddress + " for StunMappingCandidateHarvester (localAddress="
|
|
||||||
+ localAddress + ").");
|
|
||||||
final StunMappingCandidateHarvester stunHarvester
|
|
||||||
= new StunMappingCandidateHarvester(localAddress, remoteAddress);
|
|
||||||
|
|
||||||
Callable<StunMappingCandidateHarvester> task = () ->
|
|
||||||
{
|
|
||||||
stunHarvester.discover();
|
|
||||||
return stunHarvester;
|
|
||||||
};
|
|
||||||
tasks.add(task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tasks.isEmpty())
|
|
||||||
{
|
|
||||||
logger.warning("STUN mapping harvesters are configured, but no allowed local addresses were found." +
|
|
||||||
" Not using STUN.");
|
|
||||||
return stunHarvesters;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now run discover() on all created harvesters in parallel and pick the ones which succeeded.
|
|
||||||
ExecutorService es = ExecutorFactory.createFixedThreadPool(tasks.size(), "ice4j.Harvester-executor-");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
List<Future<StunMappingCandidateHarvester>> futures;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
futures = es.invokeAll(tasks);
|
|
||||||
}
|
|
||||||
catch (InterruptedException ie)
|
|
||||||
{
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
return stunHarvesters;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Future<StunMappingCandidateHarvester> future : futures)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
StunMappingCandidateHarvester harvester = future.get();
|
|
||||||
|
|
||||||
// The STUN server replied successfully.
|
|
||||||
if (harvester.getMask() != null)
|
|
||||||
{
|
|
||||||
stunHarvesters.add(harvester);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (ExecutionException ee)
|
|
||||||
{
|
|
||||||
// The harvester failed for some reason, discard it.
|
|
||||||
}
|
|
||||||
catch (InterruptedException ie)
|
|
||||||
{
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
throw new RuntimeException(ie);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
es.shutdown();
|
|
||||||
}
|
|
||||||
return stunHarvesters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prevent instance creation.
|
|
||||||
*/
|
|
||||||
private MappingCandidateHarvesters()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -18,9 +18,12 @@
|
|||||||
package org.ice4j.ice.harvest;
|
package org.ice4j.ice.harvest;
|
||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
|
import org.ice4j.attribute.*;
|
||||||
import org.ice4j.ice.*;
|
import org.ice4j.ice.*;
|
||||||
|
import org.ice4j.message.*;
|
||||||
import org.ice4j.socket.*;
|
import org.ice4j.socket.*;
|
||||||
import org.ice4j.stack.*;
|
import org.ice4j.stack.*;
|
||||||
|
import org.ice4j.util.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
@ -39,16 +42,17 @@ import java.util.logging.*;
|
|||||||
* and associates the component's local username fragment (ufrag) with this
|
* and associates the component's local username fragment (ufrag) with this
|
||||||
* candidate.
|
* candidate.
|
||||||
*
|
*
|
||||||
* When a STUN Binding Request with a given ufrag is received, if the ufrag
|
* When a datagram from an unknown source is received, it is parsed as a STUN
|
||||||
* matches one of the registered candidates, then a new socket is created, which
|
* Binding Request, and if it has a USERNAME attribute, its ufrag is extracted.
|
||||||
* is to receive further packets from the remote address, and the socket is
|
* If this ufrag is associated with a candidate of this harvester, a new socket
|
||||||
* added to the candidate.
|
* is created and added to the candidate, and the remote address of the datagram
|
||||||
|
* is associated with this socket. This mapping is then used to de-multiplex
|
||||||
|
* received datagrams based on their remote address.
|
||||||
*
|
*
|
||||||
* @author Boris Grozev
|
* @author Boris Grozev
|
||||||
*/
|
*/
|
||||||
public class SinglePortUdpHarvester
|
public class SinglePortUdpHarvester
|
||||||
extends AbstractUdpListener
|
extends CandidateHarvester
|
||||||
implements CandidateHarvester
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Our class logger.
|
* Our class logger.
|
||||||
@ -56,6 +60,21 @@ public class SinglePortUdpHarvester
|
|||||||
private static final Logger logger
|
private static final Logger logger
|
||||||
= Logger.getLogger(SinglePortUdpHarvester.class.getName());
|
= Logger.getLogger(SinglePortUdpHarvester.class.getName());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The size for newly allocated <tt>Buffer</tt> instances. This limits the
|
||||||
|
* maximum size of datagrams we can receive.
|
||||||
|
*
|
||||||
|
* XXX should we increase this in case of other MTUs, or set it dynamically
|
||||||
|
* according to the available network interfaces?
|
||||||
|
*/
|
||||||
|
private static final int BUFFER_SIZE
|
||||||
|
= /* assumed MTU */ 1500 - /* IPv4 header */ 20 - /* UDP header */ 8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of <tt>Buffer</tt> instances to keep in {@link #pool}.
|
||||||
|
*/
|
||||||
|
private static final int POOL_SIZE = 256;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new <tt>SinglePortUdpHarvester</tt> instance for each allowed
|
* Creates a new <tt>SinglePortUdpHarvester</tt> instance for each allowed
|
||||||
* IP address found on each allowed network interface, with the given port.
|
* IP address found on each allowed network interface, with the given port.
|
||||||
@ -63,12 +82,58 @@ public class SinglePortUdpHarvester
|
|||||||
* @param port the UDP port number to use.
|
* @param port the UDP port number to use.
|
||||||
* @return the list of created <tt>SinglePortUdpHarvester</tt>s.
|
* @return the list of created <tt>SinglePortUdpHarvester</tt>s.
|
||||||
*/
|
*/
|
||||||
public static List<SinglePortUdpHarvester> createHarvesters(int port)
|
public static List<SinglePortUdpHarvester>
|
||||||
|
createHarvesters(int port)
|
||||||
{
|
{
|
||||||
List<SinglePortUdpHarvester> harvesters = new LinkedList<>();
|
List<SinglePortUdpHarvester> harvesters = new LinkedList<>();
|
||||||
|
|
||||||
for (TransportAddress address
|
List<TransportAddress> addresses = new LinkedList<>();
|
||||||
: AbstractUdpListener.getAllowedAddresses(port))
|
boolean isIPv6Disabled = StackProperties.getBoolean(
|
||||||
|
StackProperties.DISABLE_IPv6,
|
||||||
|
false);
|
||||||
|
boolean isIPv6LinkLocalDisabled = StackProperties.getBoolean(
|
||||||
|
StackProperties.DISABLE_LINK_LOCAL_ADDRESSES,
|
||||||
|
false);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
for (NetworkInterface iface
|
||||||
|
: Collections.list(NetworkInterface.getNetworkInterfaces()))
|
||||||
|
{
|
||||||
|
if (NetworkUtils.isInterfaceLoopback(iface)
|
||||||
|
|| !NetworkUtils.isInterfaceUp(iface)
|
||||||
|
|| !HostCandidateHarvester.isInterfaceAllowed(iface))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Enumeration<InetAddress> ifaceAddresses
|
||||||
|
= iface.getInetAddresses();
|
||||||
|
while (ifaceAddresses.hasMoreElements())
|
||||||
|
{
|
||||||
|
InetAddress address = ifaceAddresses.nextElement();
|
||||||
|
|
||||||
|
if (!HostCandidateHarvester.isAddressAllowed(address))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (isIPv6Disabled && address instanceof Inet6Address)
|
||||||
|
continue;
|
||||||
|
if (isIPv6LinkLocalDisabled
|
||||||
|
&& address instanceof Inet6Address
|
||||||
|
&& address.isLinkLocalAddress())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
addresses.add(
|
||||||
|
new TransportAddress(address, port, Transport.UDP));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SocketException se)
|
||||||
|
{
|
||||||
|
logger.info("Failed to get network interfaces: " + se);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (TransportAddress address : addresses)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -85,6 +150,15 @@ public class SinglePortUdpHarvester
|
|||||||
return harvesters;
|
return harvesters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The map which keeps the known remote addresses and their associated
|
||||||
|
* candidateSockets.
|
||||||
|
* {@link #thread} is the only thread which adds new entries, while
|
||||||
|
* other threads remove entries when candidates are freed.
|
||||||
|
*/
|
||||||
|
private final Map<SocketAddress, MySocket> sockets
|
||||||
|
= new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The map which keeps all currently active <tt>Candidate</tt>s created by
|
* The map which keeps all currently active <tt>Candidate</tt>s created by
|
||||||
* this harvester. The keys are the local username fragments (ufrags) of
|
* this harvester. The keys are the local username fragments (ufrags) of
|
||||||
@ -94,59 +168,129 @@ public class SinglePortUdpHarvester
|
|||||||
= new ConcurrentHashMap<>();
|
= new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages statistics about harvesting time.
|
* A pool of <tt>Buffer</tt> instances used to avoid creating of new java
|
||||||
|
* objects.
|
||||||
*/
|
*/
|
||||||
private HarvestStatistics harvestStatistics = new HarvestStatistics();
|
private final ArrayBlockingQueue<Buffer> pool
|
||||||
|
= new ArrayBlockingQueue<>(POOL_SIZE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The local address that this harvester is bound to.
|
||||||
|
*/
|
||||||
|
private final TransportAddress localAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The "main" socket that this harvester reads from.
|
||||||
|
*/
|
||||||
|
private final DatagramSocket socket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The thread reading from {@link #socket}.
|
||||||
|
*/
|
||||||
|
private final Thread thread;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a new <tt>SinglePortUdpHarvester</tt> instance which is to
|
* Initializes a new <tt>SinglePortUdpHarvester</tt> instance which is to
|
||||||
* bind on the specified local address.
|
* bind on the specified local address.
|
||||||
* @param localAddress the address to bind to. If the port is 0 an ephemeral port is chosen by the OS and the
|
* @param localAddress the address to bind to.
|
||||||
* SinglePortUdpHarvester.localAddress will reflect the allocated port number.
|
|
||||||
* @throws IOException if initialization fails.
|
* @throws IOException if initialization fails.
|
||||||
*/
|
*/
|
||||||
public SinglePortUdpHarvester(TransportAddress localAddress)
|
public SinglePortUdpHarvester(TransportAddress localAddress)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
super(localAddress);
|
this.localAddress = localAddress;
|
||||||
|
this.socket = new DatagramSocket(localAddress);
|
||||||
logger.info("Initialized SinglePortUdpHarvester with address "
|
logger.info("Initialized SinglePortUdpHarvester with address "
|
||||||
+ this.localAddress);
|
+ localAddress);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
thread = new Thread()
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public HarvestStatistics getHarvestStatistics()
|
|
||||||
{
|
{
|
||||||
return harvestStatistics;
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
SinglePortUdpHarvester.this.runInHarvesterThread();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
thread.setName(SinglePortUdpHarvester.class.getName() + " thread");
|
||||||
|
thread.setDaemon(true);
|
||||||
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* Perpetually reads datagrams from {@link #socket} and handles them
|
||||||
|
* accordingly.
|
||||||
*
|
*
|
||||||
* Looks for an ICE candidate registered with this harvester, which has a
|
* It is important that this blocks are little as possible (except on
|
||||||
* local ufrag of {@code ufrag}, and if one is found it accepts the new
|
* socket.receive(), of course), because it could potentially delay the
|
||||||
* socket and adds it to the candidate.
|
* reception of both ICE and media packets for the whole application.
|
||||||
*/
|
*/
|
||||||
protected void maybeAcceptNewSession(Buffer buf,
|
private void runInHarvesterThread()
|
||||||
InetSocketAddress remoteAddress,
|
|
||||||
String ufrag)
|
|
||||||
{
|
{
|
||||||
MyCandidate candidate = candidates.get(ufrag);
|
Buffer buf;
|
||||||
if (candidate == null)
|
DatagramPacket pkt = null;
|
||||||
|
Component component;
|
||||||
|
MyCandidate candidate;
|
||||||
|
MySocket destinationSocket;
|
||||||
|
InetSocketAddress remoteAddress;
|
||||||
|
|
||||||
|
do
|
||||||
{
|
{
|
||||||
// A STUN Binding Request with an unknown USERNAME. Drop it.
|
// TODO: implement stopping the thread with a switch?
|
||||||
return;
|
|
||||||
|
buf = getFreeBuffer();
|
||||||
|
|
||||||
|
if (pkt == null)
|
||||||
|
pkt = new DatagramPacket(buf.buffer, 0, buf.buffer.length);
|
||||||
|
else
|
||||||
|
pkt.setData(buf.buffer, 0, buf.buffer.length);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
socket.receive(pkt);
|
||||||
|
}
|
||||||
|
catch (IOException ioe)
|
||||||
|
{
|
||||||
|
logger.severe("Failed to receive from socket: " + ioe);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buf.len = pkt.getLength();
|
||||||
|
|
||||||
|
|
||||||
|
remoteAddress = (InetSocketAddress) pkt.getSocketAddress();
|
||||||
|
destinationSocket = sockets.get(remoteAddress);
|
||||||
|
if (destinationSocket != null)
|
||||||
|
{
|
||||||
|
//make 'pkt' available for reading through destinationSocket
|
||||||
|
destinationSocket.addBuffer(buf);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Packet from an unknown source. Is it a STUN Binding Request?
|
||||||
|
String ufrag = getUfrag(buf.buffer, 0, buf.len);
|
||||||
|
if (ufrag == null)
|
||||||
|
{
|
||||||
|
// Not a STUN Binding Request or doesn't have a valid
|
||||||
|
// USERNAME attribute. Drop it.
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
candidate = candidates.get(ufrag);
|
||||||
|
component
|
||||||
|
= candidate == null ? null : candidate.getParentComponent();
|
||||||
|
if (component != null)
|
||||||
|
{
|
||||||
// This is a STUN Binding Request destined for this
|
// This is a STUN Binding Request destined for this
|
||||||
// specific Candidate/Component/Agent.
|
// specific Candidate/Component/Agent.
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 1. Create a socket for this remote address
|
// 1. Create a socket for this remote address
|
||||||
|
MySocket newSocket = new MySocket(remoteAddress);
|
||||||
|
|
||||||
// 2. Set-up de-multiplexing for future datagrams
|
// 2. Set-up de-multiplexing for future datagrams
|
||||||
// with this address to this socket.
|
// with this address to this socket.
|
||||||
MySocket newSocket = addSocket(remoteAddress, ufrag);
|
sockets.put(remoteAddress, newSocket);
|
||||||
|
|
||||||
// 3. Let the candidate and its STUN stack no about the
|
// 3. Let the candidate and its STUN stack no about the
|
||||||
// new socket.
|
// new socket.
|
||||||
@ -164,6 +308,105 @@ public class SinglePortUdpHarvester
|
|||||||
logger.info("Failed to handle new socket: " + ioe);
|
logger.info("Failed to handle new socket: " + ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// A STUN Binding Request with an unknown USERNAME. Drop it.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (true);
|
||||||
|
|
||||||
|
// TODO we are all done, clean up.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an unused <tt>Buffer</tt> instance, creating it if necessary.
|
||||||
|
* @return an unused <tt>Buffer</tt> instance, creating it if necessary.
|
||||||
|
*/
|
||||||
|
private Buffer getFreeBuffer()
|
||||||
|
{
|
||||||
|
Buffer buf = pool.poll();
|
||||||
|
if (buf == null)
|
||||||
|
{
|
||||||
|
buf = new Buffer(new byte[BUFFER_SIZE], 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to parse the bytes in <tt>buf</tt> at offset <tt>off</tt> (and
|
||||||
|
* length <tt>len</tt>) as a STUN Binding Request message. If successful,
|
||||||
|
* looks for a USERNAME attribute and returns the local username fragment
|
||||||
|
* part (see RFC5245 Section 7.1.2.3).
|
||||||
|
* In case of any failure returns <tt>null</tt>.
|
||||||
|
*
|
||||||
|
* @param buf the bytes.
|
||||||
|
* @param off the offset.
|
||||||
|
* @param len the length.
|
||||||
|
* @return the local ufrag from the USERNAME attribute of the STUN message
|
||||||
|
* contained in <tt>buf</tt>, or <tt>null</tt>.
|
||||||
|
*/
|
||||||
|
private String getUfrag(byte[] buf, int off, int len)
|
||||||
|
{
|
||||||
|
// RFC5389, Section 6:
|
||||||
|
// All STUN messages MUST start with a 20-byte header followed by zero
|
||||||
|
// or more Attributes.
|
||||||
|
if (buf == null || buf.length < off + len || len < 20)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// RFC5389, Section 6:
|
||||||
|
// The magic cookie field MUST contain the fixed value 0x2112A442 in
|
||||||
|
// network byte order.
|
||||||
|
if ( !( (buf[off + 4] & 0xFF) == 0x21 &&
|
||||||
|
(buf[off + 5] & 0xFF) == 0x12 &&
|
||||||
|
(buf[off + 6] & 0xFF) == 0xA4 &&
|
||||||
|
(buf[off + 7] & 0xFF) == 0x42))
|
||||||
|
{
|
||||||
|
if (logger.isLoggable(Level.FINE))
|
||||||
|
{
|
||||||
|
logger.fine("Not a STUN packet, magic cookie not found.");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Message stunMessage
|
||||||
|
= Message.decode(buf,
|
||||||
|
(char) off,
|
||||||
|
(char) len);
|
||||||
|
|
||||||
|
if (stunMessage.getMessageType()
|
||||||
|
!= Message.BINDING_REQUEST)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
UsernameAttribute usernameAttribute
|
||||||
|
= (UsernameAttribute)
|
||||||
|
stunMessage.getAttribute(Attribute.USERNAME);
|
||||||
|
if (usernameAttribute == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
String usernameString
|
||||||
|
= new String(usernameAttribute.getUsername());
|
||||||
|
return usernameString.split(":")[0];
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
// Catch everything. We are going to log, and then drop the packet
|
||||||
|
// anyway.
|
||||||
|
if (logger.isLoggable(Level.FINE))
|
||||||
|
{
|
||||||
|
logger.fine("Failed to extract local ufrag: " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
@ -205,6 +448,249 @@ public class SinglePortUdpHarvester
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements a <tt>DatagramSocket</tt> for the purposes of a specific
|
||||||
|
* <tt>MyCandidate</tt>.
|
||||||
|
*
|
||||||
|
* It is not bound to a specific port, but shares the same local address
|
||||||
|
* as the bound socket held by the harvester.
|
||||||
|
*/
|
||||||
|
private class MySocket
|
||||||
|
extends DatagramSocket
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The size of {@link #queue}.
|
||||||
|
*/
|
||||||
|
private static final int QUEUE_SIZE = 128;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The FIFO which acts as a buffer for this socket.
|
||||||
|
*/
|
||||||
|
private final ArrayBlockingQueue<Buffer> queue
|
||||||
|
= new ArrayBlockingQueue<>(QUEUE_SIZE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link QueueStatistics} instance optionally used to collect and
|
||||||
|
* print detailed statistics about {@link #queue}.
|
||||||
|
*/
|
||||||
|
private final QueueStatistics queueStatistics;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The remote address that is associated with this socket.
|
||||||
|
*/
|
||||||
|
private SocketAddress remoteAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The flag which indicates that this <tt>DatagramSocket</tt> has been
|
||||||
|
* closed.
|
||||||
|
*/
|
||||||
|
private boolean closed = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes a new <tt>MySocket</tt> instance with the given
|
||||||
|
* remote address.
|
||||||
|
* @param remoteAddress the remote address to be associated with the
|
||||||
|
* new instance.
|
||||||
|
* @throws SocketException
|
||||||
|
*/
|
||||||
|
public MySocket(SocketAddress remoteAddress)
|
||||||
|
throws SocketException
|
||||||
|
{
|
||||||
|
// unbound
|
||||||
|
super((SocketAddress)null);
|
||||||
|
|
||||||
|
this.remoteAddress = remoteAddress;
|
||||||
|
if (logger.isLoggable(Level.FINEST))
|
||||||
|
{
|
||||||
|
queueStatistics = new QueueStatistics(
|
||||||
|
"SinglePort" + remoteAddress.toString().replace('/', '-'));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
queueStatistics = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds pkt to this socket. If the queue is full, drops a packet. Does
|
||||||
|
* not block.
|
||||||
|
*/
|
||||||
|
private void addBuffer(Buffer buf)
|
||||||
|
{
|
||||||
|
synchronized (queue)
|
||||||
|
{
|
||||||
|
// Drop the first rather than the current packet, so that
|
||||||
|
// receivers can notice the loss earlier.
|
||||||
|
if (queue.size() == QUEUE_SIZE)
|
||||||
|
{
|
||||||
|
logger.info("Dropping a packet because the queue is full.");
|
||||||
|
if (queueStatistics != null)
|
||||||
|
{
|
||||||
|
queueStatistics.remove(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
queue.poll();
|
||||||
|
}
|
||||||
|
|
||||||
|
queue.offer(buf);
|
||||||
|
if (queueStatistics != null)
|
||||||
|
{
|
||||||
|
queueStatistics.add(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
queue.notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* Delegates to the actual socket of the harvester.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public InetAddress getLocalAddress()
|
||||||
|
{
|
||||||
|
return localAddress.getAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* Delegates to the actual socket of the harvester.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int getLocalPort()
|
||||||
|
{
|
||||||
|
return localAddress.getPort();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* Delegates to the actual socket of the harvester.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public SocketAddress getLocalSocketAddress()
|
||||||
|
{
|
||||||
|
return localAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* Removes the association of the remote address with this socket from
|
||||||
|
* the harvester's map.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void close()
|
||||||
|
{
|
||||||
|
closed = true;
|
||||||
|
|
||||||
|
synchronized (queue)
|
||||||
|
{
|
||||||
|
// Wake up any threads still in receive()
|
||||||
|
queue.notifyAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
// We could be called by the super-class constructor, in which
|
||||||
|
// case this.removeAddress is not initialized yet.
|
||||||
|
if (remoteAddress != null)
|
||||||
|
SinglePortUdpHarvester.this.sockets.remove(remoteAddress);
|
||||||
|
|
||||||
|
super.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the data from the first element of {@link #queue} into
|
||||||
|
* <tt>p</tt>. Blocks until {@link #queue} has an element.
|
||||||
|
* @param p
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void receive(DatagramPacket p)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
Buffer buf = null;
|
||||||
|
|
||||||
|
while (buf == null)
|
||||||
|
{
|
||||||
|
if (closed)
|
||||||
|
throw new SocketException("Socket closed");
|
||||||
|
|
||||||
|
synchronized (queue)
|
||||||
|
{
|
||||||
|
if (queue.isEmpty())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
queue.wait();
|
||||||
|
}
|
||||||
|
catch (InterruptedException ie)
|
||||||
|
{}
|
||||||
|
}
|
||||||
|
|
||||||
|
buf = queue.poll();
|
||||||
|
if (queueStatistics != null)
|
||||||
|
{
|
||||||
|
queueStatistics.remove(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] pData = p.getData();
|
||||||
|
|
||||||
|
// XXX Should we use p.setData() here with a buffer of our own?
|
||||||
|
if (pData == null || pData.length < buf.len)
|
||||||
|
throw new IOException("packet buffer not available");
|
||||||
|
|
||||||
|
System.arraycopy(buf.buffer, 0, pData, 0, buf.len);
|
||||||
|
p.setLength(buf.len);
|
||||||
|
p.setSocketAddress(remoteAddress);
|
||||||
|
|
||||||
|
pool.offer(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* Delegates to the actual socket of the harvester.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void send(DatagramPacket p)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
socket.send(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a buffer for the purposes of <tt>SinglePortUdpHarvester</tt>.
|
||||||
|
* Wraps a byte[] and adds a length field specifying the number of elements
|
||||||
|
* actually used.
|
||||||
|
*/
|
||||||
|
private class Buffer
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The actual data.
|
||||||
|
*/
|
||||||
|
byte[] buffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of elements of {@link #buffer} actually used.
|
||||||
|
*/
|
||||||
|
int len;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes a new <tt>Buffer</tt> instance.
|
||||||
|
* @param buffer the data.
|
||||||
|
* @param len the length.
|
||||||
|
*/
|
||||||
|
private Buffer(byte[] buffer, int len)
|
||||||
|
{
|
||||||
|
this.buffer = buffer;
|
||||||
|
this.len = len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements a <tt>Candidate</tt> for the purposes of this
|
* Implements a <tt>Candidate</tt> for the purposes of this
|
||||||
* <tt>SinglePortUdpHarvester</tt>.
|
* <tt>SinglePortUdpHarvester</tt>.
|
||||||
@ -227,7 +713,7 @@ public class SinglePortUdpHarvester
|
|||||||
* The collection of <tt>IceSocketWrapper</tt>s that can potentially
|
* The collection of <tt>IceSocketWrapper</tt>s that can potentially
|
||||||
* be used by the ice4j user to read/write from/to this candidate.
|
* be used by the ice4j user to read/write from/to this candidate.
|
||||||
* The keys are the remote addresses for each socket.
|
* The keys are the remote addresses for each socket.
|
||||||
* <p>
|
*
|
||||||
* There are wrappers over <tt>MultiplexedDatagramSocket</tt>s over
|
* There are wrappers over <tt>MultiplexedDatagramSocket</tt>s over
|
||||||
* a corresponding socket in {@link #sockets}.
|
* a corresponding socket in {@link #sockets}.
|
||||||
*/
|
*/
|
||||||
@ -237,7 +723,7 @@ public class SinglePortUdpHarvester
|
|||||||
/**
|
/**
|
||||||
* The collection of <tt>DatagramSocket</tt>s added to this candidate.
|
* The collection of <tt>DatagramSocket</tt>s added to this candidate.
|
||||||
* The keys are the remote addresses for each socket.
|
* The keys are the remote addresses for each socket.
|
||||||
* <p>
|
*
|
||||||
* These are the "raw" sockets, before any wrappers are added for
|
* These are the "raw" sockets, before any wrappers are added for
|
||||||
* the STUN stack or the user of ice4j.
|
* the STUN stack or the user of ice4j.
|
||||||
*/
|
*/
|
||||||
@ -247,7 +733,6 @@ public class SinglePortUdpHarvester
|
|||||||
/**
|
/**
|
||||||
* Initializes a new <tt>MyCandidate</tt> instance with the given
|
* Initializes a new <tt>MyCandidate</tt> instance with the given
|
||||||
* <tt>Component</tt> and the given local username fragment.
|
* <tt>Component</tt> and the given local username fragment.
|
||||||
*
|
|
||||||
* @param component the <tt>Component</tt> for which this candidate will
|
* @param component the <tt>Component</tt> for which this candidate will
|
||||||
* serve.
|
* serve.
|
||||||
* @param ufrag the local ICE username fragment for this candidate (and
|
* @param ufrag the local ICE username fragment for this candidate (and
|
||||||
@ -261,7 +746,7 @@ public class SinglePortUdpHarvester
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
* <p>
|
*
|
||||||
* Closes all sockets in use by this <tt>LocalCandidate</tt>.
|
* Closes all sockets in use by this <tt>LocalCandidate</tt>.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -292,8 +777,7 @@ public class SinglePortUdpHarvester
|
|||||||
socket.getLocalPort(),
|
socket.getLocalPort(),
|
||||||
Transport.UDP);
|
Transport.UDP);
|
||||||
TransportAddress remoteAddress
|
TransportAddress remoteAddress
|
||||||
= new TransportAddress(
|
= new TransportAddress((InetSocketAddress) e.getKey(),
|
||||||
(InetSocketAddress) e.getKey(),
|
|
||||||
|
|
||||||
Transport.UDP);
|
Transport.UDP);
|
||||||
|
|
||||||
@ -308,11 +792,6 @@ public class SinglePortUdpHarvester
|
|||||||
|
|
||||||
synchronized (candidateSockets)
|
synchronized (candidateSockets)
|
||||||
{
|
{
|
||||||
for (IceSocketWrapper wrapper : candidateSockets.values())
|
|
||||||
{
|
|
||||||
wrapper.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
candidateSockets.clear();
|
candidateSockets.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,7 +801,6 @@ public class SinglePortUdpHarvester
|
|||||||
/**
|
/**
|
||||||
* Adds a new <tt>Socket</tt> to this candidate, which is associated
|
* Adds a new <tt>Socket</tt> to this candidate, which is associated
|
||||||
* with a particular remote address.
|
* with a particular remote address.
|
||||||
*
|
|
||||||
* @param socket the socket to add.
|
* @param socket the socket to add.
|
||||||
* @param remoteAddress the remote address for the socket.
|
* @param remoteAddress the remote address for the socket.
|
||||||
*/
|
*/
|
||||||
@ -343,16 +821,11 @@ public class SinglePortUdpHarvester
|
|||||||
|
|
||||||
IceProcessingState state
|
IceProcessingState state
|
||||||
= component.getParentStream().getParentAgent().getState();
|
= component.getParentStream().getParentAgent().getState();
|
||||||
if (state == IceProcessingState.FAILED)
|
if (!IceProcessingState.WAITING.equals(state)
|
||||||
|
&& !IceProcessingState.RUNNING.equals(state))
|
||||||
{
|
{
|
||||||
throw new IOException(
|
throw new IOException(
|
||||||
"Cannot add socket to an Agent in state FAILED.");
|
"Agent state is " + state + ". Cannot add socket.");
|
||||||
}
|
|
||||||
else if (state != null && state.isOver()
|
|
||||||
&& logger.isLoggable(Level.FINE))
|
|
||||||
{
|
|
||||||
logger.fine(
|
|
||||||
"Adding a socket to a completed Agent, state=" + state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiplexingDatagramSocket multiplexing
|
MultiplexingDatagramSocket multiplexing
|
||||||
@ -372,23 +845,11 @@ public class SinglePortUdpHarvester
|
|||||||
stunSocket,
|
stunSocket,
|
||||||
new TransportAddress(remoteAddress, Transport.UDP));
|
new TransportAddress(remoteAddress, Transport.UDP));
|
||||||
|
|
||||||
MergingDatagramSocket componentSocket
|
|
||||||
= component.getComponentSocket();
|
|
||||||
if (componentSocket != null)
|
|
||||||
{
|
|
||||||
componentSocket.add(multiplexing);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// XXX is this necessary?
|
||||||
synchronized (candidateSockets)
|
synchronized (candidateSockets)
|
||||||
{
|
{
|
||||||
IceSocketWrapper oldSocket
|
candidateSockets.put(remoteAddress, candidateSocket);
|
||||||
= candidateSockets.put(remoteAddress, candidateSocket);
|
|
||||||
if (oldSocket != null)
|
|
||||||
{
|
|
||||||
logger.warning("Replacing the socket for remote address "
|
|
||||||
+ remoteAddress);
|
|
||||||
oldSocket.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX is this necessary?
|
// XXX is this necessary?
|
||||||
@ -397,17 +858,14 @@ public class SinglePortUdpHarvester
|
|||||||
sockets.put(remoteAddress, socket);
|
sockets.put(remoteAddress, socket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected IceSocketWrapper getCandidateIceSocketWrapper(
|
public IceSocketWrapper getIceSocketWrapper(SocketAddress remoteAddress)
|
||||||
SocketAddress remoteAddress)
|
|
||||||
{
|
|
||||||
synchronized (candidateSockets)
|
|
||||||
{
|
{
|
||||||
return candidateSockets.get(remoteAddress);
|
return candidateSockets.get(remoteAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -547,7 +547,7 @@ public class StunCandidateHarvest
|
|||||||
Attribute attribute
|
Attribute attribute
|
||||||
= response.getAttribute(Attribute.XOR_MAPPED_ADDRESS);
|
= response.getAttribute(Attribute.XOR_MAPPED_ADDRESS);
|
||||||
|
|
||||||
if (attribute instanceof XorMappedAddressAttribute)
|
if(attribute instanceof XorMappedAddressAttribute)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
((XorMappedAddressAttribute) attribute)
|
((XorMappedAddressAttribute) attribute)
|
||||||
@ -558,7 +558,7 @@ public class StunCandidateHarvest
|
|||||||
attribute
|
attribute
|
||||||
= response.getAttribute(Attribute.MAPPED_ADDRESS);
|
= response.getAttribute(Attribute.MAPPED_ADDRESS);
|
||||||
|
|
||||||
if (attribute instanceof MappedAddressAttribute)
|
if(attribute instanceof MappedAddressAttribute)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
((MappedAddressAttribute) attribute)
|
((MappedAddressAttribute) attribute)
|
||||||
@ -1433,7 +1433,7 @@ public class StunCandidateHarvest
|
|||||||
* instance. The <tt>StunCandidateHarvest</tt> is referenced by a
|
* instance. The <tt>StunCandidateHarvest</tt> is referenced by a
|
||||||
* <tt>WeakReference</tt> in an attempt to reduce the risk that the
|
* <tt>WeakReference</tt> in an attempt to reduce the risk that the
|
||||||
* <tt>Thread</tt> may live regardless of the fact that the specified
|
* <tt>Thread</tt> may live regardless of the fact that the specified
|
||||||
* <tt>StunCandidateHarvest</tt> may no longer be reachable.
|
* <tt>StunCandidateHarvest<tt> may no longer be reachable.
|
||||||
*/
|
*/
|
||||||
private final WeakReference<StunCandidateHarvest> harvest;
|
private final WeakReference<StunCandidateHarvest> harvest;
|
||||||
|
|
||||||
|
|||||||
@ -36,7 +36,7 @@ import org.ice4j.stack.*;
|
|||||||
* @author Lyubomir Marinov
|
* @author Lyubomir Marinov
|
||||||
*/
|
*/
|
||||||
public class StunCandidateHarvester
|
public class StunCandidateHarvester
|
||||||
extends AbstractCandidateHarvester
|
extends CandidateHarvester
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,9 +111,9 @@ public class StunCandidateHarvester
|
|||||||
this.shortTermCredentialUsername = shortTermCredentialUsername;
|
this.shortTermCredentialUsername = shortTermCredentialUsername;
|
||||||
|
|
||||||
//these should be configurable.
|
//these should be configurable.
|
||||||
if (System.getProperty(StackProperties.MAX_CTRAN_RETRANS_TIMER) == null)
|
if(System.getProperty(StackProperties.MAX_CTRAN_RETRANS_TIMER) == null)
|
||||||
System.setProperty(StackProperties.MAX_CTRAN_RETRANS_TIMER, "400");
|
System.setProperty(StackProperties.MAX_CTRAN_RETRANS_TIMER, "400");
|
||||||
if (System.getProperty(StackProperties.MAX_CTRAN_RETRANSMISSIONS) == null)
|
if(System.getProperty(StackProperties.MAX_CTRAN_RETRANSMISSIONS) == null)
|
||||||
System.setProperty(StackProperties.MAX_CTRAN_RETRANSMISSIONS, "3");
|
System.setProperty(StackProperties.MAX_CTRAN_RETRANSMISSIONS, "3");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ public class StunCandidateHarvester
|
|||||||
|
|
||||||
synchronized(startedHarvests)
|
synchronized(startedHarvests)
|
||||||
{
|
{
|
||||||
if (doNotify)
|
if(doNotify)
|
||||||
startedHarvests.notify();
|
startedHarvests.notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -234,14 +234,10 @@ public class StunCandidateHarvester
|
|||||||
* @return the <tt>LocalCandidate</tt>s gathered by this
|
* @return the <tt>LocalCandidate</tt>s gathered by this
|
||||||
* <tt>CandidateHarvester</tt>
|
* <tt>CandidateHarvester</tt>
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public Collection<LocalCandidate> harvest(Component component)
|
public Collection<LocalCandidate> harvest(Component component)
|
||||||
{
|
|
||||||
if (logger.isLoggable(Level.FINE))
|
|
||||||
{
|
{
|
||||||
logger.fine("starting " + component.toShortString()
|
logger.fine("starting " + component.toShortString()
|
||||||
+ " harvest for: " + toString());
|
+ " harvest for: " + toString() );
|
||||||
}
|
|
||||||
stunStack = component.getParentStream().getParentAgent().getStunStack();
|
stunStack = component.getParentStream().getParentAgent().getStunStack();
|
||||||
|
|
||||||
for (Candidate<?> cand : component.getLocalCandidates())
|
for (Candidate<?> cand : component.getLocalCandidates())
|
||||||
@ -290,7 +286,7 @@ public class StunCandidateHarvester
|
|||||||
private String listCandidates(Collection<? extends Candidate<?>> candidates)
|
private String listCandidates(Collection<? extends Candidate<?>> candidates)
|
||||||
{
|
{
|
||||||
StringBuilder retval = new StringBuilder();
|
StringBuilder retval = new StringBuilder();
|
||||||
for (Candidate<?> candidate : candidates)
|
for(Candidate<?> candidate : candidates)
|
||||||
{
|
{
|
||||||
retval.append(candidate.toShortString());
|
retval.append(candidate.toShortString());
|
||||||
}
|
}
|
||||||
@ -313,7 +309,7 @@ public class StunCandidateHarvester
|
|||||||
|
|
||||||
HostCandidate cand = getHostCandidate(hostCand);
|
HostCandidate cand = getHostCandidate(hostCand);
|
||||||
|
|
||||||
if (cand == null)
|
if(cand == null)
|
||||||
{
|
{
|
||||||
logger.info(
|
logger.info(
|
||||||
"server/candidate address type mismatch,"
|
"server/candidate address type mismatch,"
|
||||||
@ -441,32 +437,21 @@ public class StunCandidateHarvester
|
|||||||
*/
|
*/
|
||||||
protected HostCandidate getHostCandidate(HostCandidate hostCand)
|
protected HostCandidate getHostCandidate(HostCandidate hostCand)
|
||||||
{
|
{
|
||||||
HostCandidate cand;
|
HostCandidate cand = null;
|
||||||
|
|
||||||
// create a new TCP HostCandidate
|
// create a new TCP HostCandidate
|
||||||
if (hostCand.getTransport() == Transport.TCP)
|
if(hostCand.getTransport() == Transport.TCP)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Socket sock = new Socket(stunServer.getAddress(),
|
Socket sock = new Socket(stunServer.getAddress(),
|
||||||
stunServer.getPort());
|
stunServer.getPort());
|
||||||
MultiplexingSocket multiplexing = new MultiplexingSocket(sock);
|
cand = new HostCandidate(new IceTcpSocketWrapper(
|
||||||
Component component = hostCand.getParentComponent();
|
new MultiplexingSocket(sock)),
|
||||||
cand
|
hostCand.getParentComponent(), Transport.TCP);
|
||||||
= new HostCandidate(
|
hostCand.getParentComponent().getParentStream().
|
||||||
new IceTcpSocketWrapper(multiplexing),
|
|
||||||
component,
|
|
||||||
Transport.TCP);
|
|
||||||
component.getParentStream().
|
|
||||||
getParentAgent().getStunStack().addSocket(
|
getParentAgent().getStunStack().addSocket(
|
||||||
cand.getStunSocket(null));
|
cand.getStunSocket(null));
|
||||||
|
|
||||||
ComponentSocket componentSocket
|
|
||||||
= component.getComponentSocket();
|
|
||||||
if (componentSocket != null)
|
|
||||||
{
|
|
||||||
componentSocket.add(multiplexing);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch(Exception io)
|
catch(Exception io)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -18,18 +18,15 @@
|
|||||||
package org.ice4j.ice.harvest;
|
package org.ice4j.ice.harvest;
|
||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
import org.ice4j.socket.*;
|
import org.ice4j.ice.*;
|
||||||
import org.ice4j.stunclient.*;
|
|
||||||
import org.jetbrains.annotations.*;
|
|
||||||
|
|
||||||
import java.net.*;
|
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link MappingCandidateHarvester} which uses a STUN servers to discover its public IP address.
|
* A MappingCandidateHarvester which use a list of pre-configured stun servers
|
||||||
|
* to discover its public ip address.
|
||||||
*
|
*
|
||||||
* @author Damian Minkov
|
* @author Damian Minkov
|
||||||
* @author Boris Grozev
|
|
||||||
*/
|
*/
|
||||||
public class StunMappingCandidateHarvester
|
public class StunMappingCandidateHarvester
|
||||||
extends MappingCandidateHarvester
|
extends MappingCandidateHarvester
|
||||||
@ -38,97 +35,135 @@ public class StunMappingCandidateHarvester
|
|||||||
* The <tt>Logger</tt> used by the <tt>StunMappingCandidateHarvester</tt>
|
* The <tt>Logger</tt> used by the <tt>StunMappingCandidateHarvester</tt>
|
||||||
* class and its instances for logging output.
|
* class and its instances for logging output.
|
||||||
*/
|
*/
|
||||||
private static final Logger logger = Logger.getLogger(StunMappingCandidateHarvester.class.getName());
|
private static final Logger logger
|
||||||
|
= Logger.getLogger(StunMappingCandidateHarvester.class.getName());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The addresses that we will use as a mask
|
||||||
|
*/
|
||||||
|
private static TransportAddress mask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The addresses that we will be masking
|
||||||
|
*/
|
||||||
|
private static TransportAddress face;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether we have already checked and found the mapping addresses.
|
||||||
|
*/
|
||||||
|
private static boolean addressChecked = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of servers we will use to discover our public address.
|
* The list of servers we will use to discover our public address.
|
||||||
*/
|
*/
|
||||||
private final TransportAddress stunServerAddress;
|
private static String[] stunServers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The local address this {@link StunMappingCandidateHarvester} was initialized with, and which will be used to
|
* Creates a mapping harvester with the specified <tt>mask</tt>
|
||||||
* communicate to STUN servers.
|
* @param servers list of stun servers in the form address:port
|
||||||
*/
|
*/
|
||||||
@NotNull
|
public StunMappingCandidateHarvester(String[] servers)
|
||||||
private TransportAddress localAddress;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The public address discovered through STUN, if any.
|
|
||||||
*/
|
|
||||||
private TransportAddress publicAddress = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes a new {@link StunMappingCandidateHarvester} instance with
|
|
||||||
* a given local address and a STUN server address. Note that the actual
|
|
||||||
* discovery of the public address needs to be initiated to a separate call
|
|
||||||
* to {@link #discover()}.
|
|
||||||
* @param localAddress The local address.
|
|
||||||
* @param stunServerAddress The address of the STUN server.
|
|
||||||
*/
|
|
||||||
public StunMappingCandidateHarvester(
|
|
||||||
@NotNull TransportAddress localAddress,
|
|
||||||
TransportAddress stunServerAddress)
|
|
||||||
{
|
{
|
||||||
super("stun");
|
super(null, null);
|
||||||
this.localAddress = localAddress;
|
|
||||||
this.stunServerAddress = stunServerAddress;
|
StunMappingCandidateHarvester.stunServers = servers;
|
||||||
|
|
||||||
|
// we have the list of addresses lets, try discovering
|
||||||
|
obtainAddresses();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to discover the the public address (mask) via the STUN server.
|
* Creates a mapping harvester with the specified <tt>mask</tt>
|
||||||
* Note that this will block until we either receive a response from the
|
|
||||||
* STUN server, or a timeout occurs.
|
|
||||||
*/
|
*/
|
||||||
public void discover()
|
public StunMappingCandidateHarvester()
|
||||||
{
|
{
|
||||||
|
super(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses the pre-configured list of stun servers to discover our public
|
||||||
|
* address. Uses the first successful one and ignore the rest.
|
||||||
|
* Learn the private (face) and public (mask) addresses of this instance.
|
||||||
|
*/
|
||||||
|
private static synchronized void obtainAddresses()
|
||||||
|
{
|
||||||
|
if (addressChecked)
|
||||||
|
return;
|
||||||
|
addressChecked = true;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SimpleAddressDetector sad
|
for (String server : stunServers)
|
||||||
= new SimpleAddressDetector(stunServerAddress);
|
|
||||||
sad.start();
|
|
||||||
|
|
||||||
IceSocketWrapper localSocket = new IceUdpSocketWrapper(new DatagramSocket(localAddress));
|
|
||||||
|
|
||||||
publicAddress = sad.getMappingFor(localSocket);
|
|
||||||
|
|
||||||
/* Record bound address as face. */
|
|
||||||
SocketAddress boundAddr = localSocket.getLocalSocketAddress();
|
|
||||||
if (boundAddr instanceof InetSocketAddress)
|
|
||||||
{
|
{
|
||||||
localAddress = new TransportAddress((InetSocketAddress)boundAddr, localAddress.getTransport());
|
String[] addressAndPort = server.split(":");
|
||||||
|
|
||||||
|
StunCandidateHarvester stunHarv = new StunCandidateHarvester(
|
||||||
|
new TransportAddress(
|
||||||
|
addressAndPort[0],
|
||||||
|
Integer.valueOf(addressAndPort[1]),
|
||||||
|
Transport.UDP));
|
||||||
|
|
||||||
|
Agent agent = new Agent();
|
||||||
|
agent.setTrickling(false);
|
||||||
|
agent.addCandidateHarvester(stunHarv);
|
||||||
|
|
||||||
|
IceMediaStream stream = agent.createMediaStream("audio");
|
||||||
|
// local ports does not matter, just to be something
|
||||||
|
// out of the default used range
|
||||||
|
agent.createComponent(
|
||||||
|
stream, Transport.UDP, 32020, 32020, 32020 + 100);
|
||||||
|
|
||||||
|
IceMediaStream iceMediaStream = agent.getStreams().get(0);
|
||||||
|
TransportAddress addr = iceMediaStream
|
||||||
|
.getComponent(Component.RTP).getDefaultCandidate()
|
||||||
|
.getTransportAddress();
|
||||||
|
mask = addr;
|
||||||
|
|
||||||
|
Candidate<?> candidate =
|
||||||
|
iceMediaStream.getComponents().get(0).getDefaultCandidate();
|
||||||
|
face = candidate.getHostAddress();
|
||||||
|
|
||||||
|
agent.free();
|
||||||
|
|
||||||
|
if (mask != null && face != null)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (publicAddress != null)
|
logger.info("Detected through stun local IP: " + face);
|
||||||
{
|
logger.info("Detected through stun public IP: " + mask);
|
||||||
logger.info("Discovered public address " + publicAddress
|
|
||||||
+ " from STUN server " + stunServerAddress
|
|
||||||
+ " using local address " + localSocket);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception exc)
|
catch (Exception exc)
|
||||||
{
|
{
|
||||||
//whatever happens, we just log
|
//whatever happens, we just log and fail
|
||||||
logger.log(Level.INFO, "We failed to obtain addresses for the following reason: ", exc);
|
logger.log(Level.INFO, "We failed to obtain addresses "
|
||||||
|
+ "for the following reason: ", exc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* Returns the public (mask) address, or null.
|
||||||
|
* @return the public (mask) address, or null.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public TransportAddress getFace()
|
|
||||||
{
|
|
||||||
return localAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public TransportAddress getMask()
|
public TransportAddress getMask()
|
||||||
{
|
{
|
||||||
return publicAddress;
|
if (mask == null)
|
||||||
|
{
|
||||||
|
obtainAddresses();
|
||||||
|
}
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the local (face) address, or null.
|
||||||
|
* @return the local (face) address, or null.
|
||||||
|
*/
|
||||||
|
public TransportAddress getFace()
|
||||||
|
{
|
||||||
|
if (face == null)
|
||||||
|
{
|
||||||
|
obtainAddresses();
|
||||||
|
}
|
||||||
|
return face;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -258,13 +258,6 @@ public class TurnCandidateHarvest
|
|||||||
harvester.getStunStack().addSocket(
|
harvester.getStunStack().addSocket(
|
||||||
relayedCandidate.getStunSocket(null));
|
relayedCandidate.getStunSocket(null));
|
||||||
|
|
||||||
ComponentSocket componentSocket
|
|
||||||
= relayedCandidate.getParentComponent().getComponentSocket();
|
|
||||||
if (componentSocket != null)
|
|
||||||
{
|
|
||||||
componentSocket.add(
|
|
||||||
relayedCandidate.getCandidateIceSocketWrapper());
|
|
||||||
}
|
|
||||||
addCandidate(relayedCandidate);
|
addCandidate(relayedCandidate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,7 +34,7 @@ import org.bitlet.weupnp.*;
|
|||||||
* @author Sebastien Vincent
|
* @author Sebastien Vincent
|
||||||
*/
|
*/
|
||||||
public class UPNPHarvester
|
public class UPNPHarvester
|
||||||
extends AbstractCandidateHarvester
|
extends CandidateHarvester
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The logger.
|
* The logger.
|
||||||
@ -93,10 +93,10 @@ public class UPNPHarvester
|
|||||||
logger.fine("Begin UPnP harvesting");
|
logger.fine("Begin UPnP harvesting");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (device == null)
|
if(device == null)
|
||||||
{
|
{
|
||||||
// do it only once
|
// do it only once
|
||||||
if (finishThreads == 0)
|
if(finishThreads == 0)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -108,17 +108,17 @@ public class UPNPHarvester
|
|||||||
|
|
||||||
synchronized(rootSync)
|
synchronized(rootSync)
|
||||||
{
|
{
|
||||||
while (finishThreads != 2)
|
while(finishThreads != 2)
|
||||||
{
|
{
|
||||||
rootSync.wait();
|
rootSync.wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wanIPThread.getDevice() != null)
|
if(wanIPThread.getDevice() != null)
|
||||||
{
|
{
|
||||||
device = wanIPThread.getDevice();
|
device = wanIPThread.getDevice();
|
||||||
}
|
}
|
||||||
else if (wanPPPThread.getDevice() != null)
|
else if(wanPPPThread.getDevice() != null)
|
||||||
{
|
{
|
||||||
device = wanPPPThread.getDevice();
|
device = wanPPPThread.getDevice();
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ public class UPNPHarvester
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device == null)
|
if(device == null)
|
||||||
return candidates;
|
return candidates;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,12 +143,12 @@ public class UPNPHarvester
|
|||||||
int port = socket.getLocalPort();
|
int port = socket.getLocalPort();
|
||||||
int externalPort = socket.getLocalPort();
|
int externalPort = socket.getLocalPort();
|
||||||
|
|
||||||
while (retries < MAX_RETRIES)
|
while(retries < MAX_RETRIES)
|
||||||
{
|
{
|
||||||
if (!device.getSpecificPortMappingEntry(port, "UDP",
|
if(!device.getSpecificPortMappingEntry(port, "UDP",
|
||||||
portMapping))
|
portMapping))
|
||||||
{
|
{
|
||||||
if (device.addPortMapping(
|
if(device.addPortMapping(
|
||||||
externalPort,
|
externalPort,
|
||||||
port,
|
port,
|
||||||
localAddress.getHostAddress(),
|
localAddress.getHostAddress(),
|
||||||
@ -165,11 +165,11 @@ public class UPNPHarvester
|
|||||||
// if we don't add the base, we won't be able to add
|
// if we don't add the base, we won't be able to add
|
||||||
// peer reflexive candidate if someone contact us on the
|
// peer reflexive candidate if someone contact us on the
|
||||||
// UPNPCandidate
|
// UPNPCandidate
|
||||||
for (LocalCandidate cand : cands)
|
for(LocalCandidate cand : cands)
|
||||||
{
|
{
|
||||||
//try to add the candidate to the component and then
|
//try to add the candidate to the component and then
|
||||||
//only add it to the harvest not redundant
|
//only add it to the harvest not redundant
|
||||||
if (component.addLocalCandidate(cand))
|
if(component.addLocalCandidate(cand))
|
||||||
{
|
{
|
||||||
candidates.add(cand);
|
candidates.add(cand);
|
||||||
}
|
}
|
||||||
@ -203,29 +203,25 @@ public class UPNPHarvester
|
|||||||
* @param socket local socket
|
* @param socket local socket
|
||||||
* @param externalIP external IP address
|
* @param externalIP external IP address
|
||||||
* @param port local port
|
* @param port local port
|
||||||
* @param component parent component
|
* @param cmp parent component
|
||||||
* @param device the UPnP gateway device
|
* @param device the UPnP gateway device
|
||||||
* @return a new <tt>UPNPCandidate</tt> instance which
|
* @return a new <tt>UPNPCandidate</tt> instance which
|
||||||
* represents the specified <tt>TransportAddress</tt>
|
* represents the specified <tt>TransportAddress</tt>
|
||||||
|
* @throws Exception if something goes wrong during candidate creation
|
||||||
*/
|
*/
|
||||||
private List<LocalCandidate> createUPNPCandidate(IceSocketWrapper socket,
|
public List<LocalCandidate> createUPNPCandidate(IceSocketWrapper socket,
|
||||||
String externalIP, int port, Component component, GatewayDevice device)
|
String externalIP, int port, Component cmp, GatewayDevice device)
|
||||||
|
throws Exception
|
||||||
{
|
{
|
||||||
List<LocalCandidate> ret = new ArrayList<>();
|
List<LocalCandidate> ret = new ArrayList<>();
|
||||||
TransportAddress addr
|
TransportAddress addr
|
||||||
= new TransportAddress(externalIP, port, Transport.UDP);
|
= new TransportAddress(externalIP, port, Transport.UDP);
|
||||||
|
|
||||||
HostCandidate base = new HostCandidate(socket, component);
|
HostCandidate base = new HostCandidate(socket, cmp);
|
||||||
|
|
||||||
UPNPCandidate candidate
|
UPNPCandidate candidate = new UPNPCandidate(addr, base, cmp, device);
|
||||||
= new UPNPCandidate(addr, base, component, device);
|
|
||||||
IceSocketWrapper stunSocket = candidate.getStunSocket(null);
|
IceSocketWrapper stunSocket = candidate.getStunSocket(null);
|
||||||
candidate.getStunStack().addSocket(stunSocket);
|
candidate.getStunStack().addSocket(stunSocket);
|
||||||
ComponentSocket componentSocket = component.getComponentSocket();
|
|
||||||
if (componentSocket != null)
|
|
||||||
{
|
|
||||||
componentSocket.add(candidate.getCandidateIceSocketWrapper());
|
|
||||||
}
|
|
||||||
|
|
||||||
ret.add(candidate);
|
ret.add(candidate);
|
||||||
ret.add(base);
|
ret.add(base);
|
||||||
@ -280,7 +276,7 @@ public class UPNPHarvester
|
|||||||
|
|
||||||
gd.discover();
|
gd.discover();
|
||||||
|
|
||||||
if (gd.getValidGateway() != null)
|
if(gd.getValidGateway() != null)
|
||||||
{
|
{
|
||||||
device = gd.getValidGateway();
|
device = gd.getValidGateway();
|
||||||
}
|
}
|
||||||
@ -294,7 +290,7 @@ public class UPNPHarvester
|
|||||||
* a method, it is important that it be rethrown so that the
|
* a method, it is important that it be rethrown so that the
|
||||||
* thread actually dies.
|
* thread actually dies.
|
||||||
*/
|
*/
|
||||||
if (e instanceof ThreadDeath)
|
if(e instanceof ThreadDeath)
|
||||||
throw (ThreadDeath)e;
|
throw (ThreadDeath)e;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|||||||
@ -151,15 +151,15 @@ public class IceSdpUtils
|
|||||||
Component firstComponent = null;
|
Component firstComponent = null;
|
||||||
|
|
||||||
//add candidates
|
//add candidates
|
||||||
for (Component component : iceMediaStream.getComponents())
|
for(Component component : iceMediaStream.getComponents())
|
||||||
{
|
{
|
||||||
//if this is the first component, remember it so that we can
|
//if this is the first component, remember it so that we can
|
||||||
//later use it for default candidates.
|
//later use it for default candidates.
|
||||||
if (firstComponent == null)
|
if(firstComponent == null)
|
||||||
firstComponent = component;
|
firstComponent = component;
|
||||||
|
|
||||||
Vector attributes = mediaDescription.getAttributes(true);
|
Vector attributes = mediaDescription.getAttributes(true);
|
||||||
for (Candidate<?> candidate : component.getLocalCandidates())
|
for(Candidate<?> candidate : component.getLocalCandidates())
|
||||||
{
|
{
|
||||||
attributes.add(new CandidateAttribute(candidate));
|
attributes.add(new CandidateAttribute(candidate));
|
||||||
}
|
}
|
||||||
@ -177,19 +177,19 @@ public class IceSdpUtils
|
|||||||
: Connection.IP4;
|
: Connection.IP4;
|
||||||
|
|
||||||
mediaDescription.setConnection(sdpFactory.createConnection(
|
mediaDescription.setConnection(sdpFactory.createConnection(
|
||||||
"IN", addressFamily, defaultAddress.getHostAddress()));
|
"IN", defaultAddress.getHostAddress(), addressFamily));
|
||||||
|
|
||||||
//now check if the RTCP port for the default candidate is different
|
//now check if the RTCP port for the default candidate is different
|
||||||
//than RTP.port +1, in which case we need to mention it.
|
//than RTP.port +1, in which case we need to mention it.
|
||||||
Component rtcpComponent
|
Component rtcpComponent
|
||||||
= iceMediaStream.getComponent(Component.RTCP);
|
= iceMediaStream.getComponent(Component.RTCP);
|
||||||
|
|
||||||
if ( rtcpComponent != null )
|
if( rtcpComponent != null )
|
||||||
{
|
{
|
||||||
TransportAddress defaultRtcpCandidate = rtcpComponent
|
TransportAddress defaultRtcpCandidate = rtcpComponent
|
||||||
.getDefaultCandidate().getTransportAddress();
|
.getDefaultCandidate().getTransportAddress();
|
||||||
|
|
||||||
if (defaultRtcpCandidate.getPort() != defaultAddress.getPort()+1)
|
if(defaultRtcpCandidate.getPort() != defaultAddress.getPort()+1)
|
||||||
{
|
{
|
||||||
mediaDescription.setAttribute(
|
mediaDescription.setAttribute(
|
||||||
RTCP, Integer.toString(defaultRtcpCandidate.getPort()));
|
RTCP, Integer.toString(defaultRtcpCandidate.getPort()));
|
||||||
@ -255,7 +255,7 @@ public class IceSdpUtils
|
|||||||
//origin
|
//origin
|
||||||
Origin o = sDes.getOrigin();
|
Origin o = sDes.getOrigin();
|
||||||
|
|
||||||
if ( o == null || "user".equals(o.getUsername()))
|
if( o == null || "user".equals(o.getUsername()))
|
||||||
{
|
{
|
||||||
//looks like there wasn't any origin set: jain-sdp creates a
|
//looks like there wasn't any origin set: jain-sdp creates a
|
||||||
//default origin that has "user" as the user name so we use this
|
//default origin that has "user" as the user name so we use this
|
||||||
@ -277,7 +277,7 @@ public class IceSdpUtils
|
|||||||
List<IceMediaStream> streams = agent.getStreams();
|
List<IceMediaStream> streams = agent.getStreams();
|
||||||
Vector<MediaDescription> mDescs
|
Vector<MediaDescription> mDescs
|
||||||
= new Vector<>(agent.getStreamCount());
|
= new Vector<>(agent.getStreamCount());
|
||||||
for (IceMediaStream stream : streams)
|
for(IceMediaStream stream : streams)
|
||||||
{
|
{
|
||||||
MediaDescription mLine = sdpFactory.createMediaDescription(
|
MediaDescription mLine = sdpFactory.createMediaDescription(
|
||||||
stream.getName(), 0, //default port comes later
|
stream.getName(), 0, //default port comes later
|
||||||
@ -320,7 +320,7 @@ public class IceSdpUtils
|
|||||||
{
|
{
|
||||||
List<Attribute> trickleUpdate = null;
|
List<Attribute> trickleUpdate = null;
|
||||||
|
|
||||||
if (localCandidates == null || localCandidates.size() == 0)
|
if(localCandidates == null || localCandidates.size() == 0)
|
||||||
{
|
{
|
||||||
trickleUpdate = new ArrayList<>(1);
|
trickleUpdate = new ArrayList<>(1);
|
||||||
trickleUpdate.add(
|
trickleUpdate.add(
|
||||||
@ -333,7 +333,7 @@ public class IceSdpUtils
|
|||||||
|
|
||||||
String streamName = null;
|
String streamName = null;
|
||||||
|
|
||||||
for (LocalCandidate candidate : localCandidates)
|
for(LocalCandidate candidate : localCandidates)
|
||||||
{
|
{
|
||||||
streamName = candidate.getParentComponent()
|
streamName = candidate.getParentComponent()
|
||||||
.getParentStream().getName();
|
.getParentStream().getName();
|
||||||
|
|||||||
@ -100,24 +100,25 @@ public class ChannelData
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the data length (without padding).
|
* Get the data length.
|
||||||
*
|
*
|
||||||
* @return data length
|
* @return data length
|
||||||
*/
|
*/
|
||||||
public char getDataLength()
|
public char getDataLength()
|
||||||
{
|
{
|
||||||
if (data == null)
|
char length = 0;
|
||||||
return 0;
|
if(data == null)
|
||||||
|
{
|
||||||
return (char)data.length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* pad to a multiple of four */
|
||||||
* @return num padded to 4
|
if((length % 4) > 0)
|
||||||
*/
|
|
||||||
private static int padTo4(int num)
|
|
||||||
{
|
{
|
||||||
return (num + 3) & ~3;
|
length += (4 - (length % 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
return (char)data.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,32 +135,18 @@ public class ChannelData
|
|||||||
return (channelNumber > 0x3FFF);
|
return (channelNumber > 0x3FFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a non padded binary representation of this message.
|
|
||||||
* @return a non padded binary representation of this message.
|
|
||||||
* @throws StunException if the channel number is invalid
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
public byte[] encode() throws StunException
|
|
||||||
{
|
|
||||||
return encode(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a binary representation of this message.
|
* Returns a binary representation of this message.
|
||||||
* @param pad determine if we pad this message
|
|
||||||
* @return a binary representation of this message.
|
* @return a binary representation of this message.
|
||||||
* @throws StunException if the channel number is invalid
|
* @throws StunException if the channel number is invalid
|
||||||
*/
|
*/
|
||||||
public byte[] encode(boolean pad) throws StunException
|
public byte[] encode() throws StunException
|
||||||
{
|
{
|
||||||
int dataLength = getDataLength();
|
char dataLength = getDataLength();
|
||||||
if (pad)
|
|
||||||
dataLength = padTo4(dataLength);
|
|
||||||
byte binMsg[] = new byte[HEADER_LENGTH + dataLength];
|
byte binMsg[] = new byte[HEADER_LENGTH + dataLength];
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
if (!validateChannelNumber(channelNumber))
|
if(!validateChannelNumber(channelNumber))
|
||||||
{
|
{
|
||||||
throw new StunException(StunException.ILLEGAL_ARGUMENT, "Channel number invalid");
|
throw new StunException(StunException.ILLEGAL_ARGUMENT, "Channel number invalid");
|
||||||
}
|
}
|
||||||
@ -172,7 +159,7 @@ public class ChannelData
|
|||||||
binMsg[offset++] = (byte)((data != null) ? data.length >> 8 : 0);
|
binMsg[offset++] = (byte)((data != null) ? data.length >> 8 : 0);
|
||||||
binMsg[offset++] = (byte)((data != null) ? data.length & 0xff : 0);
|
binMsg[offset++] = (byte)((data != null) ? data.length & 0xff : 0);
|
||||||
|
|
||||||
if (data != null)
|
if(data != null)
|
||||||
{
|
{
|
||||||
System.arraycopy(data, 0, binMsg, offset, data.length);
|
System.arraycopy(data, 0, binMsg, offset, data.length);
|
||||||
}
|
}
|
||||||
@ -188,42 +175,28 @@ public class ChannelData
|
|||||||
* @return a Message object constructed from the binMessage array
|
* @return a Message object constructed from the binMessage array
|
||||||
* @throws StunException ILLEGAL_ARGUMENT if one or more of the arguments
|
* @throws StunException ILLEGAL_ARGUMENT if one or more of the arguments
|
||||||
* have invalid values.
|
* have invalid values.
|
||||||
* @deprecated
|
|
||||||
*/
|
*/
|
||||||
public static ChannelData decode(byte binMessage[], char offset, char arrayLen) throws StunException
|
public static ChannelData decode(byte binMessage[], char offset, char arrayLen) throws StunException
|
||||||
{
|
|
||||||
return decode(binMessage, offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a message from its binary representation.
|
|
||||||
* @param binMessage the binary array that contains the encoded message
|
|
||||||
* @param offset the index where the message starts.
|
|
||||||
* @return a Message object constructed from the binMessage array
|
|
||||||
* @throws StunException ILLEGAL_ARGUMENT if one or more of the arguments
|
|
||||||
* have invalid values.
|
|
||||||
*/
|
|
||||||
public static ChannelData decode(byte binMessage[], char offset) throws StunException
|
|
||||||
{
|
{
|
||||||
char msgLen = 0;
|
char msgLen = 0;
|
||||||
char channelNumber = 0;
|
char channelNumber = 0;
|
||||||
ChannelData channelData = null;
|
ChannelData channelData = null;
|
||||||
byte data[] = null;
|
byte data[] = null;
|
||||||
|
|
||||||
if ((binMessage.length - offset) < HEADER_LENGTH)
|
if(arrayLen < 4)
|
||||||
{
|
{
|
||||||
throw new StunException(StunException.ILLEGAL_ARGUMENT, "Size too short");
|
throw new StunException(StunException.ILLEGAL_ARGUMENT, "Size too short");
|
||||||
}
|
}
|
||||||
|
|
||||||
channelNumber = (char)((binMessage[offset++]<<8) | (binMessage[offset++]&0xFF));
|
channelNumber = (char)((binMessage[offset++]<<8) | (binMessage[offset++]&0xFF));
|
||||||
|
|
||||||
if (!validateChannelNumber(channelNumber))
|
if(!validateChannelNumber(channelNumber))
|
||||||
{
|
{
|
||||||
throw new StunException(StunException.ILLEGAL_ARGUMENT, "Channel number invalid");
|
throw new StunException(StunException.ILLEGAL_ARGUMENT, "Channel number invalid");
|
||||||
}
|
}
|
||||||
|
|
||||||
msgLen = (char)((binMessage[offset++]<<8) | (binMessage[offset++]&0xFF));
|
msgLen = (char)((binMessage[offset++]<<8) | (binMessage[offset++]&0xFF));
|
||||||
if (msgLen > (binMessage.length - offset))
|
if(msgLen != (binMessage.length - 4))
|
||||||
{
|
{
|
||||||
throw new StunException(StunException.ILLEGAL_ARGUMENT, "Size mismatch");
|
throw new StunException(StunException.ILLEGAL_ARGUMENT, "Size mismatch");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,7 +50,7 @@ public class Indication
|
|||||||
/* old TURN DATA indication type is an indication despite
|
/* old TURN DATA indication type is an indication despite
|
||||||
* 0x0115 & 0x0110 indicates STUN error response type
|
* 0x0115 & 0x0110 indicates STUN error response type
|
||||||
*/
|
*/
|
||||||
if (!isIndicationType(indicationType) &&
|
if(!isIndicationType(indicationType) &&
|
||||||
indicationType != OLD_DATA_INDICATION)
|
indicationType != OLD_DATA_INDICATION)
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
(int)(indicationType)
|
(int)(indicationType)
|
||||||
|
|||||||
@ -22,7 +22,6 @@ import java.util.logging.*;
|
|||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
import org.ice4j.attribute.*;
|
import org.ice4j.attribute.*;
|
||||||
import org.ice4j.ice.*;
|
|
||||||
import org.ice4j.stack.*;
|
import org.ice4j.stack.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,12 +45,7 @@ public abstract class Message
|
|||||||
private static final Logger logger
|
private static final Logger logger
|
||||||
= Logger.getLogger(Message.class.getName());
|
= Logger.getLogger(Message.class.getName());
|
||||||
|
|
||||||
/**
|
/* general declaration */
|
||||||
* The mask of the two bits from the message type structure, which indicate
|
|
||||||
* the message class.
|
|
||||||
*/
|
|
||||||
private static final char MESSAGE_CLASS_MASK = 0x0110;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* STUN request code.
|
* STUN request code.
|
||||||
*/
|
*/
|
||||||
@ -81,26 +75,26 @@ public abstract class Message
|
|||||||
/**
|
/**
|
||||||
* STUN binding request code.
|
* STUN binding request code.
|
||||||
*/
|
*/
|
||||||
public static final char BINDING_REQUEST
|
public static final char BINDING_REQUEST =
|
||||||
= (STUN_METHOD_BINDING | STUN_REQUEST);
|
(STUN_METHOD_BINDING | STUN_REQUEST);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* STUN binding success response code.
|
* STUN binding success response code.
|
||||||
*/
|
*/
|
||||||
public static final char BINDING_SUCCESS_RESPONSE
|
public static final char BINDING_SUCCESS_RESPONSE =
|
||||||
= (STUN_METHOD_BINDING | STUN_SUCCESS_RESP);
|
(STUN_METHOD_BINDING | STUN_SUCCESS_RESP);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* STUN binding error response code.
|
* STUN binding error response code.
|
||||||
*/
|
*/
|
||||||
public static final char BINDING_ERROR_RESPONSE
|
public static final char BINDING_ERROR_RESPONSE =
|
||||||
= (STUN_METHOD_BINDING | STUN_ERROR_RESP);
|
(STUN_METHOD_BINDING | STUN_ERROR_RESP);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* STUN binding request code.
|
* STUN binding request code.
|
||||||
*/
|
*/
|
||||||
public static final char BINDING_INDICATION
|
public static final char BINDING_INDICATION =
|
||||||
= (STUN_METHOD_BINDING | STUN_INDICATION);
|
(STUN_METHOD_BINDING | STUN_INDICATION);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* STUN shared secret request.
|
* STUN shared secret request.
|
||||||
@ -166,134 +160,134 @@ public abstract class Message
|
|||||||
/**
|
/**
|
||||||
* TURN allocate request code.
|
* TURN allocate request code.
|
||||||
*/
|
*/
|
||||||
public static final char ALLOCATE_REQUEST
|
public static final char ALLOCATE_REQUEST =
|
||||||
= (TURN_METHOD_ALLOCATE | STUN_REQUEST);
|
(TURN_METHOD_ALLOCATE | STUN_REQUEST);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN allocate response code.
|
* TURN allocate response code.
|
||||||
*/
|
*/
|
||||||
public static final char ALLOCATE_RESPONSE
|
public static final char ALLOCATE_RESPONSE =
|
||||||
= (TURN_METHOD_ALLOCATE | STUN_SUCCESS_RESP);
|
(TURN_METHOD_ALLOCATE | STUN_SUCCESS_RESP);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN allocate error response code.
|
* TURN allocate error response code.
|
||||||
*/
|
*/
|
||||||
public static final char ALLOCATE_ERROR_RESPONSE
|
public static final char ALLOCATE_ERROR_RESPONSE =
|
||||||
= (TURN_METHOD_ALLOCATE | STUN_ERROR_RESP);
|
(TURN_METHOD_ALLOCATE | STUN_ERROR_RESP);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN refresh request code.
|
* TURN refresh request code.
|
||||||
*/
|
*/
|
||||||
public static final char REFRESH_REQUEST
|
public static final char REFRESH_REQUEST =
|
||||||
= (TURN_METHOD_REFRESH | STUN_REQUEST);
|
(TURN_METHOD_REFRESH | STUN_REQUEST);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN allocate refresh request code.
|
* TURN allocate refresh request code.
|
||||||
*/
|
*/
|
||||||
public static final char ALLOCATE_REFRESH_REQUEST
|
public static final char ALLOCATE_REFRESH_REQUEST =
|
||||||
= (TURN_METHOD_ALLOCATE | REFRESH_REQUEST);
|
(TURN_METHOD_ALLOCATE | REFRESH_REQUEST);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN refresh response code.
|
* TURN refresh response code.
|
||||||
*/
|
*/
|
||||||
public static final char REFRESH_RESPONSE
|
public static final char REFRESH_RESPONSE =
|
||||||
= (TURN_METHOD_REFRESH | STUN_SUCCESS_RESP);
|
(TURN_METHOD_REFRESH | STUN_SUCCESS_RESP);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN refresh error response code.
|
* TURN refresh error response code.
|
||||||
*/
|
*/
|
||||||
public static final char REFRESH_ERROR_RESPONSE
|
public static final char REFRESH_ERROR_RESPONSE =
|
||||||
= (TURN_METHOD_REFRESH | STUN_ERROR_RESP);
|
(TURN_METHOD_REFRESH | STUN_ERROR_RESP);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN ChannelBind request code.
|
* TURN ChannelBind request code.
|
||||||
*/
|
*/
|
||||||
public static final char CHANNELBIND_REQUEST
|
public static final char CHANNELBIND_REQUEST =
|
||||||
= (TURN_METHOD_CHANNELBIND | STUN_REQUEST);
|
(TURN_METHOD_CHANNELBIND | STUN_REQUEST);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN ChannelBind response code.
|
* TURN ChannelBind response code.
|
||||||
*/
|
*/
|
||||||
public static final char CHANNELBIND_RESPONSE
|
public static final char CHANNELBIND_RESPONSE =
|
||||||
= (TURN_METHOD_CHANNELBIND | STUN_SUCCESS_RESP);
|
(TURN_METHOD_CHANNELBIND | STUN_SUCCESS_RESP);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN ChannelBind error response code.
|
* TURN ChannelBind error response code.
|
||||||
*/
|
*/
|
||||||
public static final char CHANNELBIND_ERROR_RESPONSE
|
public static final char CHANNELBIND_ERROR_RESPONSE =
|
||||||
= (TURN_METHOD_CHANNELBIND | STUN_ERROR_RESP);
|
(TURN_METHOD_CHANNELBIND | STUN_ERROR_RESP);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN CreatePermission request code.
|
* TURN CreatePermission request code.
|
||||||
*/
|
*/
|
||||||
public static final char CREATEPERMISSION_REQUEST
|
public static final char CREATEPERMISSION_REQUEST =
|
||||||
= (TURN_METHOD_CREATEPERMISSION | STUN_REQUEST);
|
(TURN_METHOD_CREATEPERMISSION | STUN_REQUEST);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN CreatePermission response code.
|
* TURN CreatePermission response code.
|
||||||
*/
|
*/
|
||||||
public static final char CREATEPERMISSION_RESPONSE
|
public static final char CREATEPERMISSION_RESPONSE =
|
||||||
= (TURN_METHOD_CREATEPERMISSION | STUN_SUCCESS_RESP);
|
(TURN_METHOD_CREATEPERMISSION | STUN_SUCCESS_RESP);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN CreatePermission error response code.
|
* TURN CreatePermission error response code.
|
||||||
*/
|
*/
|
||||||
public static final char CREATEPERMISSION_ERROR_RESPONSE
|
public static final char CREATEPERMISSION_ERROR_RESPONSE =
|
||||||
= (TURN_METHOD_CREATEPERMISSION | STUN_ERROR_RESP);
|
(TURN_METHOD_CREATEPERMISSION | STUN_ERROR_RESP);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN send indication code.
|
* TURN send indication code.
|
||||||
*/
|
*/
|
||||||
public static final char SEND_INDICATION
|
public static final char SEND_INDICATION =
|
||||||
= (TURN_METHOD_SEND | STUN_INDICATION);
|
(TURN_METHOD_SEND | STUN_INDICATION);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN data indication code.
|
* TURN data indication code.
|
||||||
*/
|
*/
|
||||||
public static final char DATA_INDICATION
|
public static final char DATA_INDICATION =
|
||||||
= (TURN_METHOD_DATA | STUN_INDICATION);
|
(TURN_METHOD_DATA | STUN_INDICATION);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN Connect Request code.
|
* TURN Connect Request code.
|
||||||
*/
|
*/
|
||||||
public static final char CONNECT_REQUEST
|
public static final char CONNECT_REQUEST =
|
||||||
= (TURN_METHOD_CONNECT | STUN_REQUEST);
|
(TURN_METHOD_CONNECT | STUN_REQUEST);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN Connect Success Response code.
|
* TURN Connect Success Response code.
|
||||||
*/
|
*/
|
||||||
public static final char CONNECT_RESPONSE
|
public static final char CONNECT_RESPONSE =
|
||||||
= (TURN_METHOD_CONNECT | STUN_SUCCESS_RESP);
|
(TURN_METHOD_CONNECT | STUN_SUCCESS_RESP);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN Connect Error Response code.
|
* TURN Connect Error Response code.
|
||||||
*/
|
*/
|
||||||
public static final char CONNECT_ERROR_RESPONSE
|
public static final char CONNECT_ERROR_RESPONSE =
|
||||||
= (TURN_METHOD_CONNECT | STUN_ERROR_RESP);
|
(TURN_METHOD_CONNECT | STUN_ERROR_RESP);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN Connection Bind Request code.
|
* TURN Connection Bind Request code.
|
||||||
*/
|
*/
|
||||||
public static final char CONNECTION_BIND_REQUEST
|
public static final char CONNECTION_BIND_REQUEST =
|
||||||
= (TURN_METHOD_CONNECTION_BIND | STUN_REQUEST);
|
(TURN_METHOD_CONNECTION_BIND | STUN_REQUEST);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN Connection Bind Success Response code.
|
* TURN Connection Bind Success Response code.
|
||||||
*/
|
*/
|
||||||
public static final char CONNECTION_BIND_SUCCESS_RESPONSE
|
public static final char CONNECTION_BIND_SUCCESS_RESPONSE =
|
||||||
= (TURN_METHOD_CONNECTION_BIND | STUN_SUCCESS_RESP);
|
(TURN_METHOD_CONNECTION_BIND | STUN_SUCCESS_RESP);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN Connection Bind error code.
|
* TURN Connection Bind error code.
|
||||||
*/
|
*/
|
||||||
public static final char CONNECTION_BIND_ERROR_RESPONSE
|
public static final char CONNECTION_BIND_ERROR_RESPONSE =
|
||||||
= (TURN_METHOD_CONNECTION_BIND | STUN_ERROR_RESP);
|
(TURN_METHOD_CONNECTION_BIND | STUN_ERROR_RESP);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TURN Connection Attempt Indication code.
|
* TURN Connection Attempt Indication code.
|
||||||
*/
|
*/
|
||||||
public static final char CONNECTION_ATTEMPT_INDICATION
|
public static final char CONNECTION_ATTEMPT_INDICATION =
|
||||||
= (TURN_METHOD_CONNECTION_ATTEMPT | STUN_INDICATION);
|
(TURN_METHOD_CONNECTION_ATTEMPT | STUN_INDICATION);
|
||||||
|
|
||||||
/* Old TURN method */
|
/* Old TURN method */
|
||||||
/**
|
/**
|
||||||
@ -347,7 +341,7 @@ public abstract class Message
|
|||||||
* so we'll be using a <tt>LinkedHashMap</tt>
|
* so we'll be using a <tt>LinkedHashMap</tt>
|
||||||
*/
|
*/
|
||||||
//not sure this is the best solution but I'm trying to keep entry order
|
//not sure this is the best solution but I'm trying to keep entry order
|
||||||
protected final LinkedHashMap<Character, Attribute> attributes
|
protected LinkedHashMap<Character, Attribute> attributes
|
||||||
= new LinkedHashMap<>();
|
= new LinkedHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -367,34 +361,34 @@ public abstract class Message
|
|||||||
*
|
*
|
||||||
* For classic STUN :
|
* For classic STUN :
|
||||||
*
|
*
|
||||||
* <pre>
|
*
|
||||||
* Binding Shared Shared Shared
|
* Binding Shared Shared Shared <br/>
|
||||||
* Binding Binding Error Secret Secret Secret
|
* Binding Binding Error Secret Secret Secret <br/>
|
||||||
* Att. Req. Resp. Resp. Req. Resp. Error
|
* Att. Req. Resp. Resp. Req. Resp. Error <br/>
|
||||||
* Resp.
|
* Resp. <br/>
|
||||||
* _____________________________________________________________________
|
* _____________________________________________________________________ <br/>
|
||||||
* MAPPED-ADDRESS N/A M N/A N/A N/A N/A
|
* MAPPED-ADDRESS N/A M N/A N/A N/A N/A <br/>
|
||||||
* RESPONSE-ADDRESS O N/A N/A N/A N/A N/A
|
* RESPONSE-ADDRESS O N/A N/A N/A N/A N/A <br/>
|
||||||
* CHANGE-REQUEST O N/A N/A N/A N/A N/A
|
* CHANGE-REQUEST O N/A N/A N/A N/A N/A <br/>
|
||||||
* SOURCE-ADDRESS N/A M N/A N/A N/A N/A
|
* SOURCE-ADDRESS N/A M N/A N/A N/A N/A <br/>
|
||||||
* CHANGED-ADDRESS N/A M N/A N/A N/A N/A
|
* CHANGED-ADDRESS N/A M N/A N/A N/A N/A <br/>
|
||||||
* USERNAME O N/A N/A N/A M N/A
|
* USERNAME O N/A N/A N/A M N/A <br/>
|
||||||
* PASSWORD N/A N/A N/A N/A M N/A
|
* PASSWORD N/A N/A N/A N/A M N/A <br/>
|
||||||
* MESSAGE-INTEGRITY O O N/A N/A N/A N/A
|
* MESSAGE-INTEGRITY O O N/A N/A N/A N/A <br/>
|
||||||
* ERROR-CODE N/A N/A M N/A N/A M
|
* ERROR-CODE N/A N/A M N/A N/A M <br/>
|
||||||
* UNKNOWN-ATTRIBUTES N/A N/A C N/A N/A C
|
* UNKNOWN-ATTRIBUTES N/A N/A C N/A N/A C <br/>
|
||||||
* REFLECTED-FROM N/A C N/A N/A N/A N/A
|
* REFLECTED-FROM N/A C N/A N/A N/A N/A <br/>
|
||||||
* XOR-MAPPED-ADDRESS N/A M N/A N/A N/A N/A
|
* XOR-MAPPED-ADDRESS N/A M N/A N/A N/A N/A <br/>
|
||||||
* XOR-ONLY O N/A N/A N/A N/A N/A
|
* XOR-ONLY O N/A N/A N/A N/A N/A <br/>
|
||||||
* SOFTWARE N/A O O N/A O O
|
* SOFTWARE N/A O O N/A O O <br/>
|
||||||
* </pre>
|
*
|
||||||
*/
|
*/
|
||||||
private static final byte N_A = 0;
|
public static final byte N_A = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* C means it's conditional based on some other aspect of the message.
|
* C means it's conditional based on some other aspect of the message.
|
||||||
*/
|
*/
|
||||||
private static final byte C = 1;
|
public static final byte C = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* O means the parameter is optional.
|
* O means the parameter is optional.
|
||||||
@ -470,7 +464,6 @@ public abstract class Message
|
|||||||
/* Old TURN attributes */
|
/* Old TURN attributes */
|
||||||
protected static final byte DESTINATION_ADDRESS_PRESENTITY_INDEX = 29;
|
protected static final byte DESTINATION_ADDRESS_PRESENTITY_INDEX = 29;
|
||||||
|
|
||||||
// CHECKSTYLE:OFF
|
|
||||||
protected final static byte attributePresentities[][] = new byte[][]{
|
protected final static byte attributePresentities[][] = new byte[][]{
|
||||||
// Binding Shared Shared Shared Alloc Alloc Rfrsh Rfrsh ChnlBnd ChnlBnd Send Data
|
// Binding Shared Shared Shared Alloc Alloc Rfrsh Rfrsh ChnlBnd ChnlBnd Send Data
|
||||||
// Binding Binding Error Secret Secret Secret Req. Resp. Req. Resp. Req. Resp. Indic. Indic.
|
// Binding Binding Error Secret Secret Secret Req. Resp. Req. Resp. Req. Resp. Indic. Indic.
|
||||||
@ -511,7 +504,6 @@ public abstract class Message
|
|||||||
/*USE-CANDIDATE*/ { O, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A},
|
/*USE-CANDIDATE*/ { O, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A},
|
||||||
/*DESTINATION-ADDRESS*/{N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, O, N_A, N_A, N_A, M, N_A},
|
/*DESTINATION-ADDRESS*/{N_A, N_A, N_A, N_A, N_A, N_A, N_A, N_A, O, N_A, N_A, N_A, M, N_A},
|
||||||
};
|
};
|
||||||
// CHECKSTYLE:ON
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an empty STUN Message.
|
* Creates an empty STUN Message.
|
||||||
@ -690,7 +682,7 @@ public abstract class Message
|
|||||||
public void setTransactionID(byte[] tranID)
|
public void setTransactionID(byte[] tranID)
|
||||||
throws StunException
|
throws StunException
|
||||||
{
|
{
|
||||||
if (tranID == null
|
if(tranID == null
|
||||||
|| (tranID.length != TRANSACTION_ID_LENGTH &&
|
|| (tranID.length != TRANSACTION_ID_LENGTH &&
|
||||||
tranID.length != RFC3489_TRANSACTION_ID_LENGTH))
|
tranID.length != RFC3489_TRANSACTION_ID_LENGTH))
|
||||||
throw new StunException(StunException.ILLEGAL_ARGUMENT,
|
throw new StunException(StunException.ILLEGAL_ARGUMENT,
|
||||||
@ -718,13 +710,13 @@ public abstract class Message
|
|||||||
*
|
*
|
||||||
* @param attributeType the id of the attribute to check .
|
* @param attributeType the id of the attribute to check .
|
||||||
*
|
*
|
||||||
* @return Message.N_A - for not applicable <br>
|
* @return Message.N_A - for not applicable <br/>
|
||||||
* Message.C - for case depending <br>
|
* Message.C - for case depending <br/>
|
||||||
* Message.N_A - for not applicable <br>
|
* Message.N_A - for not applicable <br/>
|
||||||
*/
|
*/
|
||||||
protected byte getAttributePresentity(char attributeType)
|
protected byte getAttributePresentity(char attributeType)
|
||||||
{
|
{
|
||||||
if (!rfc3489CompatibilityMode)
|
if(!rfc3489CompatibilityMode)
|
||||||
return O;
|
return O;
|
||||||
|
|
||||||
byte msgIndex = -1;
|
byte msgIndex = -1;
|
||||||
@ -875,22 +867,23 @@ public abstract class Message
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (!(obj instanceof Message))
|
if(!(obj instanceof Message)
|
||||||
|
|| obj == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if(obj == this)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Message msg = (Message) obj;
|
Message msg = (Message) obj;
|
||||||
if ( msg.getMessageType() != getMessageType())
|
if( msg.getMessageType() != getMessageType())
|
||||||
return false;
|
return false;
|
||||||
if (msg.getDataLength() != getDataLength())
|
if(msg.getDataLength() != getDataLength())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
//compare attributes
|
//compare attributes
|
||||||
for (Attribute localAtt : attributes.values())
|
for (Attribute localAtt : attributes.values())
|
||||||
{
|
{
|
||||||
if (!localAtt.equals(msg.getAttribute(localAtt.getAttributeType())))
|
if(!localAtt.equals(msg.getAttribute(localAtt.getAttributeType())))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -933,7 +926,7 @@ public abstract class Message
|
|||||||
|
|
||||||
byte tranID[] = getTransactionID();
|
byte tranID[] = getTransactionID();
|
||||||
|
|
||||||
if (tranID.length == 12)
|
if(tranID.length == 12)
|
||||||
{
|
{
|
||||||
System.arraycopy(MAGIC_COOKIE, 0, binMsg, offset, 4);
|
System.arraycopy(MAGIC_COOKIE, 0, binMsg, offset, 4);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
@ -1021,7 +1014,7 @@ public abstract class Message
|
|||||||
|
|
||||||
//add a SOFTWARE attribute if the user said so, and unless they did it
|
//add a SOFTWARE attribute if the user said so, and unless they did it
|
||||||
//themselves.
|
//themselves.
|
||||||
String software = AgentConfig.config.getSoftware();
|
String software = System.getProperty(StackProperties.SOFTWARE);
|
||||||
|
|
||||||
if (getAttribute(Attribute.SOFTWARE) == null
|
if (getAttribute(Attribute.SOFTWARE) == null
|
||||||
&& software != null && software.length() > 0)
|
&& software != null && software.length() > 0)
|
||||||
@ -1060,13 +1053,13 @@ public abstract class Message
|
|||||||
* @throws StunException <tt>ILLEGAL_ARGUMENT</tt> if one or more of the
|
* @throws StunException <tt>ILLEGAL_ARGUMENT</tt> if one or more of the
|
||||||
* arguments have invalid values.
|
* arguments have invalid values.
|
||||||
*/
|
*/
|
||||||
public static Message decode(byte[] binMessage, int offset, int arrayLen)
|
public static Message decode(byte binMessage[], char offset, char arrayLen)
|
||||||
throws StunException
|
throws StunException
|
||||||
{
|
{
|
||||||
int originalOffset = offset;
|
int originalOffset = offset;
|
||||||
arrayLen = Math.min(binMessage.length, arrayLen);
|
arrayLen = (char)Math.min(binMessage.length, arrayLen);
|
||||||
|
|
||||||
if (arrayLen - offset < Message.HEADER_LENGTH)
|
if(binMessage == null || arrayLen - offset < Message.HEADER_LENGTH)
|
||||||
{
|
{
|
||||||
throw new StunException( StunException.ILLEGAL_ARGUMENT,
|
throw new StunException( StunException.ILLEGAL_ARGUMENT,
|
||||||
"The given binary array is not a valid StunMessage");
|
"The given binary array is not a valid StunMessage");
|
||||||
@ -1080,7 +1073,7 @@ public abstract class Message
|
|||||||
if (Message.isResponseType(messageType) &&
|
if (Message.isResponseType(messageType) &&
|
||||||
messageType != OLD_DATA_INDICATION)
|
messageType != OLD_DATA_INDICATION)
|
||||||
message = new Response();
|
message = new Response();
|
||||||
else if (Message.isRequestType(messageType))
|
else if(Message.isRequestType(messageType))
|
||||||
message = new Request();
|
message = new Request();
|
||||||
else /* indication */
|
else /* indication */
|
||||||
message = new Indication();
|
message = new Indication();
|
||||||
@ -1091,38 +1084,38 @@ public abstract class Message
|
|||||||
| (binMessage[offset++] & 0xFF));
|
| (binMessage[offset++] & 0xFF));
|
||||||
|
|
||||||
/* copy the cookie */
|
/* copy the cookie */
|
||||||
byte[] cookie = new byte[4];
|
byte cookie[] = new byte[4];
|
||||||
System.arraycopy(binMessage, offset, cookie, 0, 4);
|
System.arraycopy(binMessage, offset, cookie, 0, 4);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
|
|
||||||
boolean rfc3489Compat = false;
|
boolean rfc3489Compat = false;
|
||||||
|
|
||||||
if (!Arrays.equals(MAGIC_COOKIE, cookie))
|
if(!Arrays.equals(MAGIC_COOKIE, cookie))
|
||||||
{
|
{
|
||||||
rfc3489Compat = true;
|
rfc3489Compat = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arrayLen - offset - TRANSACTION_ID_LENGTH < length)
|
if(arrayLen - offset - TRANSACTION_ID_LENGTH < length)
|
||||||
{
|
{
|
||||||
throw
|
throw
|
||||||
new StunException(
|
new StunException(
|
||||||
StunException.ILLEGAL_ARGUMENT,
|
StunException.ILLEGAL_ARGUMENT,
|
||||||
"The given binary array does not seem to contain"
|
"The given binary array does not seem to contain"
|
||||||
+ " a whole StunMessage: given "
|
+ " a whole StunMessage: given "
|
||||||
+ arrayLen
|
+ ((int) arrayLen)
|
||||||
+ " bytes of "
|
+ " bytes of "
|
||||||
+ message.getName()
|
+ message.getName()
|
||||||
+ " but expecting "
|
+ " but expecting "
|
||||||
+ (offset + TRANSACTION_ID_LENGTH + length));
|
+ (offset + TRANSACTION_ID_LENGTH + length));
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] tranID = new byte[TRANSACTION_ID_LENGTH];
|
byte tranID[] = new byte[TRANSACTION_ID_LENGTH];
|
||||||
System.arraycopy(binMessage, offset, tranID, 0, TRANSACTION_ID_LENGTH);
|
System.arraycopy(binMessage, offset, tranID, 0, TRANSACTION_ID_LENGTH);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (rfc3489Compat)
|
if(rfc3489Compat)
|
||||||
{
|
{
|
||||||
byte[] rfc3489TranID = new byte[TRANSACTION_ID_LENGTH + 4];
|
byte rfc3489TranID[] = new byte[TRANSACTION_ID_LENGTH + 4];
|
||||||
System.arraycopy(cookie, 0, rfc3489TranID, 0, 4);
|
System.arraycopy(cookie, 0, rfc3489TranID, 0, 4);
|
||||||
System.arraycopy(tranID, 0, rfc3489TranID, 4,
|
System.arraycopy(tranID, 0, rfc3489TranID, 4,
|
||||||
TRANSACTION_ID_LENGTH);
|
TRANSACTION_ID_LENGTH);
|
||||||
@ -1142,7 +1135,7 @@ public abstract class Message
|
|||||||
|
|
||||||
offset += TRANSACTION_ID_LENGTH;
|
offset += TRANSACTION_ID_LENGTH;
|
||||||
|
|
||||||
while (offset - Message.HEADER_LENGTH < length)
|
while(offset - Message.HEADER_LENGTH < length)
|
||||||
{
|
{
|
||||||
Attribute att = AttributeDecoder.decode(
|
Attribute att = AttributeDecoder.decode(
|
||||||
binMessage, offset, (char)(length - offset));
|
binMessage, offset, (char)(length - offset));
|
||||||
@ -1155,7 +1148,7 @@ public abstract class Message
|
|||||||
|
|
||||||
//now also skip any potential padding that might have come with
|
//now also skip any potential padding that might have come with
|
||||||
//this attribute.
|
//this attribute.
|
||||||
if ((att.getDataLength() % 4) > 0)
|
if((att.getDataLength() % 4) > 0)
|
||||||
{
|
{
|
||||||
offset += (4 - (att.getDataLength() % 4));
|
offset += (4 - (att.getDataLength() % 4));
|
||||||
}
|
}
|
||||||
@ -1252,11 +1245,11 @@ public abstract class Message
|
|||||||
protected void validateAttributePresentity()
|
protected void validateAttributePresentity()
|
||||||
throws IllegalStateException
|
throws IllegalStateException
|
||||||
{
|
{
|
||||||
if (! rfc3489CompatibilityMode )
|
if(! rfc3489CompatibilityMode )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (char i = Attribute.MAPPED_ADDRESS; i < Attribute.REFLECTED_FROM; i++)
|
for(char i = Attribute.MAPPED_ADDRESS; i < Attribute.REFLECTED_FROM;i++)
|
||||||
if (getAttributePresentity(i) == M && getAttribute(i) == null)
|
if(getAttributePresentity(i) == M && getAttribute(i) == null)
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"A mandatory attribute (type=" + (int)i + ") is missing!");
|
"A mandatory attribute (type=" + (int)i + ") is missing!");
|
||||||
}
|
}
|
||||||
@ -1268,7 +1261,7 @@ public abstract class Message
|
|||||||
*/
|
*/
|
||||||
public static boolean isErrorResponseType(char type)
|
public static boolean isErrorResponseType(char type)
|
||||||
{
|
{
|
||||||
return ((type & MESSAGE_CLASS_MASK) == STUN_ERROR_RESP);
|
return ((type & 0x0110) == STUN_ERROR_RESP);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1278,7 +1271,7 @@ public abstract class Message
|
|||||||
*/
|
*/
|
||||||
public static boolean isSuccessResponseType(char type)
|
public static boolean isSuccessResponseType(char type)
|
||||||
{
|
{
|
||||||
return ((type & MESSAGE_CLASS_MASK) == STUN_SUCCESS_RESP);
|
return ((type & 0x0110) == STUN_SUCCESS_RESP);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1296,11 +1289,11 @@ public abstract class Message
|
|||||||
/**
|
/**
|
||||||
* Determines if the message type is Indication.
|
* Determines if the message type is Indication.
|
||||||
* @param type type to test
|
* @param type type to test
|
||||||
* @return true if the type is Indication, false otherwise
|
* @return true if the type is Indictation, false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean isIndicationType(char type)
|
public static boolean isIndicationType(char type)
|
||||||
{
|
{
|
||||||
return ((type & MESSAGE_CLASS_MASK) == STUN_INDICATION);
|
return ((type & 0x0110) == STUN_INDICATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1312,7 +1305,7 @@ public abstract class Message
|
|||||||
public static boolean isRequestType(char type)
|
public static boolean isRequestType(char type)
|
||||||
{
|
{
|
||||||
/* return !isResponseType(type); */
|
/* return !isResponseType(type); */
|
||||||
return ((type & MESSAGE_CLASS_MASK) == STUN_REQUEST);
|
return ((type & 0x0110) == STUN_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -54,8 +54,7 @@ public class MessageFactory
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
bindingRequest.setMessageType(Message.BINDING_REQUEST);
|
bindingRequest.setMessageType(Message.BINDING_REQUEST);
|
||||||
}
|
} catch (IllegalArgumentException ex)
|
||||||
catch (IllegalArgumentException ex)
|
|
||||||
{
|
{
|
||||||
// there should be no exc here since we're the creators.
|
// there should be no exc here since we're the creators.
|
||||||
logger.log(Level.FINE, "Failed to set message type.", ex);
|
logger.log(Level.FINE, "Failed to set message type.", ex);
|
||||||
@ -123,8 +122,7 @@ public class MessageFactory
|
|||||||
IceControllingAttribute iceControllingAttribute = AttributeFactory
|
IceControllingAttribute iceControllingAttribute = AttributeFactory
|
||||||
.createIceControllingAttribute(tieBreaker);
|
.createIceControllingAttribute(tieBreaker);
|
||||||
bindingRequest.putAttribute(iceControllingAttribute);
|
bindingRequest.putAttribute(iceControllingAttribute);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
IceControlledAttribute iceControlledAttribute = AttributeFactory
|
IceControlledAttribute iceControlledAttribute = AttributeFactory
|
||||||
.createIceControlledAttribute(tieBreaker);
|
.createIceControlledAttribute(tieBreaker);
|
||||||
@ -358,8 +356,7 @@ public class MessageFactory
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
allocateRequest.setMessageType(Message.ALLOCATE_REQUEST);
|
allocateRequest.setMessageType(Message.ALLOCATE_REQUEST);
|
||||||
}
|
} catch (IllegalArgumentException ex)
|
||||||
catch (IllegalArgumentException ex)
|
|
||||||
{
|
{
|
||||||
// there should be no exc here since we're the creators.
|
// there should be no exc here since we're the creators.
|
||||||
logger.log(Level.FINE, "Failed to set message type.", ex);
|
logger.log(Level.FINE, "Failed to set message type.", ex);
|
||||||
@ -432,7 +429,7 @@ public class MessageFactory
|
|||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return createAllocationResponse(
|
return createAllocationResponse(
|
||||||
request, mappedAddress, relayedAddress, null , lifetime);
|
request, mappedAddress, relayedAddress, null ,lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -487,7 +484,7 @@ public class MessageFactory
|
|||||||
|
|
||||||
allocationSuccessResponse.putAttribute(lifetimeAttribute);
|
allocationSuccessResponse.putAttribute(lifetimeAttribute);
|
||||||
|
|
||||||
if (token != null)
|
if(token != null)
|
||||||
{
|
{
|
||||||
//reservation token
|
//reservation token
|
||||||
ReservationTokenAttribute reservationTokenAttribute
|
ReservationTokenAttribute reservationTokenAttribute
|
||||||
@ -511,7 +508,7 @@ public class MessageFactory
|
|||||||
*/
|
*/
|
||||||
public static Response createAllocationErrorResponse(char errorCode)
|
public static Response createAllocationErrorResponse(char errorCode)
|
||||||
{
|
{
|
||||||
return createAllocationErrorResponse(errorCode, null);
|
return createAllocationErrorResponse(errorCode,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -672,8 +669,7 @@ public class MessageFactory
|
|||||||
LifetimeAttribute lifetimeReq = AttributeFactory
|
LifetimeAttribute lifetimeReq = AttributeFactory
|
||||||
.createLifetimeAttribute(lifetime);
|
.createLifetimeAttribute(lifetime);
|
||||||
refreshRequest.putAttribute(lifetimeReq);
|
refreshRequest.putAttribute(lifetimeReq);
|
||||||
}
|
} catch (IllegalArgumentException ex)
|
||||||
catch (IllegalArgumentException ex)
|
|
||||||
{
|
{
|
||||||
logger.log(Level.FINE, "Failed to set message type.", ex);
|
logger.log(Level.FINE, "Failed to set message type.", ex);
|
||||||
}
|
}
|
||||||
@ -830,7 +826,7 @@ public class MessageFactory
|
|||||||
|
|
||||||
ErrorCodeAttribute errorCodeAttribute
|
ErrorCodeAttribute errorCodeAttribute
|
||||||
= AttributeFactory
|
= AttributeFactory
|
||||||
.createErrorCodeAttribute(errorCode, reasonPhrase);
|
.createErrorCodeAttribute(errorCode,reasonPhrase);
|
||||||
|
|
||||||
channelBindErrorResponse.putAttribute(errorCodeAttribute);
|
channelBindErrorResponse.putAttribute(errorCodeAttribute);
|
||||||
|
|
||||||
@ -916,7 +912,7 @@ public class MessageFactory
|
|||||||
ErrorCodeAttribute errorCodeAttribute
|
ErrorCodeAttribute errorCodeAttribute
|
||||||
= AttributeFactory
|
= AttributeFactory
|
||||||
.createErrorCodeAttribute(
|
.createErrorCodeAttribute(
|
||||||
errorCode, reasonPhrase);
|
errorCode,reasonPhrase);
|
||||||
|
|
||||||
createPermissionErrorResponse.putAttribute(errorCodeAttribute);
|
createPermissionErrorResponse.putAttribute(errorCodeAttribute);
|
||||||
|
|
||||||
@ -953,8 +949,7 @@ public class MessageFactory
|
|||||||
.createDataAttribute(data);
|
.createDataAttribute(data);
|
||||||
sendIndication.putAttribute(dataAttribute);
|
sendIndication.putAttribute(dataAttribute);
|
||||||
}
|
}
|
||||||
}
|
} catch (IllegalArgumentException ex)
|
||||||
catch (IllegalArgumentException ex)
|
|
||||||
{
|
{
|
||||||
logger.log(Level.FINE, "Failed to set message type.", ex);
|
logger.log(Level.FINE, "Failed to set message type.", ex);
|
||||||
}
|
}
|
||||||
@ -1275,7 +1270,7 @@ public class MessageFactory
|
|||||||
public static Response createConnectionBindErrorResponse(char errorCode)
|
public static Response createConnectionBindErrorResponse(char errorCode)
|
||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
return createConnectionBindErrorResponse(errorCode, null);
|
return createConnectionBindErrorResponse(errorCode,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1358,7 +1353,6 @@ public class MessageFactory
|
|||||||
* mandatory headers.
|
* mandatory headers.
|
||||||
* @throws IllegalArgumentException if there was something wrong with the
|
* @throws IllegalArgumentException if there was something wrong with the
|
||||||
* way we are trying to create the Request.
|
* way we are trying to create the Request.
|
||||||
* @throws StunException when the transaction id is not valid.
|
|
||||||
*/
|
*/
|
||||||
public static Indication createConnectionAttemptIndication(
|
public static Indication createConnectionAttemptIndication(
|
||||||
int connectionIdValue, TransportAddress peerAddress,
|
int connectionIdValue, TransportAddress peerAddress,
|
||||||
|
|||||||
@ -44,7 +44,7 @@ public class Request extends Message
|
|||||||
public void setMessageType(char requestType)
|
public void setMessageType(char requestType)
|
||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (!isRequestType(requestType))
|
if(!isRequestType(requestType))
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
(int)(requestType)
|
(int)(requestType)
|
||||||
+ " - is not a valid request type.");
|
+ " - is not a valid request type.");
|
||||||
|
|||||||
@ -68,7 +68,7 @@ public class Response
|
|||||||
public void setMessageType(char responseType)
|
public void setMessageType(char responseType)
|
||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if (!isResponseType(responseType))
|
if(!isResponseType(responseType))
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
Integer.toString(responseType)
|
Integer.toString(responseType)
|
||||||
+ " is not a valid response type.");
|
+ " is not a valid response type.");
|
||||||
|
|||||||
@ -364,9 +364,9 @@ public class PseudoTCPBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the MTU (maximum transmission unit) value
|
* Set the MTU value
|
||||||
*
|
*
|
||||||
* @param mtu the new MTU value
|
* @param mtu
|
||||||
*/
|
*/
|
||||||
public void notifyMTU(int mtu)
|
public void notifyMTU(int mtu)
|
||||||
{
|
{
|
||||||
@ -387,11 +387,12 @@ public class PseudoTCPBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @return current timestamp limited to 32 bits
|
* @return current timestamp limited to 32 bits
|
||||||
*/
|
*/
|
||||||
public static long now()
|
public static long now()
|
||||||
{
|
{
|
||||||
return (System.nanoTime() / 1000000) & 0xFFFFFFFFL;
|
return System.currentTimeMillis() & 0xFFFFFFFFL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -444,8 +445,7 @@ public class PseudoTCPBase
|
|||||||
|
|
||||||
long nInFlight = m_snd_nxt - m_snd_una;
|
long nInFlight = m_snd_nxt - m_snd_una;
|
||||||
m_ssthresh = Math.max(nInFlight / 2, 2 * m_mss);
|
m_ssthresh = Math.max(nInFlight / 2, 2 * m_mss);
|
||||||
//Logger.Log(LS_INFO)
|
//Logger.Log(LS_INFO) << "m_ssthresh: " << m_ssthresh << " nInFlight: " << nInFlight << " m_mss: " << m_mss;
|
||||||
// << "m_ssthresh: " << m_ssthresh << " nInFlight: " << nInFlight << " m_mss: " << m_mss;
|
|
||||||
m_cwnd = m_mss;
|
m_cwnd = m_mss;
|
||||||
|
|
||||||
// Back off retransmit timer. Note: the limit is lower when connecting.
|
// Back off retransmit timer. Note: the limit is lower when connecting.
|
||||||
@ -680,13 +680,11 @@ public class PseudoTCPBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the data available in receive buffer. This method returns 0 if
|
|
||||||
* there's no data available at the moment.
|
|
||||||
*
|
*
|
||||||
* @param buffer destination buffer
|
* @param buffer
|
||||||
* @param len bytes to be read
|
* @param len
|
||||||
* @return received byte count
|
* @return received byte count
|
||||||
* @throws IOException if the protocol is not in the connected state
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public int recv(byte[] buffer, int len) throws IOException
|
public int recv(byte[] buffer, int len) throws IOException
|
||||||
{
|
{
|
||||||
@ -694,12 +692,11 @@ public class PseudoTCPBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enqueues data in the send buffer
|
|
||||||
*
|
*
|
||||||
* @param buffer source data buffer
|
* @param buffer
|
||||||
* @param len bytes count to be sent
|
* @param len
|
||||||
* @return sent byte count
|
* @return sent byte count
|
||||||
* @throws IOException if the protocol is not in connected state
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public int send(byte[] buffer, int len) throws IOException
|
public int send(byte[] buffer, int len) throws IOException
|
||||||
{
|
{
|
||||||
@ -878,9 +875,6 @@ public class PseudoTCPBase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Method can be used in debugging utilities to parse PTCP segment
|
* Method can be used in debugging utilities to parse PTCP segment
|
||||||
* @param buffer data to parse
|
|
||||||
* @param size length of the data in the buffer
|
|
||||||
* @return the parsed segment
|
|
||||||
*/
|
*/
|
||||||
public static Segment parseSeg(byte[] buffer, int size)
|
public static Segment parseSeg(byte[] buffer, int size)
|
||||||
{
|
{
|
||||||
@ -908,13 +902,13 @@ public class PseudoTCPBase
|
|||||||
/**
|
/**
|
||||||
* Can be used to convert segments to text
|
* Can be used to convert segments to text
|
||||||
*
|
*
|
||||||
* @param seg the {@link Segment} to format
|
* @param seg
|
||||||
* @return segment in readable text form
|
* @return segment in readable text form
|
||||||
*/
|
*/
|
||||||
public static String segToStr(Segment seg)
|
public static String segToStr(Segment seg)
|
||||||
{
|
{
|
||||||
String data="data: ";
|
String data="data: ";
|
||||||
for (byte b : seg.data)
|
for(byte b : seg.data)
|
||||||
{
|
{
|
||||||
data += b;
|
data += b;
|
||||||
}
|
}
|
||||||
@ -1064,7 +1058,7 @@ public class PseudoTCPBase
|
|||||||
bConnect = true;
|
bConnect = true;
|
||||||
|
|
||||||
// TCP options are in the remainder of the payload after CTL_CONNECT.
|
// TCP options are in the remainder of the payload after CTL_CONNECT.
|
||||||
if (!parseOptions(seg.data, 1, seg.len - 1))
|
if(!parseOptions(seg.data, 1, seg.len - 1))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1252,8 +1246,7 @@ public class PseudoTCPBase
|
|||||||
m_recover = m_snd_nxt;
|
m_recover = m_snd_nxt;
|
||||||
long nInFlight = m_snd_nxt - m_snd_una;
|
long nInFlight = m_snd_nxt - m_snd_una;
|
||||||
m_ssthresh = Math.max(nInFlight / 2, 2 * m_mss);
|
m_ssthresh = Math.max(nInFlight / 2, 2 * m_mss);
|
||||||
//Logger.Log(LS_INFO)
|
//Logger.Log(LS_INFO) << "m_ssthresh: " << m_ssthresh << " nInFlight: " << nInFlight << " m_mss: " << m_mss;
|
||||||
// << "m_ssthresh: " << m_ssthresh << " nInFlight: " << nInFlight << " m_mss: " << m_mss;
|
|
||||||
m_cwnd = m_ssthresh + 3 * m_mss;
|
m_cwnd = m_ssthresh + 3 * m_mss;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1959,7 +1952,7 @@ public class PseudoTCPBase
|
|||||||
options_specified.add(kind);
|
options_specified.add(kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options_specified.contains(TCP_OPT_WND_SCALE))
|
if (options_specified.indexOf(TCP_OPT_WND_SCALE) == -1)//options_specified.size() - 1)
|
||||||
{
|
{
|
||||||
logger.log(Level.WARNING, "Peer doesn't support window scaling");
|
logger.log(Level.WARNING, "Peer doesn't support window scaling");
|
||||||
if (getM_rwnd_scale() > 0)
|
if (getM_rwnd_scale() > 0)
|
||||||
@ -2124,7 +2117,7 @@ public class PseudoTCPBase
|
|||||||
|
|
||||||
void setConversationID(long convID)
|
void setConversationID(long convID)
|
||||||
{
|
{
|
||||||
if (m_state != PseudoTcpState.TCP_LISTEN)
|
if(m_state != PseudoTcpState.TCP_LISTEN)
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
this.m_conv = convID;
|
this.m_conv = convID;
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user