org.lastbamboo.common.ice
Class IceStunUdpPeer

java.lang.Object
  extended by org.lastbamboo.common.ice.IceStunUdpPeer
All Implemented Interfaces:
org.lastbamboo.common.stun.client.StunClient, org.lastbamboo.common.stun.server.StunServer, org.littleshoot.stun.stack.StunAddressProvider

public class IceStunUdpPeer
extends Object
implements org.lastbamboo.common.stun.client.StunClient, org.lastbamboo.common.stun.server.StunServer

ICE STUN peer class for UDP. This is basically just a STUN client for candidate gathering and a STUN server for processing incoming requests from peer reflexive candidates. NOTE: This class takes a little work to wrap one's head around as far as the socket SO_REUSEADDRESS option goes. Basically, we run both a client and a server on the same port. We're using MINA as the underlying IO framework, though, and MINA has connectors and acceptors. MINA calls connect on the underlying DatagramChannel for the connector. When that call is made, the channel will only accept incoming data from the host it's connected to. We also bind to that port with an accepting channel, though, so incoming data from other hosts goes to the accepting channel.

Note also that the behavior for what packets go where differs by operating system. On Windows, for example, packets from a host that has had DatagramSocket.connect() called for that host will not necessarily go to the "connected" host when there's another server socket bound to that port (using SO_REUSEADDRESS). If you followed that sentence, this means that both the connected "client" and the listening "server" message handling code needs to be prepared to be prepared to handle any message.


Constructor Summary
IceStunUdpPeer(org.littleshoot.mina.filter.codec.ProtocolCodecFactory demuxingCodecFactory, org.littleshoot.mina.common.IoHandler ioHandler, boolean controlling, org.littleshoot.stun.stack.transaction.StunTransactionTracker<org.littleshoot.stun.stack.message.StunMessage> transactionTracker, org.littleshoot.util.CandidateProvider<InetSocketAddress> stunServerCandidateProvider)
          Creates a new ICE STUN UDP peer.
 
Method Summary
 void addIoServiceListener(org.littleshoot.mina.common.IoServiceListener serviceListener)
           
 void close()
           
 void connect()
           
 InetSocketAddress getBoundAddress()
           
 InetSocketAddress getHostAddress()
           
 InetSocketAddress getRelayAddress()
           
 InetSocketAddress getServerReflexiveAddress()
           
 org.lastbamboo.common.stun.server.StunServer getStunServer()
           
 InetAddress getStunServerAddress()
           
 boolean hostPortMapped()
           
 void start()
           
 void start(InetSocketAddress bindAddress)
           
 String toString()
           
 org.littleshoot.stun.stack.message.StunMessage write(org.littleshoot.stun.stack.message.BindingRequest request, InetSocketAddress remoteAddress)
           
 org.littleshoot.stun.stack.message.StunMessage write(org.littleshoot.stun.stack.message.BindingRequest request, InetSocketAddress remoteAddress, long rto)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IceStunUdpPeer

public IceStunUdpPeer(org.littleshoot.mina.filter.codec.ProtocolCodecFactory demuxingCodecFactory,
                      org.littleshoot.mina.common.IoHandler ioHandler,
                      boolean controlling,
                      org.littleshoot.stun.stack.transaction.StunTransactionTracker<org.littleshoot.stun.stack.message.StunMessage> transactionTracker,
                      org.littleshoot.util.CandidateProvider<InetSocketAddress> stunServerCandidateProvider)
               throws IOException
Creates a new ICE STUN UDP peer.

Parameters:
demuxingCodecFactory - The class for interpreting the multiple protocols on the wire -- STUN and whatever protocol it's negotiating a connection for.
ioHandler - The class for handling read and written messages.
controlling - Whether or not this agent is controlling.
transactionTracker - The class for tracking STUN transactions.
Throws:
IOException - If there's an error connecting the client or server.
Method Detail

connect

public void connect()
             throws IOException
Specified by:
connect in interface org.lastbamboo.common.stun.client.StunClient
Throws:
IOException

getHostAddress

public InetSocketAddress getHostAddress()
Specified by:
getHostAddress in interface org.littleshoot.stun.stack.StunAddressProvider

getRelayAddress

public InetSocketAddress getRelayAddress()
Specified by:
getRelayAddress in interface org.littleshoot.stun.stack.StunAddressProvider

getServerReflexiveAddress

public InetSocketAddress getServerReflexiveAddress()
Specified by:
getServerReflexiveAddress in interface org.littleshoot.stun.stack.StunAddressProvider

getStunServerAddress

public InetAddress getStunServerAddress()
Specified by:
getStunServerAddress in interface org.littleshoot.stun.stack.StunAddressProvider

write

public org.littleshoot.stun.stack.message.StunMessage write(org.littleshoot.stun.stack.message.BindingRequest request,
                                                            InetSocketAddress remoteAddress)
Specified by:
write in interface org.lastbamboo.common.stun.client.StunClient

write

public org.littleshoot.stun.stack.message.StunMessage write(org.littleshoot.stun.stack.message.BindingRequest request,
                                                            InetSocketAddress remoteAddress,
                                                            long rto)
Specified by:
write in interface org.lastbamboo.common.stun.client.StunClient

start

public void start()
Specified by:
start in interface org.lastbamboo.common.stun.server.StunServer

start

public void start(InetSocketAddress bindAddress)
Specified by:
start in interface org.lastbamboo.common.stun.server.StunServer

getBoundAddress

public InetSocketAddress getBoundAddress()
Specified by:
getBoundAddress in interface org.lastbamboo.common.stun.server.StunServer

addIoServiceListener

public void addIoServiceListener(org.littleshoot.mina.common.IoServiceListener serviceListener)
Specified by:
addIoServiceListener in interface org.lastbamboo.common.stun.client.StunClient
Specified by:
addIoServiceListener in interface org.lastbamboo.common.stun.server.StunServer

close

public void close()
Specified by:
close in interface org.lastbamboo.common.stun.server.StunServer
Specified by:
close in interface org.littleshoot.stun.stack.StunAddressProvider

hostPortMapped

public boolean hostPortMapped()

getStunServer

public org.lastbamboo.common.stun.server.StunServer getStunServer()

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013 LittleShoot. All Rights Reserved.