def get_connect_details(self, req, msgid, message, data): # try to find out how to connect to a server if str(data[0]) == node_id: # they're looking for us! Return our details req.send(msgid, ("RESULT_TUPLE", ((req.getsockname()[0], getOptions().port), None))) elif str(data[0]) in neighbours.keys(): # they're looking for our neighbour, ask them how to connect to them r = sendMessageToNode(str(data[0]), None, get_connect_details, str(data[0])) if isinstance(neighbours[str(data[0])], str): # we don't have a direct connection req.send(msgid, ("RESULT_TUPLE", (r[1], neighbours[str(data[0])]))) else: # we have a direct connection, tell people to go through us req.send(msgid, ("RESULT_TUPLE", (r[1], node_id))) else: # we don't know the node they're looking for req.send(msgid, (dont_know, ))
def main(): """\internal \brief Parse command line options and start the server. """ global server, domain_server, node_id, neighbours, local_ts, options options = getOptions() if not options.daemon: import subprocess subprocess.Popen("linda_monitor", shell=True) #pid = os.fork() #if pid != 0: # from monitor import monitor # return monitor.Thread(options.port).run() _linda_server.init() if options.peer: options.peer.append("127.0.0.1") # always allow local connections. def lookupname(addr): try: addr,r = addr.split("/") except ValueError: r = "32" addr = socket.gethostbyname(addr) if addr.count(".") != 3: print "%s is not in n.n.n.n[/r] format" % (addr+"/"+r) sys.exit(0) return addr+"/"+r node_id = "N"+guid.generate() _linda_server.setnodeid(node_id) if options.mdns and not options.disable_mdns: import mdns s = mdns.connect() if s: options.connect = s[0] options.connectport = s[1] if options.connect is not None and len(options.connect) > 0: if options.connectport: con = zip(options.connect, options.connectport) + [(x, 2102) for x in options.connect[len(options.connectport):]] else: con = zip(options.connect, [2102 for _ in options.connect]) assert len(con) == len(options.connect) i = 0 while True: svr, port = con[i] s = _linda_server.connect("%s:%s" % (svr, port)); if s is None: if i < len(con)-1: i += 1 continue else: print "Unable to connect to server %s:%i." % (svr, port) sys.exit(-1) s = Connection(s) s.type = None s.send(None, (get_node_id, )) node = s.recv()[2] assert utils.isNodeId(node), repr(node) s.send(None, (my_name_is, node_id)) s.recv() s.type = "SERVER" s.name = node neighbours[node] = s connections.sockets.append(s) break local_ts.newTupleSpace("UTS") while True: try: socket_watcher() except KeyboardInterrupt: cleanShutdown() raise break
QProgressBar = QtGui.QProgressBar(QSplashScreen) QProgressBar.setMinimum(0) QProgressBar.setMaximum(100) QProgressBar.setTextVisible(False) QProgressBar.setAlignment(QtCore.Qt.AlignBottom | QtCore.Qt.AlignHCenter) QProgressBar.setFixedWidth(250) QProgressBar.move(0, 220) QProgressBar.show() QSplashScreen.raise_() application.processEvents() options = getOptions() Serializer.mapFile = options.mapFile registry = model.Registry() navigator = model.Navigator() factory = model.RoomFactory() mapModel = model.Map() clipboard = model.Clipboard() di.container.register('Config', model.Config()) di.container.register('CoordinatesHelper', model.CoordinatesHelper()) di.container.register('RoomFactory', factory) di.container.register('Registry', registry) di.container.register('Navigator', navigator) di.container.register('Map', mapModel)
def socket_watcher(): global shutting_down _linda_server.serve(getOptions().use_domain, getOptions().port) for s in _linda_server.serverSockets(): if s > 0: sockets.append(Connection(s)) sockets[-1].type = "bound" Handler = server.LindaConnection() while True: socket_lock.acquire() try: iwtd, owtd, ewtd = select.select(sockets, [], sockets, 1) finally: socket_lock.release() if close: break elif len(iwtd) == 0 and len(owtd) == 0 and len(ewtd) == 0: continue for s in iwtd: if s.type == "bound": ns = _linda_server.accept(s) if ns == -1: socket_lock.acquire() try: del sockets[sockets.index(s)] finally: socket_lock.release() sys.stderr.write("Error accepting connection on %s\n" % (s, )) else: ns = Connection(ns) ns.type = "CLIENT" sockets.append(ns) continue m = _linda_server.recv(s.fileno()) if m is None: if s.type == "MONITOR": if shutting_down: continue print "Server shutting down." shutting_down = True thread_pool.giveJob(target=server.cleanShutdown, args=()) continue elif s.type == "SERVER": server.removeServer(s.name) connect_lock.acquire() try: del neighbours[str(s.name)] finally: connect_lock.release() elif s.type == "CLIENT": server.removeProcess(s.name) socket_lock.acquire() try: del sockets[sockets.index(s)] continue finally: socket_lock.release() else: msgid, msg = m[0], m[1:] if msgid is None: thread_pool.giveJob(target=Handler.handle, args=(s, None, msg)) elif str(msgid[0]) == server.node_id and str( msgid[1]) == server.node_id: ms_lock.acquire() try: try: message_store[int(msgid[2])] = (msgid, msg) except KeyError: raise KeyError, "%s not found in %s" % ( msgid, return_locks.keys()) try: return_locks[int(msgid[2])].release() except KeyError: pass # we have recieved the message before the return lock has been created! finally: ms_lock.release() elif str(msgid[0]) != server.node_id: sendMessageToNode(msgid[0], msgid, *msg) elif str(msgid[0]) == server.node_id: thread_pool.giveJob(target=Handler.handle, args=(s, msgid, msg)) else: raise SystemError
def socket_watcher(): global shutting_down _linda_server.serve(getOptions().use_domain, getOptions().port) for s in _linda_server.serverSockets(): if s > 0: sockets.append(Connection(s)) sockets[-1].type = "bound" Handler = server.LindaConnection() while True: socket_lock.acquire() try: iwtd, owtd, ewtd = select.select(sockets, [], sockets, 1) finally: socket_lock.release() if close: break elif len(iwtd) == 0 and len(owtd) == 0 and len(ewtd) == 0: continue for s in iwtd: if s.type == "bound": ns = _linda_server.accept(s) if ns == -1: socket_lock.acquire() try: del sockets[sockets.index(s)] finally: socket_lock.release() sys.stderr.write("Error accepting connection on %s\n" % (s, )) else: ns = Connection(ns) ns.type = "CLIENT" sockets.append(ns) continue m = _linda_server.recv(s.fileno()) if m is None: if s.type == "MONITOR": if shutting_down: continue print "Server shutting down." shutting_down = True thread_pool.giveJob(target=server.cleanShutdown, args=()) continue elif s.type == "SERVER": server.removeServer(s.name) connect_lock.acquire() try: del neighbours[str(s.name)] finally: connect_lock.release() elif s.type == "CLIENT": server.removeProcess(s.name) socket_lock.acquire() try: del sockets[sockets.index(s)] continue finally: socket_lock.release() else: msgid, msg = m[0], m[1:] if msgid is None: thread_pool.giveJob(target=Handler.handle, args=(s, None, msg)) elif str(msgid[0]) == server.node_id and str(msgid[1]) == server.node_id: ms_lock.acquire() try: try: message_store[int(msgid[2])] = (msgid, msg) except KeyError: raise KeyError, "%s not found in %s" % (msgid, return_locks.keys()) try: return_locks[int(msgid[2])].release() except KeyError: pass # we have recieved the message before the return lock has been created! finally: ms_lock.release() elif str(msgid[0]) != server.node_id: sendMessageToNode(msgid[0], msgid, *msg) elif str(msgid[0]) == server.node_id: thread_pool.giveJob(target=Handler.handle, args=(s, msgid, msg)) else: raise SystemError
def onGen(self, event): startDate = _wxToPyDate(self.start.GetValue()) endDate = _wxToPyDate(self.end.GetValue()) report.gen(startDate, endDate, batteryChange, getOptions())
def main(): """\internal \brief Parse command line options and start the server. """ global server, domain_server, node_id, neighbours, local_ts, options options = getOptions() if not options.daemon: import subprocess subprocess.Popen("linda_monitor", shell=True) #pid = os.fork() #if pid != 0: # from monitor import monitor # return monitor.Thread(options.port).run() _linda_server.init() if options.peer: options.peer.append("127.0.0.1") # always allow local connections. def lookupname(addr): try: addr, r = addr.split("/") except ValueError: r = "32" addr = socket.gethostbyname(addr) if addr.count(".") != 3: print "%s is not in n.n.n.n[/r] format" % (addr + "/" + r) sys.exit(0) return addr + "/" + r node_id = "N" + guid.generate() _linda_server.setnodeid(node_id) if options.mdns and not options.disable_mdns: import mdns s = mdns.connect() if s: options.connect = s[0] options.connectport = s[1] if options.connect is not None and len(options.connect) > 0: if options.connectport: con = zip(options.connect, options.connectport) + [ (x, 2102) for x in options.connect[len(options.connectport):] ] else: con = zip(options.connect, [2102 for _ in options.connect]) assert len(con) == len(options.connect) i = 0 while True: svr, port = con[i] s = _linda_server.connect("%s:%s" % (svr, port)) if s is None: if i < len(con) - 1: i += 1 continue else: print "Unable to connect to server %s:%i." % (svr, port) sys.exit(-1) s = Connection(s) s.type = None s.send(None, (get_node_id, )) node = s.recv()[2] assert utils.isNodeId(node), repr(node) s.send(None, (my_name_is, node_id)) s.recv() s.type = "SERVER" s.name = node neighbours[node] = s connections.sockets.append(s) break local_ts.newTupleSpace("UTS") while True: try: socket_watcher() except KeyboardInterrupt: cleanShutdown() raise break