cgl.narada.transport.up2p
Class UP2PLinkFactory

java.lang.Object
  extended by cgl.narada.transport.udp.UDPLinkFactory
      extended by cgl.narada.transport.up2p.UP2PLinkFactory
All Implemented Interfaces:
LinkFactory, TransportDebugFlags

public class UP2PLinkFactory
extends UDPLinkFactory
implements LinkFactory, TransportDebugFlags

This is a UDP based P2P connetion link implementation. It uses the UDP hole punching technique while leveraging the existing UDP Link factory for processing connections

To initialize the UP2PLinkFactory one needs to specify the following

  • UP2PListenerPort , this is the port on which the process running this factory would listen to for datagram packet communications
  • PeerID, a unique peer ID used by this peer
  • RelayServerHost, the location of the relay server
  • RelayServerPort, the relay server port
  • To create a link to node B. The following properties needs to be specified.

  • hostname - The destination peer's PeerID to which a connection needs to be established. The destination peer's host/port will be obtained from the relay server


    Field Summary
     
    Fields inherited from class cgl.narada.transport.udp.UDPLinkFactory
    links, transportHandler, udpListenerSocket, udppinghandler, udpReceiverThread
     
    Fields inherited from interface cgl.narada.transport.TransportDebugFlags
    IPSecLink_Debug, IPSecLinkFactory_Debug, IPSecReceiverThread_Debug, IPSecSenderThread_Debug, IPSecServerThread_Debug, MulticastLink_Debug, MulticastLinkFactory_Debug, MulticastReceiverThread_Debug, MulticastSenderThread_Debug, NIOTCPLink_Debug, NIOTCPLinkFactory_Debug, NIOTCPReceiverThread_Debug, NIOTCPSenderThread_Debug, NIOTCPServerThread_Debug, PoolTCPLink_Debug, PoolTCPLinkFactory_Debug, PoolTCPLinkReceiver_Debug, PoolTCPLinkSender_Debug, PoolTCPServerThread_Debug, PTCPLink_Debug, PTCPLinkFactory_Debug, PTCPReceiverThread_Debug, PTCPSenderThread_Debug, PTCPServerThread_Debug, ReceiveTask_Debug, RTPLink_Debug, RTPLinkFactory_Debug, RTPReceiverThread_Debug, RTPSenderThread_Debug, SendTask_Debug, TCPLink_Debug, TCPLinkFactory_Debug, TCPReceiverThread_Debug, TCPSenderThread_Debug, TCPServerThread_Debug, TransmissionManager_Debug, TransportHandlerImpl_Debug, UDPLink_Debug, UDPLinkFactory_Debug, UDPReceiverThread_Debug, UDPSenderThread_Debug
     
    Constructor Summary
    UP2PLinkFactory()
               
     
    Method Summary
     Link createLink(Properties linkProperties)
              Create a communication link based on the properties that have been specified.
     void dispose()
              This method is used to garbage collect any resources associated with the link factory
     String getManagedLinksType()
              Return the type of all the links created/managed by this factory
     void handleP2P_CONN_REQ(InetAddress remoteAddress, int remotePort, String magic)
              This handles the connection request from the destination peer.
     void handleP2PConnectionRequest(byte[] data)
              This handles the P2P connection request that gets forwarded by the Relay server.
     void handleP2PConnectionResponse(byte[] data)
               
     void handleRegisterPeerResponse(byte[] data)
               
     boolean loadLinkFactoryServices()
              Starts communication services.
    static void main(String[] args)
               
     void setLinkFactoryProperties(Properties factoryProperties)
               
     
    Methods inherited from class cgl.narada.transport.udp.UDPLinkFactory
    canManageLinkMigrationOfType, getCurrentLink, getTransportHandler, handleInboundUDPLinkRequest, manageLinkMigration, reportLinkLoss, setLinkStatusInterval, setTransportHandler
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     
    Methods inherited from interface cgl.narada.transport.LinkFactory
    canManageLinkMigrationOfType, manageLinkMigration, setLinkStatusInterval, setTransportHandler
     

    Constructor Detail

    UP2PLinkFactory

    public UP2PLinkFactory()
    Method Detail

    setLinkFactoryProperties

    public void setLinkFactoryProperties(Properties factoryProperties)
    Specified by:
    setLinkFactoryProperties in interface LinkFactory
    Overrides:
    setLinkFactoryProperties in class UDPLinkFactory

    getManagedLinksType

    public String getManagedLinksType()
    Return the type of all the links created/managed by this factory

    Specified by:
    getManagedLinksType in interface LinkFactory
    Overrides:
    getManagedLinksType in class UDPLinkFactory

    createLink

    public Link createLink(Properties linkProperties)
                    throws TransportException
    Create a communication link based on the properties that have been specified.

    Specified by:
    createLink in interface LinkFactory
    Overrides:
    createLink in class UDPLinkFactory
    Throws:
    TransportException

    dispose

    public void dispose()
    This method is used to garbage collect any resources associated with the link factory

    Specified by:
    dispose in interface LinkFactory
    Overrides:
    dispose in class UDPLinkFactory

    loadLinkFactoryServices

    public boolean loadLinkFactoryServices()
                                    throws TransportException
    Starts communication services. In this case what we do is start the UDPListener thread, which listens to datagram packets arriving at the UDPListenerPort

    Specified by:
    loadLinkFactoryServices in interface LinkFactory
    Overrides:
    loadLinkFactoryServices in class UDPLinkFactory
    Throws:
    TransportException

    handleP2P_CONN_REQ

    public void handleP2P_CONN_REQ(InetAddress remoteAddress,
                                   int remotePort,
                                   String magic)
    This handles the connection request from the destination peer. The connection is correlated with the magic bundled with the connection request.

    Parameters:
    remoteAddress -
    remotePort -
    magic -

    handleP2PConnectionResponse

    public void handleP2PConnectionResponse(byte[] data)

    handleRegisterPeerResponse

    public void handleRegisterPeerResponse(byte[] data)

    handleP2PConnectionRequest

    public void handleP2PConnectionRequest(byte[] data)
    This handles the P2P connection request that gets forwarded by the Relay server. This essentially helps to punch a hole in this peer's NAT.

    Parameters:
    data -

    main

    public static void main(String[] args)


    For comments and suggestions please send e-mail to The NaradaBrokering Project