Skip to main content

STUN server in SailFin

Posted by rampsarathy on March 9, 2009 at 12:09 AM PDT




http-equiv="content-type">
Simple Stun Server in SailFin


STUN
(Simple Traversal of User Datagram Protocol (UDP) Through Network Address Translators (NATs), defined by RFC 3489) is a
protocol that helps  devices (clients) behind a NAT firewall
or router with routing of packets. The protocol helps devices to find
out the type of NAT service (Full Cone, Restricted Cone, Port
Restricted Cone and  Symmetric) as well as their public
address. A STUN client, typically executes on a networked device (mobile
phone, soft phone..) and generates STUN requests to a STUN server that
is hosted on the public domain.



SailFin can be extended to provide STUN service, BINDING requests
primarily. A simple STUN server is now available in Project SailFin and
is implemented as a lifecycle module. When the STUN lifecycle module is
deployed and enabled, the STUN server starts up and listens for BINDING
requests from STUN clients. Soft-phones (like Xlite) can be configured
to use the STUN server in SailFin to discover the NAT service and their
public address.

Since, SailFin uses the socket connector from Project Grizzly, the
STUN  service is also implemented using the Grizzly APIs. The
picture below provides an overall view of STUN service in SailFin.




style="width: 475px; height: 553px;" alt="stun in sailfin"
src="http://weblogs.java.net/blog/rampsarathy/archive/stun_pic.jpg">





The source code for the STUN server implementation in SailFin can be
found here

http://fisheye5.cenqua.com/browse/sailfin/value-adds/stun-server



The source code is available under the value-adds/stun-server folder in the SailFin workspace. Or it can be checked out explicitely (cvs co
sailfin/value-adds/stun-server) . It can compiled either from the bootstrap folder or from the stun-server folder. On successful compilation , it generates
a lifecycle module jar file , stun-server.jar, (under
WORKSPACE/value-adds/stun-server/build/dist)  that can be
deployed to SailFin. This is a self contained jar file that contains
the STUN server implementation and the implementation of the lifecycle
interface to manage the start/stop of the server.

When using  SailFin's build workspace, the "setup" target
(under stun-server module) would deploy the lifecycle module to the
SailFin server in the workspace.



 Alternatively, the lifecycle jar file
(stun-server.jar) can be deployed to any SailFin instance using the
"create-lifecycle-module" command and providing "
org.jvnet.glassfish.comms.stun.StunServerLifecycle" as the classname
and the path to stun-server.jar as the classpath.



After deploying the lifecycle module, and restarting the server, the
STUN server should be available on port 3478. The SailFin instance
can now be used as a STUN service provider apart from
being a SIP server.

You could also enable FINEST logging for the stun server by adding the property "<property name="stun" value="FINEST"/>" to the module-log-levels section of the SailFin configuration. This should log the STUN messages (received and sent) in the server.log file.



Please note that this is a basic implementation that supports BINDING requests only (not all flags/attributes are supported today). If you find an issue where a softphone works with a public stun server and has an issue working with SailFin, please create an issue in the SailFin project.













Related Topics >>