예제 #1
0
        /// <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);
        }
예제 #2
0
파일: Peer.cs 프로젝트: lanicon/TomP2P.NET
 public Peer RemoveAutomaticTask(IAutomaticTask automaticTask)
 {
     _automaticTasks.Remove(automaticTask);
     return(this);
 }
예제 #3
0
파일: Peer.cs 프로젝트: lanicon/TomP2P.NET
 public Peer AddAutomaticTask(IAutomaticTask automaticTask)
 {
     _automaticTasks.Add(automaticTask);
     return(this);
 }
예제 #4
0
 public static Peer[] CreateNodes(int nrOfPeers, Random rnd, int port, IAutomaticTask automaticTask)
 {
     return(CreateNodes(nrOfPeers, rnd, port, automaticTask, false));
 }
예제 #5
0
 public Peer RemoveAutomaticTask(IAutomaticTask automaticTask)
 {
     _automaticTasks.Remove(automaticTask);
     return this;
 }
예제 #6
0
 public Peer AddAutomaticTask(IAutomaticTask automaticTask)
 {
     _automaticTasks.Add(automaticTask);
     return this;
 }
예제 #7
0
 public static Peer[] CreateNodes(int nrOfPeers, Random rnd, int port, IAutomaticTask automaticTask)
 {
     return CreateNodes(nrOfPeers, rnd, port, automaticTask, false);
 }
예제 #8
0
 /// <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;
 }