nl.openfortress.socket6bed4
Class ServerNode

java.lang.Object
  extended by java.net.DatagramSocket
      extended by nl.openfortress.socket6bed4.ServerNode

public class ServerNode
extends DatagramSocket

Each ServerNode instance serves a connection to a particular 6bed4 tunnel server. This is reflected by its superclass, which is the principal address serviced -- the IPv4 address and UDP port for the server. As part of the service for a node, there is a neighbor cache. This may be compared to having a per-network neighbor cache as part of an operating system. Lookups may lead to more direct routes than would otherwise be possible. TODO: Hook up handle_4to6/handle_6to4 methods with receive/send. TODO: Handle IPv6 addr chg by throwing an IOException subclass. TODO: Establish NeighborCache with lladdr_6bed4, somehow.


Field Summary
protected  nl.openfortress.socket6bed4.NeighborCache ngbcache
           
protected  Inet6Address sharedAddress
           
protected  InetSocketAddress tunserver
           
 
Constructor Summary
ServerNode(InetSocketAddress isa)
          Create a connection to a 6bed4 tunnel server, and keep it active.
 
Method Summary
 void acknowledge_playful(byte[] addr, int ofs)
          Acknowledge a playful exchange to the Neighbor Cache.
 Inet6Address getShared6bed4Address()
          Return the shared 6bed4 address, usable for anyone who wants to allocate ports for UDP/TCP through either a Socket6bed4 or a DatagramSocket6bed4.
 Inet6Address getUnique6bed4Address(BlockingQueue<byte[]> recv_TODO_OR_KEEP_INTERNAL)
          Return a unique 6bed4 address, which is available for raw communication over IPv6.
 void handle_4to6_nd(byte[] pkt, int pktlen, SocketAddress src)
           
 void handle_4to6_plain(byte[] pkt, int pktlen)
           
 void handle_4to6(DatagramPacket datagram)
          Handle a 6bed4 packet that is being stripped and passed on as an IPv6 packet.
 void handle_6to4_nd(byte[] pkt, int pktlen)
           
 void handle_6to4_plain_unicast(byte[] pkt, int pktlen)
           
 void handle_6to4(byte[] pkt, int pktlen)
           
 InetSocketAddress lookup_neighbor(Inet6Address ia, boolean playful)
          Lookup a neighbor.
 byte[] receive_datagram(int port, int timeout)
          Pull an element from the BlockingQueue for the given Datagram port.
 void registerDatagramClient(int port)
           
 void stop()
          Teardown the connection to a 6bed4 tunnel server.
 void unregisterDatagramClient(int port)
           
 boolean useLess()
          Decrement the use counter, return if it is now useless
 void useMore()
          Increment the use counter
 void validate_originator(byte[] pkt, InetSocketAddress originator)
           
 
Methods inherited from class java.net.DatagramSocket
bind, close, connect, connect, disconnect, getBroadcast, getChannel, getInetAddress, getLocalAddress, getLocalPort, getLocalSocketAddress, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getSoTimeout, getTrafficClass, isBound, isClosed, isConnected, receive, send, setBroadcast, setDatagramSocketImplFactory, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSoTimeout, setTrafficClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tunserver

protected InetSocketAddress tunserver

ngbcache

protected nl.openfortress.socket6bed4.NeighborCache ngbcache

sharedAddress

protected Inet6Address sharedAddress
Constructor Detail

ServerNode

public ServerNode(InetSocketAddress isa)
           throws SocketException
Create a connection to a 6bed4 tunnel server, and keep it active.

Throws:
SocketException
Method Detail

stop

public void stop()
Teardown the connection to a 6bed4 tunnel server.


useMore

public void useMore()
Increment the use counter


useLess

public boolean useLess()
Decrement the use counter, return if it is now useless


registerDatagramClient

public void registerDatagramClient(int port)
                            throws SocketException
Throws:
SocketException

unregisterDatagramClient

public void unregisterDatagramClient(int port)
                              throws SocketException
Throws:
SocketException

getShared6bed4Address

public Inet6Address getShared6bed4Address()
Return the shared 6bed4 address, usable for anyone who wants to allocate ports for UDP/TCP through either a Socket6bed4 or a DatagramSocket6bed4. This routine will block until an address has been obtained. To allocate recipients on the shared address, use registerDatagramClient(port) and, hopefully one day, registerStreamClient(port). Raw access is not possible with this address; for that, use getUnique6bed4Address() as long as supply lasts.


getUnique6bed4Address

public Inet6Address getUnique6bed4Address(BlockingQueue<byte[]> recv_TODO_OR_KEEP_INTERNAL)
Return a unique 6bed4 address, which is available for raw communication over IPv6. Return null if no addresses are available anymore. Addresses returned from this function can be used as raw sockets. They share the communication channel setup for getShared6bed4Address() but the contents of the IPv6 packet will not be implemented, but rather relayed directly to the provided BlockingQueue instance. TODO: Sending, NxtHdr, and how to deal with security. TODO: Implement. Consider security implications.


receive_datagram

public byte[] receive_datagram(int port,
                               int timeout)
                        throws SocketException
Pull an element from the BlockingQueue for the given Datagram port. Block if no input is available. The timeout value is in milli-seconds, zero representing infinity (just as with setSoTimeout).

Throws:
SocketException

acknowledge_playful

public void acknowledge_playful(byte[] addr,
                                int ofs)
Acknowledge a playful exchange to the Neighbor Cache. This is a complex protocol, involving an interaction with the application layer, to confirm initial messages that support resends. Please see the documentation in NeighborCache and DatagramSocket6bed4 for details.


lookup_neighbor

public InetSocketAddress lookup_neighbor(Inet6Address ia,
                                         boolean playful)
Lookup a neighbor. Forwards to NeighborCache.


handle_4to6_nd

public void handle_4to6_nd(byte[] pkt,
                           int pktlen,
                           SocketAddress src)
                    throws IOException,
                           SocketException
Throws:
IOException
SocketException

handle_4to6_plain

public void handle_4to6_plain(byte[] pkt,
                              int pktlen)
                       throws IOException
Throws:
IOException

handle_4to6

public void handle_4to6(DatagramPacket datagram)
                 throws IOException
Handle a 6bed4 packet that is being stripped and passed on as an IPv6 packet. Returns true if the packet is suitable to be relayed as IPv6.

Throws:
IOException

validate_originator

public void validate_originator(byte[] pkt,
                                InetSocketAddress originator)
                         throws IOException
Throws:
IOException

handle_6to4_plain_unicast

public void handle_6to4_plain_unicast(byte[] pkt,
                                      int pktlen)
                               throws IOException
Throws:
IOException

handle_6to4_nd

public void handle_6to4_nd(byte[] pkt,
                           int pktlen)
                    throws IOException
Throws:
IOException

handle_6to4

public void handle_6to4(byte[] pkt,
                        int pktlen)
                 throws IOException
Throws:
IOException


Copyright © 2012. All Rights Reserved.