Ejemplo n.º 1
0
 def demux(self, source, sourcePort, destination, destinationPort, data):
     logger.debug("{} received {} bytes of data from {}:{} for {}:{}".format(self, len(data), source, sourcePort, destination, destinationPort))
     for dumper in self._dumps:
         dumpPacket = WirePacket(source=source, sourcePort=sourcePort,
                                 destination=destination, destinationPort=destinationPort,
                                 data=data)
         dumper.transport.write(dumpPacket.__serialize__())
             
     remotePortKey = PortKey(source, sourcePort, destination, destinationPort)
     
     # this portkey is backwards. The source is from the remote machine
     # but our ports have the remote machine being the destination. 
     # So, invert:
     
     localPortKey = remotePortKey.inverseKey()
     
     # Check if the full port key is already in connections. If so, we're all done
     if localPortKey in self._connections:
         self._connections[localPortKey].write(data)
         return
     
     # If there's no port key in connections, check for listening port.
     listeningPort = localPortKey.sourcePort
     if listeningPort in self._ports and self._ports[listeningPort].isListener():
         # We have a new connection. Spawn.
         # use a controlled port so that if the listening port is closed,
         # all of the spawned ports are closed.
         self._connections[localPortKey] = ConnectionData(localPortKey, self._ports[listeningPort])
         self._connections[localPortKey].write(data)
         self._ports[listeningPort].spawnConnection(localPortKey)
         
     else:
         pass # drop? Fail silently?
Ejemplo n.º 2
0
    def demux(self, source, sourcePort, destination, destinationPort, data):
        remotePortKey = PortKey(source, sourcePort, destination,
                                destinationPort)

        # this portkey is backwards. The source is from the remote machine
        # but our ports have the remote machine being the destination.
        # So, invert:

        localPortKey = remotePortKey.inverseKey()

        # Check if the full port key is already in connections. If so, we're all done
        if localPortKey in self._connections:
            self._connections[localPortKey].write(data)
            return

        # If there's no port key in connections, check for listening port.
        listeningPort = localPortKey.sourcePort
        if listeningPort in self._ports and self._ports[
                listeningPort].isListener():
            # We have a new connection. Spawn.
            # use a controlled port so that if the listening port is closed,
            # all of the spawned ports are closed.
            self._connections[localPortKey] = ConnectionData(
                localPortKey, self._ports[listeningPort])
            self._connections[localPortKey].write(data)
            self._ports[listeningPort].spawnConnection(localPortKey)

        else:
            pass  # drop? Fail silently?