Exemplo n.º 1
0
    def setUp(self):
        self.autoseed = random.randint(0, 9999999999)
        self.seed = self.RAND_SEED
        if not self.seed:
            self.seed = self.autoseed
        self.myRandom = random.Random(self.seed)

        self.peer_controller = None

        self.peers = [
            self.create_peer("P%d" % i, "127.0.0.1", 8500 + i)
            for i in range(self.NO_OF_PEERS)
        ]

        self.peer_controller = PeerController(self.peers,
                                              self.WORLD_SIZE,
                                              self.TOP_SPEED,
                                              self.MAX_SPEED_CHANGE,
                                              self.RADIO_RANGE,
                                              rand_seed=self.seed)

        #Start router
        self.router = Router("127.0.0.1", 8300, self.peers,
                             self.peer_controller, self.USE_TICKS)
        self.router.start()
        self.ensure_peers_ready(self.peers)
        self.router.activate_queue()

        if self.VISUALIZE:
            self.visualizer = Visualizer(self.peers, self.peer_controller)
            self.visualizer.visualize()
Exemplo n.º 2
0
    host = sys.argv[1]
    port = int(sys.argv[2])
    if len(sys.argv) > 3:
        visualize = (sys.argv[3] == "True")
        worldwidth = int(sys.argv[4])
        worldheight = int(sys.argv[5])
        topSpeed = int(sys.argv[6])
        maxSpeedChange = int(sys.argv[7])
        radioRange = int(sys.argv[8])
    else:
        visualize = False
        worldwidth, worldheight = 2000, 2000
        topSpeed = 140
        maxSpeedChange = 50
        radioRange = 500

    peers = []

    peer_controller = PeerController(peers, {
        'width': worldwidth,
        'height': worldheight
    }, topSpeed, maxSpeedChange, radioRange)
    router = Router(host, port, peers, peer_controller, False)
    router.start()
    router.activate_queue()

    if visualize:
        peer_controller.visualize(block=False)

    router._main_loop()