def _create_dir_circuit(self, authority=True, purpose=None): if authority: router = self._authorities.get_random() else: router = self.get_random_router(has_dir_port=True) # tor ref: directory_get_from_dirserver DIR_PURPOSE_FETCH_CONSENSUS # tor ref: directory_send_command guard = TorGuard(router, purpose=purpose) return guard, guard.create_circuit(0)
def _create_dir_circuit(self, purpose=None): if self._document and self._document.is_reasonably_live: router = self.get_random_router(flags=[RouterFlags.Guard], with_renew=False) else: logger.debug( 'There is no reasonable live consensus... use fallback dirs') router = self._fallbacks.get_random() # tor ref: directory_get_from_dirserver DIR_PURPOSE_FETCH_CONSENSUS # tor ref: directory_send_command guard = TorGuard(router, purpose=purpose) return guard, guard.create_circuit(0)
def download_fp_sk(self, identity, keyid): # TODO: multiple key download authority = self.get_random() logger.info('Downloading fp-sk from %s', authority.nickname) # tor ref: directory_get_from_dirserver DIR_PURPOSE_FETCH_CONSENSUS # tor ref: directory_send_command with TorGuard(authority) as guard: with guard.create_circuit(0) as circ: with circ.create_stream() as stream: stream.connect_dir() http_client = HttpStreamClient(stream) url = f'{authority.fp_sk_url}/{identity}-{keyid}' _, response = http_client.get(authority.ip, url) return response.decode()
def download_consensus(self, prev_hash=None): authority = self.get_random() logger.info('Downloading new consensus from %s authority', authority.nickname) # tor ref: directory_get_from_dirserver DIR_PURPOSE_FETCH_CONSENSUS # tor ref: directory_send_command with TorGuard(authority) as guard: with guard.create_circuit(0) as circ: with circ.create_stream() as stream: stream.connect_dir() http_client = HttpStreamClient(stream) headers = { 'X-Or-Diff-From-Consensus': prev_hash } if prev_hash else None _, response = http_client.get(authority.ip, self.consensus_url, headers=headers) return response.decode()
def get_guard(self, by_flags=None): # TODO: add another stuff to filter guards guard_router = self._consensus.get_random_guard_node(by_flags) return TorGuard(guard_router, purpose='TorClient', consensus=self._consensus, auth_data=self._auth_data)
def get_guard(self, by_flags=None): # TODO: add another stuff to filter guards guard_router = self._consensus.get_random_guard_node(by_flags) guard = TorGuard(guard_router, self._consensus, self._auth_data) guard.connect() return guard