Пример #1
0
def main():
    try:
        config_file = "conf/solipsis.conf"
        usage = "usage: %prog [-db] [-p <port>] [-x ... -y ...] [-e ...] [-c <port>] [-n <port>] [firstpeer:port]"
        parser = OptionParser(usage)
#         parser.add_option("-h", "--help", action="help",
#                             help="display help message")
        parser.add_option("-p", "--port", type="int", dest="port",
                            help="port number for all Solipsis connections")
        parser.add_option("-b", "--robot", action="store_true", dest="bot", default=False,
                            help="bot mode (don't listen for navigator)")
        parser.add_option("-d", "--detach", action="store_true", dest="detach", default=False,
                            help="run in the background")
        parser.add_option("-x", type="long", dest="pos_x",
                            help="X start value")
        parser.add_option("-y", type="long", dest="pos_y",
                            help="Y start value")
        parser.add_option("-e", type="int", dest="expected_neighbours",
                            help="number of expected neighbours")
        parser.add_option("-c", "--control_port", type="int", dest="control_port",
                            help="control port for navigator")
        parser.add_option("-n", "--notification_port", type="int", dest="notif_port",
                            help="notification port for navigator")
        parser.add_option("-f", "--file", dest="config_file", default=config_file,
                          help="configuration file" )
        params = Parameters(parser, config_file=config_file)

        if (params.detach):
            # Create background process for daemon-like operation
            import os, signal
            # Ignore SIGHUP so as not to kill the child when the parent leaves
            signal.signal(signal.SIGHUP, signal.SIG_IGN)

            # Fork and kill the parent process
            if (os.fork()):
                os._exit(0)

            # The child detaches itself from the console
            os.setsid()
            os.chdir("/")
            os.umask(0)

            # Fork and kill the parent proces
            if (os.fork()):
                os._exit(0)

        # Create node and enter main loop
        myNode = Node(params)
        myNode.mainLoop()

    except:
        raise
Пример #2
0
    def setUp(self):
        configFileName = "../../conf/solipsis.conf"
        parser = OptionParser('')
        param = Parameters(parser, configFileName)
        n = Node(param)
        n.setPosition(Position(4,1))
        self.manager = PeersManager(n, param)
        
        p0 = Peer(id="0",position=Position(0,0))
        p1 = Peer(id="1",position=Position(0,10))
        p2 = Peer(id="2",position=Position(5,0))
        p3 = Peer(id="3",position=Position(5,20))
        p4 = Peer()
    
        self.peers = [p0, p1, p2, p3, p4]

        p10 = Peer(id="0", position=Position(2,2))
        p11 = Peer(id="1", position=Position(7,2))
        p12 = Peer(id="2", position=Position(5,3))
        p13 = Peer(id="3", position=Position(3,6))
        p14 = Peer(id="4", position=Position(4,-6))
        p15 = Peer(id="5", position=Position(4,0))

        self.geoPeers = [p10, p11, p12, p13, p14, p15]