mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-26 11:13:00 -03:00
Fix a race condition where the URL was sometimes getting copied to the clipboard before it was actually generated, causing a crash
This commit is contained in:
parent
1456361566
commit
1a4aaa70fa
4 changed files with 29 additions and 14 deletions
|
@ -122,6 +122,7 @@ def main(cwd=None):
|
||||||
try:
|
try:
|
||||||
app = OnionShare(common, onion, local_only, stay_open, shutdown_timeout)
|
app = OnionShare(common, onion, local_only, stay_open, shutdown_timeout)
|
||||||
app.set_stealth(stealth)
|
app.set_stealth(stealth)
|
||||||
|
app.choose_port()
|
||||||
app.start_onion_service()
|
app.start_onion_service()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("")
|
print("")
|
||||||
|
|
|
@ -38,6 +38,7 @@ class OnionShare(object):
|
||||||
|
|
||||||
self.hidserv_dir = None
|
self.hidserv_dir = None
|
||||||
self.onion_host = None
|
self.onion_host = None
|
||||||
|
self.port = None
|
||||||
self.stealth = None
|
self.stealth = None
|
||||||
|
|
||||||
# files and dirs to delete on shutdown
|
# files and dirs to delete on shutdown
|
||||||
|
@ -59,6 +60,15 @@ class OnionShare(object):
|
||||||
|
|
||||||
self.stealth = stealth
|
self.stealth = stealth
|
||||||
self.onion.stealth = stealth
|
self.onion.stealth = stealth
|
||||||
|
|
||||||
|
def choose_port(self):
|
||||||
|
"""
|
||||||
|
Choose a random port.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
self.port = self.common.get_available_port(17600, 17650)
|
||||||
|
except:
|
||||||
|
raise OSError(strings._('no_available_port'))
|
||||||
|
|
||||||
def start_onion_service(self):
|
def start_onion_service(self):
|
||||||
"""
|
"""
|
||||||
|
@ -66,11 +76,8 @@ class OnionShare(object):
|
||||||
"""
|
"""
|
||||||
self.common.log('OnionShare', 'start_onion_service')
|
self.common.log('OnionShare', 'start_onion_service')
|
||||||
|
|
||||||
# Choose a random port
|
if not self.port:
|
||||||
try:
|
self.choose_port()
|
||||||
self.port = self.common.get_available_port(17600, 17650)
|
|
||||||
except:
|
|
||||||
raise OSError(strings._('no_available_port'))
|
|
||||||
|
|
||||||
if self.local_only:
|
if self.local_only:
|
||||||
self.onion_host = '127.0.0.1:{0:d}'.format(self.port)
|
self.onion_host = '127.0.0.1:{0:d}'.format(self.port)
|
||||||
|
|
|
@ -419,11 +419,12 @@ class Web(object):
|
||||||
|
|
||||||
def generate_slug(self, persistent_slug=None):
|
def generate_slug(self, persistent_slug=None):
|
||||||
self.common.log('Web', 'generate_slug', 'persistent_slug={}'.format(persistent_slug))
|
self.common.log('Web', 'generate_slug', 'persistent_slug={}'.format(persistent_slug))
|
||||||
if persistent_slug != None:
|
if persistent_slug != None and persistent_slug != '':
|
||||||
self.slug = persistent_slug
|
self.slug = persistent_slug
|
||||||
|
self.common.log('Web', 'generate_slug', 'persistent_slug sent, so slug is: "{}"'.format(self.slug))
|
||||||
else:
|
else:
|
||||||
self.slug = self.common.build_slug()
|
self.slug = self.common.build_slug()
|
||||||
self.common.log('Web', 'generate_slug', 'slug is set to {}'.format(self.slug))
|
self.common.log('Web', 'generate_slug', 'built random slug: "{}"'.format(self.slug))
|
||||||
|
|
||||||
def debug_mode(self):
|
def debug_mode(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -138,6 +138,19 @@ class Mode(QtWidgets.QWidget):
|
||||||
|
|
||||||
# Start the onion service in a new thread
|
# Start the onion service in a new thread
|
||||||
def start_onion_service(self):
|
def start_onion_service(self):
|
||||||
|
# Choose a port for the web app
|
||||||
|
self.app.choose_port()
|
||||||
|
|
||||||
|
# Start http service in new thread
|
||||||
|
t = threading.Thread(target=self.web.start, args=(self.app.port, self.app.stay_open, self.common.settings.get('slug')))
|
||||||
|
t.daemon = True
|
||||||
|
t.start()
|
||||||
|
|
||||||
|
# Wait for the web app slug to generate before continuing
|
||||||
|
while self.web.slug == None:
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
# Now start the onion service
|
||||||
try:
|
try:
|
||||||
self.app.start_onion_service()
|
self.app.start_onion_service()
|
||||||
self.starting_server_step2.emit()
|
self.starting_server_step2.emit()
|
||||||
|
@ -148,13 +161,6 @@ class Mode(QtWidgets.QWidget):
|
||||||
|
|
||||||
self.app.stay_open = not self.common.settings.get('close_after_first_download')
|
self.app.stay_open = not self.common.settings.get('close_after_first_download')
|
||||||
|
|
||||||
# Start http service in new thread
|
|
||||||
t = threading.Thread(target=self.web.start, args=(self.app.port, self.app.stay_open, self.common.settings.get('slug')))
|
|
||||||
t.daemon = True
|
|
||||||
t.start()
|
|
||||||
# Wait for modules in thread to load, preventing a thread-related cx_Freeze crash
|
|
||||||
time.sleep(0.2)
|
|
||||||
|
|
||||||
self.common.log('Mode', 'start_server', 'Starting an onion thread')
|
self.common.log('Mode', 'start_server', 'Starting an onion thread')
|
||||||
self.t = OnionThread(self.common, function=start_onion_service, kwargs={'self': self})
|
self.t = OnionThread(self.common, function=start_onion_service, kwargs={'self': self})
|
||||||
self.t.daemon = True
|
self.t.daemon = True
|
||||||
|
|
Loading…
Add table
Reference in a new issue