/// <summary> /// Creates peers for testing. The first peer will be used as the master. /// This means that shutting down the master will shut down all other peers as well. /// </summary> /// <param name="nrOfPeers"></param> /// <param name="rnd"></param> /// <param name="port"></param> /// <param name="automaticTask"></param> /// <param name="maintenance"></param> /// <returns></returns> public static Peer[] CreateNodes(int nrOfPeers, Random rnd, int port, IAutomaticTask automaticTask, bool maintenance) { var bindings = new Bindings(); var peers = new Peer[nrOfPeers]; if (automaticTask != null) { var peerId = new Number160(rnd); var peerMap = new PeerMap(new PeerMapConfiguration(peerId)); peers[0] = new PeerBuilder(peerId) .SetPorts(port) .SetEnableMaintenance(maintenance) .SetExternalBindings(bindings) .SetPeerMap(peerMap) .Start() .AddAutomaticTask(automaticTask); } else { var peerId = new Number160(rnd); var peerMap = new PeerMap(new PeerMapConfiguration(peerId)); peers[0] = new PeerBuilder(peerId) .SetPorts(port) .SetEnableMaintenance(maintenance) .SetExternalBindings(bindings) .SetPeerMap(peerMap) .Start(); } Console.WriteLine("Created master peer: {0}.", peers[0].PeerId); for (int i = 1; i < nrOfPeers; i++) { if (automaticTask != null) { var peerId = new Number160(rnd); var peerMap = new PeerMap(new PeerMapConfiguration(peerId)); peers[i] = new PeerBuilder(peerId) .SetMasterPeer(peers[0]) .SetEnableMaintenance(maintenance) .SetExternalBindings(bindings) .SetPeerMap(peerMap) .Start() .AddAutomaticTask(automaticTask); } else { var peerId = new Number160(rnd); var peerMap = new PeerMap(new PeerMapConfiguration(peerId).SetPeerNoVerification()); peers[i] = new PeerBuilder(peerId) .SetMasterPeer(peers[0]) .SetEnableMaintenance(maintenance) .SetExternalBindings(bindings) .SetPeerMap(peerMap) .Start(); } Console.WriteLine("Created slave peer {0}: {1}.", i, peers[i].PeerId); } return(peers); }
public Peer RemoveAutomaticTask(IAutomaticTask automaticTask) { _automaticTasks.Remove(automaticTask); return(this); }
public Peer AddAutomaticTask(IAutomaticTask automaticTask) { _automaticTasks.Add(automaticTask); return(this); }
public static Peer[] CreateNodes(int nrOfPeers, Random rnd, int port, IAutomaticTask automaticTask) { return(CreateNodes(nrOfPeers, rnd, port, automaticTask, false)); }
public Peer RemoveAutomaticTask(IAutomaticTask automaticTask) { _automaticTasks.Remove(automaticTask); return this; }
public Peer AddAutomaticTask(IAutomaticTask automaticTask) { _automaticTasks.Add(automaticTask); return this; }
public static Peer[] CreateNodes(int nrOfPeers, Random rnd, int port, IAutomaticTask automaticTask) { return CreateNodes(nrOfPeers, rnd, port, automaticTask, false); }
/// <summary> /// Creates peers for testing. The first peer will be used as the master. /// This means that shutting down the master will shut down all other peers as well. /// </summary> /// <param name="nrOfPeers"></param> /// <param name="rnd"></param> /// <param name="port"></param> /// <param name="automaticTask"></param> /// <param name="maintenance"></param> /// <returns></returns> public static Peer[] CreateNodes(int nrOfPeers, Random rnd, int port, IAutomaticTask automaticTask, bool maintenance) { var bindings = new Bindings(); var peers = new Peer[nrOfPeers]; if (automaticTask != null) { var peerId = new Number160(rnd); var peerMap = new PeerMap(new PeerMapConfiguration(peerId)); peers[0] = new PeerBuilder(peerId) .SetPorts(port) .SetEnableMaintenance(maintenance) .SetExternalBindings(bindings) .SetPeerMap(peerMap) .Start() .AddAutomaticTask(automaticTask); } else { var peerId = new Number160(rnd); var peerMap = new PeerMap(new PeerMapConfiguration(peerId)); peers[0] = new PeerBuilder(peerId) .SetPorts(port) .SetEnableMaintenance(maintenance) .SetExternalBindings(bindings) .SetPeerMap(peerMap) .Start(); } Console.WriteLine("Created master peer: {0}.", peers[0].PeerId); for (int i = 1; i < nrOfPeers; i++) { if (automaticTask != null) { var peerId = new Number160(rnd); var peerMap = new PeerMap(new PeerMapConfiguration(peerId)); peers[i] = new PeerBuilder(peerId) .SetMasterPeer(peers[0]) .SetEnableMaintenance(maintenance) .SetExternalBindings(bindings) .SetPeerMap(peerMap) .Start() .AddAutomaticTask(automaticTask); } else { var peerId = new Number160(rnd); var peerMap = new PeerMap(new PeerMapConfiguration(peerId).SetPeerNoVerification()); peers[i] = new PeerBuilder(peerId) .SetMasterPeer(peers[0]) .SetEnableMaintenance(maintenance) .SetExternalBindings(bindings) .SetPeerMap(peerMap) .Start(); } Console.WriteLine("Created slave peer {0}: {1}.", i, peers[i].PeerId); } return peers; }