nl.openfortress.socket6bed4
Class DatagramSocket6bed4

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

public class DatagramSocket6bed4
extends DatagramSocket

Socket6bed4 describes sockets that are run over IPv6. This means that a remote IPv6 address can be contacted when there are only IPv4 addresses available locally. A Socket6bed4 can switch between IPv4 transports; it can either send to a 6bed4 server, or directly to the targeted peer. Either path is acceptable as. The Socket can arrange this automatically, using peering attempts through Neighbor Discovery. Perhaps it's a bit silly to make a 6bed4 DatagramSocket a subclass of a plain DatagramSocket. It is very practical however; it means that these objects can be substituted anywhere, without question.


Field Summary
protected  InetSocketAddress cnx6sa
           
protected  int ephemeral
           
protected  DatagramSocket ipv4socket
           
protected  InetSocketAddress my6sa
           
protected  ServerNode my6sn
           
protected  byte[] prephdr_udp
           
protected static DatagramSocket server_ipv4socket
           
 
Constructor Summary
DatagramSocket6bed4()
           
DatagramSocket6bed4(DatagramSocketImpl impl)
           
DatagramSocket6bed4(InetSocketAddress bindaddr)
          Construct a new DatagramSocket6bed4 based on an underlying DatagramSocket for IPv4.
DatagramSocket6bed4(int port)
           
DatagramSocket6bed4(int port, Inet6Address bindaddr)
           
 
Method Summary
 void acknowledge_playful(Inet6Address ia6bed4)
          In a playfully hinting exchange with send_playful() and receive_playful(), this is the final acknowledgement that should be called upon completion.
 void bind(InetSocketAddress sa)
          Attempt to bind to an address and/or port, exercising 6bed4 constraints as they arise from the router advertisement.
 void bind(int port)
           
 void connect(InetAddress address, int port)
          Connect to a remote IPv6 address and UDP port.
 void connect(InetSocketAddress addr)
           
 void disconnect()
          Disconnect from a remote IPv6 address and UDP port.
 InetAddress getInetAddress()
          Return currect remote address
 InetAddress getLocalAddress()
          Return local address
 int getLocalPort()
          Return local port
 InetSocketAddress getLocalSocketAddress()
          Return bound local socket address
 int getPort()
          Return currect local port
 InetSocketAddress getRemoteSocketAddress()
          Return remote sock address
 boolean isBound()
          Are we bound?
 boolean isConnected()
          Are we connected?
 boolean receive_playful(DatagramPacket pkt6)
          Receive a packet from the underlying IPv4 layer.
 void receive(DatagramPacket pkt6)
          The "standard" interface for receiving bytes, overriding the parent function and not supporting playful operation.
 void send_playful(DatagramPacket pkt6, boolean playful)
          The interface for DatagramPackets conceals the UDP layer underlaying the actual data exchanged.
 void send(DatagramPacket pkt6)
          The "standard" interface for sending bytes, overriding the parent function and not sending playful hints.
 void setDefaultServer(Inet4Address server4, int port4)
           
 void useDefaultServer()
           
 
Methods inherited from class java.net.DatagramSocket
bind, close, connect, getBroadcast, getChannel, getReceiveBufferSize, getReuseAddress, getSendBufferSize, getSoTimeout, getTrafficClass, isClosed, 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

server_ipv4socket

protected static DatagramSocket server_ipv4socket

ipv4socket

protected DatagramSocket ipv4socket

cnx6sa

protected InetSocketAddress cnx6sa

my6sa

protected InetSocketAddress my6sa

my6sn

protected ServerNode my6sn

ephemeral

protected int ephemeral

prephdr_udp

protected byte[] prephdr_udp
Constructor Detail

DatagramSocket6bed4

public DatagramSocket6bed4(InetSocketAddress bindaddr)
                    throws SocketException
Construct a new DatagramSocket6bed4 based on an underlying DatagramSocket for IPv4.

Throws:
SocketException

DatagramSocket6bed4

public DatagramSocket6bed4(int port,
                           Inet6Address bindaddr)
                    throws SocketException
Throws:
SocketException

DatagramSocket6bed4

public DatagramSocket6bed4(int port)
                    throws SocketException
Throws:
SocketException

DatagramSocket6bed4

public DatagramSocket6bed4()
                    throws SocketException
Throws:
SocketException

DatagramSocket6bed4

public DatagramSocket6bed4(DatagramSocketImpl impl)
                    throws SocketException
Throws:
SocketException
Method Detail

useDefaultServer

public void useDefaultServer()

setDefaultServer

public void setDefaultServer(Inet4Address server4,
                             int port4)
                      throws SocketException
Throws:
SocketException

getInetAddress

public InetAddress getInetAddress()
Return currect remote address

Overrides:
getInetAddress in class DatagramSocket

getPort

public int getPort()
Return currect local port

Overrides:
getPort in class DatagramSocket

getRemoteSocketAddress

public InetSocketAddress getRemoteSocketAddress()
Return remote sock address

Overrides:
getRemoteSocketAddress in class DatagramSocket

getLocalAddress

public InetAddress getLocalAddress()
Return local address

Overrides:
getLocalAddress in class DatagramSocket

getLocalPort

public int getLocalPort()
Return local port

Overrides:
getLocalPort in class DatagramSocket

getLocalSocketAddress

public InetSocketAddress getLocalSocketAddress()
Return bound local socket address

Overrides:
getLocalSocketAddress in class DatagramSocket

bind

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

bind

public void bind(InetSocketAddress sa)
          throws SocketException
Attempt to bind to an address and/or port, exercising 6bed4 constraints as they arise from the router advertisement.

Throws:
SocketException

isBound

public boolean isBound()
Are we bound?

Overrides:
isBound in class DatagramSocket

connect

public void connect(InetAddress address,
                    int port)
Connect to a remote IPv6 address and UDP port.

Overrides:
connect in class DatagramSocket

connect

public void connect(InetSocketAddress addr)

disconnect

public void disconnect()
Disconnect from a remote IPv6 address and UDP port.

Overrides:
disconnect in class DatagramSocket

isConnected

public boolean isConnected()
Are we connected?

Overrides:
isConnected in class DatagramSocket

send_playful

public void send_playful(DatagramPacket pkt6,
                         boolean playful)
                  throws IOException
The interface for DatagramPackets conceals the UDP layer underlaying the actual data exchanged. For 6bed4 however, a few headers will have to be prefixed. These are the IPv6 header and UDP-over-IPv6 header. The underlying DatagramSocket for IPv4 will conceal the UDP-over-IPv4. Details about playful hints are described in the class NeighborCache. In general, the hint should only be given for packets that will be re-sent upon failure, and whose success of delivery can be reported back. This can then be used to setup direct connections to peers without explicit negotiation through Neighbor Discovery. You can safely set the playful flag on all similar traffic, as it will only influence on initial attempts at traffic. A good efficiency trade-off is to use playful hints only on initiating UDP messages, such as a SIP INVITE.

Throws:
IOException

receive_playful

public boolean receive_playful(DatagramPacket pkt6)
                        throws IOException
Receive a packet from the underlying IPv4 layer. As with sending, the UDP underneath the packet is hidden, but for 6bed4 the IPv6 and UDP-over-IPv6 headers must be stripped and interpreted. Only traffic destined for our own combination of IPv6 address and UDP-over-IPv6 port will be passed on to us. The hint returned indicates if the datagram was received directly from the peer. This information may be of varying use to implementations, but it would be specifically useful for confirmation of playfully sent packets, as described for the send_playful () method. To this end, the method acknowledge_playful () is used to complete the cycle of optimistic direct connections to peers.

Throws:
IOException

acknowledge_playful

public void acknowledge_playful(Inet6Address ia6bed4)
In a playfully hinting exchange with send_playful() and receive_playful(), this is the final acknowledgement that should be called upon completion. This acknowledges a reliable direct connection to a peer without a need to go through explicit Neighbor Discovery. The pkt6 parameter holds the remote peer's address. Note that invoking this function when receive_playful() returned false for the exchane is a damn lie, and may end up configuring the NeighborCache entry for this neighbor with a direct route that does not actually function. You will then end up sending messages into oblivia. Also note that plaful sends are an optimistic variation that is not strictly necessary; the NeighborCache has its own method builtin, based on Neighbor Discovery. If a direct link to a peer is possible at all, then this will find it. Only if you wish to use the optimistic variation to avoid these extra exchanges should you consider playful mode. After all this discouraging information it should also be noted that your network traffic will look extremely cool if it manages to get through directly to a 6bed4 peer without any explicit negotiation!


send

public void send(DatagramPacket pkt6)
          throws IOException
The "standard" interface for sending bytes, overriding the parent function and not sending playful hints.

Overrides:
send in class DatagramSocket
Throws:
IOException

receive

public void receive(DatagramPacket pkt6)
             throws IOException
The "standard" interface for receiving bytes, overriding the parent function and not supporting playful operation.

Overrides:
receive in class DatagramSocket
Throws:
IOException


Copyright © 2012. All Rights Reserved.