Beispiel #1
0
 def doReadHello(self, arg):
     """
     Action method.
     """
     from transport.tcp import tcp_node
     try:
         command, payload = arg
         peeraddress, peeridurl = payload.split(' ')
         peerip, peerport = peeraddress.split(':')
         peerport = int(peerport)
         peeraddress = (peerip, peerport)
     except:
         return
     # self.peer_external_address = (self.peer_external_address[0], peerport)
     self.peer_external_address = peeraddress
     self.peer_idurl = peeridurl
     if self.peer_address != self.peer_external_address:
         tcp_node.opened_connections()[self.peer_address].remove(self)
         if len(tcp_node.opened_connections()[self.peer_address]) == 0:
             tcp_node.opened_connections().pop(self.peer_address)
         self.peer_address = self.peer_external_address
         if self.peer_address not in tcp_node.opened_connections():
             tcp_node.opened_connections()[self.peer_address] = []
         tcp_node.opened_connections()[self.peer_address].append(self)
         lg.out(
             6, '%s : external peer address changed to %s' %
             (self, self.peer_address))
Beispiel #2
0
 def doReadHello(self, *args, **kwargs):
     """
     Action method.
     """
     from transport.tcp import tcp_node
     try:
         command, payload = args[0]
         peeraddress, peeridurl = payload.split(b' ')
         peerip, peerport = peeraddress.split(b':')
         peerport = int(peerport)
         if not peerip:
             lg.warn('unknown peer IP from Hello packet: %r' % args[0])
             peerip = self.peer_external_address[0]
         peeraddress = (peerip, peerport)
     except:
         lg.exc()
         return
     # self.peer_external_address = (self.peer_external_address[0], peerport)
     self.peer_external_address = peeraddress
     self.peer_idurl = peeridurl
     if self.peer_address != self.peer_external_address:
         tcp_node.opened_connections()[self.peer_address].remove(self)
         if len(tcp_node.opened_connections()[self.peer_address]) == 0:
             tcp_node.opened_connections().pop(self.peer_address)
         old_address = self.peer_address
         self.peer_address = self.peer_external_address
         if self.peer_address not in tcp_node.opened_connections():
             tcp_node.opened_connections()[self.peer_address] = []
         tcp_node.opened_connections()[self.peer_address].append(self)
         if _Debug:
             lg.out(
                 _DebugLevel,
                 '%s : external peer address changed from %s to %s' %
                 (self, old_address, self.peer_address))
    def doReadHello(self, arg):
        """
        Action method.
        """
        from transport.tcp import tcp_node

        try:
            command, payload = arg
            peeraddress, peeridurl = payload.split(" ")
            peerip, peerport = peeraddress.split(":")
            peerport = int(peerport)
            peeraddress = (peerip, peerport)
        except:
            return
        # self.peer_external_address = (self.peer_external_address[0], peerport)
        self.peer_external_address = peeraddress
        self.peer_idurl = peeridurl
        if self.peer_address != self.peer_external_address:
            tcp_node.opened_connections()[self.peer_address].remove(self)
            if len(tcp_node.opened_connections()[self.peer_address]) == 0:
                tcp_node.opened_connections().pop(self.peer_address)
            self.peer_address = self.peer_external_address
            if self.peer_address not in tcp_node.opened_connections():
                tcp_node.opened_connections()[self.peer_address] = []
            tcp_node.opened_connections()[self.peer_address].append(self)
            lg.out(6, "%s : external peer address changed to %s" % (self, self.peer_address))
Beispiel #4
0
 def doInit(self, arg):
     """
     Action method.
     """
     from transport.tcp import tcp_node
     self.peer_address = self.getTransportAddress()
     self.peer_external_address = self.peer_address
     self.connected = time.time()
     if self.peer_address not in tcp_node.opened_connections():
         tcp_node.opened_connections()[self.peer_address] = []
     tcp_node.opened_connections()[self.peer_address].append(self)
     tcp_node.increase_connections_counter()
    def doInit(self, arg):
        """
        Action method.
        """
        from transport.tcp import tcp_node

        self.peer_address = self.getTransportAddress()
        self.peer_external_address = self.peer_address
        self.connected = time.time()
        if self.peer_address not in tcp_node.opened_connections():
            tcp_node.opened_connections()[self.peer_address] = []
        tcp_node.opened_connections()[self.peer_address].append(self)
        tcp_node.increase_connections_counter()
Beispiel #6
0
 def doInit(self, *args, **kwargs):
     """
     Action method.
     """
     from transport.tcp import tcp_node
     self.peer_address = self.getTransportAddress()
     self.peer_external_address = self.peer_address
     self.connected = time.time()
     if self.peer_address not in tcp_node.opened_connections():
         tcp_node.opened_connections()[self.peer_address] = []
     tcp_node.opened_connections()[self.peer_address].append(self)
     tcp_node.increase_connections_counter()
     if _Debug:
         lg.out(_DebugLevel, 'tcp_connection.doInit with %s, total connections to that address : %d' % (
             self.peer_address, len(tcp_node.opened_connections()[self.peer_address]), ))
Beispiel #7
0
def list_output_streams(sorted_by_time=True):
    from transport.tcp import tcp_node
    streams = []
    for connections in tcp_node.opened_connections().values():
        for connection in connections:
            if connection.stream:
                streams.extend(connection.stream.outboxFiles.values())
    if sorted_by_time:
        streams.sort(key=lambda stream: stream.started)
    return streams
Beispiel #8
0
def list_output_streams(sorted_by_time=True):
    from transport.tcp import tcp_node
    streams = []
    for connections in tcp_node.opened_connections().values():
        for connection in connections:
            if connection.stream:
                streams.extend(list(connection.stream.outboxFiles.values()))
    if sorted_by_time:
        streams.sort(key=lambda stream: stream.started)
    return streams
Beispiel #9
0
 def list_sessions(self):
     """
     """
     result = []
     for opened_connection in tcp_node.opened_connections().values():
         for channel in opened_connection:
             result.append(channel)
     for started_connection in tcp_node.started_connections().values():
         result.append(started_connection)
     return result
Beispiel #10
0
 def find_session(self, host=None, idurl=None):
     """
     """
     if idurl:
         for opened_connection in tcp_node.opened_connections().values():
             for channel in opened_connection:
                 if channel.get_idurl() and channel.get_idurl() == idurl:
                     if _Debug:
                         lg.dbg(_DebugLevel,
                                'found active connection for %r' % idurl)
                     return [
                         channel,
                     ]
         return []
     search_for_host = net_misc.normalize_address(host)
     if _Debug:
         lg.dbg(
             _DebugLevel, 'looking for %r, known connections: %r' % (
                 search_for_host,
                 list(tcp_node.opened_connections().keys()),
             ))
     return tcp_node.opened_connections().get(search_for_host, [])
Beispiel #11
0
def find_stream(file_id=None, transfer_id=None):
    from transport.tcp import tcp_node
    for connections in tcp_node.opened_connections().values():
        for connection in connections:
            if connection.stream:
                for out_file in connection.stream.outboxFiles.values():
                    if file_id and out_file.file_id == file_id:
                        return out_file
                    if transfer_id and out_file.transfer_id == transfer_id:
                        return out_file
                for in_file in connection.stream.inboxFiles.values():
                    if file_id and in_file.file_id == file_id:
                        return in_file
                    if transfer_id and in_file.transfer_id == transfer_id:
                        return in_file
    return None
Beispiel #12
0
def process_streams():
    from transport.tcp import tcp_node
    global _ProcessStreamsDelay
    global _ProcessStreamsTask
    has_activity = False
    for connections in tcp_node.opened_connections().values():
        for connection in connections:
            has_timeouts = False  # connection.stream.timeout_incoming_files()
            has_sends = False  # connection.stream.process_sending_data()
            has_outbox = connection.process_outbox_queue()
            if has_timeouts or has_sends or has_outbox:
                has_activity = True
    _ProcessStreamsDelay = misc.LoopAttenuation(
        _ProcessStreamsDelay, has_activity,
        MIN_PROCESS_STREAMS_DELAY,
        MAX_PROCESS_STREAMS_DELAY,)
    # attenuation
    _ProcessStreamsTask = reactor.callLater(
        _ProcessStreamsDelay, process_streams)
Beispiel #13
0
def process_streams():
    from transport.tcp import tcp_node
    global _ProcessStreamsDelay
    global _ProcessStreamsTask
    has_activity = False
    for connections in tcp_node.opened_connections().values():
        for connection in connections:
            has_timeouts = False  # connection.stream.timeout_incoming_files()
            has_sends = False  # connection.stream.process_sending_data()
            has_outbox = connection.process_outbox_queue()
            if has_timeouts or has_sends or has_outbox:
                has_activity = True
    _ProcessStreamsDelay = misc.LoopAttenuation(
        _ProcessStreamsDelay, has_activity,
        MIN_PROCESS_STREAMS_DELAY,
        MAX_PROCESS_STREAMS_DELAY,)
    # attenuation
    _ProcessStreamsTask = reactor.callLater(  # @UndefinedVariable
        _ProcessStreamsDelay, process_streams)
Beispiel #14
0
 def doDestroyMe(self, *args, **kwargs):
     """
     Action method.
     """
     from transport.tcp import tcp_node
     self.destroy()
     if self.peer_address in tcp_node.opened_connections():
         tcp_node.opened_connections()[self.peer_address].remove(self)
         if len(tcp_node.opened_connections()[self.peer_address]) == 0:
             tcp_node.opened_connections().pop(self.peer_address)
         tcp_node.decrease_connections_counter()
     else:
         raise Exception('not found %r in the opened connections' % self.peer_address)
     self.stream = None
     self.peer_address = None
     self.peer_external_address = None
     self.peer_idurl = None
     self.outboxQueue = []
    def doDestroyMe(self, arg):
        """
        Action method.
        """
        from transport.tcp import tcp_node

        # lg.out(18, 'tcp_connection.doDestroyMe %s' % str(self))
        self.destroy()
        if self.peer_address in tcp_node.opened_connections():
            tcp_node.opened_connections()[self.peer_address].remove(self)
            if len(tcp_node.opened_connections()[self.peer_address]) == 0:
                tcp_node.opened_connections().pop(self.peer_address)
            tcp_node.decrease_connections_counter()
        else:
            raise Exception("not found %s in the opened connections" % self.peer_address)
        self.stream = None
        self.peer_address = None
        self.peer_external_address = None
        self.peer_idurl = None
        self.outboxQueue = []
Beispiel #16
0
 def find_session(self, host):
     """
     """
     return tcp_node.opened_connections().get(
         net_misc.normalize_address(host), [])
Beispiel #17
0
 def find_session(self, host):
     """
     """
     return tcp_node.opened_connections().get(self._normalize_host(host), [])