Compare commits
257 Commits
ice4j-1.0.
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d289f125a4 | ||
|
|
0d8af275cd | ||
|
|
1c60acc59b | ||
|
|
fd43e6c181 | ||
|
|
27ad37d1af | ||
|
|
9fe2d69cf1 | ||
|
|
a947919f40 | ||
|
|
76e8a1968d | ||
|
|
28a23e1859 | ||
|
|
71e244dd67 | ||
|
|
f41542dd7c | ||
|
|
dec3a87d21 | ||
|
|
1f97cf2b26 | ||
|
|
32a8aadae8 | ||
|
|
2baae57d53 | ||
|
|
f195378a3d | ||
|
|
a9ba80efb9 | ||
|
|
86f1eaede2 | ||
|
|
ddfc498d0b | ||
|
|
d825218ab7 | ||
|
|
fc1498ef7e | ||
|
|
2e43ba1b3e | ||
|
|
64a7ca8c30 | ||
|
|
f637413a98 | ||
|
|
15981cf5f3 | ||
|
|
0811007990 | ||
|
|
cd2d21a8d0 | ||
|
|
626c35e460 | ||
|
|
a1b3c9b503 | ||
|
|
15d69b316c | ||
|
|
d4a145374f | ||
|
|
d7c0e27a1c | ||
|
|
9dc08bd299 | ||
|
|
adca67b17f | ||
|
|
076281c76b | ||
|
|
311a495b21 | ||
|
|
10346acade | ||
|
|
924f40c4e0 | ||
|
|
2586d8b2da | ||
|
|
3e0a9f97ef | ||
|
|
f6550a80ac | ||
|
|
c829b3a766 | ||
|
|
f176d021f8 | ||
|
|
5a299cd694 | ||
|
|
34c2ce50ec | ||
|
|
a86c4be742 | ||
|
|
67ffceb81d | ||
|
|
3a55627ba0 | ||
|
|
29ae8061ad | ||
|
|
f8a506ef70 | ||
|
|
686164ffc4 | ||
|
|
ed63ae8e11 | ||
|
|
9a580a9401 | ||
|
|
8ffa9030f4 | ||
|
|
7016902b21 | ||
|
|
e6e36856c6 | ||
|
|
e90c796d6d | ||
|
|
ca3868ac26 | ||
|
|
982e78212b | ||
|
|
35e149848e | ||
|
|
36f732ba1c | ||
|
|
e0fccdaf4d | ||
|
|
b504c2cc2e | ||
|
|
78e006cbac | ||
|
|
fe30fe8a31 | ||
|
|
7989977e1e | ||
|
|
43a9f282d2 | ||
|
|
e854e4efaf | ||
|
|
43fa07d9a5 | ||
|
|
0b052e8f85 | ||
|
|
c7c4719c45 | ||
|
|
59461c9d13 | ||
|
|
105a49749e | ||
|
|
0ea60d85b3 | ||
|
|
17bbc9b97a | ||
|
|
80471b751a | ||
|
|
5aec41fc02 | ||
|
|
f9a357ec17 | ||
|
|
0be8f1aae7 | ||
|
|
e87d331e57 | ||
|
|
e3e78dcda3 | ||
|
|
ce42c77b82 | ||
|
|
4027cf429d | ||
|
|
c56fcc3a3f | ||
|
|
8b43209b8d | ||
|
|
6beca2903c | ||
|
|
c325421927 | ||
|
|
17b9bd9c17 | ||
|
|
ee4e8c9452 | ||
|
|
3239ed12fc | ||
|
|
513fb588d6 | ||
|
|
3fe34dcb97 | ||
|
|
6bed63795f | ||
|
|
ba7e30c189 | ||
|
|
7d2ad8f9a2 | ||
|
|
4aef25b91f | ||
|
|
38e7b9226d | ||
|
|
59693a4894 | ||
|
|
200b383752 | ||
|
|
f2cd3891e1 | ||
|
|
9810024b73 | ||
|
|
48956f82ba | ||
|
|
a2e5ca1d4c | ||
|
|
610a438dac | ||
|
|
c26679744c | ||
|
|
39403816f8 | ||
|
|
4c5cc1642a | ||
|
|
9da28850f5 | ||
|
|
3f97648918 | ||
|
|
c52dbf7956 | ||
|
|
c2f08ceca2 | ||
|
|
5188097479 | ||
|
|
f6e3deb9a5 | ||
|
|
c25288460d | ||
|
|
ed26be48d7 | ||
|
|
907b36c6c0 | ||
|
|
feecacefc5 | ||
|
|
51baa62ee2 | ||
|
|
b6e5d035e5 | ||
|
|
e472f6ac1c | ||
|
|
e099d4acbe | ||
|
|
969e363bc6 | ||
|
|
dffdf0cbc8 | ||
|
|
f9eded5078 | ||
|
|
b3c304146b | ||
|
|
8cf47c00c2 | ||
|
|
a524e1b2c0 | ||
|
|
5085b042bb | ||
|
|
3784d5681b | ||
|
|
3547d35e9b | ||
|
|
7f3a3806ca | ||
|
|
bf0892e8d2 | ||
|
|
36553e203a | ||
|
|
4847672519 | ||
|
|
183e115cf2 | ||
|
|
47acf238bf | ||
|
|
9348af1624 | ||
|
|
02992ee8d1 | ||
|
|
7a78b72d5b | ||
|
|
6401fcd436 | ||
|
|
77fe6973c4 | ||
|
|
6bfe2ac5e5 | ||
|
|
0f86b8797f | ||
|
|
cefd964509 | ||
|
|
7c63d5202c | ||
|
|
72d1b1441c | ||
|
|
e1338126fe | ||
|
|
2e4bf351fe | ||
|
|
203ffbd92b | ||
|
|
383002efe2 | ||
|
|
43e6e5359d | ||
|
|
cf61003e5b | ||
|
|
e300997924 | ||
|
|
0d769bb46d | ||
|
|
19e86e3bc9 | ||
|
|
a1796c9bfb | ||
|
|
abec6b79e5 | ||
|
|
fe2b1a3239 | ||
|
|
c46c1a2613 | ||
|
|
5f554565b1 | ||
|
|
b340fa22f0 | ||
|
|
1cd1128b89 | ||
|
|
9adab9094f | ||
|
|
7cac0e50a7 | ||
|
|
6d6f4710e0 | ||
|
|
9c8d22a5bd | ||
|
|
d0587e99e6 | ||
|
|
cb2856a8ae | ||
|
|
75e8948f4b | ||
|
|
9a2fe509d4 | ||
|
|
d5410b922b | ||
|
|
b4a5e2eb83 | ||
|
|
dae6d32875 | ||
|
|
633f05b4e5 | ||
|
|
d0afb0a55b | ||
|
|
6603ac3c28 | ||
|
|
ff6eeb343e | ||
|
|
67f301eebc | ||
|
|
82544254c4 | ||
|
|
c378329b8c | ||
|
|
15a2df1e59 | ||
|
|
91858ba6a3 | ||
|
|
3ddb19ff2c | ||
|
|
eaceca57ac | ||
|
|
f19dbc1984 | ||
|
|
f08feea707 | ||
|
|
25b0cfdc30 | ||
|
|
2718728e92 | ||
|
|
44ca871888 | ||
|
|
aafe003974 | ||
|
|
12a4ef19a0 | ||
|
|
f9f2c0f3e9 | ||
|
|
c30ebeca53 | ||
|
|
c82717e8e7 | ||
|
|
425cf9bb0d | ||
|
|
d538ca30c0 | ||
|
|
6bc252fdd4 | ||
|
|
c47ecee639 | ||
|
|
a8729dda22 | ||
|
|
1d13bc7175 | ||
|
|
c919de1b3a | ||
|
|
256176dde6 | ||
|
|
a08c77a3c1 | ||
|
|
99600368f6 | ||
|
|
3e01bff25e | ||
|
|
a7ff3b8dca | ||
|
|
452af370a5 | ||
|
|
dc4e05e5d9 | ||
|
|
7acb9fd5cc | ||
|
|
b5d3bb2ddc | ||
|
|
2b8b025fbe | ||
|
|
84ca00a325 | ||
|
|
38cfe178c6 | ||
|
|
350fb833ac | ||
|
|
3aaee5acde | ||
|
|
4216982445 | ||
|
|
35e603d346 | ||
|
|
0abaef19e8 | ||
|
|
94b3cb2661 | ||
|
|
1dc41efb1e | ||
|
|
bed87bcbd3 | ||
|
|
4ba7247480 | ||
|
|
4e8f3474e7 | ||
|
|
d6c4c62689 | ||
|
|
a21088dc7a | ||
|
|
5f2261af43 | ||
|
|
58c319981c | ||
|
|
26aa42cc37 | ||
|
|
6fe376a56d | ||
|
|
2af7613491 | ||
|
|
27f6f62c27 | ||
|
|
dc29172a2c | ||
|
|
ded13aa230 | ||
|
|
aa22012c5d | ||
|
|
4f946f38a4 | ||
|
|
568ace382b | ||
|
|
e4f5534b3d | ||
|
|
7312077fd9 | ||
|
|
164ca04236 | ||
|
|
a363a973eb | ||
|
|
a51af3f90f | ||
|
|
b76f9abfc9 | ||
|
|
84bd07c665 | ||
|
|
d33d8b87e4 | ||
|
|
b877467bc4 | ||
|
|
249ebb913a | ||
|
|
de1260610d | ||
|
|
caa313739a | ||
|
|
08f6ee8c64 | ||
|
|
ce4126701e | ||
|
|
9155707329 | ||
|
|
af8c32ecd7 | ||
|
|
7e152e0367 | ||
|
|
71b2874d46 | ||
|
|
02e1217144 | ||
|
|
8536ff347b | ||
|
|
0f0fb9d06f |
17
.editorconfig
Normal file
17
.editorconfig
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
[*]
|
||||||
|
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
Normal file
82
.github/workflows/maven.yml
vendored
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
# 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,3 +7,7 @@
|
|||||||
.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 [dev mailing list](https://jitsi.org/Development/MailingLists) for questions and discussions.
|
ice4j is maintained by the [Jitsi](https://jitsi.org/) community. Use Jitsi's [community forum](https://community.jitsi.org) for questions and discussions.
|
||||||
|
|
||||||
Thanks
|
Thanks
|
||||||
------
|
------
|
||||||
|
|||||||
6
bnd.bnd
Normal file
6
bnd.bnd
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Export-Package: org.ice4j.*
|
||||||
|
Import-Package: *;version=!
|
||||||
|
Bundle-SymbolicName: org.jitsi.ice4j
|
||||||
|
-noextraheaders: true
|
||||||
|
-snapshot: SNAPSHOT
|
||||||
|
-removeheaders: Require-Capability, Bundle-SCM
|
||||||
306
build.xml
306
build.xml
@ -1,306 +0,0 @@
|
|||||||
<?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>
|
|
||||||
40
checkstyle.xml
Normal file
40
checkstyle.xml
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?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>
|
||||||
87
doc/configuration.md
Normal file
87
doc/configuration.md
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
# 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
BIN
lib/junit.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
514
pom.xml
514
pom.xml
@ -1,42 +1,119 @@
|
|||||||
<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>1.0</version>
|
<version>3.0-SNAPSHOT</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</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>
|
||||||
</dependency>
|
<version>1.2</version>
|
||||||
<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>junit</groupId>
|
<groupId>org.junit.platform</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-platform-launcher</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>
|
||||||
@ -44,39 +121,422 @@
|
|||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>kotlin-maven-plugin</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>compile</id>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>compile</goal>
|
||||||
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<includes>
|
<sourceDirs>
|
||||||
<include>**/*TestSuite.*</include>
|
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
|
||||||
</includes>
|
<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>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.felix</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-bundle-plugin</artifactId>
|
<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>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>3.0.0-M6</version>
|
||||||
|
<configuration>
|
||||||
|
<includes>**/*</includes>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<java.util.logging.config.file>${project.build.testSourceDirectory}/../resources/logging.properties</java.util.logging.config.file>
|
||||||
|
</systemPropertyVariables>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-deploy-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>
|
||||||
<jdk>(,1.8)</jdk>
|
<property>
|
||||||
|
<name>release</name>
|
||||||
|
<value>true</value>
|
||||||
|
</property>
|
||||||
</activation>
|
</activation>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>build-helper-maven-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>generate-sources</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>add-source</goal>
|
||||||
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<excludes>
|
<sources>
|
||||||
<exclude>**/jdk8/**</exclude>
|
<source>src/main/kotlin</source>
|
||||||
</excludes>
|
</sources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-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>
|
||||||
|
<gpgArguments>
|
||||||
|
<arg>--pinentry-mode</arg>
|
||||||
|
<arg>loopback</arg>
|
||||||
|
</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,6 +110,9 @@ 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,6 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.ice4j;
|
package org.ice4j;
|
||||||
|
|
||||||
|
import org.ice4j.ice.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
|
|
||||||
@ -48,6 +50,15 @@ 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.
|
||||||
@ -75,19 +86,6 @@ 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.
|
||||||
@ -116,14 +114,6 @@ 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.
|
||||||
@ -142,11 +132,6 @@ 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.
|
||||||
@ -171,13 +156,6 @@ 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.
|
||||||
@ -188,13 +166,6 @@ 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
|
||||||
|
|||||||
@ -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.
|
||||||
|
|||||||
@ -24,34 +24,32 @@ 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:
|
||||||
*<p>
|
*<ul>
|
||||||
* MAPPED-ADDRESS <br/>
|
* <li>MAPPED-ADDRESS
|
||||||
* RESPONSE-ADDRESS <br/>
|
* <li>RESPONSE-ADDRESS
|
||||||
* SOURCE-ADDRESS <br/>
|
* <li>SOURCE-ADDRESS
|
||||||
* CHANGED-ADDRESS <br/>
|
* <li>CHANGED-ADDRESS
|
||||||
* REFLECTED-FROM <br/>
|
* <li>REFLECTED-FROM
|
||||||
* ALTERNATE-SERVER <br/>
|
* <li>ALTERNATE-SERVER
|
||||||
* XOR-PEER-ADDRESS <br/>
|
* <li>XOR-PEER-ADDRESS
|
||||||
* XOR-RELAYED-ADDRESS <br/>
|
* <li>XOR-RELAYED-ADDRESS
|
||||||
*</p>
|
*</ul>
|
||||||
*<p>
|
*<p>
|
||||||
* The different attributes are distinguished by the attributeType of
|
* The different attributes are distinguished by the attributeType of
|
||||||
* org.ice4j.attribute.Attribute.
|
* {@link 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.
|
||||||
*<code>
|
*<pre>
|
||||||
* 0 1 2 3 <br/>
|
* 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 <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/>
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
* |x x x x x x x x| Family | Port | <br/>
|
* |x x x x x x x x| Family | Port |
|
||||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ <br/>
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
* | Address | <br/>
|
* | Address |
|
||||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ <br/>
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
* <br/>
|
* </pre>
|
||||||
* </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
|
||||||
@ -161,8 +159,7 @@ 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)
|
||||||
@ -224,10 +221,12 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,52 +22,53 @@ 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 ....
|
||||||
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
*
|
*
|
||||||
* 0 1 2 3 <br/>
|
* The following types are defined:
|
||||||
* 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/>
|
|
||||||
*
|
*
|
||||||
* ICE attributes:<br/>
|
* STUN attributes:
|
||||||
* 0x0024: PRIORITY <br/>
|
* 0x0001: MAPPED-ADDRESS
|
||||||
* 0x0025: USE-CANDIDATE <br/>
|
* 0x0002: RESPONSE-ADDRESS
|
||||||
* 0x8029: ICE-CONTROLLED <br/>
|
* 0x0003: CHANGE-REQUEST
|
||||||
* 0x802A: ICE-CONTROLLING <br/>
|
* 0x0004: SOURCE-ADDRESS
|
||||||
|
* 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,8 +43,8 @@ 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,
|
||||||
char offset,
|
int offset,
|
||||||
char length)
|
int length)
|
||||||
throws StunException
|
throws StunException
|
||||||
{
|
{
|
||||||
if (bytes == null || bytes.length < Attribute.HEADER_LENGTH)
|
if (bytes == null || bytes.length < Attribute.HEADER_LENGTH)
|
||||||
@ -54,10 +54,10 @@ public class AttributeDecoder
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Discover attribute type
|
//Discover attribute type
|
||||||
char attributeType = (char)((bytes[offset] << 8) | bytes[offset + 1]);
|
char attributeType = (char)
|
||||||
int len1 = bytes[offset + 2] & 0xff;
|
(((bytes[offset] & 0xFF) << 8) | (bytes[offset + 1] & 0xFF));
|
||||||
int len2 = bytes[offset + 3] & 0xff;
|
char attributeLength = (char)
|
||||||
char attributeLength = (char)((len1 << 8) | len2);
|
(((bytes[offset + 2] & 0xFF) << 8) | (bytes[offset + 3] & 0xFF));
|
||||||
|
|
||||||
if (attributeLength > bytes.length - offset )
|
if (attributeLength > bytes.length - offset )
|
||||||
throw new StunException( StunException.ILLEGAL_ARGUMENT,
|
throw new StunException( StunException.ILLEGAL_ARGUMENT,
|
||||||
|
|||||||
@ -544,7 +544,8 @@ 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 > (2^31 - 1)
|
* @throws IllegalArgumentException if priority < 0 or priority >
|
||||||
|
* (2^31 - 1)
|
||||||
*/
|
*/
|
||||||
public static PriorityAttribute createPriorityAttribute(long priority)
|
public static PriorityAttribute createPriorityAttribute(long priority)
|
||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
|
|||||||
@ -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 <br/>
|
* 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 <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/>
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
* |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/>
|
* |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/>
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
*
|
* </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,8 +100,7 @@ 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,8 +60,7 @@ 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)
|
||||||
@ -169,7 +168,7 @@ 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)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -52,7 +52,7 @@ public class DataAttribute
|
|||||||
private final boolean padding;
|
private final boolean padding;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Creates a new instance of this class with padding enabled.
|
||||||
*/
|
*/
|
||||||
protected DataAttribute()
|
protected DataAttribute()
|
||||||
{
|
{
|
||||||
@ -60,7 +60,9 @@ public class DataAttribute
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Creates a new instance of this class.
|
||||||
|
* @param padding true to pad the data if the length is not on a word
|
||||||
|
* boundary.
|
||||||
*/
|
*/
|
||||||
protected DataAttribute(boolean padding)
|
protected DataAttribute(boolean padding)
|
||||||
{
|
{
|
||||||
@ -170,8 +172,7 @@ 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,11 +54,8 @@ 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;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -488,8 +488,7 @@ 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 are one flag supported : <br/>
|
* There is one flag supported: <br>
|
||||||
* R : ask to reserve a second port.<br/>
|
* R : ask to reserve a second port.
|
||||||
*
|
*
|
||||||
* @author Sebastien Vincent
|
* @author Sebastien Vincent
|
||||||
*/
|
*/
|
||||||
@ -62,8 +62,7 @@ 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)
|
||||||
|
|||||||
@ -122,7 +122,7 @@ public class FingerprintAttribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof FingerprintAttribute) || obj == null)
|
if (! (obj instanceof FingerprintAttribute))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
|
|||||||
@ -125,8 +125,7 @@ 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)
|
||||||
|
|||||||
@ -61,8 +61,7 @@ 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)
|
||||||
|
|||||||
@ -83,8 +83,7 @@ public class MagicCookieAttribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof LifetimeAttribute)
|
if (! (obj instanceof MagicCookieAttribute))
|
||||||
|| obj == null)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
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.*;
|
||||||
@ -37,7 +38,6 @@ 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,7 +54,6 @@ 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>
|
||||||
@ -88,6 +87,13 @@ 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.
|
||||||
*/
|
*/
|
||||||
@ -282,26 +288,32 @@ public class MessageIntegrityAttribute
|
|||||||
binValue[3] = (byte)(getDataLength() & 0x00FF);
|
binValue[3] = (byte)(getDataLength() & 0x00FF);
|
||||||
|
|
||||||
byte[] key = null;
|
byte[] key = null;
|
||||||
char msgType = (char)((content[0] << 8) + content[1]);
|
char msgType =
|
||||||
|
(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 = stunStack.getCredentialsManager().getRemoteKey(username,
|
key
|
||||||
media);
|
= stunStack.getCredentialsManager()
|
||||||
|
.getRemoteKey(username, media);
|
||||||
}
|
}
|
||||||
else if(Message.isSuccessResponseType(msgType) ||
|
else if (Message.isResponseType(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, 4, getDataLength());
|
System.arraycopy(hmacSha1Content, 0, binValue, HEADER_LENGTH, getDataLength());
|
||||||
|
|
||||||
return binValue;
|
return binValue;
|
||||||
}
|
}
|
||||||
@ -335,7 +347,7 @@ public class MessageIntegrityAttribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof MessageIntegrityAttribute) || obj == null)
|
if (! (obj instanceof MessageIntegrityAttribute))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
|
|||||||
@ -134,8 +134,7 @@ public class OptionalAttribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if(obj == null
|
if (! (obj instanceof OptionalAttribute) )
|
||||||
|| !(obj instanceof OptionalAttribute) )
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|||||||
@ -118,8 +118,7 @@ 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)
|
||||||
|
|||||||
@ -141,7 +141,7 @@ public class RealmAttribute extends Attribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof RealmAttribute) || obj == null)
|
if (! (obj instanceof RealmAttribute))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
|
|||||||
@ -70,8 +70,7 @@ 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)
|
||||||
|
|||||||
@ -216,8 +216,7 @@ 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,8 +151,7 @@ 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)
|
||||||
|
|||||||
@ -191,8 +191,7 @@ 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)
|
||||||
@ -229,8 +228,8 @@ public class UnknownAttributesAttribute extends Attribute
|
|||||||
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++] << 8) |
|
char attributeID = (char) (((attributeValue[offset++] & 0xFF) << 8)
|
||||||
(attributeValue[offset++]) );
|
| (attributeValue[offset++] & 0xFF));
|
||||||
addAttributeID(attributeID);
|
addAttributeID(attributeID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -89,8 +89,7 @@ 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)
|
||||||
|
|||||||
@ -56,6 +56,7 @@ 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];
|
||||||
@ -147,7 +148,7 @@ public class UsernameAttribute extends Attribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof UsernameAttribute) || obj == null)
|
if (! (obj instanceof UsernameAttribute))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
|
|||||||
@ -111,8 +111,7 @@ 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
@ -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 {@link CandidatePairState#
|
* check over this pair in case it is in the
|
||||||
* IN_PROGRESS} state.
|
* {@link CandidatePairState#IN_PROGRESS} state.
|
||||||
*/
|
*/
|
||||||
private TransactionID connCheckTranID = null;
|
private TransactionID connCheckTranID = null;
|
||||||
|
|
||||||
@ -296,7 +296,7 @@ public class CandidatePair
|
|||||||
{
|
{
|
||||||
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"
|
||||||
+ " accomapnied with the TransactionID of the"
|
+ " accompanied 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 == null) || !(obj instanceof CandidatePair))
|
if (! (obj instanceof CandidatePair))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
CandidatePair candidatePair = (CandidatePair) obj;
|
CandidatePair candidatePair = (CandidatePair) obj;
|
||||||
@ -723,6 +723,7 @@ 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();
|
||||||
@ -733,18 +734,28 @@ 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()
|
||||||
{
|
{
|
||||||
IceSocketWrapper wrapper = getIceSocketWrapper();
|
return null;
|
||||||
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)
|
||||||
{
|
{
|
||||||
@ -753,7 +764,9 @@ 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)
|
||||||
@ -761,9 +774,11 @@ 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.getIceSocketWrapper();
|
return localCandidate.getCandidateIceSocketWrapper();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,11 +79,12 @@ 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,6 +74,8 @@ 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.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -17,9 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
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
|
||||||
@ -34,17 +35,23 @@ import java.util.logging.*;
|
|||||||
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.
|
||||||
*/
|
*/
|
||||||
@ -78,16 +85,9 @@ public class CheckList
|
|||||||
= new LinkedList<>();
|
= new LinkedList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the {@link PropertyChangeEvent} that we use to deliver
|
* The {@link Logger} used by {@link CheckList} instances.
|
||||||
* changes on the state of this check list.
|
|
||||||
*/
|
*/
|
||||||
public static final String PROPERTY_CHECK_LIST_STATE = "CheckListState";
|
private Logger logger;
|
||||||
|
|
||||||
/**
|
|
||||||
* 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,6 +98,7 @@ public class CheckList
|
|||||||
protected CheckList(IceMediaStream parentStream)
|
protected CheckList(IceMediaStream parentStream)
|
||||||
{
|
{
|
||||||
this.parentStream = parentStream;
|
this.parentStream = parentStream;
|
||||||
|
logger = parentStream.getLogger().createChildLogger(this.getClass().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -208,6 +209,25 @@ 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
|
||||||
|
|||||||
@ -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:
|
||||||
* <p/>
|
* <br>
|
||||||
* 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.
|
||||||
* <p/>
|
* <br>
|
||||||
* 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.
|
||||||
* <p/>
|
* <br>
|
||||||
* 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.
|
||||||
* <p/>
|
* <br>
|
||||||
* 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,10 +17,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.ice4j.ice;
|
package org.ice4j.ice;
|
||||||
|
|
||||||
|
import java.beans.*;
|
||||||
|
import java.net.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.*;
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
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
|
||||||
@ -35,13 +39,8 @@ import org.ice4j.*;
|
|||||||
* @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.
|
||||||
*/
|
*/
|
||||||
@ -112,6 +111,48 @@ 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>.
|
||||||
@ -119,13 +160,62 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -345,7 +435,6 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -371,8 +460,28 @@ public class Component
|
|||||||
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()
|
||||||
|
+ ".");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -594,11 +703,7 @@ public class Component
|
|||||||
&& (cand.getPriority() >= cand2.getPriority()))
|
&& (cand.getPriority() >= cand2.getPriority()))
|
||||||
{
|
{
|
||||||
localCandidates.remove(j);
|
localCandidates.remove(j);
|
||||||
if(logger.isLoggable(Level.FINEST))
|
logger.trace(() -> "eliminating redundant cand: "+ cand2);
|
||||||
{
|
|
||||||
logger.finest(
|
|
||||||
"eliminating redundant cand: "+ cand2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
j++;
|
j++;
|
||||||
@ -765,6 +870,17 @@ public class Component
|
|||||||
localCandidateIter.remove();
|
localCandidateIter.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getParentStream().removePairStateChangeListener(this);
|
||||||
|
keepAlivePairs.clear();
|
||||||
|
if (componentSocket != null)
|
||||||
|
{
|
||||||
|
componentSocket.close();
|
||||||
|
}
|
||||||
|
if (socket != null)
|
||||||
|
{
|
||||||
|
socket.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -788,12 +904,7 @@ public class Component
|
|||||||
*/
|
*/
|
||||||
if (t instanceof ThreadDeath)
|
if (t instanceof ThreadDeath)
|
||||||
throw (ThreadDeath) t;
|
throw (ThreadDeath) t;
|
||||||
if (logger.isLoggable(Level.INFO))
|
logger.info(() -> "Failed to free LocalCandidate: " + localCandidate);
|
||||||
{
|
|
||||||
logger.log(
|
|
||||||
Level.INFO,
|
|
||||||
"Failed to free LocalCandidate: " + localCandidate);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -810,10 +921,47 @@ public class Component
|
|||||||
*/
|
*/
|
||||||
public LocalCandidate findLocalCandidate(TransportAddress localAddress)
|
public LocalCandidate findLocalCandidate(TransportAddress localAddress)
|
||||||
{
|
{
|
||||||
for (LocalCandidate localCnd : localCandidates)
|
return findLocalCandidate(localAddress, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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)
|
||||||
{
|
{
|
||||||
if (localCnd.getTransportAddress().equals(localAddress))
|
for (LocalCandidate localCandidate : localCandidates)
|
||||||
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;
|
||||||
@ -835,8 +983,10 @@ public class Component
|
|||||||
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;
|
||||||
}
|
}
|
||||||
@ -849,6 +999,12 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -876,12 +1032,18 @@ 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,
|
||||||
@ -892,9 +1054,129 @@ public class Component
|
|||||||
* parent of this component.
|
* parent of this component.
|
||||||
* @return Component
|
* @return Component
|
||||||
*/
|
*/
|
||||||
public static Component build(int componentID, IceMediaStream mediaStream)
|
public static Component build(int componentID, IceMediaStream mediaStream, Logger parentLogger)
|
||||||
{
|
{
|
||||||
return new Component(componentID, mediaStream);
|
return
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
202
src/main/java/org/ice4j/ice/ComponentSocket.java
Normal file
202
src/main/java/org/ice4j/ice/ComponentSocket.java
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
/*
|
||||||
|
* 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,14 +18,17 @@
|
|||||||
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.logging.*;
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
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
|
||||||
@ -37,18 +40,21 @@ import org.ice4j.stack.*;
|
|||||||
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.
|
||||||
*/
|
*/
|
||||||
@ -57,29 +63,52 @@ 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 List<PaceMaker> paceMakers = new LinkedList<>();
|
private final Queue<PaceMaker> paceMakers
|
||||||
|
= 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 Map<String, Timer> timers = new HashMap<>();
|
private ConcurrentMap<String, ScheduledFuture<?>>
|
||||||
|
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(Agent parentAgent)
|
public ConnectivityCheckClient(
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
@ -115,7 +144,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());
|
||||||
@ -136,13 +165,16 @@ class ConnectivityCheckClient
|
|||||||
*/
|
*/
|
||||||
public void startChecks(CheckList checkList)
|
public void startChecks(CheckList checkList)
|
||||||
{
|
{
|
||||||
PaceMaker paceMaker = new PaceMaker(checkList);
|
|
||||||
|
|
||||||
synchronized (paceMakers)
|
synchronized (paceMakers)
|
||||||
{
|
{
|
||||||
paceMakers.add(paceMaker);
|
if (stopped)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PaceMaker paceMaker = new PaceMaker(checkList);
|
||||||
|
paceMakers.add(paceMaker);
|
||||||
|
paceMaker.schedule();
|
||||||
}
|
}
|
||||||
paceMaker.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -163,23 +195,18 @@ class ConnectivityCheckClient
|
|||||||
indication,
|
indication,
|
||||||
candidatePair.getRemoteCandidate().getTransportAddress(),
|
candidatePair.getRemoteCandidate().getTransportAddress(),
|
||||||
localCandidate.getBase().getTransportAddress());
|
localCandidate.getBase().getTransportAddress());
|
||||||
if(logger.isLoggable(Level.FINEST))
|
logger.trace(() ->
|
||||||
{
|
|
||||||
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.log(
|
logger.info("Failed to send " + indication + " through "
|
||||||
Level.INFO,
|
+ stunSocket.getLocalSocketAddress() + "\n" +
|
||||||
"Failed to send " + indication + " through "
|
ex.toString());
|
||||||
+ stunSocket.getLocalSocketAddress(),
|
|
||||||
ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -250,7 +277,7 @@ class ConnectivityCheckClient
|
|||||||
//nominated pairs.
|
//nominated pairs.
|
||||||
if (candidatePair.isNominated())
|
if (candidatePair.isNominated())
|
||||||
{
|
{
|
||||||
logger.fine(
|
logger.debug(() ->
|
||||||
"Add USE-CANDIDATE in check for: "
|
"Add USE-CANDIDATE in check for: "
|
||||||
+ candidatePair.toShortString());
|
+ candidatePair.toShortString());
|
||||||
request.putAttribute(
|
request.putAttribute(
|
||||||
@ -294,9 +321,12 @@ class ConnectivityCheckClient
|
|||||||
|
|
||||||
tran.setApplicationData(candidatePair);
|
tran.setApplicationData(candidatePair);
|
||||||
|
|
||||||
logger.fine(
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug(
|
||||||
"start check for " + candidatePair.toShortString() + " tid "
|
"start check for " + candidatePair.toShortString() + " tid "
|
||||||
+ tran);
|
+ tran);
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
tran
|
tran
|
||||||
@ -310,12 +340,15 @@ class ConnectivityCheckClient
|
|||||||
originalWaitInterval,
|
originalWaitInterval,
|
||||||
maxWaitInterval,
|
maxWaitInterval,
|
||||||
maxRetransmissions);
|
maxRetransmissions);
|
||||||
if(logger.isLoggable(Level.FINEST))
|
if (logger.isTraceEnabled())
|
||||||
{
|
{
|
||||||
logger.finest(
|
logger.trace("checking pair " + candidatePair + " tid " + tran);
|
||||||
"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;
|
||||||
@ -335,7 +368,11 @@ class ConnectivityCheckClient
|
|||||||
msg += " No route to host.";
|
msg += " No route to host.";
|
||||||
ex = null;
|
ex = null;
|
||||||
}
|
}
|
||||||
logger.log(Level.INFO, msg, ex);
|
logger.info(msg + (ex == null ? "" : "\n" + ex.toString()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.warn("Failed to send " + request, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,7 +412,7 @@ class ConnectivityCheckClient
|
|||||||
{
|
{
|
||||||
if (!response.containsAttribute(Attribute.ERROR_CODE))
|
if (!response.containsAttribute(Attribute.ERROR_CODE))
|
||||||
{
|
{
|
||||||
logger.fine("Received a malformed error response.");
|
logger.debug(() -> "Received a malformed error response.");
|
||||||
return; //malformed error response
|
return; //malformed error response
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,14 +456,12 @@ class ConnectivityCheckClient
|
|||||||
if ( !stream.validListContainsAllComponents())
|
if ( !stream.validListContainsAllComponents())
|
||||||
{
|
{
|
||||||
final String streamName = stream.getName();
|
final String streamName = stream.getName();
|
||||||
Timer timer = timers.get(streamName);
|
if (!checkListCompletionCheckers.containsKey(streamName))
|
||||||
|
|
||||||
if(timer == null)
|
|
||||||
{
|
{
|
||||||
logger.info("CheckList will failed in a few seconds if no" +
|
logger.info("CheckList will failed in a few seconds" +
|
||||||
"succeeded checks come");
|
" if no succeeded checks come");
|
||||||
|
|
||||||
TimerTask task = new TimerTask()
|
Runnable checkLickCompletedChecker = new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
@ -441,9 +476,20 @@ class ConnectivityCheckClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
timer = new Timer();
|
|
||||||
timers.put(streamName, timer);
|
final ScheduledFuture<?> scheduledCheckerFuture
|
||||||
timer.schedule(task, 5000);
|
= scheduledExecutorService.schedule(
|
||||||
|
checkLickCompletedChecker,
|
||||||
|
5000,
|
||||||
|
TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
|
final ScheduledFuture<?> existingCheckerFuture
|
||||||
|
= checkListCompletionCheckers
|
||||||
|
.putIfAbsent(streamName, scheduledCheckerFuture);
|
||||||
|
if (existingCheckerFuture != null)
|
||||||
|
{
|
||||||
|
scheduledCheckerFuture.cancel(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,10 +533,10 @@ class ConnectivityCheckClient
|
|||||||
|
|
||||||
if (!response.containsAttribute(Attribute.XOR_MAPPED_ADDRESS))
|
if (!response.containsAttribute(Attribute.XOR_MAPPED_ADDRESS))
|
||||||
{
|
{
|
||||||
logger.fine("Received a success response with no "
|
logger.debug(() -> "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
|
||||||
}
|
}
|
||||||
@ -512,9 +558,12 @@ class ConnectivityCheckClient
|
|||||||
Transport.TCP);
|
Transport.TCP);
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalCandidate validLocalCandidate = null;
|
// In some situations we may have more than one local candidate matching
|
||||||
|
// the mapped address. In this case we want to find the that matches
|
||||||
validLocalCandidate = parentAgent.findLocalCandidate(mappedAddress);
|
// the socket we received the response on.
|
||||||
|
LocalCandidate base = checkedPair.getLocalCandidate().getBase();
|
||||||
|
LocalCandidate validLocalCandidate
|
||||||
|
= parentAgent.findLocalCandidate(mappedAddress, base);
|
||||||
|
|
||||||
RemoteCandidate validRemoteCandidate = checkedPair.getRemoteCandidate();
|
RemoteCandidate validRemoteCandidate = checkedPair.getRemoteCandidate();
|
||||||
|
|
||||||
@ -558,9 +607,9 @@ class ConnectivityCheckClient
|
|||||||
|
|
||||||
if (checkedPair.getParentComponent().getSelectedPair() == null)
|
if (checkedPair.getParentComponent().getSelectedPair() == null)
|
||||||
{
|
{
|
||||||
logger.info(
|
logger.info("Receive a peer-reflexive candidate: "
|
||||||
"Receive a peer-reflexive candidate: "
|
+ peerReflexiveCandidate.getTransportAddress()
|
||||||
+ peerReflexiveCandidate.getTransportAddress());
|
+ ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,14 +645,18 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -674,7 +727,8 @@ 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-
|
||||||
@ -685,14 +739,14 @@ class ConnectivityCheckClient
|
|||||||
{
|
{
|
||||||
if (validPair.getParentComponent().getSelectedPair() == null)
|
if (validPair.getParentComponent().getSelectedPair() == null)
|
||||||
{
|
{
|
||||||
logger.info(
|
logger.info("Nomination confirmed for pair: "
|
||||||
"Nomination confirmed for pair: "
|
+ validPair.toShortString()
|
||||||
+ validPair.toShortString());
|
+ ".");
|
||||||
parentAgent.nominationConfirmed( validPair );
|
parentAgent.nominationConfirmed( validPair );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger.fine(
|
logger.debug(() ->
|
||||||
"Keep alive for pair: " + validPair.toShortString());
|
"Keep alive for pair: " + validPair.toShortString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -714,15 +768,18 @@ class ConnectivityCheckClient
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger.fine(
|
logger.debug(() ->
|
||||||
"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.
|
||||||
if (checkedPair == checkedPair.getParentComponent().getSelectedPair())
|
// XXX Should we also confirm consent freshness for non-selected pairs?
|
||||||
|
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
|
||||||
@ -781,7 +838,7 @@ class ConnectivityCheckClient
|
|||||||
CandidatePair pair
|
CandidatePair pair
|
||||||
= (CandidatePair) ev.getTransactionID().getApplicationData();
|
= (CandidatePair) ev.getTransactionID().getApplicationData();
|
||||||
|
|
||||||
logger.finer("Received error code " + ((int) errorCode));
|
logger.trace(() -> "Received error code " + ((int) errorCode));
|
||||||
|
|
||||||
//RESOLVE ROLE_CONFLICTS
|
//RESOLVE ROLE_CONFLICTS
|
||||||
if (errorCode == ErrorCodeAttribute.ROLE_CONFLICT)
|
if (errorCode == ErrorCodeAttribute.ROLE_CONFLICT)
|
||||||
@ -789,7 +846,7 @@ class ConnectivityCheckClient
|
|||||||
boolean wasControlling
|
boolean wasControlling
|
||||||
= originalRequest.containsAttribute(Attribute.ICE_CONTROLLING);
|
= originalRequest.containsAttribute(Attribute.ICE_CONTROLLING);
|
||||||
|
|
||||||
logger.finer("Swithing to isControlling=" + !wasControlling);
|
logger.trace(() -> "Switching to isControlling=" + !wasControlling);
|
||||||
parentAgent.setControlling(!wasControlling);
|
parentAgent.setControlling(!wasControlling);
|
||||||
|
|
||||||
pair.getParentComponent().getParentStream().getCheckList()
|
pair.getParentComponent().getParentStream().getCheckList()
|
||||||
@ -798,10 +855,12 @@ 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 + ")");
|
"(class=" + cl + "; number=" + co + "): " + trimmedReason);
|
||||||
pair.setStateFailed();
|
pair.setStateFailed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -825,17 +884,11 @@ class ConnectivityCheckClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The thread that actually sends the checks for a particular check list
|
* A class to control periodically scheduled runnable that actually sends
|
||||||
* in the pace defined in RFC 5245.
|
* the checks for a particular check list in the pace defined in RFC 5245.
|
||||||
*/
|
*/
|
||||||
private class PaceMaker
|
private final class PaceMaker extends PeriodicRunnable
|
||||||
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.
|
||||||
@ -851,39 +904,8 @@ class ConnectivityCheckClient
|
|||||||
*/
|
*/
|
||||||
public PaceMaker(CheckList checkList)
|
public PaceMaker(CheckList checkList)
|
||||||
{
|
{
|
||||||
super("ICE PaceMaker: " + parentAgent.getLocalUfrag());
|
super(scheduledExecutorService, executorService);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -892,39 +914,15 @@ class ConnectivityCheckClient
|
|||||||
* or the regular check lists.
|
* or the regular check lists.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized void run()
|
protected 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)
|
||||||
{
|
{
|
||||||
@ -948,9 +946,11 @@ class ConnectivityCheckClient
|
|||||||
pairToCheck.setStateFailed();
|
pairToCheck.setStateFailed();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
pairToCheck.setStateInProgress(transactionID);
|
pairToCheck.setStateInProgress(transactionID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -958,21 +958,30 @@ 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.finest("will skip a check beat.");
|
logger.trace(() -> "will skip a check beat.");
|
||||||
checkList.fireEndOfOrdinaryChecks();
|
checkList.fireEndOfOrdinaryChecks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
finally
|
/**
|
||||||
|
* 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()
|
||||||
{
|
{
|
||||||
synchronized (paceMakers)
|
int activeCheckLists = parentAgent.getActiveCheckListCount();
|
||||||
|
|
||||||
|
if (activeCheckLists < 1)
|
||||||
{
|
{
|
||||||
synchronized(this)
|
//don't multiply by 0. even when we no longer have active check
|
||||||
{
|
//lists we may still have nomination checks to
|
||||||
paceMakers.remove(this);
|
activeCheckLists = 1;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Duration.ofMillis(parentAgent.calculateTa() * activeCheckLists);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -983,19 +992,15 @@ class ConnectivityCheckClient
|
|||||||
{
|
{
|
||||||
synchronized (paceMakers)
|
synchronized (paceMakers)
|
||||||
{
|
{
|
||||||
Iterator<PaceMaker> paceMakersIter = paceMakers.iterator();
|
stopped = true;
|
||||||
|
while (true)
|
||||||
while(paceMakersIter.hasNext())
|
|
||||||
{
|
{
|
||||||
PaceMaker paceMaker = paceMakersIter.next();
|
final PaceMaker paceMaker = paceMakers.poll();
|
||||||
|
if (paceMaker == null)
|
||||||
synchronized(paceMaker)
|
|
||||||
{
|
{
|
||||||
paceMaker.running = false;
|
break;
|
||||||
paceMaker.notify();
|
|
||||||
}
|
}
|
||||||
|
paceMaker.cancel();
|
||||||
paceMakersIter.remove();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,13 +17,12 @@
|
|||||||
*/
|
*/
|
||||||
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
|
||||||
@ -36,30 +35,6 @@ 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.
|
||||||
*/
|
*/
|
||||||
@ -81,6 +56,11 @@ 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
|
||||||
@ -91,6 +71,7 @@ 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);
|
||||||
@ -130,8 +111,7 @@ class ConnectivityCheckServer
|
|||||||
public void processRequest(StunMessageEvent evt)
|
public void processRequest(StunMessageEvent evt)
|
||||||
throws IllegalArgumentException
|
throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
if(logger.isLoggable(Level.FINER))
|
logger.trace(() -> "Received request " + evt);
|
||||||
logger.finer("Received request " + evt);
|
|
||||||
|
|
||||||
alive = true;
|
alive = true;
|
||||||
|
|
||||||
@ -201,11 +181,9 @@ class ConnectivityCheckServer
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
logger.log(
|
logger.info("Failed to send " + response
|
||||||
Level.INFO,
|
+ " through " + evt.getLocalAddress() + "\n" +
|
||||||
"Failed to send " + response
|
e.toString());
|
||||||
+ " 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);
|
||||||
@ -238,11 +216,8 @@ class ConnectivityCheckServer
|
|||||||
//extract priority
|
//extract priority
|
||||||
if (priorityAttr == null)
|
if (priorityAttr == null)
|
||||||
{
|
{
|
||||||
if(logger.isLoggable(Level.FINE))
|
logger.debug(() -> "Received a connectivity check with"
|
||||||
{
|
|
||||||
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!");
|
||||||
}
|
}
|
||||||
@ -267,89 +242,51 @@ class ConnectivityCheckServer
|
|||||||
*/
|
*/
|
||||||
private boolean repairRoleConflict(StunMessageEvent evt)
|
private boolean repairRoleConflict(StunMessageEvent evt)
|
||||||
{
|
{
|
||||||
Message req = evt.getMessage();
|
final Message req = evt.getMessage();
|
||||||
long ourTieBreaker = parentAgent.getTieBreaker();
|
final boolean selfIceControlling = parentAgent.isControlling();
|
||||||
|
|
||||||
|
|
||||||
// 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:
|
||||||
if(parentAgent.isControlling()
|
final boolean bothControllingConflict = selfIceControlling &&
|
||||||
&& req.containsAttribute(Attribute.ICE_CONTROLLING))
|
req.containsAttribute(Attribute.ICE_CONTROLLING);
|
||||||
{
|
|
||||||
IceControllingAttribute controlling = (IceControllingAttribute)
|
|
||||||
req.getAttribute(Attribute.ICE_CONTROLLING);
|
|
||||||
|
|
||||||
long theirTieBreaker = controlling.getTieBreaker();
|
|
||||||
|
|
||||||
// If the agent's tie-breaker is larger than or equal to the
|
|
||||||
// contents of the ICE-CONTROLLING 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.
|
|
||||||
if(compareUnsignedLong(ourTieBreaker, theirTieBreaker) >= 0)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//If the agent's tie-breaker is less than the contents of the
|
|
||||||
//ICE-CONTROLLING attribute, the agent switches to the controlled
|
|
||||||
//role.
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.finer(
|
|
||||||
"Switching to controlled because theirTieBreaker="
|
|
||||||
+ theirTieBreaker + " and ourTieBreaker="
|
|
||||||
+ ourTieBreaker);
|
|
||||||
parentAgent.setControlling(false);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If the agent is in the controlled role, and the ICE-CONTROLLED
|
// If the agent is in the controlled role, and the ICE-CONTROLLED
|
||||||
// attribute is present in the request:
|
// attribute is present in the request:
|
||||||
else if(!parentAgent.isControlling()
|
final boolean bothControlledConflict = !selfIceControlling &&
|
||||||
&& req.containsAttribute(Attribute.ICE_CONTROLLED))
|
req.containsAttribute(Attribute.ICE_CONTROLLED);
|
||||||
{
|
|
||||||
IceControlledAttribute controlled = (IceControlledAttribute)
|
|
||||||
req.getAttribute(Attribute.ICE_CONTROLLED);
|
|
||||||
|
|
||||||
long theirTieBreaker = controlled.getTieBreaker();
|
if (!(bothControllingConflict || bothControlledConflict))
|
||||||
|
|
||||||
//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(
|
// we don't have a role conflict
|
||||||
"Switching to controlling because theirTieBreaker="
|
|
||||||
+ theirTieBreaker + " and ourTieBreaker="
|
|
||||||
+ ourTieBreaker);
|
|
||||||
parentAgent.setControlling(true);
|
|
||||||
return 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
|
final long selfTieBreaker = parentAgent.getTieBreaker();
|
||||||
// response and includes an ERROR-CODE attribute with a value of
|
|
||||||
// 487 (Role Conflict) but retains its role.
|
final IceControlAttribute theirIceControl = bothControllingConflict
|
||||||
else
|
? (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
|
||||||
|
// contents of the ICE control 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.
|
||||||
|
if (Long.compareUnsigned(selfTieBreaker, theirTieBreaker) >= 0)
|
||||||
{
|
{
|
||||||
Response response = MessageFactory.createBindingErrorResponse(
|
final UsernameAttribute requestUserName = (UsernameAttribute)req
|
||||||
|
.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(
|
||||||
@ -357,7 +294,6 @@ class ConnectivityCheckServer
|
|||||||
response,
|
response,
|
||||||
evt.getLocalAddress(),
|
evt.getLocalAddress(),
|
||||||
evt.getRemoteAddress());
|
evt.getRemoteAddress());
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
catch(Exception exc)
|
catch(Exception exc)
|
||||||
@ -366,8 +302,19 @@ class ConnectivityCheckServer
|
|||||||
throw new RuntimeException("Failed to send a 487", exc);
|
throw new RuntimeException("Failed to send a 487", exc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//If the agent's tie-breaker is less than the contents of the
|
||||||
|
//ICE control attribute, the agent toggles its ICE control role.
|
||||||
|
else
|
||||||
|
{
|
||||||
|
final String selfNextControlState
|
||||||
|
= selfIceControlling ? "controlled" : "controlling";
|
||||||
|
logger.trace(() ->
|
||||||
|
"Switching to " + selfNextControlState + " because " +
|
||||||
|
" theirTieBreaker= " + theirTieBreaker + " and " +
|
||||||
|
"selfTieBreaker= " + selfTieBreaker);
|
||||||
|
parentAgent.setControlling(!selfIceControlling);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true; // we don't have a role conflict
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -17,9 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
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.
|
||||||
@ -29,12 +30,6 @@ import java.util.logging.*;
|
|||||||
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.
|
||||||
*/
|
*/
|
||||||
@ -48,10 +43,15 @@ 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 use with the NOMINATE_FIRST_HIGHEST_VALID strategy.
|
* and a timer. It is used 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,6 +62,7 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,17 +98,20 @@ public class DefaultNominator
|
|||||||
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(
|
if (IceMediaStream.PROPERTY_PAIR_CONSENT_FRESHNESS_CHANGED.equals(propertyName))
|
||||||
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 selected pair for
|
// do not nominate pair if there is currently a nominated pair for
|
||||||
// the component
|
// the component
|
||||||
if(validPair.getParentComponent().getSelectedPair() != null)
|
if (parentStream.validListContainsNomineeForComponent(parentComponent))
|
||||||
{
|
{
|
||||||
logger.fine(
|
logger.debug(() ->
|
||||||
"Keep-alive for pair: " + validPair.toShortString());
|
"Keep-alive for pair: " + validPair.toShortString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -131,11 +135,13 @@ public class DefaultNominator
|
|||||||
*/
|
*/
|
||||||
private void strategyNominateFirstValid(PropertyChangeEvent evt)
|
private void strategyNominateFirstValid(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();
|
||||||
|
|
||||||
logger.info("Nominate (first valid): " + validPair.toShortString());
|
logger.info("Nominate (first valid): " + validPair.toShortString()
|
||||||
|
+ ".");
|
||||||
parentAgent.nominate(validPair);
|
parentAgent.nominate(validPair);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,6 +185,18 @@ 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
|
||||||
@ -303,10 +321,16 @@ public class DefaultNominator
|
|||||||
*/
|
*/
|
||||||
public void propertyChange(PropertyChangeEvent evt)
|
public void propertyChange(PropertyChangeEvent evt)
|
||||||
{
|
{
|
||||||
/* check list has running out of ordinary checks, see if all other
|
// Make it clear that PROPERTY_CHECK_LIST_CHECKS is in use here.
|
||||||
* candidates are FAILED, in which case we nominate immediately
|
if (!CheckList.PROPERTY_CHECK_LIST_CHECKS.equals(
|
||||||
* the relayed candidate
|
evt.getPropertyName()))
|
||||||
*/
|
{
|
||||||
|
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;
|
||||||
|
|
||||||
|
|||||||
@ -191,9 +191,10 @@ 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#getIceSocketWrapper()
|
* @see LocalCandidate#getCandidateIceSocketWrapper()
|
||||||
*/
|
*/
|
||||||
public synchronized IceSocketWrapper getIceSocketWrapper()
|
@Override
|
||||||
|
public synchronized IceSocketWrapper getCandidateIceSocketWrapper()
|
||||||
{
|
{
|
||||||
if (socket == null)
|
if (socket == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -131,13 +131,12 @@ public class HostCandidate extends LocalCandidate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the <tt>DatagramSocket</tt> associated with this <tt>Candidate</tt>.
|
* {@inheritDoc}
|
||||||
*
|
* SHOULD NOT be used outside ice4j. Only exposed for use in the
|
||||||
* @return the <tt>DatagramSocket</tt> associated with this
|
* org.ice4j.socket package.
|
||||||
* <tt>Candidate</tt>
|
|
||||||
* @see LocalCandidate#getIceSocketWrapper()
|
|
||||||
*/
|
*/
|
||||||
public IceSocketWrapper getIceSocketWrapper()
|
@Override
|
||||||
|
public IceSocketWrapper getCandidateIceSocketWrapper()
|
||||||
{
|
{
|
||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,9 +19,12 @@ 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
|
||||||
@ -32,12 +35,6 @@ import org.ice4j.*;
|
|||||||
*/
|
*/
|
||||||
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.
|
||||||
@ -63,6 +60,19 @@ 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.
|
||||||
@ -119,7 +129,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 = Agent.DEFAULT_MAX_CHECK_LIST_SIZE;
|
private int maxCheckListSize = config.getMaxCheckListSize();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user fragment that we received from the remote party.
|
* The user fragment that we received from the remote party.
|
||||||
@ -131,6 +141,11 @@ 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.
|
||||||
*
|
*
|
||||||
@ -140,6 +155,9 @@ 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);
|
||||||
@ -151,16 +169,29 @@ 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 = new Component(++lastComponentID, this);
|
component
|
||||||
|
= new Component(
|
||||||
|
++lastComponentID,
|
||||||
|
this,
|
||||||
|
keepAliveStrategy,
|
||||||
|
useComponentSocket,
|
||||||
|
logger);
|
||||||
components.put(component.getComponentID(), component);
|
components.put(component.getComponentID(), component);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,18 +292,6 @@ 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.
|
||||||
*
|
*
|
||||||
@ -345,7 +364,7 @@ public class IceMediaStream
|
|||||||
|
|
||||||
orderCheckList();
|
orderCheckList();
|
||||||
pruneCheckList(checkList);
|
pruneCheckList(checkList);
|
||||||
logger.finest("Checklist initialized.");
|
logger.trace(() -> "Checklist initialized.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,7 +441,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.
|
||||||
* <p/>
|
* <br>
|
||||||
* 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).
|
||||||
@ -492,23 +511,28 @@ public class IceMediaStream
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the local <tt>LocalCandidate</tt> with the specified
|
* Returns the local <tt>LocalCandidate</tt> with the specified
|
||||||
* <tt>localAddress</tt> if it belongs to any of this stream's components
|
* <tt>address</tt> if it belongs to any of this stream's components
|
||||||
* or <tt>null</tt> otherwise.
|
* or <tt>null</tt> otherwise. If {@code base} is also specified, tries to
|
||||||
|
* find a candidate whose base matches {@code base}.
|
||||||
*
|
*
|
||||||
* @param localAddress the {@link TransportAddress} we are looking for.
|
* @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
|
* @return the local <tt>LocalCandidate</tt> with the specified
|
||||||
* <tt>localAddress</tt> if it belongs to any of this stream's components
|
* <tt>address</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 localAddress)
|
public LocalCandidate findLocalCandidate(TransportAddress address, LocalCandidate base)
|
||||||
{
|
{
|
||||||
for( Component cmp : components.values())
|
for (Component component : components.values())
|
||||||
{
|
{
|
||||||
LocalCandidate cnd = cmp.findLocalCandidate(localAddress);
|
LocalCandidate localCandidate
|
||||||
|
= component.findLocalCandidate(address, base);
|
||||||
|
|
||||||
if(cnd != null)
|
if (localCandidate != null)
|
||||||
return cnd;
|
{
|
||||||
|
return localCandidate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -900,17 +924,8 @@ 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 new IceMediaStream(parentAgent, name);
|
return logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
71
src/main/java/org/ice4j/ice/KeepAliveStrategy.java
Normal file
71
src/main/java/org/ice4j/ice/KeepAliveStrategy.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* 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,6 +35,16 @@ import org.ice4j.stack.*;
|
|||||||
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
|
||||||
@ -53,11 +63,9 @@ public abstract class LocalCandidate
|
|||||||
private boolean isSSL = false;
|
private boolean isSSL = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <tt>Logger</tt> used by the <tt>LocalCandidate</tt> class and its
|
* The {@link Logger} used by {@link LocalCandidate} instances.
|
||||||
* instances for logging output.
|
|
||||||
*/
|
*/
|
||||||
private static final Logger logger
|
private 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
|
||||||
@ -82,8 +90,10 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,8 +105,7 @@ 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.CandidatePair#getDatagramSocket()}
|
* should use {@link org.ice4j.ice.Component#getSocket()} instead.
|
||||||
* on the appropriate <tt>CandidatePair</tt> instead.
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public DatagramSocket getDatagramSocket()
|
public DatagramSocket getDatagramSocket()
|
||||||
@ -113,37 +122,47 @@ 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.CandidatePair#getSocket()} on the
|
* should use {@link org.ice4j.ice.Component#getSocket()} instead.
|
||||||
* appropriate <tt>CandidatePair</tt> instead.
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Socket getSocket()
|
public Socket getSocket()
|
||||||
{
|
{
|
||||||
IceSocketWrapper wrapper = getIceSocketWrapper();
|
return null;
|
||||||
return wrapper == null ? null : wrapper.getTCPSocket();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the <tt>IceSocketWrapper</tt> associated with this
|
* @return the {@link IceSocketWrapper} instance of the {@link Component}
|
||||||
* <tt>Candidate</tt>.
|
* which owns this {@link LocalCandidate}. Note that this IS NOT an
|
||||||
*
|
* instance specific to this {@link LocalCandidate}. See
|
||||||
* @return the <tt>IceSocketWrapper</tt> associated with this
|
* {@link #getCandidateIceSocketWrapper()}.
|
||||||
* <tt>Candidate</tt>
|
|
||||||
*/
|
*/
|
||||||
protected abstract IceSocketWrapper getIceSocketWrapper();
|
protected IceSocketWrapper getIceSocketWrapper()
|
||||||
|
{
|
||||||
|
return getParentComponent().getSocketWrapper();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the <tt>IceSocketWrapper</tt> associated with this
|
* @return the {@link IceSocketWrapper} instance, if any, associated with
|
||||||
* <tt>Candidate</tt> which is to be used for a specific remote address.
|
* this candidate. Note that this IS NOT the instance which should be used
|
||||||
* This default implementation ignores the remote address.
|
* for reading and writing by the application, and SHOULD NOT be used from
|
||||||
*
|
* outside ice4j (even if a subclass exposes it as public). Also see
|
||||||
* @param remoteAddress the remote address for which to get a socket.
|
* {@link #getIceSocketWrapper()}.
|
||||||
* @return the <tt>IceSocketWrapper</tt> associated with this
|
|
||||||
* <tt>Candidate</tt> which is to be used for a specific remote address.
|
|
||||||
*/
|
*/
|
||||||
protected IceSocketWrapper getIceSocketWrapper(SocketAddress remoteAddress)
|
protected abstract IceSocketWrapper getCandidateIceSocketWrapper();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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)
|
||||||
{
|
{
|
||||||
return getIceSocketWrapper();
|
// The default implementation just refers to the method which doesn't
|
||||||
|
// involve a remove address. Extenders which support multiple instances
|
||||||
|
// mapped by remote address should override.
|
||||||
|
return getCandidateIceSocketWrapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -161,7 +180,7 @@ public abstract class LocalCandidate
|
|||||||
*/
|
*/
|
||||||
public IceSocketWrapper getStunSocket(TransportAddress serverAddress)
|
public IceSocketWrapper getStunSocket(TransportAddress serverAddress)
|
||||||
{
|
{
|
||||||
IceSocketWrapper hostSocket = getIceSocketWrapper();
|
IceSocketWrapper hostSocket = getCandidateIceSocketWrapper();
|
||||||
|
|
||||||
if (hostSocket != null
|
if (hostSocket != null
|
||||||
&& hostSocket.getTCPSocket() != null)
|
&& hostSocket.getTCPSocket() != null)
|
||||||
@ -183,8 +202,7 @@ 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.log(Level.SEVERE,
|
logger.error("Failed to acquire Socket"
|
||||||
"Failed to acquire Socket"
|
|
||||||
+ " specific to STUN communication.",
|
+ " specific to STUN communication.",
|
||||||
sex);
|
sex);
|
||||||
exception = sex;
|
exception = sex;
|
||||||
@ -240,8 +258,7 @@ 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.log(Level.SEVERE,
|
logger.error("Failed to acquire DatagramSocket"
|
||||||
"Failed to acquire DatagramSocket"
|
|
||||||
+ " specific to STUN communication.",
|
+ " specific to STUN communication.",
|
||||||
sex);
|
sex);
|
||||||
exception = sex;
|
exception = sex;
|
||||||
@ -310,7 +327,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 = getIceSocketWrapper();
|
IceSocketWrapper socket = getCandidateIceSocketWrapper();
|
||||||
|
|
||||||
if (socket != null)
|
if (socket != null)
|
||||||
{
|
{
|
||||||
@ -318,7 +335,7 @@ public abstract class LocalCandidate
|
|||||||
|
|
||||||
if ((base == null)
|
if ((base == null)
|
||||||
|| (base == this)
|
|| (base == this)
|
||||||
|| (base.getIceSocketWrapper() != socket))
|
|| (base.getCandidateIceSocketWrapper() != socket))
|
||||||
{
|
{
|
||||||
//remove our socket from the stack.
|
//remove our socket from the stack.
|
||||||
getStunStack().removeSocket(getTransportAddress());
|
getStunStack().removeSocket(getTransportAddress());
|
||||||
|
|||||||
@ -98,35 +98,6 @@ 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).
|
||||||
@ -138,44 +109,16 @@ public class NetworkUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a random local port number, greater than min and lower than max.
|
* Returns a random local port number in the interval [min, 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 located between greater than min and lower than max.
|
* @return a random int in the interval [min, max].
|
||||||
*/
|
*/
|
||||||
public static int getRandomPortNumber(int min, int max)
|
public static int getRandomPortNumber(int min, int max)
|
||||||
{
|
{
|
||||||
return portNumberGenerator.nextInt(max - min) + min;
|
return portNumberGenerator.nextInt(max - min + 1) + 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -399,6 +342,15 @@ 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] != ':')
|
||||||
@ -530,7 +482,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, IN6_ADDR_SIZE);
|
System.arraycopy(addr, 12, newAddr, 0, IN4_ADDR_SIZE);
|
||||||
return newAddr;
|
return newAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -683,11 +635,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>alse</tt> otherwise.
|
* <tt>false</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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -44,8 +44,11 @@ public enum NominationStrategy
|
|||||||
NOMINATE_FIRST_VALID("NominateFirstValid"),
|
NOMINATE_FIRST_VALID("NominateFirstValid"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The strategy consists in nominating the highest priority valid pair once
|
* The strategy consists in nominating the highest priority valid pair.
|
||||||
* all checks in a list have completed.
|
* Once a pair is validated, if no higher-priority pairs remain outstanding,
|
||||||
|
* 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"),
|
||||||
|
|
||||||
@ -90,4 +93,19 @@ 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,18 +61,15 @@ public class PeerReflexiveCandidate
|
|||||||
base);
|
base);
|
||||||
super.setBase(base);
|
super.setBase(base);
|
||||||
super.priority = priority;
|
super.priority = priority;
|
||||||
|
super.setTcpType(base.getTcpType());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the <tt>DatagramSocket</tt> associated with this
|
* {@inheritDoc}
|
||||||
* <tt>Candidate</tt>.
|
|
||||||
*
|
|
||||||
* @return the <tt>DatagramSocket</tt> associated with this
|
|
||||||
* <tt>Candidate</tt>
|
|
||||||
* @see LocalCandidate#getIceSocketWrapper()
|
|
||||||
*/
|
*/
|
||||||
public IceSocketWrapper getIceSocketWrapper()
|
@Override
|
||||||
|
public IceSocketWrapper getCandidateIceSocketWrapper()
|
||||||
{
|
{
|
||||||
return getBase().getIceSocketWrapper();
|
return getBase().getCandidateIceSocketWrapper();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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>
|
||||||
*/
|
*/
|
||||||
public synchronized RelayedCandidateDatagramSocket
|
private 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()
|
|
||||||
*/
|
*/
|
||||||
public synchronized IceSocketWrapper getIceSocketWrapper()
|
@Override
|
||||||
|
public synchronized IceSocketWrapper getCandidateIceSocketWrapper()
|
||||||
{
|
{
|
||||||
if (socket == null)
|
if (socket == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -104,16 +104,12 @@ public class ServerReflexiveCandidate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the <tt>DatagramSocket</tt> associated with this <tt>Candidate</tt>.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* @return the <tt>DatagramSocket</tt> associated with this
|
|
||||||
* <tt>Candidate</tt>
|
|
||||||
* @see LocalCandidate#getIceSocketWrapper()
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public IceSocketWrapper getIceSocketWrapper()
|
public IceSocketWrapper getCandidateIceSocketWrapper()
|
||||||
{
|
{
|
||||||
return getBase().getIceSocketWrapper();
|
return getBase().getCandidateIceSocketWrapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -54,6 +54,23 @@ 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);
|
||||||
@ -83,16 +100,4 @@ 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,7 +79,7 @@ public class UPNPCandidate
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
IceSocketWrapper socket = getIceSocketWrapper();
|
IceSocketWrapper socket = getCandidateIceSocketWrapper();
|
||||||
if (socket != null)
|
if (socket != null)
|
||||||
{
|
{
|
||||||
socket.close();
|
socket.close();
|
||||||
@ -89,13 +89,19 @@ public class UPNPCandidate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the <tt>DatagramSocket</tt> associated with this <tt>Candidate</tt>.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* @return the <tt>DatagramSocket</tt> associated with this
|
|
||||||
* <tt>Candidate</tt>
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public IceSocketWrapper getIceSocketWrapper()
|
public IceSocketWrapper getCandidateIceSocketWrapper()
|
||||||
|
{
|
||||||
|
return getBase().getCandidateIceSocketWrapper();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected IceSocketWrapper getIceSocketWrapper()
|
||||||
{
|
{
|
||||||
return getBase().getIceSocketWrapper();
|
return getBase().getIceSocketWrapper();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
1024
src/main/java/org/ice4j/ice/harvest/AbstractTcpListener.java
Normal file
1024
src/main/java/org/ice4j/ice/harvest/AbstractTcpListener.java
Normal file
File diff suppressed because it is too large
Load Diff
703
src/main/java/org/ice4j/ice/harvest/AbstractUdpListener.java
Normal file
703
src/main/java/org/ice4j/ice/harvest/AbstractUdpListener.java
Normal file
@ -0,0 +1,703 @@
|
|||||||
|
/*
|
||||||
|
* 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(null, null);
|
super("aws");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -130,6 +130,7 @@ 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())
|
||||||
@ -144,6 +145,7 @@ 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,14 +28,10 @@ import org.ice4j.ice.*;
|
|||||||
*
|
*
|
||||||
* @author Emil Ivov
|
* @author Emil Ivov
|
||||||
* @author Lyubomir Marinov
|
* @author Lyubomir Marinov
|
||||||
|
* @author Boris Grozev
|
||||||
*/
|
*/
|
||||||
public abstract class CandidateHarvester
|
public interface 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
|
||||||
@ -52,7 +48,7 @@ public abstract class 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.
|
||||||
*/
|
*/
|
||||||
public abstract Collection<LocalCandidate> harvest(Component component);
|
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
|
||||||
@ -61,10 +57,7 @@ public abstract class CandidateHarvester
|
|||||||
* @return The {@link HarvestStatistics} describing this harvester's
|
* @return The {@link HarvestStatistics} describing this harvester's
|
||||||
* harvests.
|
* harvests.
|
||||||
*/
|
*/
|
||||||
public HarvestStatistics getHarvestStatistics()
|
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
|
||||||
@ -77,8 +70,5 @@ public abstract class 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.
|
||||||
*/
|
*/
|
||||||
public boolean isHostHarvester()
|
boolean isHostHarvester();
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,7 @@ 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.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -197,7 +198,17 @@ public class CandidateHarvesterSet
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
future.get();
|
future.get(HarvestConfig.config.timeout().toMillis(), TimeUnit.MILLISECONDS);
|
||||||
|
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)
|
||||||
|
|||||||
@ -143,7 +143,7 @@ class CandidateHarvesterSetElement
|
|||||||
*/
|
*/
|
||||||
public void setEnabled(boolean enabled)
|
public void setEnabled(boolean enabled)
|
||||||
{
|
{
|
||||||
logger.info((enabled ? "Enabling: " : "Disabling: ") + harvester);
|
logger.fine((enabled ? "Enabling: " : "Disabling: ") + harvester);
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -133,6 +133,18 @@ 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,43 +29,109 @@ 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.
|
* Data for the SSL message sent by the server ('server-hello').
|
||||||
*/
|
*/
|
||||||
static final byte SSL_SERVER_HANDSHAKE[] =
|
static final byte SSL_SERVER_HANDSHAKE[] =
|
||||||
{
|
{
|
||||||
0x16, 0x03, 0x01, 0x00, 0x4a, 0x02, 0x00, 0x00,
|
// Content type: Handshake
|
||||||
0x46, 0x03, 0x01, 0x42, (byte)0x85, 0x45, (byte)0xa7, 0x27,
|
0x16,
|
||||||
(byte)0xa9, 0x5d, (byte)0xa0, (byte)0xb3, (byte)0xc5, (byte)0xe7, 0x53,
|
|
||||||
(byte)0xda,
|
// Version: TLS 1.0
|
||||||
0x48, 0x2b, 0x3f, (byte)0xc6, 0x5a, (byte)0xca, (byte)0x89, (byte)0xc1,
|
0x03, 0x01,
|
||||||
0x58, 0x52, (byte)0xa1, 0x78, 0x3c, 0x5b, 0x17, 0x46,
|
|
||||||
0x00, (byte)0x85, 0x3f, 0x20, 0x0e, (byte)0xd3, 0x06, 0x72,
|
// Length: 74
|
||||||
0x5b, 0x5b, 0x1b, 0x5f, 0x15, (byte)0xac, 0x13, (byte)0xf9,
|
0x00, 0x4a,
|
||||||
(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, 0x00, 0x04, 0x00
|
0x41, 0x6c, 0x34, 0x5c,
|
||||||
|
|
||||||
|
// Selected Cipher suite
|
||||||
|
0x00, 0x04, // TLS_RSA_WITH_RC4_128_MD5
|
||||||
|
|
||||||
|
// Compression method: null
|
||||||
|
0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data for the SSL message sent by the client.
|
* Data for the SSL message sent by the client (client-hello).
|
||||||
*/
|
*/
|
||||||
public static final byte SSL_CLIENT_HANDSHAKE[] =
|
public static final byte SSL_CLIENT_HANDSHAKE[] =
|
||||||
{
|
{
|
||||||
(byte)0x80, 0x46, 0x01, 0x03, 0x01, 0x00, 0x2d, 0x00,
|
// Version: SSL 2.0 (0x0002) and length: 70
|
||||||
0x00, 0x00, 0x10, 0x01, 0x00, (byte)0x80, 0x03, 0x00,
|
(byte)0x80, 0x46,
|
||||||
(byte)0x80, 0x07, 0x00, (byte)0xc0, 0x06, 0x00, 0x40, 0x02,
|
|
||||||
0x00, (byte)0x80, 0x04, 0x00, (byte)0x80, 0x00, 0x00, 0x04,
|
// Handshake message type: Client Hello
|
||||||
0x00, (byte)0xfe, (byte)0xff, 0x00, 0x00, 0x0a, 0x00, (byte)0xfe,
|
0x01,
|
||||||
(byte)0xfe, 0x00, 0x00, 0x09, 0x00, 0x00, 0x64, 0x00,
|
|
||||||
0x00, 0x62, 0x00, 0x00, 0x03, 0x00, 0x00, 0x06,
|
// Version TLS 1.0
|
||||||
0x1f, 0x17, 0x0c, (byte)0xa6, 0x2f, 0x00, 0x78, (byte)0xfc,
|
0x03, 0x01,
|
||||||
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
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,7 +187,7 @@ public class GoogleTurnSSLCandidateHarvester
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the host candidate.
|
* Returns the host candidate.
|
||||||
* For UDP it simply returns the candidate passed as paramter
|
* For UDP it simply returns the candidate passed as parameter
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@ -146,11 +212,11 @@ public class GoogleTurnSSLCandidateHarvester
|
|||||||
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(
|
new IceTcpSocketWrapper(multiplexing),
|
||||||
new MultiplexingSocket(sock)),
|
|
||||||
parentComponent,
|
parentComponent,
|
||||||
Transport.TCP);
|
Transport.TCP);
|
||||||
parentComponent
|
parentComponent
|
||||||
@ -158,6 +224,12 @@ 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)
|
||||||
@ -187,12 +259,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 explicitely need <tt>InputStream</tt> and
|
* certificate). We explicitly 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>OuputStream</tt> of the socket
|
* @param outputStream <tt>OutputStream</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
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -26,6 +26,8 @@ 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
|
||||||
@ -129,18 +131,17 @@ public class HostCandidateHarvester
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the list of explicitly allowed addresses.
|
* Gets the list of addresses which have been explicitly allowed via
|
||||||
|
* 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 List<InetAddress> getAllowedAddresses()
|
public static synchronized List<InetAddress> getAllowedAddresses()
|
||||||
{
|
|
||||||
synchronized (HostCandidateHarvester.class)
|
|
||||||
{
|
{
|
||||||
if (!addressFiltersInitialized)
|
if (!addressFiltersInitialized)
|
||||||
{
|
{
|
||||||
initializeAddressFilters();
|
initializeAddressFilters();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return allowedAddresses;
|
return allowedAddresses;
|
||||||
}
|
}
|
||||||
@ -149,15 +150,12 @@ 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 List<InetAddress> getBlockedAddresses()
|
public static synchronized List<InetAddress> getBlockedAddresses()
|
||||||
{
|
|
||||||
synchronized (HostCandidateHarvester.class)
|
|
||||||
{
|
{
|
||||||
if (!addressFiltersInitialized)
|
if (!addressFiltersInitialized)
|
||||||
{
|
{
|
||||||
initializeAddressFilters();
|
initializeAddressFilters();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return blockedAddresses;
|
return blockedAddresses;
|
||||||
}
|
}
|
||||||
@ -166,12 +164,11 @@ 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 void initializeAddressFilters()
|
private static synchronized void initializeAddressFilters()
|
||||||
{
|
|
||||||
synchronized (HostCandidateHarvester.class)
|
|
||||||
{
|
{
|
||||||
if (addressFiltersInitialized)
|
if (addressFiltersInitialized)
|
||||||
return;
|
return;
|
||||||
|
addressFiltersInitialized = true;
|
||||||
|
|
||||||
String[] allowedAddressesStr
|
String[] allowedAddressesStr
|
||||||
= StackProperties.getStringArray(
|
= StackProperties.getStringArray(
|
||||||
@ -225,9 +222,51 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -237,6 +276,8 @@ 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
|
||||||
@ -248,7 +289,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.
|
||||||
@ -263,24 +304,16 @@ public class HostCandidateHarvester
|
|||||||
{
|
{
|
||||||
harvestStatistics.startHarvestTiming();
|
harvestStatistics.startHarvestTiming();
|
||||||
|
|
||||||
Enumeration<NetworkInterface> interfaces
|
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
|
||||||
= NetworkInterface.getNetworkInterfaces();
|
|
||||||
|
|
||||||
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)
|
if (transport != Transport.UDP && transport != Transport.TCP)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException("Transport protocol not supported: " + transport);
|
||||||
"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();
|
||||||
@ -292,6 +325,7 @@ 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();
|
||||||
|
|
||||||
@ -304,22 +338,20 @@ public class HostCandidateHarvester
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isIPv6LinkLocalDisabled
|
if (!config.useLinkLocalAddresses() && addr.isLinkLocalAddress())
|
||||||
&& (addr instanceof Inet6Address)
|
|
||||||
&& addr.isLinkLocalAddress())
|
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
foundAtLeastOneUsableAddress = true;
|
||||||
|
|
||||||
if((addr instanceof Inet4Address) || !isIPv6Disabled)
|
if ((addr instanceof Inet4Address) || config.useIpv6())
|
||||||
{
|
{
|
||||||
IceSocketWrapper sock = null;
|
IceSocketWrapper sock = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (transport == Transport.UDP)
|
if (transport == Transport.UDP)
|
||||||
{
|
{
|
||||||
sock = createDatagramSocket(
|
sock = createDatagramSocket(addr, preferredPort, minPort, maxPort);
|
||||||
addr, preferredPort, minPort, maxPort);
|
|
||||||
boundAtLeastOneSocket = true;
|
boundAtLeastOneSocket = true;
|
||||||
}
|
}
|
||||||
else if (transport == Transport.TCP)
|
else if (transport == Transport.TCP)
|
||||||
@ -354,10 +386,8 @@ public class HostCandidateHarvester
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
HostCandidate candidate
|
HostCandidate candidate = new HostCandidate(sock, component, transport);
|
||||||
= new HostCandidate(sock, component, transport);
|
candidate.setVirtual(NetworkUtils.isInterfaceVirtual(iface));
|
||||||
candidate.setVirtual(
|
|
||||||
NetworkUtils.isInterfaceVirtual(iface));
|
|
||||||
component.addLocalCandidate(candidate);
|
component.addLocalCandidate(candidate);
|
||||||
|
|
||||||
if (transport == Transport.TCP)
|
if (transport == Transport.TCP)
|
||||||
@ -372,6 +402,12 @@ 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -383,11 +419,14 @@ public class HostCandidateHarvester
|
|||||||
+ component
|
+ component
|
||||||
+ " preferredPort=" + preferredPort
|
+ " preferredPort=" + preferredPort
|
||||||
+ " minPort=" + minPort
|
+ " minPort=" + minPort
|
||||||
+ " maxPort=" + maxPort);
|
+ " maxPort=" + maxPort
|
||||||
|
+ " foundAtLeastOneUsableInterface="
|
||||||
|
+ foundAtLeastOneUsableInterface
|
||||||
|
+ " foundAtLeastOneUsableAddress="
|
||||||
|
+ foundAtLeastOneUsableAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.harvestStatistics
|
this.harvestStatistics.stopHarvestTiming(component.getLocalCandidateCount());
|
||||||
.stopHarvestTiming(component.getLocalCandidateCount());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -402,7 +441,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.
|
||||||
*/
|
*/
|
||||||
static boolean isInterfaceAllowed(NetworkInterface iface)
|
public 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");
|
||||||
@ -482,6 +521,8 @@ 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
|
||||||
@ -492,7 +533,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.
|
||||||
@ -508,7 +549,18 @@ public class HostCandidateHarvester
|
|||||||
BindException
|
BindException
|
||||||
{
|
{
|
||||||
// make sure port numbers are valid
|
// make sure port numbers are valid
|
||||||
this.checkPorts(preferredPort, minPort, maxPort);
|
boolean ephemeral = 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,
|
||||||
@ -523,7 +575,8 @@ 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(sock,
|
= new IceTcpServerSocketWrapper(
|
||||||
|
new DelegatingServerSocket(sock),
|
||||||
component);
|
component);
|
||||||
|
|
||||||
if (logger.isLoggable(Level.FINEST))
|
if (logger.isLoggable(Level.FINEST))
|
||||||
@ -551,8 +604,7 @@ public class HostCandidateHarvester
|
|||||||
port = minPort;
|
port = minPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new BindException("Could not bind to any port between "
|
throw new BindException("Could not bind to any port between " + minPort + " and " + (port - 1));
|
||||||
+ minPort + " and " + (port - 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -567,6 +619,8 @@ 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
|
||||||
@ -577,7 +631,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.
|
||||||
@ -594,7 +648,16 @@ public class HostCandidateHarvester
|
|||||||
BindException
|
BindException
|
||||||
{
|
{
|
||||||
// make sure port numbers are valid.
|
// make sure port numbers are valid.
|
||||||
this.checkPorts(preferredPort, minPort, maxPort);
|
boolean ephemeral = 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,
|
||||||
@ -656,8 +719,10 @@ public class HostCandidateHarvester
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the different ports are correctly set. If not, throws an
|
* Checks if the different ports are correctly set. If not, throws {@link IllegalArgumentException}. The
|
||||||
* IllegalArgumentException.
|
* special values 0, 0, 0 for the parameters are interpreted as "use an ephemeral port".
|
||||||
|
*
|
||||||
|
* @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
|
||||||
@ -669,9 +734,14 @@ 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 void checkPorts(int preferredPort, int minPort, int maxPort)
|
private static boolean 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))
|
||||||
@ -696,6 +766,8 @@ public class HostCandidateHarvester
|
|||||||
+") must be between minPort (" + minPort
|
+") must be between minPort (" + minPort
|
||||||
+ ") and maxPort (" + maxPort + ")");
|
+ ") and maxPort (" + maxPort + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -718,19 +790,13 @@ 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 void initializeInterfaceFilters()
|
public static synchronized 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, ";");
|
||||||
|
|||||||
@ -1,143 +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.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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,334 @@
|
|||||||
|
/*
|
||||||
|
* 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,12 +18,9 @@
|
|||||||
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.*;
|
||||||
@ -42,17 +39,16 @@ 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 datagram from an unknown source is received, it is parsed as a STUN
|
* When a STUN Binding Request with a given ufrag is received, if the ufrag
|
||||||
* Binding Request, and if it has a USERNAME attribute, its ufrag is extracted.
|
* matches one of the registered candidates, then a new socket is created, which
|
||||||
* If this ufrag is associated with a candidate of this harvester, a new socket
|
* is to receive further packets from the remote address, and the socket is
|
||||||
* is created and added to the candidate, and the remote address of the datagram
|
* added to the candidate.
|
||||||
* 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 CandidateHarvester
|
extends AbstractUdpListener
|
||||||
|
implements CandidateHarvester
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Our class logger.
|
* Our class logger.
|
||||||
@ -60,21 +56,6 @@ 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.
|
||||||
@ -82,58 +63,12 @@ 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>
|
public static List<SinglePortUdpHarvester> createHarvesters(int port)
|
||||||
createHarvesters(int port)
|
|
||||||
{
|
{
|
||||||
List<SinglePortUdpHarvester> harvesters = new LinkedList<>();
|
List<SinglePortUdpHarvester> harvesters = new LinkedList<>();
|
||||||
|
|
||||||
List<TransportAddress> addresses = new LinkedList<>();
|
for (TransportAddress address
|
||||||
boolean isIPv6Disabled = StackProperties.getBoolean(
|
: AbstractUdpListener.getAllowedAddresses(port))
|
||||||
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
|
||||||
{
|
{
|
||||||
@ -150,15 +85,6 @@ 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
|
||||||
@ -168,129 +94,59 @@ public class SinglePortUdpHarvester
|
|||||||
= new ConcurrentHashMap<>();
|
= new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A pool of <tt>Buffer</tt> instances used to avoid creating of new java
|
* Manages statistics about harvesting time.
|
||||||
* objects.
|
|
||||||
*/
|
*/
|
||||||
private final ArrayBlockingQueue<Buffer> pool
|
private HarvestStatistics harvestStatistics = new HarvestStatistics();
|
||||||
= 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.
|
* @param localAddress the address to bind to. If the port is 0 an ephemeral port is chosen by the OS and the
|
||||||
|
* 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
|
||||||
{
|
{
|
||||||
this.localAddress = localAddress;
|
super(localAddress);
|
||||||
this.socket = new DatagramSocket(localAddress);
|
|
||||||
logger.info("Initialized SinglePortUdpHarvester with address "
|
logger.info("Initialized SinglePortUdpHarvester with address "
|
||||||
+ localAddress);
|
+ this.localAddress);
|
||||||
|
|
||||||
thread = new Thread()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
SinglePortUdpHarvester.this.runInHarvesterThread();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
thread.setName(SinglePortUdpHarvester.class.getName() + " thread");
|
|
||||||
thread.setDaemon(true);
|
|
||||||
thread.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perpetually reads datagrams from {@link #socket} and handles them
|
* {@inheritDoc}
|
||||||
* 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()
|
public HarvestStatistics getHarvestStatistics()
|
||||||
{
|
{
|
||||||
Buffer buf;
|
return harvestStatistics;
|
||||||
DatagramPacket pkt = null;
|
|
||||||
Component component;
|
|
||||||
MyCandidate candidate;
|
|
||||||
MySocket destinationSocket;
|
|
||||||
InetSocketAddress remoteAddress;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
// TODO: implement stopping the thread with a switch?
|
|
||||||
|
|
||||||
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
|
* {@inheritDoc}
|
||||||
= candidate == null ? null : candidate.getParentComponent();
|
*
|
||||||
if (component != null)
|
* Looks for an ICE candidate registered with this harvester, which has a
|
||||||
|
* local ufrag of {@code ufrag}, and if one is found it accepts the new
|
||||||
|
* socket and adds it to the candidate.
|
||||||
|
*/
|
||||||
|
protected void maybeAcceptNewSession(Buffer buf,
|
||||||
|
InetSocketAddress remoteAddress,
|
||||||
|
String ufrag)
|
||||||
{
|
{
|
||||||
|
MyCandidate candidate = candidates.get(ufrag);
|
||||||
|
if (candidate == null)
|
||||||
|
{
|
||||||
|
// A STUN Binding Request with an unknown USERNAME. Drop it.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
sockets.put(remoteAddress, newSocket);
|
MySocket newSocket = addSocket(remoteAddress, ufrag);
|
||||||
|
|
||||||
// 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.
|
||||||
@ -308,105 +164,6 @@ 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}
|
||||||
@ -448,249 +205,6 @@ 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>.
|
||||||
@ -713,7 +227,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}.
|
||||||
*/
|
*/
|
||||||
@ -723,7 +237,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.
|
||||||
*/
|
*/
|
||||||
@ -733,6 +247,7 @@ 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
|
||||||
@ -746,7 +261,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
|
||||||
@ -777,7 +292,8 @@ public class SinglePortUdpHarvester
|
|||||||
socket.getLocalPort(),
|
socket.getLocalPort(),
|
||||||
Transport.UDP);
|
Transport.UDP);
|
||||||
TransportAddress remoteAddress
|
TransportAddress remoteAddress
|
||||||
= new TransportAddress((InetSocketAddress) e.getKey(),
|
= new TransportAddress(
|
||||||
|
(InetSocketAddress) e.getKey(),
|
||||||
|
|
||||||
Transport.UDP);
|
Transport.UDP);
|
||||||
|
|
||||||
@ -792,6 +308,11 @@ public class SinglePortUdpHarvester
|
|||||||
|
|
||||||
synchronized (candidateSockets)
|
synchronized (candidateSockets)
|
||||||
{
|
{
|
||||||
|
for (IceSocketWrapper wrapper : candidateSockets.values())
|
||||||
|
{
|
||||||
|
wrapper.close();
|
||||||
|
}
|
||||||
|
|
||||||
candidateSockets.clear();
|
candidateSockets.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -801,6 +322,7 @@ 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.
|
||||||
*/
|
*/
|
||||||
@ -821,11 +343,16 @@ public class SinglePortUdpHarvester
|
|||||||
|
|
||||||
IceProcessingState state
|
IceProcessingState state
|
||||||
= component.getParentStream().getParentAgent().getState();
|
= component.getParentStream().getParentAgent().getState();
|
||||||
if (!IceProcessingState.WAITING.equals(state)
|
if (state == IceProcessingState.FAILED)
|
||||||
&& !IceProcessingState.RUNNING.equals(state))
|
|
||||||
{
|
{
|
||||||
throw new IOException(
|
throw new IOException(
|
||||||
"Agent state is " + state + ". Cannot add socket.");
|
"Cannot add socket to an Agent in state FAILED.");
|
||||||
|
}
|
||||||
|
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
|
||||||
@ -845,11 +372,23 @@ 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)
|
||||||
{
|
{
|
||||||
candidateSockets.put(remoteAddress, candidateSocket);
|
IceSocketWrapper oldSocket
|
||||||
|
= 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?
|
||||||
@ -858,14 +397,17 @@ public class SinglePortUdpHarvester
|
|||||||
sockets.put(remoteAddress, socket);
|
sockets.put(remoteAddress, socket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public IceSocketWrapper getIceSocketWrapper(SocketAddress remoteAddress)
|
protected IceSocketWrapper getCandidateIceSocketWrapper(
|
||||||
|
SocketAddress remoteAddress)
|
||||||
|
{
|
||||||
|
synchronized (candidateSockets)
|
||||||
{
|
{
|
||||||
return candidateSockets.get(remoteAddress);
|
return candidateSockets.get(remoteAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -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 CandidateHarvester
|
extends AbstractCandidateHarvester
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -234,10 +234,14 @@ 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())
|
||||||
@ -437,7 +441,7 @@ public class StunCandidateHarvester
|
|||||||
*/
|
*/
|
||||||
protected HostCandidate getHostCandidate(HostCandidate hostCand)
|
protected HostCandidate getHostCandidate(HostCandidate hostCand)
|
||||||
{
|
{
|
||||||
HostCandidate cand = null;
|
HostCandidate cand;
|
||||||
|
|
||||||
// create a new TCP HostCandidate
|
// create a new TCP HostCandidate
|
||||||
if (hostCand.getTransport() == Transport.TCP)
|
if (hostCand.getTransport() == Transport.TCP)
|
||||||
@ -446,12 +450,23 @@ public class StunCandidateHarvester
|
|||||||
{
|
{
|
||||||
Socket sock = new Socket(stunServer.getAddress(),
|
Socket sock = new Socket(stunServer.getAddress(),
|
||||||
stunServer.getPort());
|
stunServer.getPort());
|
||||||
cand = new HostCandidate(new IceTcpSocketWrapper(
|
MultiplexingSocket multiplexing = new MultiplexingSocket(sock);
|
||||||
new MultiplexingSocket(sock)),
|
Component component = hostCand.getParentComponent();
|
||||||
hostCand.getParentComponent(), Transport.TCP);
|
cand
|
||||||
hostCand.getParentComponent().getParentStream().
|
= new HostCandidate(
|
||||||
|
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,15 +18,18 @@
|
|||||||
package org.ice4j.ice.harvest;
|
package org.ice4j.ice.harvest;
|
||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
import org.ice4j.ice.*;
|
import org.ice4j.socket.*;
|
||||||
|
import org.ice4j.stunclient.*;
|
||||||
|
import org.jetbrains.annotations.*;
|
||||||
|
|
||||||
|
import java.net.*;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A MappingCandidateHarvester which use a list of pre-configured stun servers
|
* A {@link MappingCandidateHarvester} which uses a STUN servers to discover its public IP address.
|
||||||
* 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
|
||||||
@ -35,135 +38,97 @@ 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
|
private static final Logger logger = Logger.getLogger(StunMappingCandidateHarvester.class.getName());
|
||||||
= 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 static String[] stunServers;
|
private final TransportAddress stunServerAddress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a mapping harvester with the specified <tt>mask</tt>
|
* The local address this {@link StunMappingCandidateHarvester} was initialized with, and which will be used to
|
||||||
* @param servers list of stun servers in the form address:port
|
* communicate to STUN servers.
|
||||||
*/
|
*/
|
||||||
public StunMappingCandidateHarvester(String[] servers)
|
@NotNull
|
||||||
|
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(null, null);
|
super("stun");
|
||||||
|
this.localAddress = localAddress;
|
||||||
StunMappingCandidateHarvester.stunServers = servers;
|
this.stunServerAddress = stunServerAddress;
|
||||||
|
|
||||||
// we have the list of addresses lets, try discovering
|
|
||||||
obtainAddresses();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a mapping harvester with the specified <tt>mask</tt>
|
* Attempts to discover the the public address (mask) via the STUN server.
|
||||||
|
* Note that this will block until we either receive a response from the
|
||||||
|
* STUN server, or a timeout occurs.
|
||||||
*/
|
*/
|
||||||
public StunMappingCandidateHarvester()
|
public void discover()
|
||||||
{
|
{
|
||||||
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
|
||||||
{
|
{
|
||||||
for (String server : stunServers)
|
SimpleAddressDetector sad
|
||||||
|
= 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)
|
||||||
{
|
{
|
||||||
String[] addressAndPort = server.split(":");
|
localAddress = new TransportAddress((InetSocketAddress)boundAddr, localAddress.getTransport());
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Detected through stun local IP: " + face);
|
if (publicAddress != null)
|
||||||
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 and fail
|
//whatever happens, we just log
|
||||||
logger.log(Level.INFO, "We failed to obtain addresses "
|
logger.log(Level.INFO, "We failed to obtain addresses for the following reason: ", exc);
|
||||||
+ "for the following reason: ", exc);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the public (mask) address, or null.
|
* {@inheritDoc}
|
||||||
* @return the public (mask) address, or null.
|
|
||||||
*/
|
|
||||||
public TransportAddress getMask()
|
|
||||||
{
|
|
||||||
if (mask == null)
|
|
||||||
{
|
|
||||||
obtainAddresses();
|
|
||||||
}
|
|
||||||
return mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the local (face) address, or null.
|
|
||||||
* @return the local (face) address, or null.
|
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
public TransportAddress getFace()
|
public TransportAddress getFace()
|
||||||
{
|
{
|
||||||
if (face == null)
|
return localAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public TransportAddress getMask()
|
||||||
{
|
{
|
||||||
obtainAddresses();
|
return publicAddress;
|
||||||
}
|
|
||||||
return face;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -258,6 +258,13 @@ 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 CandidateHarvester
|
extends AbstractCandidateHarvester
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The logger.
|
* The logger.
|
||||||
@ -203,25 +203,29 @@ 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 cmp parent component
|
* @param component 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
|
|
||||||
*/
|
*/
|
||||||
public List<LocalCandidate> createUPNPCandidate(IceSocketWrapper socket,
|
private List<LocalCandidate> createUPNPCandidate(IceSocketWrapper socket,
|
||||||
String externalIP, int port, Component cmp, GatewayDevice device)
|
String externalIP, int port, Component component, 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, cmp);
|
HostCandidate base = new HostCandidate(socket, component);
|
||||||
|
|
||||||
UPNPCandidate candidate = new UPNPCandidate(addr, base, cmp, device);
|
UPNPCandidate candidate
|
||||||
|
= 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);
|
||||||
|
|||||||
@ -177,7 +177,7 @@ public class IceSdpUtils
|
|||||||
: Connection.IP4;
|
: Connection.IP4;
|
||||||
|
|
||||||
mediaDescription.setConnection(sdpFactory.createConnection(
|
mediaDescription.setConnection(sdpFactory.createConnection(
|
||||||
"IN", defaultAddress.getHostAddress(), addressFamily));
|
"IN", addressFamily, defaultAddress.getHostAddress()));
|
||||||
|
|
||||||
//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.
|
||||||
|
|||||||
@ -100,27 +100,26 @@ public class ChannelData
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the data length.
|
* Get the data length (without padding).
|
||||||
*
|
*
|
||||||
* @return data length
|
* @return data length
|
||||||
*/
|
*/
|
||||||
public char getDataLength()
|
public char getDataLength()
|
||||||
{
|
{
|
||||||
char length = 0;
|
|
||||||
if (data == null)
|
if (data == null)
|
||||||
{
|
return 0;
|
||||||
return length;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* pad to a multiple of four */
|
|
||||||
if((length % 4) > 0)
|
|
||||||
{
|
|
||||||
length += (4 - (length % 4));
|
|
||||||
}
|
|
||||||
|
|
||||||
return (char)data.length;
|
return (char)data.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return num padded to 4
|
||||||
|
*/
|
||||||
|
private static int padTo4(int num)
|
||||||
|
{
|
||||||
|
return (num + 3) & ~3;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether a specific channel number is in the valid channel
|
* Determines whether a specific channel number is in the valid channel
|
||||||
* number range defined by the TURN RFC.
|
* number range defined by the TURN RFC.
|
||||||
@ -136,13 +135,27 @@ public class ChannelData
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a binary representation of this message.
|
* Returns a non padded binary representation of this message.
|
||||||
* @return a binary representation of this message.
|
* @return a non padded binary representation of this message.
|
||||||
* @throws StunException if the channel number is invalid
|
* @throws StunException if the channel number is invalid
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
public byte[] encode() throws StunException
|
public byte[] encode() throws StunException
|
||||||
{
|
{
|
||||||
char dataLength = getDataLength();
|
return encode(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a binary representation of this message.
|
||||||
|
* @param pad determine if we pad this message
|
||||||
|
* @return a binary representation of this message.
|
||||||
|
* @throws StunException if the channel number is invalid
|
||||||
|
*/
|
||||||
|
public byte[] encode(boolean pad) throws StunException
|
||||||
|
{
|
||||||
|
int 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;
|
||||||
|
|
||||||
@ -175,15 +188,29 @@ 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(arrayLen < 4)
|
if ((binMessage.length - offset) < HEADER_LENGTH)
|
||||||
{
|
{
|
||||||
throw new StunException(StunException.ILLEGAL_ARGUMENT, "Size too short");
|
throw new StunException(StunException.ILLEGAL_ARGUMENT, "Size too short");
|
||||||
}
|
}
|
||||||
@ -196,7 +223,7 @@ public class ChannelData
|
|||||||
}
|
}
|
||||||
|
|
||||||
msgLen = (char)((binMessage[offset++]<<8) | (binMessage[offset++]&0xFF));
|
msgLen = (char)((binMessage[offset++]<<8) | (binMessage[offset++]&0xFF));
|
||||||
if(msgLen != (binMessage.length - 4))
|
if (msgLen > (binMessage.length - offset))
|
||||||
{
|
{
|
||||||
throw new StunException(StunException.ILLEGAL_ARGUMENT, "Size mismatch");
|
throw new StunException(StunException.ILLEGAL_ARGUMENT, "Size mismatch");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,7 @@ 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.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,7 +46,12 @@ 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.
|
||||||
*/
|
*/
|
||||||
@ -75,26 +81,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.
|
||||||
@ -160,134 +166,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 */
|
||||||
/**
|
/**
|
||||||
@ -341,7 +347,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 LinkedHashMap<Character, Attribute> attributes
|
protected final LinkedHashMap<Character, Attribute> attributes
|
||||||
= new LinkedHashMap<>();
|
= new LinkedHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -361,34 +367,34 @@ public abstract class Message
|
|||||||
*
|
*
|
||||||
* For classic STUN :
|
* For classic STUN :
|
||||||
*
|
*
|
||||||
*
|
* <pre>
|
||||||
* Binding Shared Shared Shared <br/>
|
* Binding Shared Shared Shared
|
||||||
* Binding Binding Error Secret Secret Secret <br/>
|
* Binding Binding Error Secret Secret Secret
|
||||||
* Att. Req. Resp. Resp. Req. Resp. Error <br/>
|
* Att. Req. Resp. Resp. Req. Resp. Error
|
||||||
* Resp. <br/>
|
* Resp.
|
||||||
* _____________________________________________________________________ <br/>
|
* _____________________________________________________________________
|
||||||
* MAPPED-ADDRESS N/A M N/A N/A N/A N/A <br/>
|
* MAPPED-ADDRESS N/A M N/A N/A N/A N/A
|
||||||
* RESPONSE-ADDRESS O N/A N/A N/A N/A N/A <br/>
|
* RESPONSE-ADDRESS 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/>
|
* CHANGE-REQUEST O N/A N/A N/A N/A N/A
|
||||||
* SOURCE-ADDRESS N/A M N/A N/A N/A N/A <br/>
|
* SOURCE-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/>
|
* CHANGED-ADDRESS N/A M N/A N/A N/A N/A
|
||||||
* USERNAME O N/A N/A N/A M N/A <br/>
|
* USERNAME O N/A N/A N/A M N/A
|
||||||
* PASSWORD N/A N/A N/A N/A M N/A <br/>
|
* PASSWORD N/A N/A N/A N/A M N/A
|
||||||
* MESSAGE-INTEGRITY O O N/A N/A N/A N/A <br/>
|
* MESSAGE-INTEGRITY O O N/A N/A N/A N/A
|
||||||
* ERROR-CODE N/A N/A M N/A N/A M <br/>
|
* ERROR-CODE N/A N/A M N/A N/A M
|
||||||
* UNKNOWN-ATTRIBUTES N/A N/A C N/A N/A C <br/>
|
* UNKNOWN-ATTRIBUTES N/A N/A C N/A N/A C
|
||||||
* REFLECTED-FROM N/A C N/A N/A N/A N/A <br/>
|
* REFLECTED-FROM N/A C N/A N/A N/A N/A
|
||||||
* XOR-MAPPED-ADDRESS N/A M N/A N/A N/A N/A <br/>
|
* XOR-MAPPED-ADDRESS N/A M N/A N/A N/A N/A
|
||||||
* XOR-ONLY O N/A N/A N/A N/A N/A <br/>
|
* XOR-ONLY O N/A N/A N/A N/A N/A
|
||||||
* SOFTWARE N/A O O N/A O O <br/>
|
* SOFTWARE N/A O O N/A O O
|
||||||
*
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public static final byte N_A = 0;
|
private 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.
|
||||||
*/
|
*/
|
||||||
public static final byte C = 1;
|
private static final byte C = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* O means the parameter is optional.
|
* O means the parameter is optional.
|
||||||
@ -464,6 +470,7 @@ 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.
|
||||||
@ -504,6 +511,7 @@ 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.
|
||||||
@ -710,9 +718,9 @@ 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)
|
||||||
{
|
{
|
||||||
@ -867,8 +875,7 @@ 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)
|
||||||
@ -1014,7 +1021,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 = System.getProperty(StackProperties.SOFTWARE);
|
String software = AgentConfig.config.getSoftware();
|
||||||
|
|
||||||
if (getAttribute(Attribute.SOFTWARE) == null
|
if (getAttribute(Attribute.SOFTWARE) == null
|
||||||
&& software != null && software.length() > 0)
|
&& software != null && software.length() > 0)
|
||||||
@ -1053,13 +1060,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[], char offset, char arrayLen)
|
public static Message decode(byte[] binMessage, int offset, int arrayLen)
|
||||||
throws StunException
|
throws StunException
|
||||||
{
|
{
|
||||||
int originalOffset = offset;
|
int originalOffset = offset;
|
||||||
arrayLen = (char)Math.min(binMessage.length, arrayLen);
|
arrayLen = Math.min(binMessage.length, arrayLen);
|
||||||
|
|
||||||
if(binMessage == null || arrayLen - offset < Message.HEADER_LENGTH)
|
if (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");
|
||||||
@ -1084,7 +1091,7 @@ 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;
|
||||||
|
|
||||||
@ -1102,20 +1109,20 @@ public abstract class Message
|
|||||||
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 "
|
||||||
+ ((int) arrayLen)
|
+ 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);
|
||||||
@ -1261,7 +1268,7 @@ public abstract class Message
|
|||||||
*/
|
*/
|
||||||
public static boolean isErrorResponseType(char type)
|
public static boolean isErrorResponseType(char type)
|
||||||
{
|
{
|
||||||
return ((type & 0x0110) == STUN_ERROR_RESP);
|
return ((type & MESSAGE_CLASS_MASK) == STUN_ERROR_RESP);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1271,7 +1278,7 @@ public abstract class Message
|
|||||||
*/
|
*/
|
||||||
public static boolean isSuccessResponseType(char type)
|
public static boolean isSuccessResponseType(char type)
|
||||||
{
|
{
|
||||||
return ((type & 0x0110) == STUN_SUCCESS_RESP);
|
return ((type & MESSAGE_CLASS_MASK) == STUN_SUCCESS_RESP);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1289,11 +1296,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 Indictation, false otherwise
|
* @return true if the type is Indication, false otherwise
|
||||||
*/
|
*/
|
||||||
public static boolean isIndicationType(char type)
|
public static boolean isIndicationType(char type)
|
||||||
{
|
{
|
||||||
return ((type & 0x0110) == STUN_INDICATION);
|
return ((type & MESSAGE_CLASS_MASK) == STUN_INDICATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1305,7 +1312,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 & 0x0110) == STUN_REQUEST);
|
return ((type & MESSAGE_CLASS_MASK) == STUN_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -54,7 +54,8 @@ 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);
|
||||||
@ -122,7 +123,8 @@ 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);
|
||||||
@ -356,7 +358,8 @@ 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);
|
||||||
@ -669,7 +672,8 @@ 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);
|
||||||
}
|
}
|
||||||
@ -949,7 +953,8 @@ 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);
|
||||||
}
|
}
|
||||||
@ -1353,6 +1358,7 @@ 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,
|
||||||
|
|||||||
@ -364,9 +364,9 @@ public class PseudoTCPBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the MTU value
|
* Set the MTU (maximum transmission unit) value
|
||||||
*
|
*
|
||||||
* @param mtu
|
* @param mtu the new MTU value
|
||||||
*/
|
*/
|
||||||
public void notifyMTU(int mtu)
|
public void notifyMTU(int mtu)
|
||||||
{
|
{
|
||||||
@ -387,12 +387,11 @@ 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.currentTimeMillis() & 0xFFFFFFFFL;
|
return (System.nanoTime() / 1000000) & 0xFFFFFFFFL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -445,7 +444,8 @@ 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) << "m_ssthresh: " << m_ssthresh << " nInFlight: " << nInFlight << " m_mss: " << m_mss;
|
//Logger.Log(LS_INFO)
|
||||||
|
// << "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,11 +680,13 @@ 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
|
* @param buffer destination buffer
|
||||||
* @param len
|
* @param len bytes to be read
|
||||||
* @return received byte count
|
* @return received byte count
|
||||||
* @throws IOException
|
* @throws IOException if the protocol is not in the connected state
|
||||||
*/
|
*/
|
||||||
public int recv(byte[] buffer, int len) throws IOException
|
public int recv(byte[] buffer, int len) throws IOException
|
||||||
{
|
{
|
||||||
@ -692,11 +694,12 @@ public class PseudoTCPBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Enqueues data in the send buffer
|
||||||
*
|
*
|
||||||
* @param buffer
|
* @param buffer source data buffer
|
||||||
* @param len
|
* @param len bytes count to be sent
|
||||||
* @return sent byte count
|
* @return sent byte count
|
||||||
* @throws IOException
|
* @throws IOException if the protocol is not in connected state
|
||||||
*/
|
*/
|
||||||
public int send(byte[] buffer, int len) throws IOException
|
public int send(byte[] buffer, int len) throws IOException
|
||||||
{
|
{
|
||||||
@ -875,6 +878,9 @@ 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)
|
||||||
{
|
{
|
||||||
@ -902,7 +908,7 @@ public class PseudoTCPBase
|
|||||||
/**
|
/**
|
||||||
* Can be used to convert segments to text
|
* Can be used to convert segments to text
|
||||||
*
|
*
|
||||||
* @param seg
|
* @param seg the {@link Segment} to format
|
||||||
* @return segment in readable text form
|
* @return segment in readable text form
|
||||||
*/
|
*/
|
||||||
public static String segToStr(Segment seg)
|
public static String segToStr(Segment seg)
|
||||||
@ -1246,7 +1252,8 @@ 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) << "m_ssthresh: " << m_ssthresh << " nInFlight: " << nInFlight << " m_mss: " << m_mss;
|
//Logger.Log(LS_INFO)
|
||||||
|
// << "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
|
||||||
@ -1952,7 +1959,7 @@ public class PseudoTCPBase
|
|||||||
options_specified.add(kind);
|
options_specified.add(kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options_specified.indexOf(TCP_OPT_WND_SCALE) == -1)//options_specified.size() - 1)
|
if (!options_specified.contains(TCP_OPT_WND_SCALE))
|
||||||
{
|
{
|
||||||
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)
|
||||||
|
|||||||
@ -29,33 +29,33 @@ public interface PseudoTcpNotify
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Called when TCP enters opened state
|
* Called when TCP enters opened state
|
||||||
* @param tcp
|
* @param tcp the socket that was opened
|
||||||
*/
|
*/
|
||||||
void onTcpOpen(PseudoTCPBase tcp);
|
void onTcpOpen(PseudoTCPBase tcp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when any data is available in read buffer
|
* Called when any data is available in read buffer
|
||||||
* @param tcp
|
* @param tcp the socket that became readable
|
||||||
*/
|
*/
|
||||||
void onTcpReadable(PseudoTCPBase tcp);
|
void onTcpReadable(PseudoTCPBase tcp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when there is free space available in the send buffer
|
* Called when there is free space available in the send buffer
|
||||||
* @param tcp
|
* @param tcp the socket that became writable
|
||||||
*/
|
*/
|
||||||
void onTcpWriteable(PseudoTCPBase tcp);
|
void onTcpWriteable(PseudoTCPBase tcp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when tcp enters closed state
|
* Called when tcp enters closed state
|
||||||
* @param tcp
|
* @param tcp the socket that was closed
|
||||||
* @param e null means no error
|
* @param e null means no error
|
||||||
*/
|
*/
|
||||||
void onTcpClosed(PseudoTCPBase tcp, IOException e);
|
void onTcpClosed(PseudoTCPBase tcp, IOException e);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when protocol requests packet transfer through the network.
|
* Called when protocol requests packet transfer through the network.
|
||||||
* @param tcp
|
* @param tcp the socket on which the write occurred
|
||||||
* @param buffer data
|
* @param buffer the data that was written
|
||||||
* @param len data length
|
* @param len data length
|
||||||
* @return the result, see {@link WriteResult} description for more info
|
* @return the result, see {@link WriteResult} description for more info
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -52,7 +52,7 @@ public class PseudoTcpSocket extends Socket
|
|||||||
* Set conversation ID for the socket
|
* Set conversation ID for the socket
|
||||||
* Must be called on unconnected socket
|
* Must be called on unconnected socket
|
||||||
*
|
*
|
||||||
* @param convID
|
* @param convID the conversation ID to set
|
||||||
* @throws IllegalStateException when called on connected or closed socket
|
* @throws IllegalStateException when called on connected or closed socket
|
||||||
*/
|
*/
|
||||||
public void setConversationID(long convID)
|
public void setConversationID(long convID)
|
||||||
@ -62,8 +62,8 @@ public class PseudoTcpSocket extends Socket
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets MTU value
|
* Sets MTU (maximum transmission unit) value
|
||||||
* @param mtu
|
* @param mtu the MTU value
|
||||||
*/
|
*/
|
||||||
public void setMTU(int mtu)
|
public void setMTU(int mtu)
|
||||||
{
|
{
|
||||||
@ -71,7 +71,7 @@ public class PseudoTcpSocket extends Socket
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Gets MTU (maximum transmission unit) value
|
||||||
* @return MTU value
|
* @return MTU value
|
||||||
*/
|
*/
|
||||||
public int getMTU()
|
public int getMTU()
|
||||||
@ -80,9 +80,10 @@ public class PseudoTcpSocket extends Socket
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Sets an {@link Option} on this socket.
|
||||||
* @return PseudoTCP option value
|
* @return PseudoTCP option value
|
||||||
*
|
*
|
||||||
|
* @param option the option to set on this socket.
|
||||||
* @see Option
|
* @see Option
|
||||||
*/
|
*/
|
||||||
public long getOption(Option option)
|
public long getOption(Option option)
|
||||||
@ -116,7 +117,7 @@ public class PseudoTcpSocket extends Socket
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets debug name that will be displayed in log messages for this socket
|
* Sets debug name that will be displayed in log messages for this socket
|
||||||
* @param debugName
|
* @param debugName the name of this socket for debug messages
|
||||||
*/
|
*/
|
||||||
public void setDebugName(String debugName)
|
public void setDebugName(String debugName)
|
||||||
{
|
{
|
||||||
@ -244,6 +245,7 @@ public class PseudoTcpSocket extends Socket
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public synchronized void close()
|
public synchronized void close()
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
@ -255,6 +257,12 @@ public class PseudoTcpSocket extends Socket
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OutputStream getOutputStream() throws IOException
|
||||||
|
{
|
||||||
|
return socketImpl.getOutputStream();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows to set up the remote address directly.
|
* Allows to set up the remote address directly.
|
||||||
* Otherwise, when using the other <tt>accept</tt> methods,
|
* Otherwise, when using the other <tt>accept</tt> methods,
|
||||||
@ -265,6 +273,7 @@ public class PseudoTcpSocket extends Socket
|
|||||||
* accepted as remote packet's source
|
* accepted as remote packet's source
|
||||||
* @param timeout connection accept timeout value in milliseconds, after
|
* @param timeout connection accept timeout value in milliseconds, after
|
||||||
* which the exception will be thrown.
|
* which the exception will be thrown.
|
||||||
|
* @throws IOException if socket is closed or timeout expires
|
||||||
*/
|
*/
|
||||||
public void accept(SocketAddress remoteAddress, int timeout)
|
public void accept(SocketAddress remoteAddress, int timeout)
|
||||||
throws IOException
|
throws IOException
|
||||||
|
|||||||
@ -67,9 +67,10 @@ public class PseudoTcpSocketFactory
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates socket bound to local <tt>sockAddr</tt>
|
* Creates socket bound to local <tt>sockAddr</tt>
|
||||||
* @param sockAddr
|
* @param sockAddr address for the pseudo socket
|
||||||
* @return socket bound to local address
|
* @return socket bound to local address
|
||||||
* @throws IOException
|
* @throws IOException if the socket could not be opened, or the socket
|
||||||
|
* could not bind to the specified local port.
|
||||||
*/
|
*/
|
||||||
public Socket createBoundSocket(InetSocketAddress sockAddr)
|
public Socket createBoundSocket(InetSocketAddress sockAddr)
|
||||||
throws IOException
|
throws IOException
|
||||||
@ -110,9 +111,10 @@ public class PseudoTcpSocketFactory
|
|||||||
/**
|
/**
|
||||||
* Creates a socket that will run on given <tt>datagramSocket</tt>
|
* Creates a socket that will run on given <tt>datagramSocket</tt>
|
||||||
*
|
*
|
||||||
* @param datagramSocket
|
* @param datagramSocket the socket to run on
|
||||||
* @return new socket running on given <tt>datagramSocket</tt>
|
* @return new socket running on given <tt>datagramSocket</tt>
|
||||||
* @throws SocketException
|
* @throws SocketException if there is an error in the underlying protocol,
|
||||||
|
* such as a TCP error.
|
||||||
*/
|
*/
|
||||||
public PseudoTcpSocket createSocket(DatagramSocket datagramSocket)
|
public PseudoTcpSocket createSocket(DatagramSocket datagramSocket)
|
||||||
throws SocketException
|
throws SocketException
|
||||||
|
|||||||
@ -78,15 +78,8 @@ class PseudoTcpSocketImpl
|
|||||||
*/
|
*/
|
||||||
private long readTimeout;
|
private long readTimeout;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private PseudoTcpInputStream inputStream;
|
private PseudoTcpInputStream inputStream;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private PseudoTcpOutputStream outputstream;
|
private PseudoTcpOutputStream outputstream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -196,6 +189,7 @@ class PseudoTcpSocketImpl
|
|||||||
* @param stream if true, create a stream socket; otherwise, create a datagram socket.
|
* @param stream if true, create a stream socket; otherwise, create a datagram socket.
|
||||||
* @throws IOException if an I/O error occurs while creating the socket.
|
* @throws IOException if an I/O error occurs while creating the socket.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void create(boolean stream)
|
protected void create(boolean stream)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
@ -208,6 +202,7 @@ class PseudoTcpSocketImpl
|
|||||||
* @param port the port number.
|
* @param port the port number.
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void connect(String host, int port)
|
protected void connect(String host, int port)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
@ -220,6 +215,7 @@ class PseudoTcpSocketImpl
|
|||||||
* @param port the port number.
|
* @param port the port number.
|
||||||
* @throws IOException if an I/O error occurs when attempting a connection.
|
* @throws IOException if an I/O error occurs when attempting a connection.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void connect(InetAddress address, int port)
|
protected void connect(InetAddress address, int port)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
@ -234,6 +230,7 @@ class PseudoTcpSocketImpl
|
|||||||
* @param timeout the timeout value, in milliseconds, or zero for no timeout.
|
* @param timeout the timeout value, in milliseconds, or zero for no timeout.
|
||||||
* @throws IOException if an I/O error occurs when attempting a connection.
|
* @throws IOException if an I/O error occurs when attempting a connection.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void connect(SocketAddress address, int timeout)
|
protected void connect(SocketAddress address, int timeout)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
@ -247,6 +244,7 @@ class PseudoTcpSocketImpl
|
|||||||
* @param port the port number.
|
* @param port the port number.
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void bind(InetAddress host, int port)
|
public void bind(InetAddress host, int port)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
@ -264,6 +262,7 @@ class PseudoTcpSocketImpl
|
|||||||
* @param backlog the maximum length of the queue.
|
* @param backlog the maximum length of the queue.
|
||||||
* @throws IOException if an I/O error occurs when creating the queue.
|
* @throws IOException if an I/O error occurs when creating the queue.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void listen(int backlog)
|
protected void listen(int backlog)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
@ -271,6 +270,7 @@ class PseudoTcpSocketImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Map<Integer, Object> options = new HashMap<>();
|
private Map<Integer, Object> options = new HashMap<>();
|
||||||
|
@Override
|
||||||
public void setOption(int optID, Object value)
|
public void setOption(int optID, Object value)
|
||||||
throws SocketException
|
throws SocketException
|
||||||
{
|
{
|
||||||
@ -278,6 +278,7 @@ class PseudoTcpSocketImpl
|
|||||||
options.put(optID, value);
|
options.put(optID, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object getOption(int optID)
|
public Object getOption(int optID)
|
||||||
throws SocketException
|
throws SocketException
|
||||||
{
|
{
|
||||||
@ -334,7 +335,6 @@ class PseudoTcpSocketImpl
|
|||||||
*
|
*
|
||||||
* @param remoteAddress to which this socket connects to
|
* @param remoteAddress to which this socket connects to
|
||||||
* @param timeout for this operation in ms
|
* @param timeout for this operation in ms
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
void doConnect(InetSocketAddress remoteAddress, long timeout)
|
void doConnect(InetSocketAddress remoteAddress, long timeout)
|
||||||
throws IOException
|
throws IOException
|
||||||
@ -355,10 +355,9 @@ class PseudoTcpSocketImpl
|
|||||||
while (pseudoTcp.getState() != PseudoTcpState.TCP_ESTABLISHED
|
while (pseudoTcp.getState() != PseudoTcpState.TCP_ESTABLISHED
|
||||||
&& (noTimeout || (elapsed < timeout)) )
|
&& (noTimeout || (elapsed < timeout)) )
|
||||||
{
|
{
|
||||||
long start = System.currentTimeMillis();
|
long start = System.nanoTime();
|
||||||
state_notify.wait(timeout);
|
state_notify.wait(timeout);
|
||||||
long end = System.currentTimeMillis();
|
elapsed += TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
|
||||||
elapsed += end - start;
|
|
||||||
}
|
}
|
||||||
if (pseudoTcp.getState() != PseudoTcpState.TCP_ESTABLISHED)
|
if (pseudoTcp.getState() != PseudoTcpState.TCP_ESTABLISHED)
|
||||||
{
|
{
|
||||||
@ -431,6 +430,7 @@ class PseudoTcpSocketImpl
|
|||||||
* @param s the accepted connection.
|
* @param s the accepted connection.
|
||||||
* @throws IOException if an I/O error occurs when accepting the connection.
|
* @throws IOException if an I/O error occurs when accepting the connection.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void accept(SocketImpl s)
|
protected void accept(SocketImpl s)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
@ -464,6 +464,7 @@ class PseudoTcpSocketImpl
|
|||||||
pseudoTcp.notifyClock(PseudoTCPBase.now());
|
pseudoTcp.notifyClock(PseudoTCPBase.now());
|
||||||
receiveThread = new Thread(new Runnable()
|
receiveThread = new Thread(new Runnable()
|
||||||
{
|
{
|
||||||
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
receivePackets();
|
receivePackets();
|
||||||
@ -483,6 +484,7 @@ class PseudoTcpSocketImpl
|
|||||||
* @param tcp the {@link PseudoTCPBase} that caused an event
|
* @param tcp the {@link PseudoTCPBase} that caused an event
|
||||||
* @see PseudoTcpNotify#onTcpOpen(PseudoTCPBase)
|
* @see PseudoTcpNotify#onTcpOpen(PseudoTCPBase)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void onTcpOpen(PseudoTCPBase tcp)
|
public void onTcpOpen(PseudoTCPBase tcp)
|
||||||
{
|
{
|
||||||
logger.log(Level.FINE, "tcp opened");
|
logger.log(Level.FINE, "tcp opened");
|
||||||
@ -501,6 +503,7 @@ class PseudoTcpSocketImpl
|
|||||||
* @param tcp the {@link PseudoTCPBase} that caused an event
|
* @param tcp the {@link PseudoTCPBase} that caused an event
|
||||||
* @see PseudoTcpNotify#onTcpReadable(PseudoTCPBase)
|
* @see PseudoTcpNotify#onTcpReadable(PseudoTCPBase)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void onTcpReadable(PseudoTCPBase tcp)
|
public void onTcpReadable(PseudoTCPBase tcp)
|
||||||
{
|
{
|
||||||
if (logger.isLoggable(Level.FINER))
|
if (logger.isLoggable(Level.FINER))
|
||||||
@ -522,6 +525,7 @@ class PseudoTcpSocketImpl
|
|||||||
* @param tcp the {@link PseudoTCPBase} that caused an event
|
* @param tcp the {@link PseudoTCPBase} that caused an event
|
||||||
* @see PseudoTcpNotify#onTcpWriteable(PseudoTCPBase)
|
* @see PseudoTcpNotify#onTcpWriteable(PseudoTCPBase)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void onTcpWriteable(PseudoTCPBase tcp)
|
public void onTcpWriteable(PseudoTCPBase tcp)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -545,6 +549,7 @@ class PseudoTcpSocketImpl
|
|||||||
*
|
*
|
||||||
* @see PseudoTcpNotify#onTcpClosed(PseudoTCPBase, IOException)
|
* @see PseudoTcpNotify#onTcpClosed(PseudoTCPBase, IOException)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void onTcpClosed(PseudoTCPBase tcp, IOException e)
|
public void onTcpClosed(PseudoTCPBase tcp, IOException e)
|
||||||
{
|
{
|
||||||
if (e != null)
|
if (e != null)
|
||||||
@ -606,6 +611,7 @@ class PseudoTcpSocketImpl
|
|||||||
*
|
*
|
||||||
* @see PseudoTcpNotify#tcpWritePacket(PseudoTCPBase, byte[], int)
|
* @see PseudoTcpNotify#tcpWritePacket(PseudoTCPBase, byte[], int)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public WriteResult tcpWritePacket(PseudoTCPBase tcp, byte[] buffer, int len)
|
public WriteResult tcpWritePacket(PseudoTCPBase tcp, byte[] buffer, int len)
|
||||||
{
|
{
|
||||||
if (logger.isLoggable(Level.FINEST))
|
if (logger.isLoggable(Level.FINEST))
|
||||||
@ -739,13 +745,7 @@ class PseudoTcpSocketImpl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Runnable clockTaskRunner = new Runnable()
|
private final Runnable clockTaskRunner = this::runClock;
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
runClock();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private void scheduleClockTask(long sleep)
|
private void scheduleClockTask(long sleep)
|
||||||
{
|
{
|
||||||
@ -777,6 +777,7 @@ class PseudoTcpSocketImpl
|
|||||||
* @return an output stream for writing to this socket.
|
* @return an output stream for writing to this socket.
|
||||||
* @throws IOException if an I/O error occurs when creating the output stream.
|
* @throws IOException if an I/O error occurs when creating the output stream.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public OutputStream getOutputStream()
|
public OutputStream getOutputStream()
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
@ -793,6 +794,7 @@ class PseudoTcpSocketImpl
|
|||||||
* @return a stream for reading from this socket.
|
* @return a stream for reading from this socket.
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public InputStream getInputStream()
|
public InputStream getInputStream()
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
@ -808,6 +810,7 @@ class PseudoTcpSocketImpl
|
|||||||
* @return the number of bytes that can be read from this socket without blocking.
|
* @return the number of bytes that can be read from this socket without blocking.
|
||||||
* @throws IOException if an I/O error occurs when determining the number of bytes available.
|
* @throws IOException if an I/O error occurs when determining the number of bytes available.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected int available()
|
protected int available()
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
@ -816,16 +819,16 @@ class PseudoTcpSocketImpl
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes this socket.
|
* Closes this socket.
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void close()
|
public void close()
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pseudoTcp.close(true);
|
pseudoTcp.close(true);
|
||||||
//System.out.println("ON CLOSE: in flight "+pseudoTcp.GetBytesInFlight());
|
//System.out.println("ON CLOSE: in flight "+pseudoTcp.getBytesInFlight());
|
||||||
//System.out.println("ON CLOSE: buff not sent "+pseudoTcp.GetBytesBufferedNotSent());
|
//System.out.println("ON CLOSE: buff not sent "+pseudoTcp.getBytesBufferedNotSent());
|
||||||
onTcpClosed(pseudoTcp, null);
|
onTcpClosed(pseudoTcp, null);
|
||||||
socket.close();
|
socket.close();
|
||||||
joinAllThreads();
|
joinAllThreads();
|
||||||
@ -851,6 +854,7 @@ class PseudoTcpSocketImpl
|
|||||||
* @param data The byte of data to send
|
* @param data The byte of data to send
|
||||||
* @throws IOException if there is an error sending the data.
|
* @throws IOException if there is an error sending the data.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void sendUrgentData(int data)
|
protected void sendUrgentData(int data)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
@ -908,7 +912,7 @@ class PseudoTcpSocketImpl
|
|||||||
public int read(byte[] buffer, int offset, int length)
|
public int read(byte[] buffer, int offset, int length)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
long start = System.currentTimeMillis();
|
long start = System.nanoTime();
|
||||||
int read;
|
int read;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@ -929,7 +933,7 @@ class PseudoTcpSocketImpl
|
|||||||
if (readTimeout > 0)
|
if (readTimeout > 0)
|
||||||
{
|
{
|
||||||
//Check for timeout
|
//Check for timeout
|
||||||
long elapsed = System.currentTimeMillis() - start;
|
long elapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
|
||||||
long left = readTimeout - elapsed;
|
long left = readTimeout - elapsed;
|
||||||
if (left <= 0)
|
if (left <= 0)
|
||||||
{
|
{
|
||||||
@ -1033,12 +1037,6 @@ class PseudoTcpSocketImpl
|
|||||||
write(bytes);
|
write(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(byte[] bytes) throws IOException
|
|
||||||
{
|
|
||||||
write(bytes, 0, bytes.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method blocks until all data has been written.
|
* This method blocks until all data has been written.
|
||||||
*
|
*
|
||||||
@ -1053,7 +1051,7 @@ class PseudoTcpSocketImpl
|
|||||||
{
|
{
|
||||||
int toSend = length;
|
int toSend = length;
|
||||||
int sent;
|
int sent;
|
||||||
long start = System.currentTimeMillis();
|
long start = System.nanoTime();
|
||||||
while (toSend > 0)
|
while (toSend > 0)
|
||||||
{
|
{
|
||||||
synchronized (pseudoTcp)
|
synchronized (pseudoTcp)
|
||||||
@ -1073,7 +1071,7 @@ class PseudoTcpSocketImpl
|
|||||||
{
|
{
|
||||||
if (writeTimeout > 0)
|
if (writeTimeout > 0)
|
||||||
{
|
{
|
||||||
long elapsed = System.currentTimeMillis() - start;
|
long elapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
|
||||||
long left = writeTimeout - elapsed;
|
long left = writeTimeout - elapsed;
|
||||||
if (left <= 0)
|
if (left <= 0)
|
||||||
{
|
{
|
||||||
@ -1121,7 +1119,7 @@ class PseudoTcpSocketImpl
|
|||||||
public synchronized void flush() throws IOException
|
public synchronized void flush() throws IOException
|
||||||
{
|
{
|
||||||
logger.log(Level.FINE, "Flushing...");
|
logger.log(Level.FINE, "Flushing...");
|
||||||
long start = System.currentTimeMillis();
|
long start = System.nanoTime();
|
||||||
final Object ackNotify = pseudoTcp.getAckNotify();
|
final Object ackNotify = pseudoTcp.getAckNotify();
|
||||||
synchronized (ackNotify)
|
synchronized (ackNotify)
|
||||||
{
|
{
|
||||||
@ -1132,7 +1130,7 @@ class PseudoTcpSocketImpl
|
|||||||
if (writeTimeout > 0)
|
if (writeTimeout > 0)
|
||||||
{
|
{
|
||||||
//Check write timeout
|
//Check write timeout
|
||||||
long elapsed = System.currentTimeMillis() - start;
|
long elapsed = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
|
||||||
long left = writeTimeout - elapsed;
|
long left = writeTimeout - elapsed;
|
||||||
if (left <= 0)
|
if (left <= 0)
|
||||||
{
|
{
|
||||||
@ -1160,6 +1158,7 @@ class PseudoTcpSocketImpl
|
|||||||
@Override
|
@Override
|
||||||
public void close() throws IOException
|
public void close() throws IOException
|
||||||
{
|
{
|
||||||
|
PseudoTcpSocketImpl.this.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -62,12 +62,12 @@ public class ByteFifoBuffer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method reads <tt>count</tt> bytes into <tt>out_buffer</tt>.
|
* Reads <tt>count</tt> bytes into <tt>out_buffer</tt>.
|
||||||
* Current read position is incremented by count of bytes
|
* Current read position is incremented by count of bytes
|
||||||
* that has been successfully read.
|
* that has been successfully read.
|
||||||
*
|
*
|
||||||
* @param out_buffer
|
* @param out_buffer read count bytes into this buffer
|
||||||
* @param count
|
* @param count number of bytes to read into the out_buffer
|
||||||
* @return bytes successfully read
|
* @return bytes successfully read
|
||||||
*/
|
*/
|
||||||
public int read(byte[] out_buffer, int count)
|
public int read(byte[] out_buffer, int count)
|
||||||
@ -77,8 +77,9 @@ public class ByteFifoBuffer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Read with buffer offset
|
* Read with buffer offset
|
||||||
* @param out_buffer
|
*
|
||||||
* @param buff_offset
|
* @param out_buffer read count bytes into this buffer
|
||||||
|
* @param buff_offset offset where to start writing into out_buffer
|
||||||
* @param count bytes to read
|
* @param count bytes to read
|
||||||
* @return read byte count
|
* @return read byte count
|
||||||
*/
|
*/
|
||||||
@ -95,8 +96,8 @@ public class ByteFifoBuffer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Limits <tt>desiredReadCount</tt> to count that is actually available
|
* Limits <tt>desiredReadCount</tt> to count that is actually available
|
||||||
* @param desiredReadCount
|
* @param desiredReadCount desired amount of bytes to read
|
||||||
* @return
|
* @return min(buffered, desiredReadCount)
|
||||||
*/
|
*/
|
||||||
private int readLimit(int desiredReadCount)
|
private int readLimit(int desiredReadCount)
|
||||||
{
|
{
|
||||||
@ -154,8 +155,8 @@ public class ByteFifoBuffer
|
|||||||
/**
|
/**
|
||||||
* Writes <tt>count</tt> of bytes from the <tt>buffer</tt>
|
* Writes <tt>count</tt> of bytes from the <tt>buffer</tt>
|
||||||
*
|
*
|
||||||
* @param buffer
|
* @param buffer data to write into the buffer
|
||||||
* @param count
|
* @param count number of bytes to read from the buffer
|
||||||
* @return bytes successfully written to buffer
|
* @return bytes successfully written to buffer
|
||||||
*/
|
*/
|
||||||
public int write(byte[] buffer, int count)
|
public int write(byte[] buffer, int count)
|
||||||
@ -164,10 +165,11 @@ public class ByteFifoBuffer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Writes data into the buffer.
|
||||||
*
|
*
|
||||||
* @param data source data
|
* @param data source data
|
||||||
* @param offset source buffer's offset
|
* @param offset source buffer's offset
|
||||||
* @param count
|
* @param count number of bytes to read from the buffer
|
||||||
* @return byte count actually read
|
* @return byte count actually read
|
||||||
*/
|
*/
|
||||||
public int write(byte[] data, int offset, int count)
|
public int write(byte[] data, int offset, int count)
|
||||||
@ -262,7 +264,7 @@ public class ByteFifoBuffer
|
|||||||
/**
|
/**
|
||||||
* Advances current buffer's write position by <tt>count</tt> bytes
|
* Advances current buffer's write position by <tt>count</tt> bytes
|
||||||
*
|
*
|
||||||
* @param count
|
* @param count number of bytes to move forward
|
||||||
*/
|
*/
|
||||||
public void consumeWriteBuffer(int count)
|
public void consumeWriteBuffer(int count)
|
||||||
throws IllegalArgumentException,
|
throws IllegalArgumentException,
|
||||||
@ -286,7 +288,7 @@ public class ByteFifoBuffer
|
|||||||
/**
|
/**
|
||||||
* Sets new buffer's capacity
|
* Sets new buffer's capacity
|
||||||
*
|
*
|
||||||
* @param new_size
|
* @param new_size number of bytes
|
||||||
* @return <tt>true</tt> if operation is possible to perform, that is if new
|
* @return <tt>true</tt> if operation is possible to perform, that is if new
|
||||||
* buffered data fits into new buffer
|
* buffered data fits into new buffer
|
||||||
*/
|
*/
|
||||||
@ -305,7 +307,7 @@ public class ByteFifoBuffer
|
|||||||
/**
|
/**
|
||||||
* Aligns current read position by <tt>count</tt>
|
* Aligns current read position by <tt>count</tt>
|
||||||
*
|
*
|
||||||
* @param count
|
* @param count number of bytes to move the read position
|
||||||
* @throws BufferUnderflowException if new position exceeds buffered data
|
* @throws BufferUnderflowException if new position exceeds buffered data
|
||||||
* count
|
* count
|
||||||
*/
|
*/
|
||||||
@ -332,7 +334,7 @@ public class ByteFifoBuffer
|
|||||||
/**
|
/**
|
||||||
* Reads <tt>count</tt> bytes from buffer without storing new read position
|
* Reads <tt>count</tt> bytes from buffer without storing new read position
|
||||||
*
|
*
|
||||||
* @param dst_buff
|
* @param dst_buff buffer to write the read data to
|
||||||
* @param dst_buff_offset offset of destination buffer
|
* @param dst_buff_offset offset of destination buffer
|
||||||
* @param count bytes to read
|
* @param count bytes to read
|
||||||
* @param offset from current read position
|
* @param offset from current read position
|
||||||
@ -358,8 +360,8 @@ public class ByteFifoBuffer
|
|||||||
* Writes <tt>count</tt> bytes from <tt>data</tt> to the buffer without
|
* Writes <tt>count</tt> bytes from <tt>data</tt> to the buffer without
|
||||||
* affecting buffer's write position
|
* affecting buffer's write position
|
||||||
*
|
*
|
||||||
* @param data
|
* @param data the data to write to the buffer
|
||||||
* @param count
|
* @param count number of bytes to read from data
|
||||||
* @param nOffset from buffer's write position
|
* @param nOffset from buffer's write position
|
||||||
* @return bytes successfully written
|
* @return bytes successfully written
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -27,7 +27,7 @@ import java.util.*;
|
|||||||
* possible users (such as STUN/TURN servers) or others that would only work
|
* possible users (such as STUN/TURN servers) or others that would only work
|
||||||
* with a few, like for example an ICE implementation.
|
* with a few, like for example an ICE implementation.
|
||||||
*
|
*
|
||||||
* @todo just throwing a user name at the manager and expecting it to find
|
* TODO: just throwing a user name at the manager and expecting it to find
|
||||||
* an authority that knows about it may lead to ambiguities so we may need
|
* an authority that knows about it may lead to ambiguities so we may need
|
||||||
* to add other parameters in here that would allow us to better select an
|
* to add other parameters in here that would allow us to better select an
|
||||||
* authority.
|
* authority.
|
||||||
|
|||||||
@ -36,12 +36,23 @@ public class DTLSDatagramFilter
|
|||||||
*/
|
*/
|
||||||
public static boolean isDTLS(DatagramPacket p)
|
public static boolean isDTLS(DatagramPacket p)
|
||||||
{
|
{
|
||||||
int len = p.getLength();
|
return p != null && isDTLS(p.getData(), p.getOffset(), p.getLength());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the buffer represented by {@code data}, {@code off}
|
||||||
|
* and {@code len} looks like a DTLS packet.
|
||||||
|
*
|
||||||
|
* @param data the array that contains the data.
|
||||||
|
* @param off the offset.
|
||||||
|
* @param len the length.
|
||||||
|
* @return {@code true} if the buffer looks like a DTLS packet; otherwise,
|
||||||
|
* {@code false}.
|
||||||
|
*/
|
||||||
|
public static boolean isDTLS(byte[] data, int off, int len)
|
||||||
|
{
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
{
|
{
|
||||||
byte[] data = p.getData();
|
|
||||||
int off = p.getOffset();
|
|
||||||
int fb = data[off] & 0xff;
|
int fb = data[off] & 0xff;
|
||||||
|
|
||||||
return 19 < fb && fb < 64;
|
return 19 < fb && fb < 64;
|
||||||
|
|||||||
@ -115,6 +115,11 @@ public class DelegatingDatagramSocket
|
|||||||
*/
|
*/
|
||||||
private long nbSentPackets = 0;
|
private long nbSentPackets = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this socket has been closed.
|
||||||
|
*/
|
||||||
|
private boolean closed = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a new <tt>DelegatingDatagramSocket</tt> instance and binds it
|
* Initializes a new <tt>DelegatingDatagramSocket</tt> instance and binds it
|
||||||
* to any available port on the local host machine. The socket will be
|
* to any available port on the local host machine. The socket will be
|
||||||
@ -282,10 +287,14 @@ public class DelegatingDatagramSocket
|
|||||||
@Override
|
@Override
|
||||||
public void close()
|
public void close()
|
||||||
{
|
{
|
||||||
if (delegate == null)
|
// We want both #delegate and super to actually get closed (and release
|
||||||
super.close();
|
// the FDs which they hold). But super will not close unless isClosed()
|
||||||
else
|
// returns false. So we update the #closed flag last.
|
||||||
|
if (delegate != null)
|
||||||
delegate.close();
|
delegate.close();
|
||||||
|
|
||||||
|
super.close();
|
||||||
|
closed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -610,7 +619,7 @@ public class DelegatingDatagramSocket
|
|||||||
@Override
|
@Override
|
||||||
public boolean isClosed()
|
public boolean isClosed()
|
||||||
{
|
{
|
||||||
return (delegate == null) ? super.isClosed() : delegate.isClosed();
|
return closed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -662,6 +671,12 @@ public class DelegatingDatagramSocket
|
|||||||
// after the first packet is received, the length is set to the size
|
// after the first packet is received, the length is set to the size
|
||||||
// of the first packet and the second packet is truncated.
|
// of the first packet and the second packet is truncated.
|
||||||
// http://docs.oracle.com/javase/6/docs/api/java/net/DatagramSocket.html
|
// http://docs.oracle.com/javase/6/docs/api/java/net/DatagramSocket.html
|
||||||
|
//
|
||||||
|
// XXX(boris): I think the above is wrong. I don't interpret the
|
||||||
|
// API description this way, and testing on a couple of different
|
||||||
|
// environments shows that DatagramSocket.receive() grows the
|
||||||
|
// packet's length to as much as much as the array (and offset)
|
||||||
|
// would allow. I am leaving the code because it seems harmless.
|
||||||
byte[] data = p.getData();
|
byte[] data = p.getData();
|
||||||
|
|
||||||
p.setLength((data == null) ? 0 : (data.length - p.getOffset()));
|
p.setLength((data == null) ? 0 : (data.length - p.getOffset()));
|
||||||
@ -740,7 +755,10 @@ public class DelegatingDatagramSocket
|
|||||||
p.setAddress(newAddr);
|
p.setAddress(newAddr);
|
||||||
|
|
||||||
super.send(p);
|
super.send(p);
|
||||||
|
}
|
||||||
|
else if (ex instanceof IOException)
|
||||||
|
{
|
||||||
|
throw((IOException)ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -47,7 +47,7 @@ public class DelegatingServerSocket
|
|||||||
*
|
*
|
||||||
* @param delegate the {@code ServerSocket} the new instance is to delegate
|
* @param delegate the {@code ServerSocket} the new instance is to delegate
|
||||||
* (it method calls) to
|
* (it method calls) to
|
||||||
* @throws IOException
|
* @throws IOException never thrown
|
||||||
*/
|
*/
|
||||||
public DelegatingServerSocket(ServerSocket delegate)
|
public DelegatingServerSocket(ServerSocket delegate)
|
||||||
throws IOException
|
throws IOException
|
||||||
@ -64,7 +64,7 @@ public class DelegatingServerSocket
|
|||||||
* (it method calls) to
|
* (it method calls) to
|
||||||
* @param channel the {@code ServerSocketChannel} to be reported by the new
|
* @param channel the {@code ServerSocketChannel} to be reported by the new
|
||||||
* instance or {@code null} to report the one of {@code delegate}
|
* instance or {@code null} to report the one of {@code delegate}
|
||||||
* @throws IOException
|
* @throws IOException never thrown
|
||||||
*/
|
*/
|
||||||
public DelegatingServerSocket(
|
public DelegatingServerSocket(
|
||||||
ServerSocket delegate,
|
ServerSocket delegate,
|
||||||
|
|||||||
@ -155,8 +155,9 @@ public class DelegatingSocket
|
|||||||
/**
|
/**
|
||||||
* Initializes a new <tt>DelegatingSocket</tt>.
|
* Initializes a new <tt>DelegatingSocket</tt>.
|
||||||
*
|
*
|
||||||
* @param address
|
* @param address ignored
|
||||||
* @param port
|
* @param port ignored
|
||||||
|
* @throws IOException never thrown
|
||||||
* @see Socket#Socket(InetAddress, int)
|
* @see Socket#Socket(InetAddress, int)
|
||||||
*/
|
*/
|
||||||
public DelegatingSocket(InetAddress address, int port)
|
public DelegatingSocket(InetAddress address, int port)
|
||||||
@ -168,11 +169,12 @@ public class DelegatingSocket
|
|||||||
/**
|
/**
|
||||||
* Initializes a new <tt>DelegatingSocket</tt>.
|
* Initializes a new <tt>DelegatingSocket</tt>.
|
||||||
*
|
*
|
||||||
* @param address
|
* @param address ignored
|
||||||
* @param port
|
* @param port ignored
|
||||||
* @param localAddr
|
* @param localAddr ignored
|
||||||
* @param localPort
|
* @param localPort ignored
|
||||||
* @see Socket#Socket(InetAddress, int, InetAddress, int)
|
* @see Socket#Socket(InetAddress, int, InetAddress, int)
|
||||||
|
* @throws IOException never thrown
|
||||||
*/
|
*/
|
||||||
public DelegatingSocket(
|
public DelegatingSocket(
|
||||||
InetAddress address, int port,
|
InetAddress address, int port,
|
||||||
@ -185,7 +187,7 @@ public class DelegatingSocket
|
|||||||
/**
|
/**
|
||||||
* Initializes a new <tt>DelegatingSocket</tt>.
|
* Initializes a new <tt>DelegatingSocket</tt>.
|
||||||
*
|
*
|
||||||
* @param proxy
|
* @param proxy ignored
|
||||||
* @see Socket#Socket(Proxy)
|
* @see Socket#Socket(Proxy)
|
||||||
*/
|
*/
|
||||||
public DelegatingSocket(Proxy proxy)
|
public DelegatingSocket(Proxy proxy)
|
||||||
@ -243,7 +245,8 @@ public class DelegatingSocket
|
|||||||
/**
|
/**
|
||||||
* Initializes a new <tt>DelegatingSocket</tt>.
|
* Initializes a new <tt>DelegatingSocket</tt>.
|
||||||
*
|
*
|
||||||
* @param impl
|
* @param impl ignored
|
||||||
|
* @throws SocketException never thrown
|
||||||
* @see Socket#Socket(SocketImpl)
|
* @see Socket#Socket(SocketImpl)
|
||||||
*/
|
*/
|
||||||
protected DelegatingSocket(SocketImpl impl)
|
protected DelegatingSocket(SocketImpl impl)
|
||||||
@ -255,8 +258,10 @@ public class DelegatingSocket
|
|||||||
/**
|
/**
|
||||||
* Initializes a new <tt>DelegatingSocket</tt>.
|
* Initializes a new <tt>DelegatingSocket</tt>.
|
||||||
*
|
*
|
||||||
* @param host
|
* @param host ignored
|
||||||
* @param port
|
* @param port ignored
|
||||||
|
* @throws UnknownHostException never thrown
|
||||||
|
* @throws IOException never thrown
|
||||||
* @see Socket#Socket(String, int)
|
* @see Socket#Socket(String, int)
|
||||||
*/
|
*/
|
||||||
public DelegatingSocket(String host, int port)
|
public DelegatingSocket(String host, int port)
|
||||||
@ -268,10 +273,10 @@ public class DelegatingSocket
|
|||||||
/**
|
/**
|
||||||
* Initializes a new <tt>DelegatingSocket</tt>.
|
* Initializes a new <tt>DelegatingSocket</tt>.
|
||||||
*
|
*
|
||||||
* @param host
|
* @param host ignored
|
||||||
* @param port
|
* @param port ignored
|
||||||
* @param localAddr
|
* @param localAddr ignored
|
||||||
* @param localPort
|
* @param localPort ignored
|
||||||
* @see Socket#Socket(String, int, InetAddress, int)
|
* @see Socket#Socket(String, int, InetAddress, int)
|
||||||
*/
|
*/
|
||||||
public DelegatingSocket(
|
public DelegatingSocket(
|
||||||
|
|||||||
@ -140,7 +140,7 @@ public class HttpDemuxFilter
|
|||||||
{
|
{
|
||||||
byte[] buf = p.getData();
|
byte[] buf = p.getData();
|
||||||
int off = p.getOffset();
|
int off = p.getOffset();
|
||||||
// The first bytes of HTTP, SSL v2, and TCP are different so quickly
|
// The first bytes of HTTP, SSL v2, and TLS are different so quickly
|
||||||
// determine which one of the three is possible and, respectively,
|
// determine which one of the three is possible and, respectively,
|
||||||
// which two of the three are impossible.
|
// which two of the three are impossible.
|
||||||
int b0 = 0xFF & buf[off];
|
int b0 = 0xFF & buf[off];
|
||||||
@ -199,7 +199,7 @@ public class HttpDemuxFilter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Only one of HTTP, SSL v2, and TCP was deemed possible by
|
// Only one of HTTP, SSL v2, and TLS was deemed possible by
|
||||||
// looking at the first byte. If p didn't look like HTTP here,
|
// looking at the first byte. If p didn't look like HTTP here,
|
||||||
// then it will not look like SSL v2 or TLS.
|
// then it will not look like SSL v2 or TLS.
|
||||||
return accept;
|
return accept;
|
||||||
@ -230,7 +230,7 @@ public class HttpDemuxFilter
|
|||||||
accept = true;
|
accept = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Only one of HTTP, SSL v2, and TCP was deemed possible by
|
// Only one of HTTP, SSL v2, and TLS was deemed possible by
|
||||||
// looking at the first byte. If p didn't look like TLS here,
|
// looking at the first byte. If p didn't look like TLS here,
|
||||||
// then it will not look like HTTP or SSL v2.
|
// then it will not look like HTTP or SSL v2.
|
||||||
return accept;
|
return accept;
|
||||||
@ -268,7 +268,7 @@ public class HttpDemuxFilter
|
|||||||
accept = !equals;
|
accept = !equals;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Only one of HTTP, SSL v2, and TCP was deemed possible by
|
// Only one of HTTP, SSL v2, and TLS was deemed possible by
|
||||||
// looking at the first byte. If p didn't look like SSL v2 here,
|
// looking at the first byte. If p didn't look like SSL v2 here,
|
||||||
// then it will not look like HTTP or TLS.
|
// then it will not look like HTTP or TLS.
|
||||||
return accept;
|
return accept;
|
||||||
|
|||||||
@ -195,6 +195,12 @@ public class IceTcpServerSocketWrapper
|
|||||||
component.getParentStream().getParentAgent().
|
component.getParentStream().getParentAgent().
|
||||||
getStunStack().addSocket(
|
getStunStack().addSocket(
|
||||||
new IceTcpSocketWrapper(multiplexingSocket));
|
new IceTcpSocketWrapper(multiplexingSocket));
|
||||||
|
ComponentSocket componentSocket
|
||||||
|
= component.getComponentSocket();
|
||||||
|
if (componentSocket != null)
|
||||||
|
{
|
||||||
|
componentSocket.add(multiplexingSocket);
|
||||||
|
}
|
||||||
|
|
||||||
sockets.add(multiplexingSocket);
|
sockets.add(multiplexingSocket);
|
||||||
}
|
}
|
||||||
|
|||||||
1101
src/main/java/org/ice4j/socket/MergingDatagramSocket.java
Normal file
1101
src/main/java/org/ice4j/socket/MergingDatagramSocket.java
Normal file
File diff suppressed because it is too large
Load Diff
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