Rice Pastry API

org.mpisws.p2p.transport.networkinfo
Class NetworkInfoTransportLayer

java.lang.Object
  extended by org.mpisws.p2p.transport.networkinfo.NetworkInfoTransportLayer
All Implemented Interfaces:
InetSocketAddressLookup, Prober, TransportLayer<java.net.InetSocketAddress,java.nio.ByteBuffer>, TransportLayerCallback<java.net.InetSocketAddress,java.nio.ByteBuffer>, Destructable

public class NetworkInfoTransportLayer
extends java.lang.Object
implements InetSocketAddressLookup, Prober, TransportLayer<java.net.InetSocketAddress,java.nio.ByteBuffer>, TransportLayerCallback<java.net.InetSocketAddress,java.nio.ByteBuffer>

Can open a TCP connection to a known node, and it will return your IP address. Use getMyIpAddress() header = 0; // bypass header = 1; // return IP Also holds a "serialized id." This is an externally specified piece of information. It can be a NodeHandle, a PublicKey etc, any information that any node should be able to query for and may need to do so w/o having a joined PastryNode.

Author:
Jeff Hoye

Field Summary
protected  TransportLayerCallback<java.net.InetSocketAddress,java.nio.ByteBuffer> callback
           
protected  Environment environment
           
protected  ErrorHandler<java.net.InetSocketAddress> errorHandler
           
protected static byte HEADER_ID_REQUEST_BYTE
           
protected static byte[] HEADER_IP_ADDRESS_REQUEST
           
protected static byte HEADER_IP_ADDRESS_REQUEST_BYTE
           
protected static byte[] HEADER_NODES_REQUEST
           
protected static byte HEADER_NODES_REQUEST_BYTE
           
protected static byte[] HEADER_PASSTHROUGH
           
protected static byte HEADER_PASSTHROUGH_BYTE
           
protected static byte HEADER_PROBE_REQUEST_BYTE
           
protected static byte HEADER_PROBE_RESPONSE_BYTE
           
protected  Logger logger
           
protected  ProbeStrategy probeStrategy
          Ask this strategy to probe a requesting node, but from a 3rd party node
protected  TransportLayer<java.net.InetSocketAddress,java.nio.ByteBuffer> tl
           
 
Constructor Summary
NetworkInfoTransportLayer(TransportLayer<java.net.InetSocketAddress,java.nio.ByteBuffer> tl, Environment env, ErrorHandler<java.net.InetSocketAddress> errorHandler)
           
 
Method Summary
 void acceptMessages(boolean b)
          Toggle accepting incoming messages.
 void acceptSockets(boolean b)
          Toggle accepting new sockets.
 void destroy()
           
 Cancellable getExternalNodes(java.net.InetSocketAddress bootstrap, Continuation<java.util.Collection<java.net.InetSocketAddress>,java.io.IOException> c, java.util.Map<java.lang.String,java.lang.Object> options)
          find nodes outside of our firewall so I can boot
 Cancellable getId(java.net.InetSocketAddress bootstrap, byte index, Continuation<byte[],java.io.IOException> c, java.util.Map<java.lang.String,java.lang.Object> options)
           
 java.net.InetSocketAddress getLocalIdentifier()
          The local node.
 Cancellable getMyInetAddress(java.net.InetSocketAddress bootstrap, Continuation<java.net.InetSocketAddress,java.io.IOException> c, java.util.Map<java.lang.String,java.lang.Object> options)
          Returns the local node's InetSocketAddress
 void handleIdRequest(P2PSocket<java.net.InetSocketAddress> socket)
           
 void handleIpRequest(P2PSocket<java.net.InetSocketAddress> socket)
           
 void handleNodesRequest(P2PSocket<java.net.InetSocketAddress> socket)
           
 void handleProbeRequest(P2PSocket<java.net.InetSocketAddress> socket)
           
 void handleProbeResponse(P2PSocket<java.net.InetSocketAddress> socket)
           
 void incomingSocket(P2PSocket<java.net.InetSocketAddress> s)
          Notification of a new socket.
 void messageReceived(java.net.InetSocketAddress i, java.nio.ByteBuffer m, java.util.Map<java.lang.String,java.lang.Object> options)
          Called when a new message is received.
 SocketRequestHandle<java.net.InetSocketAddress> openSocket(java.net.InetSocketAddress i, byte[] header, SocketCallback<java.net.InetSocketAddress> deliverSocketToMe, java.util.Map<java.lang.String,java.lang.Object> options)
           
 SocketRequestHandle<java.net.InetSocketAddress> openSocket(java.net.InetSocketAddress i, SocketCallback<java.net.InetSocketAddress> deliverSocketToMe, java.util.Map<java.lang.String,java.lang.Object> options)
          Open a socket to the Identifier
 Cancellable probe(java.net.InetSocketAddress addr, long uid, Continuation<java.lang.Long,java.lang.Exception> deliverResponseToMe, java.util.Map<java.lang.String,java.lang.Object> options)
           
 MessageRequestHandle<java.net.InetSocketAddress,java.nio.ByteBuffer> sendMessage(java.net.InetSocketAddress i, java.nio.ByteBuffer m, MessageCallback<java.net.InetSocketAddress,java.nio.ByteBuffer> deliverAckToMe, java.util.Map<java.lang.String,java.lang.Object> options)
          Set the PASSTHROUGH header
 void setCallback(TransportLayerCallback<java.net.InetSocketAddress,java.nio.ByteBuffer> callback)
          Set the callback for incoming sockets/messages
 void setErrorHandler(ErrorHandler<java.net.InetSocketAddress> handler)
          To be notified of problems not related to an outgoing messaage/socket.
 void setId(byte index, byte[] value)
           
 void setProbeStrategy(ProbeStrategy probeStrategy)
           
 Cancellable verifyConnectivity(MultiInetSocketAddress local, java.net.InetSocketAddress probeAddress, ConnectivityResult deliverResultToMe, java.util.Map<java.lang.String,java.lang.Object> options)
          ask probeAddress to call probeStrategy.requestProbe()
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected Logger logger

environment

protected Environment environment

callback

protected TransportLayerCallback<java.net.InetSocketAddress,java.nio.ByteBuffer> callback

errorHandler

protected ErrorHandler<java.net.InetSocketAddress> errorHandler

tl

protected TransportLayer<java.net.InetSocketAddress,java.nio.ByteBuffer> tl

HEADER_PASSTHROUGH_BYTE

protected static final byte HEADER_PASSTHROUGH_BYTE
See Also:
Constant Field Values

HEADER_IP_ADDRESS_REQUEST_BYTE

protected static final byte HEADER_IP_ADDRESS_REQUEST_BYTE
See Also:
Constant Field Values

HEADER_PROBE_REQUEST_BYTE

protected static final byte HEADER_PROBE_REQUEST_BYTE
See Also:
Constant Field Values

HEADER_PROBE_RESPONSE_BYTE

protected static final byte HEADER_PROBE_RESPONSE_BYTE
See Also:
Constant Field Values

HEADER_NODES_REQUEST_BYTE

protected static final byte HEADER_NODES_REQUEST_BYTE
See Also:
Constant Field Values

HEADER_ID_REQUEST_BYTE

protected static final byte HEADER_ID_REQUEST_BYTE
See Also:
Constant Field Values

HEADER_PASSTHROUGH

protected static final byte[] HEADER_PASSTHROUGH

HEADER_IP_ADDRESS_REQUEST

protected static final byte[] HEADER_IP_ADDRESS_REQUEST

HEADER_NODES_REQUEST

protected static final byte[] HEADER_NODES_REQUEST

probeStrategy

protected ProbeStrategy probeStrategy
Ask this strategy to probe a requesting node, but from a 3rd party node

Constructor Detail

NetworkInfoTransportLayer

public NetworkInfoTransportLayer(TransportLayer<java.net.InetSocketAddress,java.nio.ByteBuffer> tl,
                                 Environment env,
                                 ErrorHandler<java.net.InetSocketAddress> errorHandler)
Method Detail

getMyInetAddress

public Cancellable getMyInetAddress(java.net.InetSocketAddress bootstrap,
                                    Continuation<java.net.InetSocketAddress,java.io.IOException> c,
                                    java.util.Map<java.lang.String,java.lang.Object> options)
Description copied from interface: InetSocketAddressLookup
Returns the local node's InetSocketAddress

Specified by:
getMyInetAddress in interface InetSocketAddressLookup
Parameters:
bootstrap - who to ask
c - where the return value is delivered
options - can be null
Returns:
you can cancel the operation

setId

public void setId(byte index,
                  byte[] value)

getId

public Cancellable getId(java.net.InetSocketAddress bootstrap,
                         byte index,
                         Continuation<byte[],java.io.IOException> c,
                         java.util.Map<java.lang.String,java.lang.Object> options)

getExternalNodes

public Cancellable getExternalNodes(java.net.InetSocketAddress bootstrap,
                                    Continuation<java.util.Collection<java.net.InetSocketAddress>,java.io.IOException> c,
                                    java.util.Map<java.lang.String,java.lang.Object> options)
Description copied from interface: InetSocketAddressLookup
find nodes outside of our firewall so I can boot

Specified by:
getExternalNodes in interface InetSocketAddressLookup
Returns:

openSocket

public SocketRequestHandle<java.net.InetSocketAddress> openSocket(java.net.InetSocketAddress i,
                                                                  SocketCallback<java.net.InetSocketAddress> deliverSocketToMe,
                                                                  java.util.Map<java.lang.String,java.lang.Object> options)
Description copied from interface: TransportLayer
Open a socket to the Identifier

Specified by:
openSocket in interface TransportLayer<java.net.InetSocketAddress,java.nio.ByteBuffer>
Parameters:
i - who to open the socket to
deliverSocketToMe - the callback when the socket is opened
options - options on how to open the socket (don't source route, encrypt etc) (may not be respected if layer cannot provide service)
Returns:
an object to cancel opening the socket if it takes to long, or is no longer relevant

openSocket

public SocketRequestHandle<java.net.InetSocketAddress> openSocket(java.net.InetSocketAddress i,
                                                                  byte[] header,
                                                                  SocketCallback<java.net.InetSocketAddress> deliverSocketToMe,
                                                                  java.util.Map<java.lang.String,java.lang.Object> options)

incomingSocket

public void incomingSocket(P2PSocket<java.net.InetSocketAddress> s)
                    throws java.io.IOException
Description copied from interface: TransportLayerCallback
Notification of a new socket.

Specified by:
incomingSocket in interface TransportLayerCallback<java.net.InetSocketAddress,java.nio.ByteBuffer>
Parameters:
s - the incoming socket
Throws:
java.io.IOException

handleIpRequest

public void handleIpRequest(P2PSocket<java.net.InetSocketAddress> socket)
                     throws java.io.IOException
Throws:
java.io.IOException

handleNodesRequest

public void handleNodesRequest(P2PSocket<java.net.InetSocketAddress> socket)
                        throws java.io.IOException
Throws:
java.io.IOException

handleIdRequest

public void handleIdRequest(P2PSocket<java.net.InetSocketAddress> socket)
                     throws java.io.IOException
Throws:
java.io.IOException

handleProbeRequest

public void handleProbeRequest(P2PSocket<java.net.InetSocketAddress> socket)

handleProbeResponse

public void handleProbeResponse(P2PSocket<java.net.InetSocketAddress> socket)

setCallback

public void setCallback(TransportLayerCallback<java.net.InetSocketAddress,java.nio.ByteBuffer> callback)
Description copied from interface: TransportLayer
Set the callback for incoming sockets/messages

Specified by:
setCallback in interface TransportLayer<java.net.InetSocketAddress,java.nio.ByteBuffer>
Parameters:
callback - the callback for incoming sockets/messages

setErrorHandler

public void setErrorHandler(ErrorHandler<java.net.InetSocketAddress> handler)
Description copied from interface: TransportLayer
To be notified of problems not related to an outgoing messaage/socket. Or to be notified if a callback isn't provided.

Specified by:
setErrorHandler in interface TransportLayer<java.net.InetSocketAddress,java.nio.ByteBuffer>
Parameters:
handler - to be notified of problems not related to a specific messaage/socket.

acceptMessages

public void acceptMessages(boolean b)
Description copied from interface: TransportLayer
Toggle accepting incoming messages. Useful in flow control if overwhelmed by incoming sockets. Default: true

Specified by:
acceptMessages in interface TransportLayer<java.net.InetSocketAddress,java.nio.ByteBuffer>

acceptSockets

public void acceptSockets(boolean b)
Description copied from interface: TransportLayer
Toggle accepting new sockets. Useful in flow control if overwhelmed by incoming sockets. Default: true

Specified by:
acceptSockets in interface TransportLayer<java.net.InetSocketAddress,java.nio.ByteBuffer>

getLocalIdentifier

public java.net.InetSocketAddress getLocalIdentifier()
Description copied from interface: TransportLayer
The local node.

Specified by:
getLocalIdentifier in interface TransportLayer<java.net.InetSocketAddress,java.nio.ByteBuffer>
Returns:
The local node.

sendMessage

public MessageRequestHandle<java.net.InetSocketAddress,java.nio.ByteBuffer> sendMessage(java.net.InetSocketAddress i,
                                                                                        java.nio.ByteBuffer m,
                                                                                        MessageCallback<java.net.InetSocketAddress,java.nio.ByteBuffer> deliverAckToMe,
                                                                                        java.util.Map<java.lang.String,java.lang.Object> options)
Set the PASSTHROUGH header

Specified by:
sendMessage in interface TransportLayer<java.net.InetSocketAddress,java.nio.ByteBuffer>
Parameters:
i - the destination
m - the message
deliverAckToMe - layer dependent notification when the message is sent (can indicate placed on the wire, point-to-point acknowledgment, or end-to-end acknowledgement)
options - delivery options (don't source route, encrypt etc) (may not be respected if layer cannot provide service)
Returns:
ability to cancel the message if no longer relevant

messageReceived

public void messageReceived(java.net.InetSocketAddress i,
                            java.nio.ByteBuffer m,
                            java.util.Map<java.lang.String,java.lang.Object> options)
                     throws java.io.IOException
Description copied from interface: TransportLayerCallback
Called when a new message is received.

Specified by:
messageReceived in interface TransportLayerCallback<java.net.InetSocketAddress,java.nio.ByteBuffer>
Parameters:
i - The node it is coming from
m - the message
options - describe how the message arrived (udp/tcp, encrypted etc)
Throws:
java.io.IOException - if there is a problem decoding the message

destroy

public void destroy()
Specified by:
destroy in interface Destructable

setProbeStrategy

public void setProbeStrategy(ProbeStrategy probeStrategy)

verifyConnectivity

public Cancellable verifyConnectivity(MultiInetSocketAddress local,
                                      java.net.InetSocketAddress probeAddress,
                                      ConnectivityResult deliverResultToMe,
                                      java.util.Map<java.lang.String,java.lang.Object> options)
ask probeAddress to call probeStrategy.requestProbe()

Specified by:
verifyConnectivity in interface InetSocketAddressLookup
Returns:

probe

public Cancellable probe(java.net.InetSocketAddress addr,
                         long uid,
                         Continuation<java.lang.Long,java.lang.Exception> deliverResponseToMe,
                         java.util.Map<java.lang.String,java.lang.Object> options)
Specified by:
probe in interface Prober
Parameters:
addr - the address to probe
uid - the uid with the probe
deliverResponseToMe - let me know how it goes
options - tl options
Returns:
call me to cancel

Rice Pastry API

Copyright © 2001-2005 - Rice Pastry.


Imprint-Dataprotection