Projects >> TomP2P >>5e4dad1fdc1619c4cbce97235f44df9739080237

Chunk
Conflicting content
=======
    private MaintenanceTask maintenanceTask;
    private DigestStorage digestStorage;
    private DigestTracker digestTracker;
<<<<<<< HEAD
    private HolePunchInitiator holePunchInitiator;
	private static final Logger LOG = LoggerFactory.getLogger(PeerBean.class);
    private LocalMap localMap;
>>>>>>> 810fe39424bd84c0710223a3da5f59caeb19a191
    
	/**
	 * This map is used for all open peerConnections which are meant to stay
Solution content
    private MaintenanceTask maintenanceTask;
    private DigestStorage digestStorage;
    private DigestTracker digestTracker;
    private HolePunchInitiator holePunchInitiator;
    private LocalMap localMap;
    
	/**
	 * This map is used for all open peerConnections which are meant to stay
File
PeerBean.java
Developer's decision
Combination
Kind of conflict
Attribute
Method invocation
Chunk
Conflicting content
	private final Dispatcher dispatcher;
	private final SendBehavior sendBehavior;
	private final Random random;
<<<<<<< HEAD
	private Peer peer;
=======
	private final PeerBean peerBean;
>>>>>>> 810fe39424bd84c0710223a3da5f59caeb19a191

	// this map caches all messages which are meant to be sent by a reverse
	private final ConcurrentHashMap cachedRequests = new ConcurrentHashMap();
Solution content
	private final Dispatcher dispatcher;
	private final SendBehavior sendBehavior;
	private final Random random;
	private final PeerBean peerBean;

	// this map caches all messages which are meant to be sent by a reverse
	private final ConcurrentHashMap cachedRequests = new ConcurrentHashMap();
File
Sender.java
Developer's decision
Version 2
Kind of conflict
Attribute
Chunk
Conflicting content
	 * @param concurrentHashMap
	 */
	public Sender(final Number160 peerId, final List peerStatusListeners,
<<<<<<< HEAD
			final ChannelClientConfiguration channelClientConfiguration, Dispatcher dispatcher, SendBehavior sendBehavior) {
=======
	        final ChannelClientConfiguration channelClientConfiguration, Dispatcher dispatcher, SendBehavior sendBehavior, PeerBean peerBean) {
>>>>>>> 810fe39424bd84c0710223a3da5f59caeb19a191
		this.peerStatusListeners = peerStatusListeners;
		this.channelClientConfiguration = channelClientConfiguration;
		this.dispatcher = dispatcher;
Solution content
	 * @param concurrentHashMap
	 */
	public Sender(final Number160 peerId, final List peerStatusListeners,
	        final ChannelClientConfiguration channelClientConfiguration, Dispatcher dispatcher, SendBehavior sendBehavior, PeerBean peerBean) {
		this.peerStatusListeners = peerStatusListeners;
		this.channelClientConfiguration = channelClientConfiguration;
		this.dispatcher = dispatcher;
File
Sender.java
Developer's decision
Version 2
Kind of conflict
Variable
Chunk
Conflicting content
				break;
			case RCON:
			final TimeoutFactory timeoutHandler = createTimeoutHandler(futureResponse, idleTCPSeconds, handler == null);

			switch (sendBehavior.tcpSendBehavior(message)) {
<<<<<<< HEAD
			case DIRECT:
				connectAndSend(handler, futureResponse, channelCreator, connectTimeoutMillis, peerConnection, timeoutHandler, message);
				handleRcon(handler, futureResponse, message, channelCreator, connectTimeoutMillis, peerConnection, timeoutHandler);
				break;
			case RELAY:
				handleRelay(handler, futureResponse, message, channelCreator, idleTCPSeconds, connectTimeoutMillis, peerConnection,
						timeoutHandler);
				break;
			default:
				throw new IllegalArgumentException("Illegal sending behavior");
=======
				case DIRECT:
					connectAndSend(handler, futureResponse, channelCreator, connectTimeoutMillis, peerConnection, timeoutHandler, message);
					break;
				case RCON:
					handleRcon(handler, futureResponse, message, channelCreator, connectTimeoutMillis, peerConnection, timeoutHandler);
					break;
				case RELAY:
					handleRelay(handler, futureResponse, message, channelCreator, idleTCPSeconds, connectTimeoutMillis, peerConnection, 
							timeoutHandler);
					break;
				case SELF:
					sendSelf(futureResponse, message);
					break;
				default:
					throw new IllegalArgumentException("Illegal sending behavior");
>>>>>>> 810fe39424bd84c0710223a3da5f59caeb19a191
			}
		}
	}
Solution content
			final TimeoutFactory timeoutHandler = createTimeoutHandler(futureResponse, idleTCPSeconds, handler == null);

			switch (sendBehavior.tcpSendBehavior(message)) {
				case DIRECT:
					connectAndSend(handler, futureResponse, channelCreator, connectTimeoutMillis, peerConnection, timeoutHandler, message);
					break;
				case RCON:
					handleRcon(handler, futureResponse, message, channelCreator, connectTimeoutMillis, peerConnection, timeoutHandler);
					break;
				case RELAY:
					handleRelay(handler, futureResponse, message, channelCreator, idleTCPSeconds, connectTimeoutMillis, peerConnection, 
							timeoutHandler);
					break;
				case SELF:
					sendSelf(futureResponse, message);
					break;
				default:
					throw new IllegalArgumentException("Illegal sending behavior");
			}
		}
	}
File
Sender.java
Developer's decision
Version 2
Kind of conflict
Break statement
Case statement
Method invocation
Throw statement
Chunk
Conflicting content
	/**
	 * Both peers are relayed, thus sending directly or over reverse connection
	 * is not possible. Send the message to one of the receiver's relays.
<<<<<<< HEAD
	 * 
=======
>>>>>>> 810fe39424bd84c0710223a3da5f59caeb19a191
	 * 
	 * @param handler
	 * @param futureResponse
Solution content
	/**
	 * Both peers are relayed, thus sending directly or over reverse connection
	 * is not possible. Send the message to one of the receiver's relays.
<<<<<<< HEAD
	 * 
=======
>>>>>>> refs/remotes/tomp-master/master
	 * 
	 * @param handler
	 * @param futureResponse
File
Sender.java
Developer's decision
Manual
Kind of conflict
Comment
Chunk
Conflicting content
		return futureDone;
	}

<<<<<<< HEAD
	private ChannelFuture sendTCPCreateChannel(InetSocketAddress recipient, ChannelCreator channelCreator, PeerConnection peerConnection,
			ChannelHandler handler, TimeoutFactory timeoutHandler, int connectTimeoutMillis, FutureResponse futureResponse) {
=======
	/**
	 * In case a message is sent to the sender itself, this is the cutoff.
	 * 
	 * @param futureResponse the future to respond as soon as the proper handler returns it
	 * @param message the request
	 */
	public void sendSelf(final FutureResponse futureResponse, final Message message) {
		LOG.debug("Handle message that is intended for the sender itself {}", message);
		final DispatchHandler handler = dispatcher.associatedHandler(message);
		handler.forwardMessage(message, null, new Responder() {

			@Override
			public void response(Message responseMessage) {
				futureResponse.response(responseMessage);
			}

			@Override
			public void failed(Type type, String reason) {
				futureResponse.failed("Failed with type " + type.name() + ". Reason: " + reason);
			}

			@Override
			public void responseFireAndForget() {
				futureResponse.emptyResponse();
			}

		});
	}
	
	private ChannelFuture sendTCPCreateChannel(InetSocketAddress recipient, ChannelCreator channelCreator,
	        PeerConnection peerConnection, ChannelHandler handler, TimeoutFactory timeoutHandler,
	        int connectTimeoutMillis, FutureResponse futureResponse) {
>>>>>>> 810fe39424bd84c0710223a3da5f59caeb19a191

		final Map> handlers;
Solution content
		return futureDone;
	}

	/**
	 * In case a message is sent to the sender itself, this is the cutoff.
	 * 
	 * @param futureResponse the future to respond as soon as the proper handler returns it
	 * @param message the request
	 */
	public void sendSelf(final FutureResponse futureResponse, final Message message) {
		LOG.debug("Handle message that is intended for the sender itself {}", message);
		final DispatchHandler handler = dispatcher.associatedHandler(message);
		handler.forwardMessage(message, null, new Responder() {

			@Override
			public void response(Message responseMessage) {
				futureResponse.response(responseMessage);
			}

			@Override
			public void failed(Type type, String reason) {
				futureResponse.failed("Failed with type " + type.name() + ". Reason: " + reason);
			}

			@Override
			public void responseFireAndForget() {
				futureResponse.emptyResponse();
			}

		});
	}
	
	private ChannelFuture sendTCPCreateChannel(InetSocketAddress recipient, ChannelCreator channelCreator,
	        PeerConnection peerConnection, ChannelHandler handler, TimeoutFactory timeoutHandler,
	        int connectTimeoutMillis, FutureResponse futureResponse) {

		final Map> handlers;
File
Sender.java
Developer's decision
Version 2
Kind of conflict
Comment
Method declaration
Method signature
Chunk
Conflicting content
		if (!isFireAndForget) {
			handlers.put("handler", new Pair(null, handler));
		}
<<<<<<< HEAD
		return handlers;
=======

		try {
			final ChannelFuture channelFuture;
			switch (sendBehavior.udpSendBehavior(message)) {
				case DIRECT:
					channelFuture = channelCreator.createUDP(broadcast, handlers, futureResponse);
					break;
				case RELAY:
					List psa = new ArrayList<>(message.recipient().peerSocketAddresses());
					LOG.debug("send neighbor request to random relay peer {}", psa);
					if (psa.size() > 0) {
						PeerSocketAddress ps = psa.get(random.nextInt(psa.size()));
						message.recipientRelay(message.recipient().changePeerSocketAddress(ps).changeRelayed(true));
						channelFuture = channelCreator.createUDP(broadcast, handlers, futureResponse);
					} else {
						futureResponse.failed("Peer is relayed, but no relay given");
						return;
					}
					break;
				case SELF:
					sendSelf(futureResponse, message);
					channelFuture = null;
					break;
				default:
					throw new IllegalArgumentException("UDP messages are not allowed to send over RCON");
			}
			afterConnect(futureResponse, message, channelFuture, handler == null);
		} catch (UnsupportedOperationException e) {
			LOG.warn(e.getMessage());
			futureResponse.failed(e);

		}
>>>>>>> 810fe39424bd84c0710223a3da5f59caeb19a191
	}

	/**
Solution content
		if (!isFireAndForget) {
			handlers.put("handler", new Pair(null, handler));
		}
		return handlers;

		
	}

	/**
File
Sender.java
Developer's decision
Version 1
Kind of conflict
Return statement
Variable
Chunk
Conflicting content
		RCON(),
		HOLEP(),
		GET_LATEST_WITH_DIGEST(),
<<<<<<< HEAD
		GCM();
=======
		GCM(),
		LOCAL_ANNOUNCE();
	
>>>>>>> 810fe39424bd84c0710223a3da5f59caeb19a191
	public byte getNr() {
		return (byte) ordinal();
	}
Solution content
		RCON(),
		HOLEP(),
		GET_LATEST_WITH_DIGEST(),
		GCM(),
		LOCAL_ANNOUNCE();
	public byte getNr() {
		return (byte) ordinal();
	}
File
RPC.java
Developer's decision
Version 2
Kind of conflict
Enum value
Chunk
Conflicting content
		}

public class UtilsNAT {

<<<<<<< HEAD
    public static PeerDHT[] createNodesDHT(int nrOfPeers, Random rnd, int port) throws Exception {
        return createNodesDHT(nrOfPeers, rnd, port, null);
    }

    public static PeerDHT[] createNodesDHT(int nrOfPeers, Random rnd, int port, AutomaticFuture automaticFuture)
            throws Exception {
        return createNodesDHT(nrOfPeers, rnd, port, automaticFuture, false);
    }

    /**
     * Creates peers for testing. The first peer (peer[0]) will be used as the master. This means that shutting down
     * peer[0] will shut down all other peers
     * 
     * @param nrOfPeers
     *            The number of peers to create including the master
     * @param rnd
     *            The random object to create random peer IDs
     * @param port
     *            The port where the master peer will listen to
     * @return All the peers, with the master peer at position 0 -> peer[0]
     * @throws Exception
     *             If the creation of nodes fail.
     */
    public static PeerDHT[] createNodesDHT(int nrOfPeers, Random rnd, int port, AutomaticFuture automaticFuture,
            boolean maintenance) throws Exception {
        if (nrOfPeers < 1) {
            throw new IllegalArgumentException("Cannot create less than 1 peer");
        }
        Bindings bindings = new Bindings();// .addInterface("lo");
        PeerDHT[] peers = new PeerDHT[nrOfPeers];
        final Peer master;
        if (automaticFuture != null) {
        	Number160 peerId = new Number160(rnd);
        	PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
        	master = new PeerBuilder(peerId)
                    .ports(port).enableMaintenance(maintenance)
                    .bindings(bindings).peerMap(peerMap).start().addAutomaticFuture(automaticFuture);
            peers[0] = new PeerBuilderDHT(master).start(); 
            
        } else {
        	Number160 peerId = new Number160(rnd);
        	PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
        	master = new PeerBuilder(peerId).enableMaintenance(maintenance).bindings(bindings)
                    .peerMap(peerMap).ports(port).start();
        	peers[0] = new PeerBuilderDHT(master).start(); 
        }

        for (int i = 1; i < nrOfPeers; i++) {
            if (automaticFuture != null) {
            	Number160 peerId = new Number160(rnd);
            	PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
                Peer peer = new PeerBuilder(peerId)
                        .masterPeer(master)
                        .enableMaintenance(maintenance).enableMaintenance(maintenance).peerMap(peerMap).bindings(bindings).start().addAutomaticFuture(automaticFuture);
                peers[i] = new PeerBuilderDHT(peer).start(); 
            } else {
            	Number160 peerId = new Number160(rnd);
            	PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId).peerNoVerification());
            	Peer peer = new PeerBuilder(peerId).enableMaintenance(maintenance)
                        .bindings(bindings).peerMap(peerMap).masterPeer(master)
                        .start();
                peers[i] = new PeerBuilderDHT(peer).start(); 
            }
        }
        System.err.println("peers created.");
        return peers;
    }

    

    /**
     * Perfect routing, where each neighbor has contacted each other. This means that for small number of peers, every
     * peer knows every other peer.
     * 
     * @param peers
     *            The peers taking part in the p2p network.
     */
    public static void perfectRouting(PeerDHT... peers) {
        for (int i = 0; i < peers.length; i++) {
            for (int j = 0; j < peers.length; j++)
                peers[i].peer().peerBean().peerMap().peerFound(peers[j].peer().peerAddress(), null, null);
        }
        System.err.println("perfect routing done.");
    }
    
    public static Peer[] createNodes(int nrOfPeers, Random rnd, int port) throws Exception {
        return createNodes(nrOfPeers, rnd, port, null);
    }

    public static Peer[] createNodes(int nrOfPeers, Random rnd, int port, AutomaticFuture automaticFuture)
            throws Exception {
        return createNodes(nrOfPeers, rnd, port, automaticFuture, false);
    }

    /**
     * Creates peers for testing. The first peer (peer[0]) will be used as the master. This means that shutting down
     * peer[0] will shut down all other peers
     * 
     * @param nrOfPeers
     *            The number of peers to create including the master
     * @param rnd
     *            The random object to create random peer IDs
     * @param port
     *            The port where the master peer will listen to
     * @return All the peers, with the master peer at position 0 -> peer[0]
     * @throws Exception
     *             If the creation of nodes fail.
     */
    public static Peer[] createNodes(int nrOfPeers, Random rnd, int port, AutomaticFuture automaticFuture,
            boolean maintenance) throws Exception {
        if (nrOfPeers < 1) {
            throw new IllegalArgumentException("Cannot create less than 1 peer");
        }
        Bindings bindings = new Bindings().addAddress(InetAddress.getLocalHost());
//        Bindings bindings = new Bindings().addInterface("lo0");
        Peer[] peers = new Peer[nrOfPeers];
        if (automaticFuture != null) {
        	Number160 peerId = new Number160(rnd);
        	PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
            peers[0] = new PeerBuilder(peerId)
                    .ports(port).enableMaintenance(maintenance)
                    .bindings(bindings).peerMap(peerMap).start().addAutomaticFuture(automaticFuture);
        } else {
        	Number160 peerId = new Number160(rnd);
        	PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
            peers[0] = new PeerBuilder(peerId).enableMaintenance(maintenance).bindings(bindings)
                   .peerMap(peerMap).ports(port).start();
        }

        for (int i = 1; i < nrOfPeers; i++) {
            if (automaticFuture != null) {
            	Number160 peerId = new Number160(rnd);
            	PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
                peers[i] = new PeerBuilder(peerId)
                        .masterPeer(peers[0])
                        .enableMaintenance(maintenance).enableMaintenance(maintenance).peerMap(peerMap).bindings(bindings).start().addAutomaticFuture(automaticFuture);
            } else {
            	Number160 peerId = new Number160(rnd);
            	PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId).peerNoVerification());
                peers[i] = new PeerBuilder(peerId).enableMaintenance(maintenance)
                        .bindings(bindings).peerMap(peerMap).masterPeer(peers[0])
                        .start();
            }
        }
        System.err.println("peers created.");
        return peers;
    }

    /**
     * Perfect routing, where each neighbor has contacted each other. This means that for small number of peers, every
     * peer knows every other peer.
     * 
     * @param peers
     *            The peers taking part in the p2p network.
     */
    public static void perfectRouting(Peer... peers) {
        for (int i = 0; i < peers.length; i++) {
            for (int j = 0; j < peers.length; j++)
                peers[i].peerBean().peerMap().peerFound(peers[j].peerAddress(), null, null);
        }
        System.err.println("perfect routing done.");
    }

    public static PeerAddress createAddress() throws UnknownHostException {
        return createAddress(new Number160("0x5678"), "127.0.0.1", 8005, 8006, false, false);
    }
    
    public static PeerAddress createAddress(Number160 idSender, String inetSender, int tcpPortSender,
            int udpPortSender, boolean firewallUDP, boolean firewallTCP) throws UnknownHostException {
        InetAddress inetSend = InetAddress.getByName(inetSender);
        PeerSocketAddress peerSocketAddress = new PeerSocketAddress(inetSend, tcpPortSender, udpPortSender);
        PeerAddress n1 = new PeerAddress(idSender, peerSocketAddress, firewallTCP, firewallUDP, false, false, false,
                PeerAddress.EMPTY_PEER_SOCKET_ADDRESSES);
        return n1;
    }
=======
	public static PeerDHT[] createNodesDHT(int nrOfPeers, Random rnd, int port) throws Exception {
		return createNodesDHT(nrOfPeers, rnd, port, null);
	}

	public static PeerDHT[] createNodesDHT(int nrOfPeers, Random rnd, int port, AutomaticFuture automaticFuture)
			throws Exception {
		return createNodesDHT(nrOfPeers, rnd, port, automaticFuture, false);
	}

	/**
	 * Creates peers for testing. The first peer (peer[0]) will be used as the master. This means that
	 * shutting down
	 * peer[0] will shut down all other peers
	 * 
	 * @param nrOfPeers
	 *            The number of peers to create including the master
	 * @param rnd
	 *            The random object to create random peer IDs
	 * @param port
	 *            The port where the master peer will listen to
	 * @return All the peers, with the master peer at position 0 -> peer[0]
	 * @throws Exception
	 *             If the creation of nodes fail.
	 */
	public static PeerDHT[] createNodesDHT(int nrOfPeers, Random rnd, int port, AutomaticFuture automaticFuture,
			boolean maintenance) throws Exception {
		if (nrOfPeers < 1) {
			throw new IllegalArgumentException("Cannot create less than 1 peer");
		}
		Bindings bindings = new Bindings();// .addInterface("lo");
		PeerDHT[] peers = new PeerDHT[nrOfPeers];
		final Peer master;
		if (automaticFuture != null) {
			Number160 peerId = new Number160(rnd);
			PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
			master = new PeerBuilder(peerId).ports(port).enableMaintenance(maintenance).bindings(bindings).peerMap(peerMap)
					.start().addAutomaticFuture(automaticFuture);
			peers[0] = new PeerBuilderDHT(master).start();

		} else {
			Number160 peerId = new Number160(rnd);
			PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
			master = new PeerBuilder(peerId).enableMaintenance(maintenance).bindings(bindings).peerMap(peerMap).ports(port)
					.start();
			peers[0] = new PeerBuilderDHT(master).start();
		}

		for (int i = 1; i < nrOfPeers; i++) {
			if (automaticFuture != null) {
				Number160 peerId = new Number160(rnd);
				PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
				Peer peer = new PeerBuilder(peerId).masterPeer(master).enableMaintenance(maintenance)
						.enableMaintenance(maintenance).peerMap(peerMap).bindings(bindings).start()
						.addAutomaticFuture(automaticFuture);
				peers[i] = new PeerBuilderDHT(peer).start();
			} else {
				Number160 peerId = new Number160(rnd);
				PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId).peerNoVerification());
				Peer peer = new PeerBuilder(peerId).enableMaintenance(maintenance).bindings(bindings).peerMap(peerMap)
						.masterPeer(master).start();
				peers[i] = new PeerBuilderDHT(peer).start();
			}
		}
		System.err.println("peers created.");
		return peers;
	}

	/**
	 * Perfect routing, where each neighbor has contacted each other. This means that for small number of
	 * peers, every
	 * peer knows every other peer.
	 * 
	 * @param peers
	 *            The peers taking part in the p2p network.
	 */
	public static void perfectRouting(PeerDHT... peers) {
		for (int i = 0; i < peers.length; i++) {
			for (int j = 0; j < peers.length; j++)
				peers[i].peer().peerBean().peerMap().peerFound(peers[j].peer().peerAddress(), null, null);
		}
		System.err.println("perfect routing done.");
	}

	public static Peer[] createNodes(int nrOfPeers, Random rnd, int port) throws Exception {
		return createNodes(nrOfPeers, rnd, port, null);
	}

	public static Peer[] createNodes(int nrOfPeers, Random rnd, int port, AutomaticFuture automaticFuture) throws Exception {
		return createNodes(nrOfPeers, rnd, port, automaticFuture, false);
	}

	/**
	 * Creates peers for testing. The first peer (peer[0]) will be used as the master. This means that
	 * shutting down
	 * peer[0] will shut down all other peers
	 * 
	 * @param nrOfPeers
	 *            The number of peers to create including the master
	 * @param rnd
	 *            The random object to create random peer IDs
	 * @param port
	 *            The port where the master peer will listen to
	 * @return All the peers, with the master peer at position 0 -> peer[0]
	 * @throws Exception
	 *             If the creation of nodes fail.
	 */
	public static Peer[] createNodes(int nrOfPeers, Random rnd, int port, AutomaticFuture automaticFuture,
			boolean maintenance) throws Exception {
		if (nrOfPeers < 1) {
			throw new IllegalArgumentException("Cannot create less than 1 peer");
		}

		Bindings bindings = new Bindings().addAddress(InetAddress.getLocalHost());
		// Bindings bindings = new Bindings().addInterface("lo0");
		Peer[] peers = new Peer[nrOfPeers];
		if (automaticFuture != null) {
			Number160 peerId = new Number160(rnd);
			PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
			peers[0] = new PeerBuilder(peerId).ports(port).enableMaintenance(maintenance).bindings(bindings)
					.peerMap(peerMap).start().addAutomaticFuture(automaticFuture);
		} else {
			Number160 peerId = new Number160(rnd);
			PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
			peers[0] = new PeerBuilder(peerId).enableMaintenance(maintenance).bindings(bindings).peerMap(peerMap)
					.ports(port).start();
		}

		for (int i = 1; i < nrOfPeers; i++) {
			if (automaticFuture != null) {
				Number160 peerId = new Number160(rnd);
				PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
				peers[i] = new PeerBuilder(peerId).masterPeer(peers[0]).enableMaintenance(maintenance)
						.enableMaintenance(maintenance).peerMap(peerMap).bindings(bindings).start()
						.addAutomaticFuture(automaticFuture);
			} else {
				Number160 peerId = new Number160(rnd);
				PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId).peerNoVerification());
				peers[i] = new PeerBuilder(peerId).enableMaintenance(maintenance).bindings(bindings).peerMap(peerMap)
						.masterPeer(peers[0]).start();
			}
		System.err.println("peers created.");
		return peers;
	}

	/**
	 * Perfect routing, where each neighbor has contacted each other. This means that for small number of
	 * peers, every
	 * peer knows every other peer.
	 * 
	 * @param peers
	 *            The peers taking part in the p2p network.
	 */
	public static void perfectRouting(Peer... peers) {
		for (int i = 0; i < peers.length; i++) {
			for (int j = 0; j < peers.length; j++)
				peers[i].peerBean().peerMap().peerFound(peers[j].peerAddress(), null, null);
		}
		System.err.println("perfect routing done.");
	}

	public static PeerAddress createAddress() throws UnknownHostException {
		return createAddress(new Number160("0x5678"), "127.0.0.1", 8005, 8006, false, false);
	}

	public static PeerAddress createRandomAddress() throws UnknownHostException {
		Random rnd = new Random();
		return createAddress(new Number160(rnd), "127.0.0.1", rnd.nextInt(10000), rnd.nextInt(10000), rnd.nextBoolean(),
				rnd.nextBoolean());
	}

	public static PeerAddress createAddress(Number160 idSender, String inetSender, int tcpPortSender, int udpPortSender,
			boolean firewallUDP, boolean firewallTCP) throws UnknownHostException {
		InetAddress inetSend = InetAddress.getByName(inetSender);
		PeerSocketAddress peerSocketAddress = new PeerSocketAddress(inetSend, tcpPortSender, udpPortSender);
		PeerAddress n1 = new PeerAddress(idSender, peerSocketAddress, firewallTCP, firewallUDP, false, false, false,
				PeerAddress.EMPTY_PEER_SOCKET_ADDRESSES);
		return n1;
	}
>>>>>>> 810fe39424bd84c0710223a3da5f59caeb19a191

	/**
	 * Creates a message with random content
Solution content
public class UtilsNAT {

	public static PeerDHT[] createNodesDHT(int nrOfPeers, Random rnd, int port) throws Exception {
		return createNodesDHT(nrOfPeers, rnd, port, null);
	}

	public static PeerDHT[] createNodesDHT(int nrOfPeers, Random rnd, int port, AutomaticFuture automaticFuture)
			throws Exception {
	 * @param rnd
		return createNodesDHT(nrOfPeers, rnd, port, automaticFuture, false);
	}

	/**
	 * Creates peers for testing. The first peer (peer[0]) will be used as the master. This means that
	 * shutting down
	 * peer[0] will shut down all other peers
	 * 
	 * @param nrOfPeers
	 *            The number of peers to create including the master
	 * @param rnd
	 *            The random object to create random peer IDs
	 * @param port
	 *            The port where the master peer will listen to
	 * @return All the peers, with the master peer at position 0 -> peer[0]
	 * @throws Exception
	 *             If the creation of nodes fail.
	 */
	public static PeerDHT[] createNodesDHT(int nrOfPeers, Random rnd, int port, AutomaticFuture automaticFuture,
			boolean maintenance) throws Exception {
		if (nrOfPeers < 1) {
			throw new IllegalArgumentException("Cannot create less than 1 peer");
		}
		Bindings bindings = new Bindings();// .addInterface("lo");
		PeerDHT[] peers = new PeerDHT[nrOfPeers];
		final Peer master;
		if (automaticFuture != null) {
			Number160 peerId = new Number160(rnd);
			PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
			master = new PeerBuilder(peerId).ports(port).enableMaintenance(maintenance).bindings(bindings).peerMap(peerMap)
					.start().addAutomaticFuture(automaticFuture);
			peers[0] = new PeerBuilderDHT(master).start();

		} else {
			Number160 peerId = new Number160(rnd);
			PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
			master = new PeerBuilder(peerId).enableMaintenance(maintenance).bindings(bindings).peerMap(peerMap).ports(port)
					.start();
			peers[0] = new PeerBuilderDHT(master).start();
		}

		for (int i = 1; i < nrOfPeers; i++) {
			if (automaticFuture != null) {
				Number160 peerId = new Number160(rnd);
				PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
				Peer peer = new PeerBuilder(peerId).masterPeer(master).enableMaintenance(maintenance)
						.enableMaintenance(maintenance).peerMap(peerMap).bindings(bindings).start()
						.addAutomaticFuture(automaticFuture);
				peers[i] = new PeerBuilderDHT(peer).start();
			} else {
				Number160 peerId = new Number160(rnd);
				PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId).peerNoVerification());
				Peer peer = new PeerBuilder(peerId).enableMaintenance(maintenance).bindings(bindings).peerMap(peerMap)
						.masterPeer(master).start();
				peers[i] = new PeerBuilderDHT(peer).start();
			}
		}
		System.err.println("peers created.");
		return peers;
	}

	/**
	 * Perfect routing, where each neighbor has contacted each other. This means that for small number of
	 * peers, every
	 * peer knows every other peer.
	 * 
	 * @param peers
	 *            The peers taking part in the p2p network.
	 */
	public static void perfectRouting(PeerDHT... peers) {
		for (int i = 0; i < peers.length; i++) {
			for (int j = 0; j < peers.length; j++)
				peers[i].peer().peerBean().peerMap().peerFound(peers[j].peer().peerAddress(), null, null);
		}
		System.err.println("perfect routing done.");
	}

	public static Peer[] createNodes(int nrOfPeers, Random rnd, int port) throws Exception {
		return createNodes(nrOfPeers, rnd, port, null);
	}

	public static Peer[] createNodes(int nrOfPeers, Random rnd, int port, AutomaticFuture automaticFuture) throws Exception {
		return createNodes(nrOfPeers, rnd, port, automaticFuture, false);
	}

	/**
	 * Creates peers for testing. The first peer (peer[0]) will be used as the master. This means that
	 * shutting down
	 * peer[0] will shut down all other peers
	 * 
	 * @param nrOfPeers
	 *            The number of peers to create including the master
	 *            The random object to create random peer IDs
	 * @param port
	 *            The port where the master peer will listen to
	 * @return All the peers, with the master peer at position 0 -> peer[0]
	 * @throws Exception
	 *             If the creation of nodes fail.
	 */
	public static Peer[] createNodes(int nrOfPeers, Random rnd, int port, AutomaticFuture automaticFuture,
			boolean maintenance) throws Exception {
		if (nrOfPeers < 1) {
			throw new IllegalArgumentException("Cannot create less than 1 peer");
		}

		Bindings bindings = new Bindings().addAddress(InetAddress.getLocalHost());
		// Bindings bindings = new Bindings().addInterface("lo0");
		Peer[] peers = new Peer[nrOfPeers];
		if (automaticFuture != null) {
			Number160 peerId = new Number160(rnd);
			PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
			peers[0] = new PeerBuilder(peerId).ports(port).enableMaintenance(maintenance).bindings(bindings)
					.peerMap(peerMap).start().addAutomaticFuture(automaticFuture);
		} else {
			Number160 peerId = new Number160(rnd);
			PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
			peers[0] = new PeerBuilder(peerId).enableMaintenance(maintenance).bindings(bindings).peerMap(peerMap)
					.ports(port).start();
		}

		for (int i = 1; i < nrOfPeers; i++) {
			if (automaticFuture != null) {
				Number160 peerId = new Number160(rnd);
				PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
				peers[i] = new PeerBuilder(peerId).masterPeer(peers[0]).enableMaintenance(maintenance)
						.enableMaintenance(maintenance).peerMap(peerMap).bindings(bindings).start()
						.addAutomaticFuture(automaticFuture);
			} else {
				Number160 peerId = new Number160(rnd);
				PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId).peerNoVerification());
				peers[i] = new PeerBuilder(peerId).enableMaintenance(maintenance).bindings(bindings).peerMap(peerMap)
						.masterPeer(peers[0]).start();
			}
		}
		System.err.println("peers created.");
		return peers;
	}

	/**
	 * Perfect routing, where each neighbor has contacted each other. This means that for small number of
	 * peers, every
	 * peer knows every other peer.
	 * 
	 * @param peers
	 *            The peers taking part in the p2p network.
	 */
	public static void perfectRouting(Peer... peers) {
		for (int i = 0; i < peers.length; i++) {
			for (int j = 0; j < peers.length; j++)
				peers[i].peerBean().peerMap().peerFound(peers[j].peerAddress(), null, null);
		}
		System.err.println("perfect routing done.");
	}

	public static PeerAddress createAddress() throws UnknownHostException {
		return createAddress(new Number160("0x5678"), "127.0.0.1", 8005, 8006, false, false);
	}

	public static PeerAddress createRandomAddress() throws UnknownHostException {
		Random rnd = new Random();
		return createAddress(new Number160(rnd), "127.0.0.1", rnd.nextInt(10000), rnd.nextInt(10000), rnd.nextBoolean(),
				rnd.nextBoolean());
	}

	public static PeerAddress createAddress(Number160 idSender, String inetSender, int tcpPortSender, int udpPortSender,
			boolean firewallUDP, boolean firewallTCP) throws UnknownHostException {
		InetAddress inetSend = InetAddress.getByName(inetSender);
		PeerSocketAddress peerSocketAddress = new PeerSocketAddress(inetSend, tcpPortSender, udpPortSender);
		PeerAddress n1 = new PeerAddress(idSender, peerSocketAddress, firewallTCP, firewallUDP, false, false, false,
				PeerAddress.EMPTY_PEER_SOCKET_ADDRESSES);
		return n1;
	}

	/**
	 * Creates a message with random content
File
UtilsNAT.java
Developer's decision
Version 2
Kind of conflict
Comment
Method declaration