Author: toad
Date: 2006-06-23 20:45:44 +0000 (Fri, 23 Jun 2006)
New Revision: 9375
Added:
trunk/plugins/jSTUN/bin/
trunk/plugins/jSTUN/bin/de/
trunk/plugins/jSTUN/bin/de/javawi/
trunk/plugins/jSTUN/bin/de/javawi/jstun/
trunk/plugins/jSTUN/bin/de/javawi/jstun/AllTests.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/ChangeRequest.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/ChangedAddress.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/Dummy.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/ErrorCode.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MappedAddress.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MappedAddressTest.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MappedResponseChangedSourceAddressReflectedFrom.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MessageAttribute.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MessageAttributeException.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MessageAttributeInterface.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MessageAttributeParsingException.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MessageIntegrity.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/Password.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/ReflectedFrom.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/ResponseAddress.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/SourceAddress.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/UnknownAttribute.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/Username.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/header/
trunk/plugins/jSTUN/bin/de/javawi/jstun/header/MessageHeader.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/header/MessageHeaderException.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/header/MessageHeaderInterface.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/header/MessageHeaderParsingException.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/test/
trunk/plugins/jSTUN/bin/de/javawi/jstun/test/BindingLifetimeTest$BindingLifetimeTask.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/test/BindingLifetimeTest.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/test/DiscoveryInfo.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/test/DiscoveryTest.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/test/demo/
trunk/plugins/jSTUN/bin/de/javawi/jstun/test/demo/BindingLifetimeTestDemo.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/test/demo/DiscoveryTestDemo.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/util/
trunk/plugins/jSTUN/bin/de/javawi/jstun/util/Address.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/util/AddressTest.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/util/Utility.class
trunk/plugins/jSTUN/bin/de/javawi/jstun/util/UtilityException.class
trunk/plugins/jSTUN/gpl.txt
trunk/plugins/jSTUN/src/
trunk/plugins/jSTUN/src/de/
trunk/plugins/jSTUN/src/de/javawi/
trunk/plugins/jSTUN/src/de/javawi/jstun/
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ChangeRequest.java
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ChangedAddress.java
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/Dummy.java
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ErrorCode.java
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MappedAddress.java
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MappedResponseChangedSourceAddressReflectedFrom.java
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageAttribute.java
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageAttributeException.java
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageAttributeInterface.java
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageAttributeParsingException.java
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageIntegrity.java
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/Password.java
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ReflectedFrom.java
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ResponseAddress.java
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/SourceAddress.java
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/UnknownAttribute.java
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/Username.java
trunk/plugins/jSTUN/src/de/javawi/jstun/header/
trunk/plugins/jSTUN/src/de/javawi/jstun/header/MessageHeader.java
trunk/plugins/jSTUN/src/de/javawi/jstun/header/MessageHeaderException.java
trunk/plugins/jSTUN/src/de/javawi/jstun/header/MessageHeaderInterface.java
trunk/plugins/jSTUN/src/de/javawi/jstun/header/MessageHeaderParsingException.java
trunk/plugins/jSTUN/src/de/javawi/jstun/test/
trunk/plugins/jSTUN/src/de/javawi/jstun/test/BindingLifetimeTest.java
trunk/plugins/jSTUN/src/de/javawi/jstun/test/DiscoveryInfo.java
trunk/plugins/jSTUN/src/de/javawi/jstun/test/DiscoveryTest.java
trunk/plugins/jSTUN/src/de/javawi/jstun/test/demo/
trunk/plugins/jSTUN/src/de/javawi/jstun/test/demo/BindingLifetimeTestDemo.java
trunk/plugins/jSTUN/src/de/javawi/jstun/test/demo/DiscoveryTestDemo.java
trunk/plugins/jSTUN/src/de/javawi/jstun/util/
trunk/plugins/jSTUN/src/de/javawi/jstun/util/Address.java
trunk/plugins/jSTUN/src/de/javawi/jstun/util/Utility.java
trunk/plugins/jSTUN/src/de/javawi/jstun/util/UtilityException.java
trunk/plugins/jSTUN/test/
trunk/plugins/jSTUN/test/de/
trunk/plugins/jSTUN/test/de/javawi/
trunk/plugins/jSTUN/test/de/javawi/jstun/
trunk/plugins/jSTUN/test/de/javawi/jstun/AllTests.java
trunk/plugins/jSTUN/test/de/javawi/jstun/attribute/
trunk/plugins/jSTUN/test/de/javawi/jstun/attribute/MappedAddressTest.java
trunk/plugins/jSTUN/test/de/javawi/jstun/util/
trunk/plugins/jSTUN/test/de/javawi/jstun/util/AddressTest.java
Log:
commit jstun source
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/AllTests.class
===================================================================
(Binary files differ)
Property changes on: trunk/plugins/jSTUN/bin/de/javawi/jstun/AllTests.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/ChangeRequest.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/ChangeRequest.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/ChangedAddress.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/ChangedAddress.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/Dummy.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/Dummy.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/ErrorCode.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/ErrorCode.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MappedAddress.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MappedAddress.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MappedAddressTest.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MappedAddressTest.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MappedResponseChangedSourceAddressReflectedFrom.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MappedResponseChangedSourceAddressReflectedFrom.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MessageAttribute.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MessageAttribute.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MessageAttributeException.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MessageAttributeException.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MessageAttributeInterface.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MessageAttributeInterface.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MessageAttributeParsingException.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MessageAttributeParsingException.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MessageIntegrity.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/MessageIntegrity.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/Password.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/Password.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/ReflectedFrom.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/ReflectedFrom.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/ResponseAddress.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/ResponseAddress.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/SourceAddress.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/SourceAddress.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/UnknownAttribute.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/UnknownAttribute.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/Username.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/attribute/Username.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/header/MessageHeader.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/header/MessageHeader.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
trunk/plugins/jSTUN/bin/de/javawi/jstun/header/MessageHeaderException.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/header/MessageHeaderException.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
trunk/plugins/jSTUN/bin/de/javawi/jstun/header/MessageHeaderInterface.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/header/MessageHeaderInterface.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
trunk/plugins/jSTUN/bin/de/javawi/jstun/header/MessageHeaderParsingException.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/header/MessageHeaderParsingException.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
trunk/plugins/jSTUN/bin/de/javawi/jstun/test/BindingLifetimeTest$BindingLifetimeTask.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/test/BindingLifetimeTest$BindingLifetimeTask.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/test/BindingLifetimeTest.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/test/BindingLifetimeTest.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/test/DiscoveryInfo.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/test/DiscoveryInfo.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/test/DiscoveryTest.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/test/DiscoveryTest.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
trunk/plugins/jSTUN/bin/de/javawi/jstun/test/demo/BindingLifetimeTestDemo.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/test/demo/BindingLifetimeTestDemo.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/test/demo/DiscoveryTestDemo.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/test/demo/DiscoveryTestDemo.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/util/Address.class
===================================================================
(Binary files differ)
Property changes on: trunk/plugins/jSTUN/bin/de/javawi/jstun/util/Address.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/util/AddressTest.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/util/AddressTest.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/util/Utility.class
===================================================================
(Binary files differ)
Property changes on: trunk/plugins/jSTUN/bin/de/javawi/jstun/util/Utility.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/bin/de/javawi/jstun/util/UtilityException.class
===================================================================
(Binary files differ)
Property changes on:
trunk/plugins/jSTUN/bin/de/javawi/jstun/util/UtilityException.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/jSTUN/gpl.txt
===================================================================
--- trunk/plugins/jSTUN/gpl.txt 2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/gpl.txt 2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ChangeRequest.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ChangeRequest.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ChangeRequest.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,89 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.attribute;
+
+import de.javawi.jstun.util.*;
+
+public class ChangeRequest extends MessageAttribute {
+ /*
+ * 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
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |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|
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+ boolean changeIP = false;
+ boolean changePort = false;
+
+ public ChangeRequest() {
+ super(MessageAttribute.MessageAttributeType.ChangeRequest);
+ }
+
+ public boolean isChangeIP() {
+ return changeIP;
+ }
+
+ public boolean isChangePort() {
+ return changePort;
+ }
+
+ public void setChangeIP() {
+ changeIP = true;
+ }
+
+ public void setChangePort() {
+ changePort = true;
+ }
+
+ public byte[] getBytes() throws UtilityException {
+ byte[] result = new byte[8];
+ // message attribute header
+ // type
+
System.arraycopy(Utility.IntegerToTwoBytes(typeToInteger(type)), 0, result, 0,
2);
+ // length
+ System.arraycopy(Utility.IntegerToTwoBytes(4), 0, result, 2, 2);
+
+ // change request header
+ if (changeIP) result[7] = Utility.IntegerToOneByte(4);
+ if (changePort) result[7] = Utility.IntegerToOneByte(2);
+ if (changeIP && changePort) result[7] =
Utility.IntegerToOneByte(6);
+ return result;
+ }
+
+ public static ChangeRequest parse(byte[] data) throws
MessageAttributeParsingException {
+ try {
+ if (data.length < 4) {
+ throw new
MessageAttributeParsingException("Data array too short");
+ }
+ ChangeRequest cr = new ChangeRequest();
+ int status = Utility.OneByteToInteger(data[3]);
+ switch (status) {
+ case 2: cr.setChangePort(); break;
+ case 4: cr.setChangeIP(); break;
+ case 6: cr.setChangeIP(); cr.setChangePort(); break;
+ default: throw new
MessageAttributeParsingException("Status parsing error");
+ }
+ return cr;
+ } catch (UtilityException ue) {
+ throw new MessageAttributeParsingException("Parsing
error");
+ }
+ }
+}
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ChangedAddress.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ChangedAddress.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ChangedAddress.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,38 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.attribute;
+
+import java.util.logging.Logger;
+
+
+public class ChangedAddress extends
MappedResponseChangedSourceAddressReflectedFrom {
+ private static Logger logger =
Logger.getLogger("de.javawi.stun.attribute.ChangedAddress");
+ public ChangedAddress() {
+ super(MessageAttribute.MessageAttributeType.ChangedAddress);
+ }
+
+ public static MessageAttribute parse(byte[] data) throws
MessageAttributeParsingException {
+ ChangedAddress ca = new ChangedAddress();
+ MappedResponseChangedSourceAddressReflectedFrom.parse(ca, data);
+ logger.finer("Message Attribute: Changed Address parsed: " +
ca.toString() + ".");
+ return ca;
+ }
+}
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/Dummy.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/Dummy.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/Dummy.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,51 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.attribute;
+
+import de.javawi.jstun.util.Utility;
+import de.javawi.jstun.util.UtilityException;
+
+public class Dummy extends MessageAttribute {
+ int lengthValue;
+ public Dummy() {
+ super(MessageAttributeType.Dummy);
+ }
+
+ public void setLengthValue(int length) {
+ this.lengthValue = length;
+ }
+
+ public byte[] getBytes() throws UtilityException {
+ byte[] result = new byte[lengthValue + 4];
+ // message attribute header
+ // type
+
System.arraycopy(Utility.IntegerToTwoBytes(typeToInteger(type)), 0, result, 0,
2);
+ // length
+ System.arraycopy(Utility.IntegerToTwoBytes(lengthValue), 0,
result, 2, 2);
+ return result;
+ }
+
+ public static Dummy parse(byte[] data) {
+ Dummy dummy = new Dummy();
+ dummy.setLengthValue(data.length);
+ return dummy;
+ }
+}
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ErrorCode.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ErrorCode.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ErrorCode.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,113 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.attribute;
+
+import de.javawi.jstun.util.Utility;
+import de.javawi.jstun.util.UtilityException;
+
+public class ErrorCode extends MessageAttribute {
+ /*
+ * 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
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | 0 |Class| Number |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Reason Phrase (variable) ..
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+
+ int responseCode;
+ String reason;
+
+ public ErrorCode() {
+ super(MessageAttribute.MessageAttributeType.ErrorCode);
+ }
+
+ public void setResponseCode(int responseCode) throws
MessageAttributeException {
+ switch (responseCode) {
+ case 400: reason = "Bad Request"; break;
+ case 401: reason = "Unauthorized"; break;
+ case 420: reason = "Unkown Attribute"; break;
+ case 430: reason = "Stale Credentials"; break;
+ case 431: reason = "Integrity Check Failure"; break;
+ case 432: reason = "Missing Username"; break;
+ case 433: reason = "Use TLS"; break;
+ case 500: reason = "Server Error"; break;
+ case 600: reason = "Global Failure"; break;
+ default: throw new MessageAttributeException("Response Code is
not valid");
+ }
+ this.responseCode = responseCode;
+ }
+
+ public int getResponseCode() {
+ return responseCode;
+ }
+
+ public String getReason() {
+ return reason;
+ }
+
+ public byte[] getBytes() throws UtilityException {
+ int length = reason.length();
+ // length adjustment
+ if ((length % 4) != 0) {
+ length += 4 - (length % 4);
+ }
+ // message attribute header
+ length += 4;
+ byte[] result = new byte[length];
+ // message attribute header
+ // type
+
System.arraycopy(Utility.IntegerToTwoBytes(typeToInteger(type)), 0, result, 0,
2);
+ // length
+ System.arraycopy(Utility.IntegerToTwoBytes(length-4), 0,
result, 2, 2);
+
+ // error code header
+ int classHeader = (int) Math.floor(((double)responseCode)/100);
+ result[6] = Utility.IntegerToOneByte(classHeader);
+ result[7] = Utility.IntegerToOneByte(responseCode%100);
+ byte[] reasonArray = reason.getBytes();
+ System.arraycopy(reasonArray, 0, result, 8,
reasonArray.length);
+ return result;
+ }
+
+ public static ErrorCode parse(byte[] data) throws
MessageAttributeParsingException {
+ try {
+ if (data.length < 4) {
+ throw new
MessageAttributeParsingException("Data array too short");
+ }
+ byte classHeaderByte = data[3];
+ int classHeader =
Utility.OneByteToInteger(classHeaderByte);
+ if ((classHeader < 1) || (classHeader > 6)) throw new
MessageAttributeParsingException("Class parsing error");
+ byte numberByte = data[4];
+ int number = Utility.OneByteToInteger(numberByte);
+ if ((number < 0) || (number > 99)) throw new
MessageAttributeParsingException("Number parsing error");
+ int responseCode = (classHeader * 100) + number;
+ ErrorCode result = new ErrorCode();
+ result.setResponseCode(responseCode);
+ return result;
+ } catch (UtilityException ue) {
+ throw new MessageAttributeParsingException("Parsing
error");
+ } catch (MessageAttributeException mae) {
+ throw new MessageAttributeParsingException("Parsing
error");
+ }
+ }
+}
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MappedAddress.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MappedAddress.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MappedAddress.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,38 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.attribute;
+
+import java.util.logging.Logger;
+
+
+public class MappedAddress extends
MappedResponseChangedSourceAddressReflectedFrom {
+ private static Logger logger =
Logger.getLogger("de.javawi.stun.attribute.MappedAddress");
+ public MappedAddress() {
+ super(MessageAttribute.MessageAttributeType.MappedAddress);
+ }
+
+ public static MessageAttribute parse(byte[] data) throws
MessageAttributeParsingException {
+ MappedAddress ma = new MappedAddress();
+ MappedResponseChangedSourceAddressReflectedFrom.parse(ma, data);
+ logger.finer("Message Attribute: Mapped Address parsed: " +
ma.toString() + ".");
+ return ma;
+ }
+}
Added:
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MappedResponseChangedSourceAddressReflectedFrom.java
===================================================================
---
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MappedResponseChangedSourceAddressReflectedFrom.java
2006-06-23 20:42:40 UTC (rev 9374)
+++
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MappedResponseChangedSourceAddressReflectedFrom.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,116 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.attribute;
+
+import de.javawi.jstun.util.*;
+
+public class MappedResponseChangedSourceAddressReflectedFrom extends
MessageAttribute {
+ int port;
+ Address address;
+
+ /*
+ * 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
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |x x x x x x x x| Family | Port |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Address |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+ public MappedResponseChangedSourceAddressReflectedFrom() {
+ super();
+ try {
+ port = 0;
+ address = new Address("0.0.0.0");
+ } catch (UtilityException ue) {
+ ue.getMessage();
+ ue.printStackTrace();
+ }
+ }
+
+ public
MappedResponseChangedSourceAddressReflectedFrom(MessageAttribute.MessageAttributeType
type) {
+ super(type);
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public Address getAddress() {
+ return address;
+ }
+
+ public void setPort(int port) throws MessageAttributeException {
+ if ((port > 65536) || (port < 0)) {
+ throw new MessageAttributeException("Port value " +
port + " out of range.");
+ }
+ this.port = port;
+ }
+
+ public void setAddress(Address address) {
+ this.address = address;
+ }
+
+ public byte[] getBytes() throws UtilityException {
+ byte[] result = new byte[12];
+ // message attribute header
+ // type
+
System.arraycopy(Utility.IntegerToTwoBytes(typeToInteger(type)), 0, result, 0,
2);
+ // length
+ System.arraycopy(Utility.IntegerToTwoBytes(8), 0, result, 2, 2);
+
+ // mappedaddress header
+ // family
+ result[5] = Utility.IntegerToOneByte(0x01);
+ // port
+ System.arraycopy(Utility.IntegerToTwoBytes(port), 0, result, 6,
2);
+ // address
+ System.arraycopy(address.getBytes(), 0, result, 8, 4);
+ return result;
+ }
+
+ protected static MappedResponseChangedSourceAddressReflectedFrom
parse(MappedResponseChangedSourceAddressReflectedFrom ma, byte[] data) throws
MessageAttributeParsingException {
+ try {
+ if (data.length < 8) {
+ throw new
MessageAttributeParsingException("Data array too short");
+ }
+ int family = Utility.OneByteToInteger(data[1]);
+ if (family != 0x01) throw new
MessageAttributeParsingException("Family " + family + " is not supported");
+ byte[] portArray = new byte[2];
+ System.arraycopy(data, 2, portArray, 0, 2);
+ ma.setPort(Utility.TwoBytesToInteger(portArray));
+ int firstOctet = Utility.OneByteToInteger(data[4]);
+ int secondOctet = Utility.OneByteToInteger(data[5]);
+ int thirdOctet = Utility.OneByteToInteger(data[6]);
+ int fourthOctet = Utility.OneByteToInteger(data[7]);
+ ma.setAddress(new Address(firstOctet, secondOctet,
thirdOctet, fourthOctet));
+ return ma;
+ } catch (UtilityException ue) {
+ throw new MessageAttributeParsingException("Parsing
error");
+ } catch (MessageAttributeException mae) {
+ throw new MessageAttributeParsingException("Port
parsing error");
+ }
+ }
+
+ public String toString() {
+ return "Address " +address.toString() + ", Port " + port;
+ }
+}
\ No newline at end of file
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageAttribute.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageAttribute.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageAttribute.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,118 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.attribute;
+
+import java.util.logging.*;
+
+import de.javawi.jstun.util.*;
+
+
+public abstract class MessageAttribute implements MessageAttributeInterface {
+ private static Logger logger =
Logger.getLogger("de.javawi.stun.util.MessageAttribute");
+ MessageAttributeType type;
+ int length;
+
+ public MessageAttribute() {
+ }
+
+ public MessageAttribute(MessageAttributeType type) {
+ setType(type);
+ }
+
+ public void setType(MessageAttributeType type) {
+ this.type = type;
+ }
+
+ public MessageAttribute.MessageAttributeType getType() {
+ return type;
+ }
+
+ public static int typeToInteger(MessageAttributeType type) {
+ if (type == MessageAttributeType.MappedAddress) return
MAPPEDADDRESS;
+ if (type == MessageAttributeType.ResponseAddress) return
RESPONSEADDRESS;
+ if (type == MessageAttributeType.ChangeRequest) return
CHANGEREQUEST;
+ if (type == MessageAttributeType.SourceAddress) return
SOURCEADDRESS;
+ if (type == MessageAttributeType.ChangedAddress) return
CHANGEDADDRESS;
+ if (type == MessageAttributeType.Username) return USERNAME;
+ if (type == MessageAttributeType.Password) return PASSWORD;
+ if (type == MessageAttributeType.MessageIntegrity) return
MESSAGEINTEGRITY;
+ if (type == MessageAttributeType.ErrorCode) return ERRORCODE;
+ if (type == MessageAttributeType.UnknownAttribute) return
UNKNOWNATTRIBUTE;
+ if (type == MessageAttributeType.ReflectedFrom) return
REFLECTEDFROM;
+ if (type == MessageAttributeType.Dummy) return DUMMY;
+ return -1;
+ }
+
+ public static MessageAttributeType intToType(long type) {
+ if (type == MAPPEDADDRESS) return
MessageAttributeType.MappedAddress;
+ if (type == RESPONSEADDRESS) return
MessageAttributeType.ResponseAddress;
+ if (type == CHANGEREQUEST) return
MessageAttributeType.ChangeRequest;
+ if (type == SOURCEADDRESS) return
MessageAttributeType.SourceAddress;
+ if (type == CHANGEDADDRESS) return
MessageAttributeType.ChangedAddress;
+ if (type == USERNAME) return MessageAttributeType.Username;
+ if (type == PASSWORD) return MessageAttributeType.Password;
+ if (type == MESSAGEINTEGRITY) return
MessageAttributeType.MessageIntegrity;
+ if (type == ERRORCODE) return MessageAttributeType.ErrorCode;
+ if (type == UNKNOWNATTRIBUTE) return
MessageAttributeType.UnknownAttribute;
+ if (type == REFLECTEDFROM ) return
MessageAttributeType.ReflectedFrom;
+ if (type == DUMMY ) return MessageAttributeType.Dummy;
+ return MessageAttributeType.Dummy;
+ }
+
+ abstract public byte[] getBytes() throws UtilityException;
+ //abstract public MessageAttribute parse(byte[] data) throws
MessageAttributeParsingException;
+
+ public int getLength() throws UtilityException {
+ int length = getBytes().length;
+ return length;
+ }
+
+ public static MessageAttribute parseCommonHeader(byte[] data) throws
MessageAttributeParsingException {
+ try {
+ byte[] typeArray = new byte[2];
+ System.arraycopy(data, 0, typeArray, 0, 2);
+ int type = Utility.TwoBytesToInteger(typeArray);
+ byte[] lengthArray = new byte[2];
+ System.arraycopy(data, 2, lengthArray, 0, 2);
+ int lengthValue =
Utility.TwoBytesToInteger(lengthArray);
+ byte[] valueArray = new byte[lengthValue];
+ System.arraycopy(data, 4, valueArray, 0, lengthValue);
+ MessageAttribute ma;
+ switch (type) {
+ case MAPPEDADDRESS: ma =
MappedAddress.parse(valueArray); break;
+ case RESPONSEADDRESS: ma =
ResponseAddress.parse(valueArray); break;
+ case CHANGEREQUEST: ma =
ChangeRequest.parse(valueArray); break;
+ case SOURCEADDRESS: ma =
SourceAddress.parse(valueArray); break;
+ case CHANGEDADDRESS: ma =
ChangedAddress.parse(valueArray); break;
+ case USERNAME: ma = Username.parse(valueArray); break;
+ case PASSWORD: ma = Password.parse(valueArray); break;
+ case MESSAGEINTEGRITY: ma =
MessageIntegrity.parse(valueArray); break;
+ case ERRORCODE: ma = ErrorCode.parse(valueArray); break;
+ case UNKNOWNATTRIBUTE: ma =
UnknownAttribute.parse(valueArray); break;
+ case REFLECTEDFROM: ma =
ReflectedFrom.parse(valueArray); break;
+ default: logger.config("MessageAttribute with type " +
type + " unkown" + "."); ma = Dummy.parse(valueArray); break;
+ }
+ return ma;
+ } catch (UtilityException ue) {
+ throw new MessageAttributeParsingException("Parsing
Error");
+ }
+ }
+}
Added:
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageAttributeException.java
===================================================================
---
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageAttributeException.java
2006-06-23 20:42:40 UTC (rev 9374)
+++
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageAttributeException.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,29 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.attribute;
+
+public class MessageAttributeException extends Exception {
+ private static final long serialVersionUID = 3258131345099404850L;
+
+ public MessageAttributeException(String mesg) {
+ super(mesg);
+ }
+}
\ No newline at end of file
Added:
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageAttributeInterface.java
===================================================================
---
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageAttributeInterface.java
2006-06-23 20:42:40 UTC (rev 9374)
+++
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageAttributeInterface.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,37 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.attribute;
+
+public interface MessageAttributeInterface {
+ public enum MessageAttributeType { Dummy, MappedAddress,
ResponseAddress, ChangeRequest, SourceAddress, ChangedAddress, Username,
Password, MessageIntegrity, ErrorCode, UnknownAttribute, ReflectedFrom };
+ final static int DUMMY = 0x0000;
+ final static int MAPPEDADDRESS = 0x0001;
+ final static int RESPONSEADDRESS = 0x0002;
+ final static int CHANGEREQUEST = 0x0003;
+ final static int SOURCEADDRESS = 0x0004;
+ final static int CHANGEDADDRESS = 0x0005;
+ final static int USERNAME = 0x0006;
+ final static int PASSWORD = 0x0007;
+ final static int MESSAGEINTEGRITY = 0x0008;
+ final static int ERRORCODE = 0x0009;
+ final static int UNKNOWNATTRIBUTE = 0x000a;
+ final static int REFLECTEDFROM = 0x000b;
+}
\ No newline at end of file
Added:
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageAttributeParsingException.java
===================================================================
---
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageAttributeParsingException.java
2006-06-23 20:42:40 UTC (rev 9374)
+++
trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageAttributeParsingException.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,29 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.attribute;
+
+public class MessageAttributeParsingException extends
MessageAttributeException {
+ private static final long serialVersionUID = 3258409534426263605L;
+
+ public MessageAttributeParsingException(String mesg) {
+ super(mesg);
+ }
+}
\ No newline at end of file
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageIntegrity.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageIntegrity.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/MessageIntegrity.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,36 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.attribute;
+
+public class MessageIntegrity extends MessageAttribute {
+ // incomplete message integrity implementation
+ public MessageIntegrity() {
+ super(MessageAttribute.MessageAttributeType.MessageIntegrity);
+ }
+
+ public byte[] getBytes() {
+ return new byte[0];
+ }
+
+ public static MessageIntegrity parse(byte[] data) {
+ return new MessageIntegrity();
+ }
+}
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/Password.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/Password.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/Password.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,73 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.attribute;
+
+import de.javawi.jstun.util.Utility;
+import de.javawi.jstun.util.UtilityException;
+
+public class Password extends MessageAttribute {
+ String password;
+
+ public Password() {
+ super(MessageAttribute.MessageAttributeType.Password);
+ }
+
+ public Password(String password) {
+ super(MessageAttribute.MessageAttributeType.Password);
+ setPassword(password);
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public byte[] getBytes() throws UtilityException {
+ int length = password.length();
+ // password header
+ if ((length % 4) != 0) {
+ length += 4 - (length % 4);
+ }
+ // message attribute header
+ length += 4;
+ byte[] result = new byte[length];
+ // message attribute header
+ // type
+
System.arraycopy(Utility.IntegerToTwoBytes(typeToInteger(type)), 0, result, 0,
2);
+ // length
+ System.arraycopy(Utility.IntegerToTwoBytes(length - 4), 0,
result, 2, 2);
+
+ // password header
+ byte[] temp = password.getBytes();
+ System.arraycopy(temp, 0, result, 4, temp.length);
+ return result;
+ }
+
+ public static Password parse(byte[] data) {
+ Password result = new Password();
+ String password = new String(data);
+ result.setPassword(password);
+ return result;
+ }
+}
\ No newline at end of file
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ReflectedFrom.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ReflectedFrom.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ReflectedFrom.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,40 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.attribute;
+
+import java.util.logging.Logger;
+
+public class ReflectedFrom extends
MappedResponseChangedSourceAddressReflectedFrom {
+ private static Logger logger =
Logger.getLogger("de.javawi.stun.attribute.ReflectedFrom");
+
+ public ReflectedFrom() {
+ super(MessageAttribute.MessageAttributeType.ReflectedFrom);
+ }
+
+ public static ReflectedFrom parse(byte[] data) throws
MessageAttributeParsingException {
+ ReflectedFrom result = new ReflectedFrom();
+ MappedResponseChangedSourceAddressReflectedFrom.parse(result,
data);
+ logger.finer("Message Attribute: ReflectedFrom parsed: " +
result.toString() + ".");
+ return result;
+ }
+
+
+}
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ResponseAddress.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ResponseAddress.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/ResponseAddress.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,38 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.attribute;
+
+import java.util.logging.Logger;
+
+
+public class ResponseAddress extends
MappedResponseChangedSourceAddressReflectedFrom {
+ private static Logger logger =
Logger.getLogger("de.javawi.stun.attribute.ResponseAddress");
+ public ResponseAddress() {
+ super(MessageAttribute.MessageAttributeType.ResponseAddress);
+ }
+
+ public static MessageAttribute parse(byte[] data) throws
MessageAttributeParsingException {
+ ResponseAddress ra = new ResponseAddress();
+ MappedResponseChangedSourceAddressReflectedFrom.parse(ra, data);
+ logger.finer("Message Attribute: Response Address parsed: " +
ra.toString() + ".");
+ return ra;
+ }
+}
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/SourceAddress.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/SourceAddress.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/SourceAddress.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,38 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.attribute;
+
+import java.util.logging.Logger;
+
+
+public class SourceAddress extends
MappedResponseChangedSourceAddressReflectedFrom {
+ private static Logger logger =
Logger.getLogger("de.javawi.stun.attribute.SourceAddress");
+ public SourceAddress() {
+ super(MessageAttribute.MessageAttributeType.SourceAddress);
+ }
+
+ public static MessageAttribute parse(byte[] data) throws
MessageAttributeParsingException {
+ SourceAddress sa = new SourceAddress();
+ MappedResponseChangedSourceAddressReflectedFrom.parse(sa, data);
+ logger.finer("Message Attribute: Source Address parsed: " +
sa.toString() + ".");
+ return sa;
+ }
+}
\ No newline at end of file
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/UnknownAttribute.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/UnknownAttribute.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/UnknownAttribute.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,91 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.attribute;
+
+import java.util.*;
+
+import de.javawi.jstun.util.Utility;
+import de.javawi.jstun.util.UtilityException;
+
+public class UnknownAttribute extends MessageAttribute {
+ /*
+ * 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
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Attribute 1 Type | Attribute 2 Type |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Attribute 3 Type | Attribute 4 Type ...
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+
+ Vector<MessageAttributeType> unkown = new
Vector<MessageAttributeType>();
+
+ public UnknownAttribute() {
+ super(MessageAttribute.MessageAttributeType.UnknownAttribute);
+ }
+
+ public void addAttribute(MessageAttributeType attribute) {
+ unkown.add(attribute);
+ }
+
+ public byte[] getBytes() throws UtilityException {
+ int length = 0;
+ if (unkown.size()%2 == 1) {
+ length = 2 * (unkown.size() + 1) + 4;
+ } else {
+ length = 2 * unkown.size() + 4;
+ }
+ byte[] result = new byte[length];
+ // message attribute header
+ // type
+
System.arraycopy(Utility.IntegerToTwoBytes(typeToInteger(type)), 0, result, 0,
2);
+ // length
+ System.arraycopy(Utility.IntegerToTwoBytes(length - 4), 0,
result, 2, 2);
+
+ // unkown attribute header
+ Iterator<MessageAttributeType> it = unkown.iterator();
+ while(it.hasNext()) {
+ MessageAttributeType attri = it.next();
+
System.arraycopy(Utility.IntegerToTwoBytes(typeToInteger(attri)), 0, result, 4,
2);
+ }
+ // padding
+ if (unkown.size()%2 == 1) {
+
System.arraycopy(Utility.IntegerToTwoBytes(typeToInteger(unkown.elementAt(1))),
0, result, 4, 2);
+ }
+ return result;
+ }
+
+ public static UnknownAttribute parse(byte[] data) throws
MessageAttributeParsingException {
+ try {
+ UnknownAttribute result = new UnknownAttribute();
+ if (data.length % 4 != 0) throw new
MessageAttributeParsingException("Data array too short");
+ for (int i = 0; i < data.length; i += 4) {
+ byte[] temp = new byte[4];
+ System.arraycopy(data, i, temp, 0, 4);
+ long attri = Utility.FourBytesToLong(temp);
+
result.addAttribute(MessageAttribute.intToType(attri));
+ }
+ return result;
+ } catch (UtilityException ue) {
+ throw new MessageAttributeParsingException("Parsing
error");
+ }
+ }
+}
\ No newline at end of file
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/Username.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/Username.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/attribute/Username.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,73 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.attribute;
+
+import de.javawi.jstun.util.Utility;
+import de.javawi.jstun.util.UtilityException;
+
+public class Username extends MessageAttribute {
+ String username;
+
+ public Username() {
+ super(MessageAttribute.MessageAttributeType.Username);
+ }
+
+ public Username(String username) {
+ super(MessageAttribute.MessageAttributeType.Username);
+ setUsername(username);
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public byte[] getBytes() throws UtilityException {
+ int length = username.length();
+ // username header
+ if ((length % 4) != 0) {
+ length += 4 - (length % 4);
+ }
+ // message attribute header
+ length += 4;
+ byte[] result = new byte[length];
+ // message attribute header
+ // type
+
System.arraycopy(Utility.IntegerToTwoBytes(typeToInteger(type)), 0, result, 0,
2);
+ // length
+ System.arraycopy(Utility.IntegerToTwoBytes(length-4), 0,
result, 2, 2);
+
+ // username header
+ byte[] temp = username.getBytes();
+ System.arraycopy(temp, 0, result, 4, temp.length);
+ return result;
+ }
+
+ public static Username parse(byte[] data) {
+ Username result = new Username();
+ String username = new String(data);
+ result.setUsername(username);
+ return result;
+ }
+}
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/header/MessageHeader.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/header/MessageHeader.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/header/MessageHeader.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,178 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.header;
+
+import de.javawi.jstun.attribute.*;
+import de.javawi.jstun.util.*;
+
+import java.util.*;
+import java.util.logging.*;
+
+public class MessageHeader implements MessageHeaderInterface {
+ /*
+ * 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
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | STUN Message Type | Message Length |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * Transaction ID
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+ private static Logger logger =
Logger.getLogger("de.javawi.stun.header.MessageHeader");
+ MessageHeaderType type;
+ byte[] id = new byte[16];
+
+ TreeMap<MessageAttribute.MessageAttributeType, MessageAttribute> ma =
new TreeMap<MessageAttribute.MessageAttributeType, MessageAttribute>();
+
+ public MessageHeader() {
+ super();
+ }
+
+ public MessageHeader(MessageHeaderType type) {
+ super();
+ setType(type);
+ }
+
+ public void setType(MessageHeaderType type) {
+ this.type = type;
+ }
+
+ public static int typeToInteger(MessageHeaderType type) {
+ if (type == MessageHeaderType.BindingRequest) return
BINDINGREQUEST;
+ if (type == MessageHeaderType.BindingResponse) return
BINDINGRESPONSE;
+ if (type == MessageHeaderType.BindingErrorResponse) return
BINDINGERRORRESPONSE;
+ if (type == MessageHeaderType.SharedSecretRequest) return
SHAREDSECRETREQUEST;
+ if (type == MessageHeaderType.SharedSecretResponse) return
SHAREDSECRETRESPONSE;
+ if (type == MessageHeaderType.SharedSecretErrorResponse) return
SHAREDSECRETERRORRESPONSE;
+ return -1;
+ }
+
+ public void setTransactionID(byte[] id) {
+ System.arraycopy(id, 0, this.id, 0, 4);
+ }
+
+ public void generateTransactionID() throws UtilityException {
+ System.arraycopy(Utility.IntegerToTwoBytes((int)(Math.random()
* 65536)), 0, id, 0, 2);
+ System.arraycopy(Utility.IntegerToTwoBytes((int)(Math.random()
* 65536)), 0, id, 2, 2);
+ System.arraycopy(Utility.IntegerToTwoBytes((int)(Math.random()
* 65536)), 0, id, 4, 2);
+ System.arraycopy(Utility.IntegerToTwoBytes((int)(Math.random()
* 65536)), 0, id, 6, 2);
+ System.arraycopy(Utility.IntegerToTwoBytes((int)(Math.random()
* 65536)), 0, id, 8, 2);
+ System.arraycopy(Utility.IntegerToTwoBytes((int)(Math.random()
* 65536)), 0, id, 10, 2);
+ System.arraycopy(Utility.IntegerToTwoBytes((int)(Math.random()
* 65536)), 0, id, 12, 2);
+ System.arraycopy(Utility.IntegerToTwoBytes((int)(Math.random()
* 65536)), 0, id, 14, 2);
+ }
+
+ public byte[] getTransactionID() {
+ return id;
+ }
+
+ public boolean equalTransactionID(MessageHeader header) {
+ byte[] idHeader = header.getTransactionID();
+ if (idHeader.length != 16) return false;
+ if ((idHeader[0] == id[0]) && (idHeader[1] == id[1]) &&
(idHeader[2] == id[2]) && (idHeader[3] == id[3]) &&
+ (idHeader[4] == id[4]) && (idHeader[5] == id[5]) &&
(idHeader[6] == id[6]) && (idHeader[7] == id[7]) &&
+ (idHeader[8] == id[8]) && (idHeader[9] == id[9]) &&
(idHeader[10] == id[10]) && (idHeader[11] == id[11]) &&
+ (idHeader[12] == id[12]) && (idHeader[13] == id[13]) &&
(idHeader[14] == id[14]) && (idHeader[15] == id[15])) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public void addMessageAttribute(MessageAttribute attri) {
+ ma.put(attri.getType(), attri);
+ }
+
+ public MessageAttribute
getMessageAttribute(MessageAttribute.MessageAttributeType type) {
+ return ma.get(type);
+ }
+
+ public byte[] getBytes() throws UtilityException {
+ int length = 20;
+ Iterator<MessageAttribute.MessageAttributeType> it =
ma.keySet().iterator();
+ while (it.hasNext()) {
+ MessageAttribute attri = ma.get(it.next());
+ length += attri.getLength();
+ }
+ // add attribute size + attributes.getSize();
+ byte[] result = new byte[length];
+
System.arraycopy(Utility.IntegerToTwoBytes(typeToInteger(type)), 0, result, 0,
2);
+ System.arraycopy(Utility.IntegerToTwoBytes(length-20), 0,
result, 2, 2);
+ System.arraycopy(id, 0, result, 4, 16);
+
+ // arraycopy of attributes
+ int offset = 20;
+ it = ma.keySet().iterator();
+ while (it.hasNext()) {
+ MessageAttribute attri = ma.get(it.next());
+ System.arraycopy(attri.getBytes(), 0, result, offset,
attri.getLength());
+ offset += attri.getLength();
+ }
+ return result;
+ }
+
+ public int getLength() throws UtilityException {
+ return getBytes().length;
+ }
+
+ public static MessageHeader parseHeader(byte[] data) throws
MessageHeaderParsingException, MessageAttributeParsingException {
+ try {
+ MessageHeader mh = new MessageHeader();
+ byte[] typeArray = new byte[2];
+ System.arraycopy(data, 0, typeArray, 0, 2);
+ int type = Utility.TwoBytesToInteger(typeArray);
+ switch (type) {
+ case BINDINGREQUEST:
mh.setType(MessageHeaderType.BindingRequest); logger.finer("Binding Request
received."); break;
+ case BINDINGRESPONSE:
mh.setType(MessageHeaderType.BindingResponse); logger.finer("Binding Response
received."); break;
+ case BINDINGERRORRESPONSE:
mh.setType(MessageHeaderType.BindingErrorResponse); logger.finer("Binding Error
Response received."); break;
+ case SHAREDSECRETREQUEST:
mh.setType(MessageHeaderType.SharedSecretRequest); logger.finer("Shared Secret
Request received."); break;
+ case SHAREDSECRETRESPONSE:
mh.setType(MessageHeaderType.SharedSecretResponse); logger.finer("Shared Secret
Response received."); break;
+ case SHAREDSECRETERRORRESPONSE:
mh.setType(MessageHeaderType.SharedSecretErrorResponse); logger.finer("Shared
Secret Error Response received.");break;
+ default: throw new
MessageHeaderParsingException("Message type " + type + "is not supported");
+ }
+ byte[] lengthArray = new byte[2];
+ System.arraycopy(data, 2, lengthArray, 0, 2);
+ int length = Utility.TwoBytesToInteger(lengthArray);
+ System.arraycopy(data, 4, mh.id, 0, 16);
+ byte[] cuttedData;
+ int offset = 20;
+ while (length > 0) {
+ cuttedData = new byte[length];
+ System.arraycopy(data, offset, cuttedData, 0,
length);
+ MessageAttribute ma =
MessageAttribute.parseCommonHeader(cuttedData);
+ if (ma.getType() !=
MessageAttribute.MessageAttributeType.Dummy) {
+ mh.addMessageAttribute(ma);
+ }
+ length -= ma.getLength();
+ offset += ma.getLength();
+ }
+ return mh;
+ } catch (UtilityException ue) {
+ throw new MessageHeaderParsingException("Parsing
error");
+ }
+ }
+}
\ No newline at end of file
Added:
trunk/plugins/jSTUN/src/de/javawi/jstun/header/MessageHeaderException.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/header/MessageHeaderException.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/header/MessageHeaderException.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,29 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.header;
+
+public class MessageHeaderException extends Exception {
+ private static final long serialVersionUID = 3689066248944103737L;
+
+ public MessageHeaderException(String mesg) {
+ super(mesg);
+ }
+}
\ No newline at end of file
Added:
trunk/plugins/jSTUN/src/de/javawi/jstun/header/MessageHeaderInterface.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/header/MessageHeaderInterface.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/header/MessageHeaderInterface.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,31 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.header;
+
+public interface MessageHeaderInterface {
+ public enum MessageHeaderType { BindingRequest, BindingResponse,
BindingErrorResponse, SharedSecretRequest, SharedSecretResponse,
SharedSecretErrorResponse };
+ final static int BINDINGREQUEST = 0x0001;
+ final static int BINDINGRESPONSE = 0x0101;
+ final static int BINDINGERRORRESPONSE = 0x0111;
+ final static int SHAREDSECRETREQUEST = 0x0002;
+ final static int SHAREDSECRETRESPONSE = 0x0102;
+ final static int SHAREDSECRETERRORRESPONSE = 0x0112;
+}
\ No newline at end of file
Added:
trunk/plugins/jSTUN/src/de/javawi/jstun/header/MessageHeaderParsingException.java
===================================================================
---
trunk/plugins/jSTUN/src/de/javawi/jstun/header/MessageHeaderParsingException.java
2006-06-23 20:42:40 UTC (rev 9374)
+++
trunk/plugins/jSTUN/src/de/javawi/jstun/header/MessageHeaderParsingException.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,29 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.header;
+
+public class MessageHeaderParsingException extends MessageHeaderException {
+ private static final long serialVersionUID = 3544393617029607478L;
+
+ public MessageHeaderParsingException(String mesg) {
+ super(mesg);
+ }
+}
\ No newline at end of file
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/test/BindingLifetimeTest.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/test/BindingLifetimeTest.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/test/BindingLifetimeTest.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,199 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.test;
+
+import java.util.logging.*;
+import java.util.*;
+import java.io.*;
+import java.net.*;
+
+import de.javawi.jstun.attribute.*;
+import de.javawi.jstun.header.*;
+import de.javawi.jstun.util.UtilityException;
+
+public class BindingLifetimeTest {
+ private static Logger logger =
Logger.getLogger("de.javawi.stun.test.BindingLifetimeTest");
+ String stunServer;
+ int port;
+ int timeout = 300; //ms
+ MappedAddress ma;
+ Timer timer;
+ DatagramSocket initialSocket;
+
+ // start value for binary search - should be carefully choosen
+ int upperBinarySearchLifetime = 345000; // ms
+ int lowerBinarySearchLifetime = 0;
+ int binarySearchLifetime = ( upperBinarySearchLifetime +
lowerBinarySearchLifetime ) / 2;
+
+ // lifetime value
+ int lifetime = -1; // -1 means undefined.
+ boolean completed = false;
+
+ public BindingLifetimeTest(String stunServer, int port) {
+ super();
+ this.stunServer = stunServer;
+ this.port = port;
+ timer = new Timer(true);
+ }
+
+ public void test() throws UtilityException, SocketException,
UnknownHostException, IOException, MessageAttributeParsingException,
MessageAttributeException, MessageHeaderParsingException {
+ initialSocket = new DatagramSocket();
+ initialSocket.connect(InetAddress.getByName(stunServer), port);
+ initialSocket.setSoTimeout(timeout);
+
+ if (BindingCommunicationInitialSocket()) {
+ return;
+ }
+ BindingLifetimeTask task = new BindingLifetimeTask();
+ timer.schedule(task, binarySearchLifetime);
+ logger.finer("Timer scheduled initially: " +
binarySearchLifetime + ".");
+ }
+
+ private boolean BindingCommunicationInitialSocket() throws
UtilityException, IOException, MessageHeaderParsingException,
MessageAttributeParsingException {
+ MessageHeader sendMH = new
MessageHeader(MessageHeader.MessageHeaderType.BindingRequest);
+ sendMH.generateTransactionID();
+ ChangeRequest changeRequest = new ChangeRequest();
+ sendMH.addMessageAttribute(changeRequest);
+ byte[] data = sendMH.getBytes();
+
+ DatagramPacket send = new DatagramPacket(data, data.length,
InetAddress.getByName(stunServer), port);
+ initialSocket.send(send);
+ logger.finer("Binding Request sent.");
+
+ MessageHeader receiveMH = new MessageHeader();
+ while (!(receiveMH.equalTransactionID(sendMH))) {
+ DatagramPacket receive = new DatagramPacket(new
byte[200], 200);
+ initialSocket.receive(receive);
+ receiveMH =
MessageHeader.parseHeader(receive.getData());
+ }
+ ma = (MappedAddress)
receiveMH.getMessageAttribute(MessageAttribute.MessageAttributeType.MappedAddress);
+ ErrorCode ec = (ErrorCode)
receiveMH.getMessageAttribute(MessageAttribute.MessageAttributeType.ErrorCode);
+ if (ec != null) {
+ logger.config("Message header contains errorcode
message attribute.");
+ return true;
+ }
+ if (ma == null) {
+ logger.config("Response does not contain a mapped
address message attribute.");
+ return true;
+ }
+ return false;
+ }
+
+ public int getLifetime() {
+ return lifetime;
+ }
+
+ public boolean isCompleted() {
+ return completed;
+ }
+
+ public void setUpperBinarySearchLifetime(int upperBinarySearchLifetime)
{
+ this.upperBinarySearchLifetime = upperBinarySearchLifetime;
+ binarySearchLifetime = ( upperBinarySearchLifetime +
lowerBinarySearchLifetime ) / 2;
+ }
+
+ class BindingLifetimeTask extends TimerTask {
+
+ public BindingLifetimeTask() {
+ super();
+ }
+
+ public void run() {
+ try {
+ lifetimeQuery();
+ } catch (Exception e) {
+ logger.config("Unhandled Exception.
BindLifetimeTasks stopped.");
+ e.printStackTrace();
+ }
+ }
+
+ public void lifetimeQuery() throws UtilityException,
MessageAttributeException, MessageHeaderParsingException,
MessageAttributeParsingException, IOException {
+ try {
+ DatagramSocket socket = new DatagramSocket();
+
socket.connect(InetAddress.getByName(stunServer), port);
+ socket.setSoTimeout(timeout);
+
+ MessageHeader sendMH = new
MessageHeader(MessageHeader.MessageHeaderType.BindingRequest);
+ sendMH.generateTransactionID();
+ ChangeRequest changeRequest = new
ChangeRequest();
+ ResponseAddress responseAddress = new
ResponseAddress();
+ responseAddress.setAddress(ma.getAddress());
+ responseAddress.setPort(ma.getPort());
+ sendMH.addMessageAttribute(changeRequest);
+ sendMH.addMessageAttribute(responseAddress);
+ byte[] data = sendMH.getBytes();
+
+ DatagramPacket send = new DatagramPacket(data,
data.length, InetAddress.getByName(stunServer), port);
+ socket.send(send);
+ logger.finer("Binding Request sent.");
+
+ MessageHeader receiveMH = new MessageHeader();
+ while (!(receiveMH.equalTransactionID(sendMH)))
{
+ DatagramPacket receive = new
DatagramPacket(new byte[200], 200);
+ initialSocket.receive(receive);
+ receiveMH =
MessageHeader.parseHeader(receive.getData());
+ }
+ ErrorCode ec = (ErrorCode)
receiveMH.getMessageAttribute(MessageAttribute.MessageAttributeType.ErrorCode);
+ if (ec != null) {
+ logger.config("Message header contains
errorcode message attribute.");
+ return;
+ }
+ logger.finer("Binding Response received.");
+ if (upperBinarySearchLifetime ==
(lowerBinarySearchLifetime + 1)) {
+ logger.config("BindingLifetimeTest
completed. UDP binding lifetime: " + binarySearchLifetime + ".");
+ completed = true;
+ return;
+ }
+ lifetime = binarySearchLifetime;
+ logger.finer("Lifetime update: " + lifetime +
".");
+ lowerBinarySearchLifetime =
binarySearchLifetime;
+ binarySearchLifetime = (
upperBinarySearchLifetime + lowerBinarySearchLifetime ) / 2;
+ if (binarySearchLifetime > 0) {
+ BindingLifetimeTask task = new
BindingLifetimeTask();
+ timer.schedule(task,
binarySearchLifetime);
+ logger.finer("Timer scheduled: " +
binarySearchLifetime + ".");
+ } else {
+ completed = true;
+ }
+ } catch (SocketTimeoutException ste) {
+ logger.finest("Read operation at query socket
timeout.");
+ if (upperBinarySearchLifetime ==
(lowerBinarySearchLifetime + 1)) {
+ logger.config("BindingLifetimeTest
completed. UDP binding lifetime: " + binarySearchLifetime + ".");
+ completed = true;
+ return;
+ }
+ upperBinarySearchLifetime =
binarySearchLifetime;
+ binarySearchLifetime = (
upperBinarySearchLifetime + lowerBinarySearchLifetime ) / 2;
+ if (binarySearchLifetime > 0) {
+ if
(BindingCommunicationInitialSocket()) {
+ return;
+ }
+ BindingLifetimeTask task = new
BindingLifetimeTask();
+ timer.schedule(task,
binarySearchLifetime);
+ logger.finer("Timer scheduled: " +
binarySearchLifetime + ".");
+ } else {
+ completed = true;
+ }
+ }
+ }
+ }
+}
+
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/test/DiscoveryInfo.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/test/DiscoveryInfo.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/test/DiscoveryInfo.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,158 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.test;
+
+import java.net.*;
+
+public class DiscoveryInfo {
+ private InetAddress testIP;
+ private boolean error = false;
+ private int errorResponseCode = 0;
+ private String errorReason;
+ private boolean openAccess = false;
+ private boolean blockedUDP = false;
+ private boolean fullCone = false;
+ private boolean restrictedCone = false;
+ private boolean portRestrictedCone = false;
+ private boolean symmetricCone = false;
+ private boolean symmetricUDPFirewall = false;
+ private InetAddress publicIP;
+
+ public DiscoveryInfo(InetAddress testIP) {
+ this.testIP = testIP;
+ }
+
+ public boolean isError() {
+ return error;
+ }
+
+ public void setError(int responseCode, String reason) {
+ this.error = true;
+ this.errorResponseCode = responseCode;
+ this.errorReason = reason;
+ }
+
+ public boolean isOpenAccess() {
+ if (error) return false;
+ return openAccess;
+ }
+
+ public void setOpenAccess() {
+ this.openAccess = true;
+ }
+
+ public boolean isBlockedUDP() {
+ if (error) return false;
+ return blockedUDP;
+ }
+
+ public void setBlockedUDP() {
+ this.blockedUDP = true;
+ }
+
+ public boolean isFullCone() {
+ if (error) return false;
+ return fullCone;
+ }
+
+ public void setFullCone() {
+ this.fullCone = true;
+ }
+
+ public boolean isPortRestrictedCone() {
+ if (error) return false;
+ return portRestrictedCone;
+ }
+
+ public void setPortRestrictedCone() {
+ this.portRestrictedCone = true;
+ }
+
+ public boolean isRestrictedCone() {
+ if (error) return false;
+ return restrictedCone;
+ }
+
+ public void setRestrictedCone() {
+ this.restrictedCone = true;
+ }
+
+ public boolean isSymmetricCone() {
+ if (error) return false;
+ return symmetricCone;
+ }
+
+ public void setSymmetricCone() {
+ this.symmetricCone = true;
+ }
+
+ public boolean isSymmetricUDPFirewall() {
+ if (error) return false;
+ return symmetricUDPFirewall;
+ }
+
+ public void setSymmetricUDPFirewall() {
+ this.symmetricUDPFirewall = true;
+ }
+
+ public InetAddress getPublicIP() {
+ return publicIP;
+ }
+
+ public void setPublicIP(InetAddress publicIP) {
+ this.publicIP = publicIP;
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("Network interface: ");
+ try {
+
sb.append(NetworkInterface.getByInetAddress(testIP).getName());
+ } catch (SocketException se) {
+ sb.append("unknown");
+ }
+ sb.append("\n");
+ sb.append("Local IP address: ");
+ sb.append(testIP.getHostAddress());
+ sb.append("\n");
+ if (error) {
+ sb.append(errorReason + " - Responsecode: " +
errorResponseCode);
+ return sb.toString();
+ }
+ sb.append("Result: ");
+ if (openAccess) sb.append("Open access to the Internet.\n");
+ if (blockedUDP) sb.append("Firewall blocks UDP.\n");
+ if (fullCone) sb.append("Full Cone NAT handles connections.\n");
+ if (restrictedCone) sb.append("Restricted Cone NAT handles
connections.\n");
+ if (portRestrictedCone) sb.append("Port restricted Cone NAT
handles connections.\n");
+ if (symmetricCone) sb.append("Symmetric Cone NAT handles
connections.\n");
+ if (symmetricUDPFirewall) sb.append ("Symmetric UDP Firewall
handles connections.\n");
+ if (!openAccess && !blockedUDP && !fullCone && !restrictedCone
&& !portRestrictedCone && !symmetricCone && !symmetricUDPFirewall)
sb.append("unkown\n");
+ sb.append("Public IP: ");
+ if (publicIP != null) {
+ sb.append(publicIP.getHostAddress());
+ } else {
+ sb.append("unknown");
+ }
+ sb.append("\n");
+ return sb.toString();
+ }
+}
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/test/DiscoveryTest.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/test/DiscoveryTest.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/test/DiscoveryTest.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,352 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.test;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.SocketException;
+import java.net.SocketTimeoutException;
+import java.net.UnknownHostException;
+import java.util.logging.Logger;
+
+import de.javawi.jstun.attribute.ChangeRequest;
+import de.javawi.jstun.attribute.ChangedAddress;
+import de.javawi.jstun.attribute.ErrorCode;
+import de.javawi.jstun.attribute.MappedAddress;
+import de.javawi.jstun.attribute.MessageAttribute;
+import de.javawi.jstun.attribute.MessageAttributeException;
+import de.javawi.jstun.attribute.MessageAttributeParsingException;
+import de.javawi.jstun.header.MessageHeader;
+import de.javawi.jstun.header.MessageHeaderParsingException;
+import de.javawi.jstun.util.UtilityException;
+
+public class DiscoveryTest {
+ private static Logger logger =
Logger.getLogger("de.javawi.stun.test.DiscoveryTest");
+ InetAddress iaddress;
+ String stunServer;
+ int port;
+ int timeoutInitValue = 300; //ms
+ MappedAddress ma = null;
+ ChangedAddress ca = null;
+ boolean nodeNatted = true;
+ DatagramSocket socketTest1 = null;
+ DiscoveryInfo di = null;
+
+ public DiscoveryTest(InetAddress iaddress , String stunServer, int
port) {
+ super();
+ this.iaddress = iaddress;
+ this.stunServer = stunServer;
+ this.port = port;
+ }
+
+ public DiscoveryInfo test() throws UtilityException, SocketException,
UnknownHostException, IOException, MessageAttributeParsingException,
MessageAttributeException, MessageHeaderParsingException{
+ ma = null;
+ ca = null;
+ nodeNatted = true;
+ socketTest1 = null;
+ di = new DiscoveryInfo(iaddress);
+
+ if (test1()) {
+ if (test2()) {
+ if (test1Redo()) {
+ test3();
+ }
+ }
+ }
+
+ socketTest1.close();
+
+ return di;
+ }
+
+ private boolean test1() throws UtilityException, SocketException,
UnknownHostException, IOException, MessageAttributeParsingException,
MessageHeaderParsingException {
+ int timeSinceFirstTransmission = 0;
+ int timeout = timeoutInitValue;
+ while (true) {
+ try {
+ // Test 1 including response
+ socketTest1 = new DatagramSocket(new
InetSocketAddress(iaddress, 0));
+ socketTest1.setReuseAddress(true);
+
socketTest1.connect(InetAddress.getByName(stunServer), port);
+ socketTest1.setSoTimeout(timeout);
+
+ MessageHeader sendMH = new
MessageHeader(MessageHeader.MessageHeaderType.BindingRequest);
+ sendMH.generateTransactionID();
+
+ ChangeRequest changeRequest = new
ChangeRequest();
+ sendMH.addMessageAttribute(changeRequest);
+
+ byte[] data = sendMH.getBytes();
+ DatagramPacket send = new DatagramPacket(data,
data.length);
+ socketTest1.send(send);
+ logger.finer("Test 1: Binding Request sent.");
+
+ MessageHeader receiveMH = new MessageHeader();
+ while (!(receiveMH.equalTransactionID(sendMH)))
{
+ DatagramPacket receive = new
DatagramPacket(new byte[200], 200);
+ socketTest1.receive(receive);
+ receiveMH =
MessageHeader.parseHeader(receive.getData());
+ }
+
+ ma = (MappedAddress)
receiveMH.getMessageAttribute(MessageAttribute.MessageAttributeType.MappedAddress);
+ ca = (ChangedAddress)
receiveMH.getMessageAttribute(MessageAttribute.MessageAttributeType.ChangedAddress);
+ ErrorCode ec = (ErrorCode)
receiveMH.getMessageAttribute(MessageAttribute.MessageAttributeType.ErrorCode);
+ if (ec != null) {
+ di.setError(ec.getResponseCode(),
ec.getReason());
+ logger.config("Message header contains
errorcode message attribute.");
+ return false;
+ }
+ if ((ma == null) || (ca == null)) {
+ di.setError(700, "The server is sending
incomplete response (Mapped Address and Changed Address message attributes are
missing). The client should not retry.");
+ logger.config("Response does not
contain a mapped address or changed address message attribute.");
+ return false;
+ } else {
+
di.setPublicIP(ma.getAddress().getInetAddress());
+ if ((ma.getPort() ==
socketTest1.getLocalPort()) &&
(ma.getAddress().getInetAddress().equals(socketTest1.getLocalAddress()))) {
+ logger.fine("Node is not
natted.");
+ nodeNatted = false;
+ } else {
+ logger.fine("Node is natted.");
+ }
+ return true;
+ }
+ } catch (SocketTimeoutException ste) {
+ if (timeSinceFirstTransmission < 7900) {
+ logger.finer("Test 1: Socket timeout
while receiving the response.");
+ timeSinceFirstTransmission += timeout;
+ int timeoutAddValue =
(timeSinceFirstTransmission * 2);
+ if (timeoutAddValue > 1600)
timeoutAddValue = 1600;
+ timeout = timeoutAddValue;
+ } else {
+ // node is not capable of udp
communication
+ logger.finer("Test 1: Socket timeout
while receiving the response. Maximum retry limit exceed. Give up.");
+ di.setBlockedUDP();
+ logger.fine("Node is not capable of udp
communication.");
+ return false;
+ }
+ }
+ }
+ }
+
+ private boolean test2() throws UtilityException, SocketException,
UnknownHostException, IOException, MessageAttributeParsingException,
MessageAttributeException, MessageHeaderParsingException {
+ int timeSinceFirstTransmission = 0;
+ int timeout = timeoutInitValue;
+ while (true) {
+ try {
+ // Test 2 including response
+ DatagramSocket sendSocket = new
DatagramSocket(new InetSocketAddress(iaddress, 0));
+
sendSocket.connect(InetAddress.getByName(stunServer), port);
+ sendSocket.setSoTimeout(timeout);
+
+ MessageHeader sendMH = new
MessageHeader(MessageHeader.MessageHeaderType.BindingRequest);
+ sendMH.generateTransactionID();
+
+ ChangeRequest changeRequest = new
ChangeRequest();
+ changeRequest.setChangeIP();
+ changeRequest.setChangePort();
+ sendMH.addMessageAttribute(changeRequest);
+
+ byte[] data = sendMH.getBytes();
+ DatagramPacket send = new DatagramPacket(data,
data.length);
+ sendSocket.send(send);
+ logger.finer("Test 2: Binding Request sent.");
+
+ int localPort = sendSocket.getLocalPort();
+ InetAddress localAddress =
sendSocket.getLocalAddress();
+
+ sendSocket.close();
+
+ DatagramSocket receiveSocket = new
DatagramSocket(localPort, localAddress);
+
receiveSocket.connect(ca.getAddress().getInetAddress(), ca.getPort());
+ receiveSocket.setSoTimeout(timeout);
+
+ MessageHeader receiveMH = new MessageHeader();
+ while(!(receiveMH.equalTransactionID(sendMH))) {
+ DatagramPacket receive = new
DatagramPacket(new byte[200], 200);
+ receiveSocket.receive(receive);
+ receiveMH =
MessageHeader.parseHeader(receive.getData());
+ }
+ ErrorCode ec = (ErrorCode)
receiveMH.getMessageAttribute(MessageAttribute.MessageAttributeType.ErrorCode);
+ if (ec != null) {
+ di.setError(ec.getResponseCode(),
ec.getReason());
+ logger.config("Message header contains
errorcode message attribute.");
+ return false;
+ }
+ if (!nodeNatted) {
+ di.setOpenAccess();
+ logger.fine("Node has open access to
the internet (or, at least the node is a full-cone NAT without translation).");
+ } else {
+ di.setFullCone();
+ logger.fine("Node is behind a full-cone
NAT.");
+ }
+ return false;
+ } catch (SocketTimeoutException ste) {
+ if (timeSinceFirstTransmission < 7900) {
+ logger.finer("Test 2: Socket timeout
while receiving the response.");
+ timeSinceFirstTransmission += timeout;
+ int timeoutAddValue =
(timeSinceFirstTransmission * 2);
+ if (timeoutAddValue > 1600)
timeoutAddValue = 1600;
+ timeout = timeoutAddValue;
+ } else {
+ logger.finer("Test 2: Socket timeout
while receiving the response. Maximum retry limit exceed. Give up.");
+ if (!nodeNatted) {
+ di.setSymmetricUDPFirewall();
+ logger.fine("Node is behind a
symmetric udp firewall.");
+ return false;
+ } else {
+ // not is natted
+ // redo test 1 with address and
port as offered in the changed-address message attribute
+ return true;
+ }
+ }
+ }
+ }
+ }
+
+ private boolean test1Redo() throws UtilityException, SocketException,
UnknownHostException, IOException, MessageAttributeParsingException,
MessageHeaderParsingException{
+ int timeSinceFirstTransmission = 0;
+ int timeout = timeoutInitValue;
+ while (true) {
+ // redo test 1 with address and port as offered in the
changed-address message attribute
+ try {
+ // Test 1 with changed port and address values
+
socketTest1.connect(ca.getAddress().getInetAddress(), ca.getPort());
+ socketTest1.setSoTimeout(timeout);
+
+ MessageHeader sendMH = new
MessageHeader(MessageHeader.MessageHeaderType.BindingRequest);
+ sendMH.generateTransactionID();
+
+ ChangeRequest changeRequest = new
ChangeRequest();
+ sendMH.addMessageAttribute(changeRequest);
+
+ byte[] data = sendMH.getBytes();
+ DatagramPacket send = new DatagramPacket(data,
data.length);
+ socketTest1.send(send);
+ logger.finer("Test 1 redo with changed address:
Binding Request sent.");
+
+ MessageHeader receiveMH = new MessageHeader();
+ while (!(receiveMH.equalTransactionID(sendMH)))
{
+ DatagramPacket receive = new
DatagramPacket(new byte[200], 200);
+ socketTest1.receive(receive);
+ receiveMH =
MessageHeader.parseHeader(receive.getData());
+ }
+ MappedAddress ma2 = (MappedAddress)
receiveMH.getMessageAttribute(MessageAttribute.MessageAttributeType.MappedAddress);
+ ErrorCode ec = (ErrorCode)
receiveMH.getMessageAttribute(MessageAttribute.MessageAttributeType.ErrorCode);
+ if (ec != null) {
+ di.setError(ec.getResponseCode(),
ec.getReason());
+ logger.config("Message header contains
errorcode message attribute.");
+ return false;
+ }
+ if (ma2 == null) {
+ di.setError(700, "The server is sending
incomplete response (Mapped Address message attribute is missing). The client
should not retry.");
+ logger.config("Response does not
contain a mapped address message attribute.");
+ return false;
+ } else {
+ if ((ma.getPort() != ma2.getPort()) ||
(!(ma.getAddress().getInetAddress().equals(ma2.getAddress().getInetAddress()))))
{
+ di.setSymmetricCone();
+ logger.fine("Node is behind a
symmetric NAT.");
+ return false;
+ }
+ }
+ return true;
+ } catch (SocketTimeoutException ste2) {
+ if (timeSinceFirstTransmission < 7900) {
+ logger.config("Test 1 redo with changed
address: Socket timeout while receiving the response.");
+ timeSinceFirstTransmission += timeout;
+ int timeoutAddValue =
(timeSinceFirstTransmission * 2);
+ if (timeoutAddValue > 1600)
timeoutAddValue = 1600;
+ timeout = timeoutAddValue;
+ } else {
+ //TODO: error handling here
+ logger.config("Test 1 redo with changed
address: Socket timeout while receiving the response. Maximum retry limit
exceed. Give up.");
+ return false;
+ }
+ }
+ }
+ }
+
+ private void test3() throws UtilityException, SocketException,
UnknownHostException, IOException, MessageAttributeParsingException,
MessageAttributeException, MessageHeaderParsingException {
+ int timeSinceFirstTransmission = 0;
+ int timeout = timeoutInitValue;
+ while (true) {
+ try {
+ // Test 3 including response
+ DatagramSocket sendSocket = new
DatagramSocket(new InetSocketAddress(iaddress, 0));
+
sendSocket.connect(InetAddress.getByName(stunServer), port);
+ sendSocket.setSoTimeout(timeout);
+
+ MessageHeader sendMH = new
MessageHeader(MessageHeader.MessageHeaderType.BindingRequest);
+ sendMH.generateTransactionID();
+
+ ChangeRequest changeRequest = new
ChangeRequest();
+ changeRequest.setChangePort();
+ sendMH.addMessageAttribute(changeRequest);
+
+ byte[] data = sendMH.getBytes();
+ DatagramPacket send = new DatagramPacket(data,
data.length);
+ sendSocket.send(send);
+ logger.finer("Test 3: Binding Request sent.");
+
+ int localPort = sendSocket.getLocalPort();
+ InetAddress localAddress =
sendSocket.getLocalAddress();
+
+ sendSocket.close();
+
+ DatagramSocket receiveSocket = new
DatagramSocket(localPort, localAddress);
+
receiveSocket.connect(InetAddress.getByName(stunServer), ca.getPort());
+ receiveSocket.setSoTimeout(timeout);
+
+ MessageHeader receiveMH = new MessageHeader();
+ while (!(receiveMH.equalTransactionID(sendMH)))
{
+ DatagramPacket receive = new
DatagramPacket(new byte[200], 200);
+ receiveSocket.receive(receive);
+ receiveMH =
MessageHeader.parseHeader(receive.getData());
+ }
+ ErrorCode ec = (ErrorCode)
receiveMH.getMessageAttribute(MessageAttribute.MessageAttributeType.ErrorCode);
+ if (ec != null) {
+ di.setError(ec.getResponseCode(),
ec.getReason());
+ logger.config("Message header contains
errorcode message attribute.");
+ return;
+ }
+ if (nodeNatted) {
+ di.setRestrictedCone();
+ logger.fine("Node is behind a
restricted NAT.");
+ }
+ } catch (SocketTimeoutException ste) {
+ if (timeSinceFirstTransmission < 7900) {
+ logger.finer("Test 3: Socket timeout
while receiving the response.");
+ timeSinceFirstTransmission += timeout;
+ int timeoutAddValue =
(timeSinceFirstTransmission * 2);
+ if (timeoutAddValue > 1600)
timeoutAddValue = 1600;
+ timeout = timeoutAddValue;
+ } else {
+ logger.finer("Test 3: Socket timeout
while receiving the response. Maximum retry limit exceed. Give up.");
+ di.setPortRestrictedCone();
+ logger.fine("Node is behind a port
restricted NAT.");
+ return;
+ }
+ }
+ }
+ }
+}
Added:
trunk/plugins/jSTUN/src/de/javawi/jstun/test/demo/BindingLifetimeTestDemo.java
===================================================================
---
trunk/plugins/jSTUN/src/de/javawi/jstun/test/demo/BindingLifetimeTestDemo.java
2006-06-23 20:42:40 UTC (rev 9374)
+++
trunk/plugins/jSTUN/src/de/javawi/jstun/test/demo/BindingLifetimeTestDemo.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,36 @@
+package de.javawi.jstun.test.demo;
+
+import java.util.logging.FileHandler;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.logging.SimpleFormatter;
+
+import de.javawi.jstun.test.BindingLifetimeTest;
+
+public class BindingLifetimeTestDemo {
+ public static void main(String[] args) {
+ try {
+ Handler fh = new FileHandler("logging.txt");
+ fh.setFormatter(new SimpleFormatter());
+ Logger.getLogger("de.javawi.stun").addHandler(fh);
+ Logger.getLogger("de.javawi.stun").setLevel(Level.ALL);
+ BindingLifetimeTest test = new
BindingLifetimeTest("iphone-stun.freenet.de", 3478);
+ // iphone-stun.freenet.de:3478
+ // larry.gloo.net:3478
+ // stun.xten.net:3478
+ test.test();
+ boolean continueWhile = true;
+ while(continueWhile) {
+ Thread.sleep(5000);
+ if (test.getLifetime() != -1) {
+ System.out.println("Lifetime: " +
test.getLifetime() + " Finished: " + test.isCompleted());
+ if (test.isCompleted()) continueWhile =
false;
+ }
+ }
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ e.printStackTrace();
+ }
+ }
+}
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/test/demo/DiscoveryTestDemo.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/test/demo/DiscoveryTestDemo.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/test/demo/DiscoveryTestDemo.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,60 @@
+package de.javawi.jstun.test.demo;
+
+import java.net.BindException;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.util.Enumeration;
+import java.util.logging.FileHandler;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.logging.SimpleFormatter;
+
+import de.javawi.jstun.test.DiscoveryTest;
+
+public class DiscoveryTestDemo implements Runnable {
+ InetAddress iaddress;
+
+ public DiscoveryTestDemo(InetAddress iaddress) {
+ this.iaddress = iaddress;
+ }
+
+ public void run() {
+ try {
+ DiscoveryTest test = new DiscoveryTest(iaddress,
"stun.xten.net", 3478);
+ // iphone-stun.freenet.de:3478
+ // larry.gloo.net:3478
+ // stun.xten.net:3478
+ System.out.println(test.test());
+ } catch (BindException be) {
+ System.out.println(iaddress.toString() + ": " +
be.getMessage());
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ public static void main(String[] args) {
+ try {
+ Handler fh = new FileHandler("logging.txt");
+ fh.setFormatter(new SimpleFormatter());
+ Logger.getLogger("de.javawi.stun").addHandler(fh);
+ Logger.getLogger("de.javawi.stun").setLevel(Level.ALL);
+
+ Enumeration<NetworkInterface> ifaces =
NetworkInterface.getNetworkInterfaces();
+ while (ifaces.hasMoreElements()) {
+ NetworkInterface iface = ifaces.nextElement();
+ Enumeration<InetAddress> iaddresses =
iface.getInetAddresses();
+ while (iaddresses.hasMoreElements()) {
+ InetAddress iaddress =
iaddresses.nextElement();
+ if (!iaddress.isLoopbackAddress() &&
!iaddress.isLinkLocalAddress()) {
+ Thread thread = new Thread(new
DiscoveryTestDemo(iaddress));
+ thread.start();
+ }
+ }
+ }
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ }
+ }
+}
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/util/Address.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/util/Address.java 2006-06-23
20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/util/Address.java 2006-06-23
20:45:44 UTC (rev 9375)
@@ -0,0 +1,106 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.util;
+
+import java.util.*;
+import java.net.*;
+
+public class Address {
+ int firstOctet;
+ int secondOctet;
+ int thirdOctet;
+ int fourthOctet;
+
+ public Address(int firstOctet, int secondOctet, int thirdOctet, int
fourthOctet) throws UtilityException {
+ if ((firstOctet < 0) || (firstOctet > 255) || (secondOctet < 0)
|| (secondOctet > 255) || (thirdOctet < 0) || (thirdOctet > 255) ||
(fourthOctet < 0) || (fourthOctet > 255)) {
+ throw new UtilityException("Address is malformed.");
+ }
+ this.firstOctet = firstOctet;
+ this.secondOctet = secondOctet;
+ this.thirdOctet = thirdOctet;
+ this.fourthOctet = fourthOctet;
+ }
+
+ public Address(String address) throws UtilityException {
+ StringTokenizer st = new StringTokenizer(address, ".");
+ if (st.countTokens() != 4) {
+ throw new UtilityException("4 octets in address string
are required.");
+ }
+ int i = 0;
+ while (st.hasMoreTokens()) {
+ int temp = Integer.parseInt(st.nextToken());
+ if ((temp < 0) || (temp > 255)) {
+ throw new UtilityException("Address is in
incorrect format.");
+ }
+ switch (i) {
+ case 0: firstOctet = temp; ++i; break;
+ case 1: secondOctet = temp; ++i; break;
+ case 2: thirdOctet = temp; ++i; break;
+ case 3: fourthOctet = temp; ++i; break;
+ }
+ }
+ }
+
+ public Address(byte[] address) throws UtilityException {
+ if (address.length < 4) {
+ throw new UtilityException("4 bytes are required.");
+ }
+ firstOctet = Utility.OneByteToInteger(address[0]);
+ secondOctet = Utility.OneByteToInteger(address[1]);
+ thirdOctet = Utility.OneByteToInteger(address[2]);
+ fourthOctet = Utility.OneByteToInteger(address[3]);
+ }
+
+ public String toString() {
+ return new String(firstOctet + "." + secondOctet + "." +
thirdOctet + "." + fourthOctet);
+ }
+
+ public byte[] getBytes() throws UtilityException {
+ byte[] result = new byte[4];
+ result[0] = Utility.IntegerToOneByte(firstOctet);
+ result[1] = Utility.IntegerToOneByte(secondOctet);
+ result[2] = Utility.IntegerToOneByte(thirdOctet);
+ result[3] = Utility.IntegerToOneByte(fourthOctet);
+ return result;
+ }
+
+ public InetAddress getInetAddress() throws UtilityException,
UnknownHostException {
+ byte[] address = new byte[4];
+ address[0] = Utility.IntegerToOneByte(firstOctet);
+ address[1] = Utility.IntegerToOneByte(secondOctet);
+ address[2] = Utility.IntegerToOneByte(thirdOctet);
+ address[3] = Utility.IntegerToOneByte(fourthOctet);
+ return InetAddress.getByAddress(address);
+ }
+
+ public boolean equals(Object obj) {
+ try {
+ byte[] data1 = this.getBytes();
+ byte[] data2 = ((Address) obj).getBytes();
+ if ((data1[0] == data2[0]) && (data1[1] == data2[1]) &&
+ (data1[2] == data2[2]) && (data1[3] == data2[3]))
return true;
+ return false;
+ } catch (UtilityException ue) {
+ return false;
+ }
+ }
+
+}
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/util/Utility.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/util/Utility.java 2006-06-23
20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/util/Utility.java 2006-06-23
20:45:44 UTC (rev 9375)
@@ -0,0 +1,77 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.util;
+
+public class Utility {
+
+ public static final byte IntegerToOneByte(int value) throws
UtilityException {
+ if ((value > Math.pow(2,15)) || (value < 0)) {
+ throw new UtilityException("Integer value " + value + "
is larger than 2^15");
+ }
+ return (byte)(value & 0xFF);
+ }
+
+ public static final byte[] IntegerToTwoBytes(int value) throws
UtilityException {
+ byte[] result = new byte[2];
+ if ((value > Math.pow(2,31)) || (value < 0)) {
+ throw new UtilityException("Integer value " + value + "
is larger than 2^31");
+ }
+ result[0] = (byte)((value >>> 8) & 0xFF);
+ result[1] = (byte)(value & 0xFF);
+ return result;
+ }
+
+ public static final byte[] IntegerToFourBytes(int value) throws
UtilityException {
+ byte[] result = new byte[4];
+ if ((value > Math.pow(2,63)) || (value < 0)) {
+ throw new UtilityException("Integer value " + value + "
is larger than 2^63");
+ }
+ result[0] = (byte)((value >>> 24) & 0xFF);
+ result[1] = (byte)((value >>> 16) & 0xFF);
+ result[2] = (byte)((value >>> 8) & 0xFF);
+ result[3] = (byte)(value & 0xFF);
+ return result;
+ }
+
+ public static final int OneByteToInteger(byte value) throws
UtilityException {
+ return (int)value & 0xFF;
+ }
+
+ public static final int TwoBytesToInteger(byte[] value) throws
UtilityException {
+ if (value.length < 2) {
+ throw new UtilityException("Byte array too short!");
+ }
+ int temp0 = value[0] & 0xFF;
+ int temp1 = value[1] & 0xFF;
+ return ((temp0 << 8) + temp1);
+ }
+
+ public static final long FourBytesToLong(byte[] value) throws
UtilityException {
+ if (value.length < 4) {
+ throw new UtilityException("Byte array too short!");
+ }
+ int temp0 = value[0] & 0xFF;
+ int temp1 = value[1] & 0xFF;
+ int temp2 = value[2] & 0xFF;
+ int temp3 = value[3] & 0xFF;
+ return (((long)temp0 << 24) + (temp1 << 16) + (temp2 << 8) + temp3);
+ }
+}
Added: trunk/plugins/jSTUN/src/de/javawi/jstun/util/UtilityException.java
===================================================================
--- trunk/plugins/jSTUN/src/de/javawi/jstun/util/UtilityException.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/src/de/javawi/jstun/util/UtilityException.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,30 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.util;
+
+public class UtilityException extends Exception {
+ private static final long serialVersionUID = 3545800974716581680L;
+
+ UtilityException(String mesg) {
+ super(mesg);
+ }
+
+}
Added: trunk/plugins/jSTUN/test/de/javawi/jstun/AllTests.java
===================================================================
--- trunk/plugins/jSTUN/test/de/javawi/jstun/AllTests.java 2006-06-23
20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/test/de/javawi/jstun/AllTests.java 2006-06-23
20:45:44 UTC (rev 9375)
@@ -0,0 +1,37 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import de.javawi.jstun.util.*;
+import de.javawi.jstun.attribute.*;
+
+public class AllTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Test for de.javawi.jstun");
+ suite.addTestSuite(AddressTest.class);
+ suite.addTestSuite(MappedAddressTest.class);
+ return suite;
+ }
+
+}
Added: trunk/plugins/jSTUN/test/de/javawi/jstun/attribute/MappedAddressTest.java
===================================================================
--- trunk/plugins/jSTUN/test/de/javawi/jstun/attribute/MappedAddressTest.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/test/de/javawi/jstun/attribute/MappedAddressTest.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,117 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.attribute;
+
+import junit.framework.TestCase;
+
+public class MappedAddressTest extends TestCase {
+ MappedAddress ma;
+ byte[] data;
+ public MappedAddressTest(String mesg) {
+ super(mesg);
+ }
+
+ public void setUp() throws Exception {
+ data = new byte[8];
+ data[0] = 0;
+ data[1] = 1;
+ data[2] = -8;
+ data[3] = 96;
+ data[4] = 84;
+ data[5] = 56;
+ data[6] = -23;
+ data[7] = 76;
+ ma = (MappedAddress) MappedAddress.parse(data);
+ }
+
+ /*
+ * Test method for
'de.javawi.jstun.attribute.MappedAddress.MappedAddress()'
+ */
+ public void testMappedAddress() {
+ new MappedAddress();
+ }
+
+ /*
+ * Test method for
'de.javawi.jstun.attribute.MappedResponseChangedSourceAddressReflectedFrom.getBytes()'
+ */
+ public void testGetBytes() {
+ try {
+ byte[] result = ma.getBytes();
+
+ assertTrue(result[0] == 0);
+ assertTrue(result[1] == 1);
+ assertTrue(result[2] == 0);
+ assertTrue(result[3] == 8);
+ assertTrue(result[4] == data[0]);
+ assertTrue(result[5] == data[1]);
+ assertTrue(result[6] == data[2]);
+ assertTrue(result[7] == data[3]);
+ assertTrue(result[8] == data[4]);
+ assertTrue(result[9] == data[5]);
+ assertTrue(result[10] == data[6]);
+ assertTrue(result[11] == data[7]);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /*
+ * Test method for
'de.javawi.jstun.attribute.MappedResponseChangedSourceAddressReflectedFrom.getPort()'
+ */
+ public void testGetPort() {
+ assertTrue(ma.getPort() == 63584);
+ }
+
+ /*
+ * Test method for
'de.javawi.jstun.attribute.MappedResponseChangedSourceAddressReflectedFrom.getAddress()'
+ */
+ public void testGetAddress() {
+ try {
+ System.out.println(ma.getAddress().toString());
+ assertTrue(ma.getAddress().equals(new
de.javawi.jstun.util.Address("84.56.233.76")));
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /*
+ * Test method for
'de.javawi.jstun.attribute.MappedResponseChangedSourceAddressReflectedFrom.setPort(int)'
+ */
+ public void testSetPort() {
+
+ }
+
+ /*
+ * Test method for
'de.javawi.jstun.attribute.MappedResponseChangedSourceAddressReflectedFrom.setAddress(Address)'
+ */
+ public void testSetAddress() {
+
+ }
+
+ /*
+ * Test method for
'de.javawi.jstun.attribute.MappedResponseChangedSourceAddressReflectedFrom.toString()'
+ */
+ public void testToString() {
+
+ }
+
+}
Added: trunk/plugins/jSTUN/test/de/javawi/jstun/util/AddressTest.java
===================================================================
--- trunk/plugins/jSTUN/test/de/javawi/jstun/util/AddressTest.java
2006-06-23 20:42:40 UTC (rev 9374)
+++ trunk/plugins/jSTUN/test/de/javawi/jstun/util/AddressTest.java
2006-06-23 20:45:44 UTC (rev 9375)
@@ -0,0 +1,131 @@
+/*
+ * This file is part of JSTUN.
+ *
+ * Copyright (c) 2005 Thomas King <king at t-king.de>
+ *
+ * JSTUN is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * JSTUN is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with JSTUN; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package de.javawi.jstun.util;
+
+import junit.framework.TestCase;
+
+public class AddressTest extends TestCase {
+ Address address;
+
+ public AddressTest(String mesg) {
+ super(mesg);
+ }
+
+ protected void setUp() throws Exception {
+ address = new Address("192.168.100.1");
+ }
+
+ /*
+ * Test method for 'de.javawi.jstun.util.Address.Address(int, int, int,
int)'
+ */
+ public void testAddressIntIntIntInt() {
+ try {
+ Address comp = new Address(192,168,100,1);
+ assertTrue(address.equals(comp));
+ } catch (UtilityException ue) {
+ ue.printStackTrace();
+ }
+ }
+
+ /*
+ * Test method for 'de.javawi.jstun.util.Address.Address(String)'
+ */
+ public void testAddressString() {
+ try {
+ Address comp = new Address("192.168.100.1");
+ assertTrue(address.equals(comp));
+ } catch (UtilityException ue) {
+ ue.printStackTrace();
+ }
+ }
+
+ /*
+ * Test method for 'de.javawi.jstun.util.Address.Address(byte[])'
+ */
+ public void testAddressByteArray() {
+ try {
+ byte[] data = {(byte)192, (byte)168, (byte)100,
(byte)1};
+ Address comp = new Address(data);
+ assertTrue(address.equals(comp));
+ } catch (UtilityException ue) {
+ ue.printStackTrace();
+ }
+ }
+
+ /*
+ * Test method for 'de.javawi.jstun.util.Address.toString()'
+ */
+ public void testToString() {
+ try {
+ Address comp = new Address("192.168.100.1");
+ assertTrue(address.equals(comp));
+ } catch (UtilityException ue) {
+ ue.printStackTrace();
+ }
+ }
+
+ /*
+ * Test method for 'de.javawi.jstun.util.Address.getBytes()'
+ */
+ public void testGetBytes() {
+ try {
+ byte[] data = address.getBytes();
+ assertTrue(data[0] == (byte)192);
+ assertTrue(data[1] == (byte)168);
+ assertTrue(data[2] == (byte)100);
+ assertTrue(data[3] == (byte)1);
+ } catch (UtilityException ue) {
+ ue.printStackTrace();
+ }
+
+ }
+
+ /*
+ * Test method for 'de.javawi.jstun.util.Address.getInetAddress()'
+ */
+ public void testGetInetAddress() {
+ try {
+ Address comp = new Address("192.168.100.1");
+
assertTrue(address.getInetAddress().equals(comp.getInetAddress()));
+ comp = new Address("192.168.100.2");
+
assertFalse(address.getInetAddress().equals(comp.getInetAddress()));
+ } catch (UtilityException ue) {
+ ue.printStackTrace();
+ } catch (java.net.UnknownHostException uhe) {
+ uhe.printStackTrace();
+ }
+ }
+
+ /*
+ * Test method for 'de.javawi.jstun.util.Address.equals(Object)'
+ */
+ public void testEqualsObject() {
+ try {
+ Address comp = new Address("192.168.100.1");
+ assertTrue(address.equals(comp));
+ comp = new Address("192.168.100.2");
+ assertFalse(address.equals(comp));
+ } catch (UtilityException ue) {
+ ue.printStackTrace();
+ }
+ }
+
+}