Пример #1
0
 def test_getSession_existingNickname_withoutEndpoint(self):
     proto = proto_helpers.AccumulatingProtocol()
     samEndpoint = FakeEndpoint()
     samEndpoint.deferred = defer.succeed(None)
     samEndpoint.facDeferred = defer.succeed(('3.1', 'STREAM', 'nick', proto, TEST_B64))
     d = session.getSession('nick', samEndpoint)
     s = self.successResultOf(d)
     d2 = session.getSession('nick')
     s2 = self.successResultOf(d2)
     self.assertEqual(1, samEndpoint.called)
     self.assertEqual(s, s2)
Пример #2
0
 def test_getSession_existingNickname_withoutEndpoint(self):
     proto = proto_helpers.AccumulatingProtocol()
     samEndpoint = FakeEndpoint()
     samEndpoint.deferred = defer.succeed(None)
     samEndpoint.facDeferred = defer.succeed(
         ('3.1', 'STREAM', 'nick', proto, TEST_B64, None))
     d = session.getSession('nick', samEndpoint)
     s = self.successResultOf(d)
     d2 = session.getSession('nick')
     s2 = self.successResultOf(d2)
     self.assertEqual(1, samEndpoint.called)
     self.assertEqual(s, s2)
Пример #3
0
    def new(cls, samEndpoint, host, port=None, nickname=None, autoClose=False, keyfile=None, options=None):
        """Create an I2P client endpoint backed by the SAM API.

        If a SAM session for ``nickname`` already exists, it will be used, and
        all options other than ``host`` and ``port`` will be ignored. Otherwise,
        a new SAM session will be created. The implication of this is that by
        default, all endpoints (both client and server) created by the same
        process will use the same SAM session.

        Args:
            samEndpoint (twisted.internet.interfaces.IStreamClientEndpoint): An
                endpoint that will connect to the SAM API.
            host (str): The I2P hostname or Destination to connect to.
            port (int): The port to connect to inside I2P. If unset or `None`,
                the default (null) port is used. Ignored because SAM doesn't
                support ports yet.
            nickname (str): The SAM session nickname.
            autoClose (bool): `true` if the session should close automatically
                once no more connections are using it.
            keyfile (str): Path to a local file containing the keypair to use
                for the session Destination. If non-existent, new keys will be
                generated and stored.
            options (dict): I2CP options to configure the session with.
        """
        d = getSession(nickname,
                       samEndpoint=samEndpoint,
                       autoClose=autoClose,
                       keyfile=keyfile,
                       options=_parseOptions(options))
        return cls(d, host, port)
Пример #4
0
    def new(cls, samEndpoint, keyfile, port=None, nickname=None, autoClose=False, options=None, sigType=None):
        """Create an I2P server endpoint backed by the SAM API.

        If a SAM session for ``nickname`` already exists, it will be used, and
        all options other than ``port`` will be ignored. Otherwise, a new SAM
        session will be created. The implication of this is that by default, all
        endpoints (both client and server) created by the same process will use
        the same SAM session.

        Args:
            samEndpoint (twisted.internet.interfaces.IStreamClientEndpoint): An
                endpoint that will connect to the SAM API.
            keyfile (str): Path to a local file containing the keypair to use
                for the session Destination. If non-existent, new keys will be
                generated and stored.
            port (int): The port to listen on inside I2P. If unset or `None`,
                the default (null) port is used. Ignored if the SAM server
                doesn't support SAM v3.2 or higher.
            nickname (str): The SAM session nickname.
            autoClose (bool): `true` if the session should close automatically
                once no more connections are using it.
            options (dict): I2CP options to configure the session with.
            sigType (str): The SigType to use if generating a new Destination.
                Defaults to Ed25519 if supported, falling back to
                ECDSA_SHA256_P256 and then DSA_SHA1.
        """
        d = getSession(nickname,
                       samEndpoint=samEndpoint,
                       autoClose=autoClose,
                       keyfile=keyfile,
                       localPort=port,
                       options=options,
                       sigType=sigType)
        return cls(d)
Пример #5
0
 def test_getSession_newNickname(self):
     proto = proto_helpers.AccumulatingProtocol()
     samEndpoint = FakeEndpoint()
     samEndpoint.deferred = defer.succeed(None)
     samEndpoint.facDeferred = defer.succeed(('3.1', 'STREAM', 'nick', proto, TEST_B64))
     d = session.getSession('nick', samEndpoint)
     s = self.successResultOf(d)
     self.assertEqual(1, samEndpoint.called)
     self.assertEqual('nick', s.nickname)
     self.assertEqual('nick', s.id)
     self.assertEqual(proto, s._proto)
     self.assertEqual(TEST_B64, s.address.destination)
Пример #6
0
 def test_getSession_newNickname_withPort(self):
     proto = proto_helpers.AccumulatingProtocol()
     samEndpoint = FakeEndpoint()
     samEndpoint.deferred = defer.succeed(None)
     samEndpoint.facDeferred = defer.succeed(
         ('3.2', 'STREAM', 'nick', proto, TEST_B64, 81))
     d = session.getSession('nick', samEndpoint)
     s = self.successResultOf(d)
     self.assertEqual(1, samEndpoint.called)
     self.assertEqual('nick', s.nickname)
     self.assertEqual('nick', s.id)
     self.assertEqual(proto, s._proto)
     self.assertEqual(TEST_B64, s.address.destination)
     self.assertEqual(81, s.address.port)
Пример #7
0
    def new(cls,
            samEndpoint,
            host,
            port=None,
            nickname=None,
            autoClose=False,
            keyfile=None,
            localPort=None,
            options=None,
            sigType=None):
        """Create an I2P client endpoint backed by the SAM API.

        If a SAM session for ``nickname`` already exists, it will be used, and
        all options other than ``host`` and ``port`` will be ignored. Otherwise,
        a new SAM session will be created. The implication of this is that by
        default, all endpoints (both client and server) created by the same
        process will use the same SAM session.

        Args:
            samEndpoint (twisted.internet.interfaces.IStreamClientEndpoint): An
                endpoint that will connect to the SAM API.
            host (str): The I2P hostname or Destination to connect to.
            port (int): The port to connect to inside I2P. If unset or `None`,
                the default (null) port is used. Ignored if the SAM server
                doesn't support SAM v3.2 or higher.
            nickname (str): The SAM session nickname.
            autoClose (bool): `true` if the session should close automatically
                once no more connections are using it.
            keyfile (str): Path to a local file containing the keypair to use
                for the session Destination. If non-existent, new keys will be
                generated and stored.
            localPort (int): The port to connect from inside I2P. This can be
                used to distinguish between multiple connections to the same
                server. If unset or `None`, the default (null) port is used.
                Ignored if the SAM server doesn't support SAM v3.2 or higher.
            options (dict): I2CP options to configure the session with.
            sigType (str): The SigType to use if generating a new Destination.
                Defaults to Ed25519 if supported, falling back to
                ECDSA_SHA256_P256 and then DSA_SHA1.
        """
        d = getSession(nickname,
                       samEndpoint=samEndpoint,
                       autoClose=autoClose,
                       keyfile=keyfile,
                       options=options,
                       sigType=sigType)
        return cls(d, host, port, localPort)