Beispiel #1
0
 def sched_udp_proc(self, coro=None):
     coro.set_daemon()
     sched_sock = asyncoro.AsyncSocket(
         socket.socket(socket.AF_INET, socket.SOCK_DGRAM))
     sched_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     sched_sock.bind(('', self.scheduler_port))
     while 1:
         msg, addr = yield sched_sock.recvfrom(1024)
         if (not msg.startswith('PING:'.encode())
                 or not self.scheduler_ip_addrs or not self.scheduler_port):
             logger.debug('Ignoring ping message from %s (%s)', addr[0],
                          addr[1])
             continue
         try:
             info = asyncoro.deserialize(msg[len('PING:'.encode()):])
             logger.debug('sched_sock: %s', info)
             assert info['version'] == __version__
             # assert isinstance(info['cpus'], int)
         except:
             logger.debug(traceback.format_exc())
         msg = {
             'ip_addrs': self.scheduler_ip_addrs,
             'port': self.scheduler_port,
             'version': __version__
         }
         if info.get('relay', None):
             logger.debug('Ignoring ping back from %s: %s', addr[0], info)
             continue
         msg['relay'] = 'y'
         relay_sock = asyncoro.AsyncSocket(
             socket.socket(socket.AF_INET, socket.SOCK_DGRAM))
         yield relay_sock.sendto('PING:'.encode() + asyncoro.serialize(msg),
                                 (info['ip_addr'], info['port']))
         relay_sock.close()
Beispiel #2
0
 def sched_udp_proc(self, coro=None):
     coro.set_daemon()
     sched_sock = asyncoro.AsyncSocket(socket.socket(socket.AF_INET, socket.SOCK_DGRAM))
     sched_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     sched_sock.bind(('', self.scheduler_port))
     while 1:
         msg, addr = yield sched_sock.recvfrom(1024)
         if (not msg.startswith('PING:'.encode()) or
            not self.scheduler_ip_addrs or not self.scheduler_port):
             logger.debug('Ignoring ping message from %s (%s)', addr[0], addr[1])
             continue
         try:
             info = asyncoro.deserialize(msg[len('PING:'.encode()):])
             logger.debug('sched_sock: %s', info)
             assert info['version'] == __version__
             # assert isinstance(info['cpus'], int)
         except:
             logger.debug(traceback.format_exc())
         msg = {'ip_addrs': self.scheduler_ip_addrs, 'port': self.scheduler_port,
                'version': __version__}
         if info.get('relay', None):
             logger.debug('Ignoring ping back from %s: %s', addr[0], info)
             continue
         msg['relay'] = 'y'
         relay_sock = asyncoro.AsyncSocket(socket.socket(socket.AF_INET, socket.SOCK_DGRAM))
         yield relay_sock.sendto('PING:'.encode() + asyncoro.serialize(msg),
                                 (info['ip_addr'], info['port']))
         relay_sock.close()
Beispiel #3
0
 def sched_udp_proc(self, coro=None):
     coro.set_daemon()
     sched_sock = asyncoro.AsyncSocket(socket.socket(socket.AF_INET, socket.SOCK_DGRAM))
     sched_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     sched_sock.bind(("", self.scheduler_port))
     while 1:
         msg, addr = yield sched_sock.recvfrom(1024)
         if not msg.startswith("PING:".encode()) or not self.scheduler_ip_addrs or not self.scheduler_port:
             logger.debug("Ignoring ping message from %s (%s)", addr[0], addr[1])
             continue
         try:
             info = asyncoro.deserialize(msg[len("PING:".encode()) :])
             logger.debug("sched_sock: %s", info)
             assert info["version"] == __version__
             # assert isinstance(info['cpus'], int)
         except:
             logger.debug(traceback.format_exc())
         msg = {"ip_addrs": self.scheduler_ip_addrs, "port": self.scheduler_port, "version": __version__}
         if info.get("relay", None):
             logger.debug("Ignoring ping back from %s: %s", addr[0], info)
             continue
         msg["relay"] = "y"
         relay_sock = asyncoro.AsyncSocket(socket.socket(socket.AF_INET, socket.SOCK_DGRAM))
         yield relay_sock.sendto("PING:".encode() + asyncoro.serialize(msg), (info["ip_addr"], info["port"]))
         relay_sock.close()
Beispiel #4
0
    def listen_udp_proc(self, coro=None):
        coro.set_daemon()
        bc_sock = asyncoro.AsyncSocket(
            socket.socket(socket.AF_INET, socket.SOCK_DGRAM))
        bc_sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

        if self.scheduler_ip_addrs and self.scheduler_port:
            relay_request = {
                'ip_addrs': self.scheduler_ip_addrs,
                'port': self.scheduler_port,
                'version': __version__,
                'sign': None
            }
            bc_sock.sendto(
                'PING:'.encode() + asyncoro.serialize(relay_request),
                ('<broadcast>', self.node_port))
        bc_sock.close()

        listen_sock = asyncoro.AsyncSocket(
            socket.socket(socket.AF_INET, socket.SOCK_DGRAM))
        listen_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        listen_sock.bind(('', self.listen_port))

        while 1:
            msg, addr = yield listen_sock.recvfrom(1024)
            if not msg.startswith('PING:'.encode()):
                logger.debug('Ignoring message "%s" from %s',
                             msg[:min(len(msg), 5)], addr[0])
                continue
            logger.debug('Ping message from %s (%s)', addr[0], addr[1])
            try:
                info = asyncoro.deserialize(msg[len('PING:'.encode()):])
                if info['version'] != __version__:
                    logger.warning(
                        'Ignoring %s due to version mismatch: %s / %s',
                        info['ip_addrs'], info['version'], __version__)
                    continue
                self.scheduler_ip_addrs = info['ip_addrs'] + [addr[0]]
                self.scheduler_port = info['port']
            except:
                logger.debug('Ignoring ping message from %s (%s)', addr[0],
                             addr[1])
                logger.debug(traceback.format_exc())
                continue
            if info.get('relay', None):
                logger.debug('Ignoring ping back (from %s)', addr[0])
                continue
            logger.debug('relaying ping from %s / %s', info['ip_addrs'],
                         addr[0])
            if self.node_port == self.listen_port:
                info[
                    'relay'] = 'y'  # 'check if this message loops back to self
            bc_sock = asyncoro.AsyncSocket(
                socket.socket(socket.AF_INET, socket.SOCK_DGRAM))
            bc_sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
            yield bc_sock.sendto('PING:'.encode() + asyncoro.serialize(info),
                                 ('<broadcast>', self.node_port))
            bc_sock.close()
    def sched_udp_proc(self, coro=None):
        coro.set_daemon()
        sched_sock = asyncoro.AsyncSocket(
            socket.socket(self.addrinfo[0], socket.SOCK_DGRAM))
        if self.addrinfo[0] == socket.AF_INET:
            sched_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            addr = ('', self.scheduler_port)
        else:  # self.addrinfo[0] == socket.AF_INET6
            sched_sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP,
                                  self.mreq)
            addr = list(self.addrinfo[4])
            addr[0] = ''
            addr[1] = self.scheduler_port
            addr = tuple(addr)
        sched_sock.bind(addr)

        while 1:
            msg, addr = yield sched_sock.recvfrom(1024)
            if (not msg.startswith('PING:'.encode())
                    or not self.scheduler_ip_addrs or not self.scheduler_port):
                logger.debug('Ignoring ping message from %s (%s)', addr[0],
                             addr[1])
                continue
            try:
                info = asyncoro.deserialize(msg[len('PING:'.encode()):])
                assert info['version'] == __version__
                # assert isinstance(info['cpus'], int)
            except:
                logger.debug(traceback.format_exc())
            msg = {
                'ip_addrs': self.scheduler_ip_addrs,
                'port': self.scheduler_port,
                'version': __version__
            }
            if info.get('relay', None):
                logger.debug('Ignoring ping back from %s: %s', addr[0], info)
                continue
            msg['relay'] = 'y'
            relay_sock = asyncoro.AsyncSocket(
                socket.socket(self.addrinfo[0], socket.SOCK_DGRAM))
            if self.addrinfo[0] == socket.AF_INET:
                addr = (info['ip_addr'], info['port'])
            else:  # self.sock_family == socket.AF_INET6
                addr = list(self.addrinfo[4])
                addr[1] = 0
                bc_sock.bind(tuple(addr))
                addr[0] = info['ip_addr']
                addr[1] = info['port']
                addr = tuple(addr)

            yield relay_sock.sendto('PING:'.encode() + asyncoro.serialize(msg),
                                    addr)
            relay_sock.close()
Beispiel #6
0
    def listen_udp_proc(self, coro=None):
        coro.set_daemon()
        bc_sock = asyncoro.AsyncSocket(socket.socket(socket.AF_INET, socket.SOCK_DGRAM))
        bc_sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

        if self.scheduler_ip_addrs and self.scheduler_port:
            relay_request = {
                "ip_addrs": self.scheduler_ip_addrs,
                "port": self.scheduler_port,
                "version": __version__,
                "sign": None,
            }
            bc_sock.sendto("PING:".encode() + asyncoro.serialize(relay_request), ("<broadcast>", self.node_port))
        bc_sock.close()

        listen_sock = asyncoro.AsyncSocket(socket.socket(socket.AF_INET, socket.SOCK_DGRAM))
        listen_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        listen_sock.bind(("", self.listen_port))

        while 1:
            msg, addr = yield listen_sock.recvfrom(1024)
            if not msg.startswith("PING:".encode()):
                logger.debug('Ignoring message "%s" from %s', msg[: min(len(msg), 5)], addr[0])
                continue
            logger.debug("Ping message from %s (%s)", addr[0], addr[1])
            try:
                info = asyncoro.deserialize(msg[len("PING:".encode()) :])
                if info["version"] != __version__:
                    logger.warning(
                        "Ignoring %s due to version mismatch: %s / %s", info["ip_addrs"], info["version"], __version__
                    )
                    continue
                self.scheduler_ip_addrs = info["ip_addrs"] + [addr[0]]
                self.scheduler_port = info["port"]
            except:
                logger.debug("Ignoring ping message from %s (%s)", addr[0], addr[1])
                logger.debug(traceback.format_exc())
                continue
            if info.get("relay", None):
                logger.debug("Ignoring ping back (from %s)", addr[0])
                continue
            logger.debug("relaying ping from %s / %s", info["ip_addrs"], addr[0])
            if self.node_port == self.listen_port:
                info["relay"] = "y"  # 'check if this message loops back to self
            bc_sock = asyncoro.AsyncSocket(socket.socket(socket.AF_INET, socket.SOCK_DGRAM))
            bc_sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
            yield bc_sock.sendto("PING:".encode() + asyncoro.serialize(info), ("<broadcast>", self.node_port))
            bc_sock.close()
Beispiel #7
0
    def listen_udp_proc(self, coro=None):
        coro.set_daemon()
        bc_sock = asyncoro.AsyncSocket(socket.socket(socket.AF_INET, socket.SOCK_DGRAM))
        bc_sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

        if self.scheduler_ip_addrs and self.scheduler_port:
            relay_request = {'ip_addrs': self.scheduler_ip_addrs, 'port': self.scheduler_port,
                             'version': __version__, 'sign': None}
            bc_sock.sendto('PING:'.encode() + asyncoro.serialize(relay_request),
                           ('<broadcast>', self.node_port))
        bc_sock.close()

        listen_sock = asyncoro.AsyncSocket(socket.socket(socket.AF_INET, socket.SOCK_DGRAM))
        listen_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        listen_sock.bind(('', self.listen_port))

        while 1:
            msg, addr = yield listen_sock.recvfrom(1024)
            if not msg.startswith('PING:'.encode()):
                logger.debug('Ignoring message "%s" from %s',
                             msg[:min(len(msg), 5)], addr[0])
                continue
            logger.debug('Ping message from %s (%s)', addr[0], addr[1])
            try:
                info = asyncoro.deserialize(msg[len('PING:'.encode()):])
                if info['version'] != __version__:
                    logger.warning('Ignoring %s due to version mismatch: %s / %s',
                                   info['ip_addrs'], info['version'], __version__)
                    continue
                self.scheduler_ip_addrs = info['ip_addrs'] + [addr[0]]
                self.scheduler_port = info['port']
            except:
                logger.debug('Ignoring ping message from %s (%s)', addr[0], addr[1])
                logger.debug(traceback.format_exc())
                continue
            if info.get('relay', None):
                logger.debug('Ignoring ping back (from %s)', addr[0])
                continue
            logger.debug('relaying ping from %s / %s', info['ip_addrs'], addr[0])
            if self.node_port == self.listen_port:
                info['relay'] = 'y'  # 'check if this message loops back to self
            bc_sock = asyncoro.AsyncSocket(socket.socket(socket.AF_INET, socket.SOCK_DGRAM))
            bc_sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
            yield bc_sock.sendto('PING:'.encode() + asyncoro.serialize(info),
                                 ('<broadcast>', self.node_port))
            bc_sock.close()
Beispiel #8
0
 def tcp_task(conn, addr, coro=None):
     conn.settimeout(5)
     try:
         msg = yield conn.recvall(auth_len)
         msg = yield conn.recv_msg()
     except:
         logger.debug(traceback.format_exc())
         logger.debug('Ignoring invalid TCP message from %s:%s',
                      addr[0], addr[1])
         raise StopIteration
     finally:
         conn.close()
     logger.debug('Ping message from %s (%s)', addr[0], addr[1])
     try:
         info = asyncoro.deserialize(msg[len('PING:'.encode()):])
         if info['version'] != __version__:
             logger.warning(
                 'Ignoring %s due to version mismatch: %s / %s',
                 info['ip_addrs'], info['version'], __version__)
             raise StopIteration
         # TODO: since dispynetrelay is not aware of computations
         # closing, if more than one client sends ping, nodes will
         # respond to different clients
         self.scheduler_ip_addrs = info['ip_addrs'] + [addr[0]]
         self.scheduler_port = info['port']
     except:
         logger.debug('Ignoring ping message from %s (%s)', addr[0],
                      addr[1])
         logger.debug(traceback.format_exc())
         raise StopIteration
     if info.get('relay', None):
         logger.debug('Ignoring ping back (from %s)', addr[0])
         raise StopIteration
     logger.debug('relaying ping from %s / %s', info['ip_addrs'],
                  addr[0])
     if self.node_port == self.listen_port:
         info[
             'relay'] = 'y'  # 'check if this message loops back to self
     bc_sock = asyncoro.AsyncSocket(
         socket.socket(socket.AF_INET, socket.SOCK_DGRAM))
     bc_sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
     yield bc_sock.sendto('PING:'.encode() + asyncoro.serialize(info),
                          ('<broadcast>', self.node_port))
     bc_sock.close()
Beispiel #9
0
 def tcp_task(conn, addr, coro=None):
     conn.settimeout(5)
     try:
         msg = yield conn.recvall(auth_len)
         msg = yield conn.recv_msg()
     except:
         logger.debug(traceback.format_exc())
         logger.debug('Ignoring invalid TCP message from %s:%s', addr[0], addr[1])
         raise StopIteration
     finally:
         conn.close()
     logger.debug('Ping message from %s (%s)', addr[0], addr[1])
     try:
         info = asyncoro.deserialize(msg[len('PING:'.encode()):])
         if info['version'] != __version__:
             logger.warning('Ignoring %s due to version mismatch: %s / %s',
                            info['ip_addrs'], info['version'], __version__)
             raise StopIteration
         # TODO: since dispynetrelay is not aware of computations
         # closing, if more than one client sends ping, nodes will
         # respond to different clients
         self.scheduler_ip_addrs = info['ip_addrs'] + [addr[0]]
         self.scheduler_port = info['port']
     except:
         logger.debug('Ignoring ping message from %s (%s)', addr[0], addr[1])
         logger.debug(traceback.format_exc())
         raise StopIteration
     if info.get('relay', None):
         logger.debug('Ignoring ping back (from %s)', addr[0])
         raise StopIteration
     logger.debug('relaying ping from %s / %s', info['ip_addrs'], addr[0])
     if self.node_port == self.listen_port:
         info['relay'] = 'y'  # 'check if this message loops back to self
     bc_sock = asyncoro.AsyncSocket(socket.socket(socket.AF_INET, socket.SOCK_DGRAM))
     bc_sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
     yield bc_sock.sendto('PING:'.encode() + asyncoro.serialize(info),
                          ('<broadcast>', self.node_port))
     bc_sock.close()
    def listen_udp_proc(self, coro=None):
        coro.set_daemon()
        bc_sock = asyncoro.AsyncSocket(
            socket.socket(self.addrinfo[0], socket.SOCK_DGRAM))
        if self.addrinfo[0] == socket.AF_INET:
            bc_sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
            addr = (self._broadcast, self.node_port)
        else:  # self.sock_family == socket.AF_INET6
            bc_sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_HOPS,
                               struct.pack('@i', 1))
            addr = list(self.addrinfo[4])
            addr[1] = 0
            bc_sock.bind(tuple(addr))
            addr[0] = self._broadcast
            addr[1] = self.node_port
            addr = tuple(addr)

        if self.scheduler_ip_addrs and self.scheduler_port:
            relay_request = {
                'ip_addrs': self.scheduler_ip_addrs,
                'port': self.scheduler_port,
                'version': __version__,
                'sign': None
            }
            bc_sock.sendto(
                'PING:'.encode() + asyncoro.serialize(relay_request), addr)

        listen_sock = asyncoro.AsyncSocket(
            socket.socket(self.addrinfo[0], socket.SOCK_DGRAM))
        if self.addrinfo[0] == socket.AF_INET:
            listen_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            addr = ('', self.listen_port)
        else:  # self.addrinfo[0] == socket.AF_INET6
            listen_sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP,
                                   self.mreq)
            addr = list(self.addrinfo[4])
            addr[0] = ''
            addr[1] = self.listen_port
            addr = tuple(addr)
        listen_sock.bind(addr)

        while 1:
            msg, addr = yield listen_sock.recvfrom(1024)
            if not msg.startswith('PING:'.encode()):
                logger.debug('Ignoring message "%s" from %s',
                             msg[:min(len(msg), 5)], addr[0])
                continue
            logger.debug('Ping message from %s (%s)', addr[0], addr[1])
            try:
                info = asyncoro.deserialize(msg[len('PING:'.encode()):])
                if info['version'] != __version__:
                    logger.warning(
                        'Ignoring %s due to version mismatch: %s / %s',
                        info['ip_addrs'], info['version'], __version__)
                    continue
                self.scheduler_ip_addrs = info['ip_addrs'] + [addr[0]]
                self.scheduler_port = info['port']
            except:
                logger.debug('Ignoring ping message from %s (%s)', addr[0],
                             addr[1])
                logger.debug(traceback.format_exc())
                continue
            if info.get('relay', None):
                logger.debug('Ignoring ping back (from %s)', addr[0])
                continue
            logger.debug('relaying ping from %s / %s', info['ip_addrs'],
                         addr[0])
            if self.node_port == self.listen_port:
                info[
                    'relay'] = 'y'  # 'check if this message loops back to self

            yield bc_sock.sendto('PING:'.encode() + asyncoro.serialize(info),
                                 addr)