mirror of
https://github.com/HelloZeroNet/ZeroNet.git
synced 2023-12-14 04:33:03 +01:00
Optimize getOnion function with less lock
This commit is contained in:
parent
00972f5d73
commit
468666cdc8
1 changed files with 13 additions and 10 deletions
|
@ -312,19 +312,22 @@ class TorManager(object):
|
|||
return CryptRsa.privatekeyToPublickey(self.privatekeys[address])
|
||||
|
||||
def getOnion(self, site_address):
|
||||
with self.lock:
|
||||
if not self.enabled:
|
||||
return None
|
||||
if config.tor == "always": # Different onion for every site
|
||||
onion = self.site_onions.get(site_address)
|
||||
else: # Same onion for every site
|
||||
onion = self.site_onions.get("global")
|
||||
site_address = "global"
|
||||
if not onion:
|
||||
if not self.enabled:
|
||||
return None
|
||||
|
||||
if config.tor == "always": # Different onion for every site
|
||||
onion = self.site_onions.get(site_address)
|
||||
else: # Same onion for every site
|
||||
onion = self.site_onions.get("global")
|
||||
site_address = "global"
|
||||
|
||||
if not onion:
|
||||
with self.lock:
|
||||
self.site_onions[site_address] = self.addOnion()
|
||||
onion = self.site_onions[site_address]
|
||||
self.log.debug("Created new hidden service for %s: %s" % (site_address, onion))
|
||||
return onion
|
||||
|
||||
return onion
|
||||
|
||||
# Creates and returns a
|
||||
# socket that has connected to the Tor Network
|
||||
|
|
Loading…
Reference in a new issue