Rev859, Don't display port closed warning in Tor always mode, Reload trackers files every minute, Log users.json save time, Use Udp connect to avoid Gevent lockdown bug, Site needfile startup command, Log uPnP punch targets
This commit is contained in:
parent
2121612a72
commit
7d25812087
7 changed files with 35 additions and 9 deletions
|
@ -8,7 +8,7 @@ class Config(object):
|
|||
|
||||
def __init__(self, argv):
|
||||
self.version = "0.3.5"
|
||||
self.rev = 843
|
||||
self.rev = 859
|
||||
self.argv = argv
|
||||
self.action = None
|
||||
self.createParser()
|
||||
|
@ -53,6 +53,11 @@ class Config(object):
|
|||
# SiteCreate
|
||||
action = self.subparsers.add_parser("siteCreate", help='Create a new site')
|
||||
|
||||
# SiteNeedFile
|
||||
action = self.subparsers.add_parser("siteNeedFile", help='Get a file from site')
|
||||
action.add_argument('address', help='Site address')
|
||||
action.add_argument('inner_path', help='File inner path')
|
||||
|
||||
# SiteSign
|
||||
action = self.subparsers.add_parser("siteSign", help='Update and sign content.json: address [privatekey]')
|
||||
action.add_argument('address', help='Site to sign')
|
||||
|
|
|
@ -91,7 +91,8 @@ class FileServer(ConnectionServer):
|
|||
data = ""
|
||||
|
||||
if "closed" in message or "Error" in message:
|
||||
self.log.info("[BAD :(] Port closed: %s" % message)
|
||||
if config.tor != "always":
|
||||
self.log.info("[BAD :(] Port closed: %s" % message)
|
||||
if port == self.port:
|
||||
self.port_opened = False # Self port, update port_opened status
|
||||
match = re.match(".*targetIP.*?value=\"(.*?)\"", data, re.DOTALL) # Try find my external ip in message
|
||||
|
@ -123,7 +124,8 @@ class FileServer(ConnectionServer):
|
|||
message = "Error: %s" % Debug.formatException(err)
|
||||
|
||||
if "Error" in message:
|
||||
self.log.info("[BAD :(] Port closed: %s" % message)
|
||||
if config.tor != "always":
|
||||
self.log.info("[BAD :(] Port closed: %s" % message)
|
||||
if port == self.port:
|
||||
self.port_opened = False # Self port, update port_opened status
|
||||
match = re.match(".*?([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)", message) # Try find my external ip in message
|
||||
|
@ -178,13 +180,18 @@ class FileServer(ConnectionServer):
|
|||
time.sleep(2) # Prevent too quick request
|
||||
site = None
|
||||
|
||||
def trackersFileReloader(self):
|
||||
while 1:
|
||||
config.loadTrackersFile()
|
||||
time.sleep(60)
|
||||
|
||||
# Announce sites every 20 min
|
||||
def announceSites(self):
|
||||
import gc
|
||||
if config.trackers_file:
|
||||
gevent.spawn(self.trackersFileReloader)
|
||||
while 1:
|
||||
# Sites health care every 20 min
|
||||
if config.trackers_file:
|
||||
config.loadTrackersFile()
|
||||
for address, site in self.sites.items():
|
||||
if not site.settings["serving"]:
|
||||
continue
|
||||
|
@ -209,8 +216,6 @@ class FileServer(ConnectionServer):
|
|||
# Find new peers
|
||||
for tracker_i in range(len(config.trackers)):
|
||||
time.sleep(60 * 20 / len(config.trackers)) # Query all trackers one-by-one in 20 minutes evenly distributed
|
||||
if config.trackers_file:
|
||||
config.loadTrackersFile()
|
||||
for address, site in self.sites.items():
|
||||
if not site.settings["serving"]:
|
||||
continue
|
||||
|
|
BIN
src/Test/testdata/bootstrapper.db
vendored
Normal file
BIN
src/Test/testdata/bootstrapper.db
vendored
Normal file
Binary file not shown.
|
@ -27,6 +27,7 @@ class User(object):
|
|||
|
||||
# Save to data/users.json
|
||||
def save(self):
|
||||
s = time.time()
|
||||
users = json.load(open("%s/users.json" % config.data_dir))
|
||||
if self.master_address not in users:
|
||||
users[self.master_address] = {} # Create if not exist
|
||||
|
@ -36,7 +37,7 @@ class User(object):
|
|||
user_data["sites"] = self.sites
|
||||
user_data["certs"] = self.certs
|
||||
helper.atomicWrite("%s/users.json" % config.data_dir, json.dumps(users, indent=2, sort_keys=True))
|
||||
self.log.debug("Saved")
|
||||
self.log.debug("Saved in %.3fs" % (time.time()-s))
|
||||
|
||||
def getAddressAuthIndex(self, address):
|
||||
return int(address.encode("hex"), 16)
|
||||
|
@ -120,6 +121,7 @@ class User(object):
|
|||
self.save()
|
||||
return True
|
||||
|
||||
# Set active cert for a site
|
||||
def setCert(self, address, domain):
|
||||
site_data = self.getSiteData(address)
|
||||
if domain:
|
||||
|
|
|
@ -123,7 +123,8 @@ class UdpTrackerClient:
|
|||
'payload': payload,
|
||||
'completed': False,
|
||||
}
|
||||
self.sock.sendto(header + payload, (self.host, self.port))
|
||||
self.sock.connect((self.host, self.port))
|
||||
self.sock.send(header + payload)
|
||||
return trans
|
||||
|
||||
def _request_header(self, action):
|
||||
|
|
12
src/main.py
12
src/main.py
|
@ -237,6 +237,18 @@ class Actions(object):
|
|||
|
||||
def siteNeedFile(self, address, inner_path):
|
||||
from Site import Site
|
||||
def checker():
|
||||
while 1:
|
||||
s = time.time()
|
||||
time.sleep(1)
|
||||
print time.time()-s
|
||||
gevent.spawn(checker)
|
||||
|
||||
logging.info("Opening a simple connection server")
|
||||
global file_server
|
||||
from Connection import ConnectionServer
|
||||
file_server = ConnectionServer("127.0.0.1", 1234)
|
||||
|
||||
site = Site(address)
|
||||
site.announce()
|
||||
print site.needFile(inner_path, update=True)
|
||||
|
|
|
@ -171,6 +171,7 @@ def _send_soap_request(location, upnp_schema, control_url, soap_message):
|
|||
),
|
||||
'Content-Type': 'text/xml'
|
||||
}
|
||||
logging.debug("Sending UPnP request to {0}:{1}...".format(location.hostname, location.port))
|
||||
conn = httplib.HTTPConnection(location.hostname, location.port)
|
||||
conn.request('POST', control_url, soap_message, headers)
|
||||
|
||||
|
|
Loading…
Reference in a new issue