// Path: src/socialkademlia/SocialKademliaNode.java
// public interface SocialKademliaNode
// {
// 
//     /**
//      * Schedule the recurring refresh operation
//      */
//     public void startRefreshOperation();
// 
//     /**
//      * Stop the recurring refresh operation
//      */
//     public void stopRefreshOperation();
// 
//     /**
//      * @return Node The local node for this system
//      */
//     public Node getNode();
// 
//     /**
//      * @return The KadServer used to send/receive messages
//      */
//     public KadServer getServer();
// 
//     /**
//      * @return The DHT for this kad instance
//      */
//     public SocialKademliaDHT getDHT();
// 
//     /**
//      * @return The current KadConfiguration object being used
//      */
//     public KadConfiguration getCurrentConfiguration();
// 
//     /**
//      * Connect to an existing peer-to-peer network.
//      *
//      * @param n The known node in the peer-to-peer network
//      *
//      * @throws RoutingException      If the bootstrap node could not be contacted
//      * @throws IOException           If a network error occurred
//      * @throws IllegalStateException If this object is closed
//      * */
//     public void bootstrap(Node n) throws IOException, RoutingException;
// 
//     /**
//      * Stores the specified value under the given key
//      * This value is stored on K nodes on the network, or all nodes if there are > K total nodes in the network
//      *
//      * @param content The content to put onto the DHT
//      *
//      * @return Integer How many nodes the content was stored on
//      *
//      * @throws java.io.IOException
//      *
//      */
//     public int put(KadContent content) throws IOException;
// 
//     /**
//      * Stores the specified value under the given key
//      * This value is stored on K nodes on the network, or all nodes if there are > K total nodes in the network
//      *
//      * @param entry The StorageEntry with the content to put onto the DHT
//      *
//      * @return Integer How many nodes the content was stored on
//      *
//      * @throws java.io.IOException
//      *
//      */
//     public int put(KademliaStorageEntry entry) throws IOException;
// 
//     /**
//      * Store a content on the local node's DHT
//      *
//      * @param content The content to put on the DHT
//      *
//      * @throws java.io.IOException
//      */
//     public void putLocally(KadContent content) throws IOException;
// 
//     /**
//      * Get some content stored on the DHT
//      *
//      * @param param The parameters used to search for the content
//      *
//      * @return DHTContent The content
//      *
//      * @throws java.io.IOException
//      * @throws kademlia.exceptions.ContentNotFoundException
//      */
//     public KademliaStorageEntry get(GetParameter param) throws NoSuchElementException, IOException, ContentNotFoundException;
// 
//     /**
//      * Allow the user of the System to call refresh even out of the normal Kad refresh timing
//      *
//      * @throws java.io.IOException
//      */
//     public void refresh() throws IOException;
// 
//     /**
//      * @return String The ID of the owner of this local network
//      */
//     public String getOwnerId();
// 
//     /**
//      * @return Integer The port on which this kad instance is running
//      */
//     public int getPort();
// 
//     /**
//      * Here we handle properly shutting down the Kademlia instance
//      *
//      * @param saveState Whether to save the application state or not
//      *
//      * @throws java.io.FileNotFoundException
//      */
//     public void shutdown(final boolean saveState) throws IOException;
// 
//     /**
//      * Saves the node state to a text file
//      *
//      * @throws java.io.FileNotFoundException
//      */
//     public void saveKadState() throws IOException;
// 
//     /**
//      * @return The routing table for this node.
//      */
//     public SocialKademliaRoutingTable getRoutingTable();
// 
//     /**
//      * @return The statistician that manages all statistics
//      */
//     public SocialKadStatistician getStatistician();
// }


import java.io.IOException;
import kademlia.KadServer;
import kademlia.message.AcknowledgeMessage;
import kademlia.message.ConnectMessage;
import kademlia.message.Message;
import kademlia.message.Receiver;
import socialkademlia.SocialKademliaNode;
package socialkademlia.message;


/**
 * Receives a ConnectMessage and sends an AcknowledgeMessage as reply.
 *
 * @author Joshua Kissoon
 * @created 20140219
 */
public class ConnectReceiver implements Receiver
{

    private final KadServer server;
    private final SocialKademliaNode localNode;

// Path: src/socialkademlia/SocialKademliaNode.java
// public interface SocialKademliaNode
// {
// 
//     /**
//      * Schedule the recurring refresh operation
//      */
//     public void startRefreshOperation();
// 
//     /**
//      * Stop the recurring refresh operation
//      */
//     public void stopRefreshOperation();
// 
//     /**
//      * @return Node The local node for this system
//      */
//     public Node getNode();
// 
//     /**
//      * @return The KadServer used to send/receive messages
//      */
//     public KadServer getServer();
// 
//     /**
//      * @return The DHT for this kad instance
//      */
//     public SocialKademliaDHT getDHT();
// 
//     /**
//      * @return The current KadConfiguration object being used
//      */
//     public KadConfiguration getCurrentConfiguration();
// 
//     /**
//      * Connect to an existing peer-to-peer network.
//      *
//      * @param n The known node in the peer-to-peer network
//      *
//      * @throws RoutingException      If the bootstrap node could not be contacted
//      * @throws IOException           If a network error occurred
//      * @throws IllegalStateException If this object is closed
//      * */
//     public void bootstrap(Node n) throws IOException, RoutingException;
// 
//     /**
//      * Stores the specified value under the given key
//      * This value is stored on K nodes on the network, or all nodes if there are > K total nodes in the network
//      *
//      * @param content The content to put onto the DHT
//      *
//      * @return Integer How many nodes the content was stored on
//      *
//      * @throws java.io.IOException
//      *
//      */
//     public int put(KadContent content) throws IOException;
// 
//     /**
//      * Stores the specified value under the given key
//      * This value is stored on K nodes on the network, or all nodes if there are > K total nodes in the network
//      *
//      * @param entry The StorageEntry with the content to put onto the DHT
//      *
//      * @return Integer How many nodes the content was stored on
//      *
//      * @throws java.io.IOException
//      *
//      */
//     public int put(KademliaStorageEntry entry) throws IOException;
// 
//     /**
//      * Store a content on the local node's DHT
//      *
//      * @param content The content to put on the DHT
//      *
//      * @throws java.io.IOException
//      */
//     public void putLocally(KadContent content) throws IOException;
// 
//     /**
//      * Get some content stored on the DHT
//      *
//      * @param param The parameters used to search for the content
//      *
//      * @return DHTContent The content
//      *
//      * @throws java.io.IOException
//      * @throws kademlia.exceptions.ContentNotFoundException
//      */
//     public KademliaStorageEntry get(GetParameter param) throws NoSuchElementException, IOException, ContentNotFoundException;
// 
//     /**
//      * Allow the user of the System to call refresh even out of the normal Kad refresh timing
//      *
//      * @throws java.io.IOException
//      */
//     public void refresh() throws IOException;
// 
//     /**
//      * @return String The ID of the owner of this local network
//      */
//     public String getOwnerId();
// 
//     /**
//      * @return Integer The port on which this kad instance is running
//      */
//     public int getPort();
// 
//     /**
//      * Here we handle properly shutting down the Kademlia instance
//      *
//      * @param saveState Whether to save the application state or not
//      *
//      * @throws java.io.FileNotFoundException
//      */
//     public void shutdown(final boolean saveState) throws IOException;
// 
//     /**
//      * Saves the node state to a text file
//      *
//      * @throws java.io.FileNotFoundException
//      */
//     public void saveKadState() throws IOException;
// 
//     /**
//      * @return The routing table for this node.
//      */
//     public SocialKademliaRoutingTable getRoutingTable();
// 
//     /**
//      * @return The statistician that manages all statistics
//      */
//     public SocialKadStatistician getStatistician();
// }


// Path: src/socialkademlia/message/ConnectReceiver.java
import java.io.IOException;
import kademlia.KadServer;
import kademlia.message.AcknowledgeMessage;
import kademlia.message.ConnectMessage;
import kademlia.message.Message;
import kademlia.message.Receiver;
import socialkademlia.SocialKademliaNode;

package socialkademlia.message;


/**
 * Receives a ConnectMessage and sends an AcknowledgeMessage as reply.
 *
 * @author Joshua Kissoon
 * @created 20140219
 */
public class ConnectReceiver implements Receiver
{

    private final KadServer server;
    private final SocialKademliaNode localNode;

    public ConnectReceiver(KadServer server, SocialKademliaNode local)