def test_do_sync(self):
        cm = dandelion.config.ConfigManager(self.TEST_FILE)
        remote_db = ContentDB(tempfile.NamedTemporaryFile().name)
        local_db = ContentDB(tempfile.NamedTemporaryFile().name)
        d = dandelion.discoverer.Discoverer(cm.discoverer_config, cm.server_config)
        d.start()
        s = dandelion.synchronizer.Synchronizer(d, cm, local_db)
        s.start()

        # Start the "remote" server
        sc = ServerConfig()
        sc.ip = "127.0.0.1"
        sc.port = 12345
        server = Server(sc, remote_db, None)
        server.start()

        # Adding the node to the discoverer should prompt it to start synchronizing.
        d.add_node("127.0.0.1", 12345, pin=True)

        msg = local_db.get_messages()
        self.assertEqual(len(msg[1]), 0)

        remote_db.add_messages([Message("fubar")])

        # Need to wait for the sync to complete...
        time.sleep(5)

        # Complete sync, so we have the message locally
        msg = local_db.get_messages()
        self.assertEqual(len(msg[1]), 1)

        # Cleanup
        s.stop()
        d.stop()
        server.stop()
Beispiel #2
0
    def __init__(self, config_file=None):
        self._config_manager = ConfigManager(config_file)

        self._server = Server(self._config_manager.server_config,
                              self._config_manager.content_db,
                              self._config_manager.identity)

        self._discoverer = Discoverer(self._config_manager.discoverer_config, server_config=self._config_manager.server_config)

        self._synchronizer = Synchronizer(self._discoverer,
                                          self._config_manager.synchronizer_config,
                                          self._config_manager.content_db)
Beispiel #3
0
class DandelionApp:

    def __init__(self, config_file=None):
        self._config_manager = ConfigManager(config_file)

        self._server = Server(self._config_manager.server_config,
                              self._config_manager.content_db,
                              self._config_manager.identity)

        self._discoverer = Discoverer(self._config_manager.discoverer_config, server_config=self._config_manager.server_config)

        self._synchronizer = Synchronizer(self._discoverer,
                                          self._config_manager.synchronizer_config,
                                          self._config_manager.content_db)

    def run_ui(self):

        self._ui = UI(self._config_manager.ui_config,
                      self._config_manager.content_db,
                      self._config_manager.identity,
                      self._server,
                      self._discoverer,
                      self._synchronizer)

        self._ui.run()

    def run_gui(self):
        from dandelion.gui.gui import GUI
        self._gui = GUI(self._config_manager.ui_config,
                        self._config_manager.content_db,
                        self._config_manager.identity,
                        self._server,
                        self._synchronizer)

    def exit(self):
        self._synchronizer.stop()
        self._discoverer.stop()
        self._server.stop()
        self._config_manager.write_file()