~nejucomo/divmod.org/fix-nevow-setup

« back to all changes in this revision

Viewing changes to Vertex/vertex/ptcp.py

  • Committer: Allen Short
  • Date: 2012-03-14 06:11:35 UTC
  • mfrom: (2667.1.16 amp-vertex-2580)
  • Revision ID: washort42@gmail.com-20120314061135-1jtoobsjbpl70shc
Merge 'amp-vertex-2580'
Author: washort
Reviewer: MostAwesomeDude

Replace JUICE with AMP in Vertex.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 
10
10
from epsilon.pending import PendingEvent
11
11
 
 
12
from twisted.python.failure import Failure
12
13
from twisted.internet import protocol, error, reactor, defer
13
14
from twisted.internet.main import CONNECTION_DONE
14
15
from twisted.python import log, util
760
761
        assert not self.disconnected
761
762
        self.disconnected = True
762
763
        try:
763
 
            self.protocol.connectionLost(CONNECTION_DONE)
 
764
            self.protocol.connectionLost(Failure(CONNECTION_DONE))
764
765
        except:
765
766
            log.err()
766
767
        self.protocol = None
831
832
            self.pseudoPeerPort)
832
833
 
833
834
class PTCP(protocol.DatagramProtocol):
 
835
    """
 
836
    L{PTCP} implements a strongly TCP-like protocol on top of UDP.  It
 
837
    provides a transport which is connection-oriented, streaming,
 
838
    ordered, and reliable.
 
839
 
 
840
    @ivar factory: A L{ServerFactory} which is used to create
 
841
        L{IProtocol} providers whenever a new PTCP connection is made
 
842
        to this port.
 
843
 
 
844
    @ivar _connections: A mapping of endpoint addresses to connection
 
845
        objects.  These are the active connections being multiplexed
 
846
        over this UDP port.  Many PTCP connections may run over the
 
847
        same L{PTCP} instance, communicating with many different
 
848
        remote hosts as well as multiplexing different PTCP
 
849
        connections to the same remote host.  The mapping keys,
 
850
        endpoint addresses, are three-tuples of:
 
851
 
 
852
            - The destination pseudo-port which is always C{1}
 
853
            - The source pseudo-port
 
854
            - A (host, port) tuple giving the UDP address of a PTCP
 
855
              peer holding the other side of the connection
 
856
 
 
857
        The mapping values, connection objects, are L{PTCPConnection}
 
858
        instances.
 
859
    @type _connections: C{dict}
 
860
 
 
861
    """
834
862
    # External API
835
863
 
836
864
    def __init__(self, factory):
837
865
        self.factory = factory
838
866
        self._allConnectionsClosed = PendingEvent()
839
867
 
 
868
 
840
869
    def connect(self, factory, host, port, pseudoPort=1):
 
870
        """
 
871
        Attempt to establish a new connection via PTCP to the given
 
872
        remote address.
 
873
 
 
874
        @param factory: A L{ClientFactory} which will be used to
 
875
            create an L{IProtocol} provider if the connection is
 
876
            successfully set up, or which will have failure callbacks
 
877
            invoked on it otherwise.
 
878
 
 
879
        @param host: The IP address of another listening PTCP port to
 
880
            connect to.
 
881
        @type host: C{str}
 
882
 
 
883
        @param port: The port number of that other listening PTCP port
 
884
            to connect to.
 
885
        @type port: C{int}
 
886
 
 
887
        @param pseudoPort: Not really implemented.  Do not pass a
 
888
            value for this parameter or things will break.
 
889
 
 
890
        @return: A L{PTCPConnection} instance representing the new
 
891
            connection, but you really shouldn't use this for
 
892
            anything.  Write a protocol!
 
893
        """
841
894
        sourcePseudoPort = genConnID() % MAX_PSEUDO_PORT
842
895
        conn = self._connections[(pseudoPort, sourcePseudoPort, (host, port))
843
896
                                 ] = PTCPConnection(