def test_version_big(self): self.assertTrue(version_at_least("0.3.3.0-alpha-dev", 0, 2, 7, 9))
def test_version_3(self): self.assertTrue(version_at_least("1.2.3.4", 1, 2, 3, 2))
def test_version_4(self): self.assertTrue(version_at_least("2.1.1.1", 2, 0, 0, 0))
def test_version_4(self): self.assertTrue( version_at_least("2.1.1.1", 2, 0, 0, 0) )
def test_version_2(self): self.assertFalse(version_at_least("1.2.3.4", 1, 2, 3, 5))
def test_version_3(self): self.assertTrue( version_at_least("1.2.3.4", 1, 2, 3, 2) )
def test_version_2(self): self.assertFalse( version_at_least("1.2.3.4", 1, 2, 3, 5) )
def test_version_big(self): self.assertTrue( version_at_least("0.3.3.0-alpha-dev", 0, 2, 7, 9) )
def create(reactor, config, hsdir, ports, version=3, group_readable=False, progress=None): """ returns a new FilesystemOnionService after adding it to the provided config and ensuring at least one of its descriptors is uploaded. :param config: a :class:`txtorcon.TorConfig` instance :param ports: a list of ports to make available; any of these can be 2-tuples of (remote, local) if you want to expose a particular port locally (otherwise, an available one is chosen) :param hsdir: the directory in which to store private keys :param version: 2 or 3, which kind of service to create :param group_readable: if True, the Tor option `HiddenServiceDirGroupReadable` is set to 1 for this service :param progress: a callable taking (percent, tag, description) that is called periodically to report progress. See also :meth:`txtorcon.Tor.create_onion_service` (which ultimately calls this). """ # if hsdir is relative, it's "least surprising" (IMO) to make # it into a absolute path here -- otherwise, it's relative to # whatever Tor's cwd is. hsdir = _canonical_hsdir(hsdir) processed_ports = yield _validate_ports(reactor, ports) fhs = FilesystemOnionService(config, hsdir, processed_ports, version=version, group_readable=group_readable) config.HiddenServices.append(fhs) # we .save() down below, after setting HS_DESC listener # XXX I *hate* this version checking crap. Can we discover a # different way if this Tor supports proper HS_DESC stuff? I # think part of the problem here is that "some" Tors have # HS_DESC event, but it's not .. sufficient? uploaded = [None] if not version_at_least(config.tor_protocol.version, 0, 2, 7, 2): if progress: progress( 102, "wait_desctiptor", "Adding an onion service to Tor requires at least version") progress( 103, "wait_desctiptor", "0.2.7.2 so that HS_DESC events work properly and we can") progress(104, "wait_desctiptor", "detect our desctiptor being uploaded.") progress( 105, "wait_desctiptor", "Your version is '{}'".format(config.tor_protocol.version), ) progress(106, "wait_desctiptor", "So, we'll just declare it done right now...") uploaded[0] = defer.succeed(None) else: # XXX actually, there's some versions of Tor when v3 # filesystem services could be added but they didn't send # HS_DESC updates -- did any of these actually get # released?! uploaded[0] = _await_descriptor_upload(config.tor_protocol, fhs, progress) yield config.save() yield uploaded[0] defer.returnValue(fhs)
def create(reactor, config, hsdir, ports, auth=None, version=3, group_readable=False, progress=None): """ returns a new FilesystemAuthenticatedOnionService after adding it to the provided config and ensureing at least one of its descriptors is uploaded. :param config: a :class:`txtorcon.TorConfig` instance :param ports: a list of ports to make available; any of these can be 2-tuples of (remote, local) if you want to expose a particular port locally (otherwise, an available one is chosen) :param auth: an instance of :class:`txtorcon.AuthBasic` or :class:`txtorcon.AuthStealth` :param version: 2 or 3, which kind of service to create :param group_readable: if True, the Tor option `HiddenServiceDirGroupReadable` is set to 1 for this service :param progress: a callable taking (percent, tag, description) that is called periodically to report progress. """ # if hsdir is relative, it's "least surprising" (IMO) to make # it into a relative path here -- otherwise, it's relative to # whatever Tor's cwd is. Issue similar warning to Tor? hsdir = _canonical_hsdir(hsdir) processed_ports = yield _validate_ports(reactor, ports) fhs = FilesystemAuthenticatedOnionService( config, hsdir, processed_ports, auth, version=version, group_readable=group_readable, ) config.HiddenServices.append(fhs) # most of this code same as non-authenticated version; can we share? # we .save() down below, after setting HS_DESC listener uploaded = [None] if not version_at_least(config.tor_protocol.version, 0, 2, 7, 2): if progress: progress( 102, "wait_desctiptor", "Adding an onion service to Tor requires at least version") progress( 103, "wait_desctiptor", "0.2.7.2 so that HS_DESC events work properly and we can") progress(104, "wait_desctiptor", "detect our desctiptor being uploaded.") progress( 105, "wait_desctiptor", "Your version is '{}'".format(config.tor_protocol.version), ) progress(106, "wait_desctiptor", "So, we'll just declare it done right now...") uploaded[0] = defer.succeed(None) else: # XXX actually, there's some versions of Tor when v3 # filesystem services could be added but they didn't send # HS_DESC updates -- did any of these actually get # released?! uploaded[0] = _await_descriptor_upload(config.tor_protocol, fhs, progress) yield config.save() yield uploaded[0] defer.returnValue(fhs)