Class TUNNEL

All Implemented Interfaces:
Lifecycle, DiagnosticsHandler.ProbeHandler, RouterStub.StubReceiver

public class TUNNEL extends TP implements RouterStub.StubReceiver
Replacement for UDP. Instead of sending packets via UDP, a TCP connection is opened to a Router (using the RouterStub client-side stub), the IP address/port of which was given using channel properties router_host and router_port. All outgoing traffic is sent via this TCP socket to the Router which distributes it to all connected TUNNELs in this group. Incoming traffic received from Router will simply be passed up the stack.

A TUNNEL layer can be used to penetrate a firewall, most firewalls allow creating TCP connections to the outside world, however, they do not permit outside hosts to initiate a TCP connection to a host inside the firewall. Therefore, the connection created by the inside host is reused by Router to send traffic from an outside host to a host inside the firewall.

  • Field Details

    • reconnect_interval

      protected long reconnect_interval
    • tcp_nodelay

      protected boolean tcp_nodelay
    • use_nio

      protected boolean use_nio
    • gossip_router_hosts

      protected String gossip_router_hosts
    • heartbeat_interval

      protected long heartbeat_interval
    • heartbeat_timeout

      protected long heartbeat_timeout
    • linger

      protected int linger
    • non_blocking_sends

      protected boolean non_blocking_sends
    • max_send_queue

      protected int max_send_queue
    • gossip_routers

      protected final List<InetSocketAddress> gossip_routers
    • tunnel_policy

      protected TUNNEL.TUNNELPolicy tunnel_policy
    • sock

      protected DatagramSocket sock
    • stubManager

      protected volatile RouterStubManager stubManager
    • tls

      protected TLS tls
  • Constructor Details

    • TUNNEL

      public TUNNEL()
  • Method Details

    • getReconnectInterval

      public long getReconnectInterval()
    • setReconnectInterval

      public TUNNEL setReconnectInterval(long r)
    • isTcpNodelay

      public boolean isTcpNodelay()
    • setTcpNodelay

      public TUNNEL setTcpNodelay(boolean nd)
    • useNio

      public boolean useNio()
    • useNio

      public TUNNEL useNio(boolean use_nio)
    • tls

      public TLS tls()
    • tls

      public TUNNEL tls(TLS t)
    • getLinger

      public int getLinger()
    • setLinger

      public TUNNEL setLinger(int l)
    • nonBlockingSends

      public boolean nonBlockingSends()
    • nonBlockingSends

      public TUNNEL nonBlockingSends(boolean b)
    • maxSendQueue

      public int maxSendQueue()
    • maxSendQueue

      public TUNNEL maxSendQueue(int s)
    • supportsMulticasting

      public boolean supportsMulticasting()
      We can simply send a message with dest == null and the GossipRouter will take care of routing it to all members in the cluster
      Specified by:
      supportsMulticasting in class TP
    • setGossipRouterHosts

      public TUNNEL setGossipRouterHosts(String hosts) throws UnknownHostException
      Throws:
      UnknownHostException
    • isReconnectorTaskRunning

      public boolean isReconnectorTaskRunning()
    • isHeartbeatTaskRunning

      public boolean isHeartbeatTaskRunning()
    • isTimeoutCheckTaskRunning

      public boolean isTimeoutCheckTaskRunning()
    • print

      public String print()
    • printStubs

      public String printStubs()
    • printReconnectList

      public String printReconnectList()
    • getStubManager

      public RouterStubManager getStubManager()
    • toString

      public String toString()
      Overrides:
      toString in class TP
    • setTUNNELPolicy

      public TUNNEL setTUNNELPolicy(TUNNEL.TUNNELPolicy policy)
    • init

      public void init() throws Exception
      Description copied from class: Protocol
      Called after a protocol has been created and before the protocol is started. Attributes are already set. Other protocols are not yet connected and events cannot yet be sent.
      Specified by:
      init in interface Lifecycle
      Overrides:
      init in class TP
      Throws:
      Exception - Thrown if protocol cannot be initialized successfully. This will cause the ProtocolStack to fail, so the the channel constructor will throw an exception
    • start

      public void start() throws Exception
      Description copied from class: TP
      Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads
      Specified by:
      start in interface Lifecycle
      Overrides:
      start in class TP
      Throws:
      Exception - Thrown if protocol cannot be started successfully. This will cause the ProtocolStack to fail, so JChannel.connect(String) will throw an exception
    • destroy

      public void destroy()
      Description copied from class: Protocol
      This method is called on a JChannel.close(). Does some cleanup; after the call, the VM will terminate
      Specified by:
      destroy in interface Lifecycle
      Overrides:
      destroy in class TP
    • disconnectStub

      private void disconnectStub()
    • down

      public Object down(Event evt)
      Description copied from class: Protocol
      An event is to be sent down the stack. A protocol may want to examine its type and perform some action on it, depending on the event's type. If the event is a message MSG, then the protocol may need to add a header to it (or do nothing at all) before sending it down the stack using down_prot.down().
      Overrides:
      down in class TP
    • receive

      public void receive(GossipData data)
      Specified by:
      receive in interface RouterStub.StubReceiver
    • sendToAll

      public void sendToAll(byte[] data, int offset, int length) throws Exception
      Description copied from class: TP
      Fetches the physical addrs for all mbrs and sends the msg to each physical address. Asks discovery for missing members' physical addresses if needed
      Overrides:
      sendToAll in class TP
      Throws:
      Exception
    • sendUnicast

      public void sendUnicast(PhysicalAddress dest, byte[] data, int offset, int length) throws Exception
      Description copied from class: TP
      Send a unicast to a member. Note that the destination address is a *physical*, not a logical address
      Specified by:
      sendUnicast in class TP
      Parameters:
      dest - Must be a non-null unicast address
      data - The data to be sent. This is not a copy, so don't modify it
      Throws:
      Exception
    • sendTo

      protected void sendTo(Address dest, byte[] buf, int offset, int length) throws Exception
      Overrides:
      sendTo in class TP
      Throws:
      Exception
    • sendUnicast

      protected void sendUnicast(Address dest, byte[] data, int offset, int length) throws Exception
      Throws:
      Exception
    • getInfo

      public String getInfo()
      Specified by:
      getInfo in class TP
    • getPhysicalAddress

      protected PhysicalAddress getPhysicalAddress()
      Specified by:
      getPhysicalAddress in class TP