Rev943, Less verbose logging by default, Load ZeroBundle SSL lib, Log loaded SSL lib
This commit is contained in:
parent
1d6f56c676
commit
dba42f5f5e
7 changed files with 44 additions and 28 deletions
|
@ -8,7 +8,7 @@ class Config(object):
|
||||||
|
|
||||||
def __init__(self, argv):
|
def __init__(self, argv):
|
||||||
self.version = "0.3.6"
|
self.version = "0.3.6"
|
||||||
self.rev = 938
|
self.rev = 943
|
||||||
self.argv = argv
|
self.argv = argv
|
||||||
self.action = None
|
self.action = None
|
||||||
self.config_file = "zeronet.conf"
|
self.config_file = "zeronet.conf"
|
||||||
|
@ -116,6 +116,7 @@ class Config(object):
|
||||||
action.add_argument('privatekey', help='Private key')
|
action.add_argument('privatekey', help='Private key')
|
||||||
|
|
||||||
# Config parameters
|
# Config parameters
|
||||||
|
self.parser.add_argument('--verbose', help='More detailed logging', action='store_true')
|
||||||
self.parser.add_argument('--debug', help='Debug mode', action='store_true')
|
self.parser.add_argument('--debug', help='Debug mode', action='store_true')
|
||||||
self.parser.add_argument('--debug_socket', help='Debug socket connections', action='store_true')
|
self.parser.add_argument('--debug_socket', help='Debug socket connections', action='store_true')
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,8 @@ class FileRequest(object):
|
||||||
|
|
||||||
def response(self, msg, streaming=False):
|
def response(self, msg, streaming=False):
|
||||||
if self.responded:
|
if self.responded:
|
||||||
self.log.debug("Req id %s already responded" % self.req_id)
|
if config.verbose:
|
||||||
|
self.log.debug("Req id %s already responded" % self.req_id)
|
||||||
return
|
return
|
||||||
if not isinstance(msg, dict): # If msg not a dict create a {"body": msg}
|
if not isinstance(msg, dict): # If msg not a dict create a {"body": msg}
|
||||||
msg = {"body": msg}
|
msg = {"body": msg}
|
||||||
|
@ -113,10 +114,11 @@ class FileRequest(object):
|
||||||
else:
|
else:
|
||||||
peer = site.addPeer(self.connection.ip, self.connection.port, return_peer=True) # Add or get peer
|
peer = site.addPeer(self.connection.ip, self.connection.port, return_peer=True) # Add or get peer
|
||||||
if peer:
|
if peer:
|
||||||
self.log.debug(
|
if config.verbose:
|
||||||
"Same version, adding new peer for locked files: %s, tasks: %s" %
|
self.log.debug(
|
||||||
(peer.key, len(site.worker_manager.tasks))
|
"Same version, adding new peer for locked files: %s, tasks: %s" %
|
||||||
)
|
(peer.key, len(site.worker_manager.tasks))
|
||||||
|
)
|
||||||
for task in site.worker_manager.tasks: # New peer add to every ongoing task
|
for task in site.worker_manager.tasks: # New peer add to every ongoing task
|
||||||
if task["peers"]:
|
if task["peers"]:
|
||||||
# Download file from this peer too if its peer locked
|
# Download file from this peer too if its peer locked
|
||||||
|
@ -248,10 +250,11 @@ class FileRequest(object):
|
||||||
|
|
||||||
if added:
|
if added:
|
||||||
site.worker_manager.onPeers()
|
site.worker_manager.onPeers()
|
||||||
self.log.debug(
|
if config.verbose:
|
||||||
"Added %s peers to %s using pex, sending back %s" %
|
self.log.debug(
|
||||||
(added, site, len(packed_peers["ip4"]) + len(packed_peers["onion"]))
|
"Added %s peers to %s using pex, sending back %s" %
|
||||||
)
|
(added, site, len(packed_peers["ip4"]) + len(packed_peers["onion"]))
|
||||||
|
)
|
||||||
|
|
||||||
back = {}
|
back = {}
|
||||||
if packed_peers["ip4"]:
|
if packed_peers["ip4"]:
|
||||||
|
@ -316,10 +319,11 @@ class FileRequest(object):
|
||||||
if hash_id not in back:
|
if hash_id not in back:
|
||||||
back[hash_id] = []
|
back[hash_id] = []
|
||||||
back[hash_id].append(helper.packAddress(my_ip, self.server.port)) # Add myself
|
back[hash_id].append(helper.packAddress(my_ip, self.server.port)) # Add myself
|
||||||
self.log.debug(
|
if config.verbose:
|
||||||
"Found: %s/%s" %
|
self.log.debug(
|
||||||
(len(back), len(params["hash_ids"]))
|
"Found: %s/%s" %
|
||||||
)
|
(len(back), len(params["hash_ids"]))
|
||||||
|
)
|
||||||
self.response({"peers": back})
|
self.response({"peers": back})
|
||||||
|
|
||||||
def actionSetHashfield(self, params):
|
def actionSetHashfield(self, params):
|
||||||
|
|
|
@ -26,13 +26,14 @@ class FileServer(ConnectionServer):
|
||||||
|
|
||||||
# Handle request to fileserver
|
# Handle request to fileserver
|
||||||
def handleRequest(self, connection, message):
|
def handleRequest(self, connection, message):
|
||||||
if "params" in message:
|
if config.verbose:
|
||||||
self.log.debug(
|
if "params" in message:
|
||||||
"FileRequest: %s %s %s %s" %
|
self.log.debug(
|
||||||
(str(connection), message["cmd"], message["params"].get("site"), message["params"].get("inner_path"))
|
"FileRequest: %s %s %s %s" %
|
||||||
)
|
(str(connection), message["cmd"], message["params"].get("site"), message["params"].get("inner_path"))
|
||||||
else:
|
)
|
||||||
self.log.debug("FileRequest: %s %s" % (str(connection), message["cmd"]))
|
else:
|
||||||
|
self.log.debug("FileRequest: %s %s" % (str(connection), message["cmd"]))
|
||||||
req = FileRequest(self, connection)
|
req = FileRequest(self, connection)
|
||||||
req.route(message["cmd"], message.get("req_id"), message.get("params"))
|
req.route(message["cmd"], message.get("req_id"), message.get("params"))
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,8 @@ class Peer(object):
|
||||||
self.download_time = 0 # Time spent to download
|
self.download_time = 0 # Time spent to download
|
||||||
|
|
||||||
def log(self, text):
|
def log(self, text):
|
||||||
|
if not config.verbose:
|
||||||
|
return # Only log if we are in debug mode
|
||||||
if self.site:
|
if self.site:
|
||||||
self.site.log.debug("%s:%s %s" % (self.ip, self.port, text))
|
self.site.log.debug("%s:%s %s" % (self.ip, self.port, text))
|
||||||
else:
|
else:
|
||||||
|
@ -107,8 +109,7 @@ class Peer(object):
|
||||||
self.onConnectionError()
|
self.onConnectionError()
|
||||||
return None # Connection failed
|
return None # Connection failed
|
||||||
|
|
||||||
if config.debug:
|
self.log("Send request: %s %s" % (params.get("site", ""), cmd))
|
||||||
self.log("Send request: %s %s" % (params.get("site", ""), cmd))
|
|
||||||
|
|
||||||
for retry in range(1, 4): # Retry 3 times
|
for retry in range(1, 4): # Retry 3 times
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -317,10 +317,11 @@ class SiteStorage:
|
||||||
bad_files.append(file_inner_path)
|
bad_files.append(file_inner_path)
|
||||||
self.log.debug("[OPTIONAL CHANGED] %s" % file_inner_path)
|
self.log.debug("[OPTIONAL CHANGED] %s" % file_inner_path)
|
||||||
|
|
||||||
self.log.debug(
|
if config.verbose:
|
||||||
"%s verified: %s, quick: %s, bad: %s, optionals: +%s -%s" %
|
self.log.debug(
|
||||||
(content_inner_path, len(content["files"]), quick_check, bad_files, optional_added, optional_removed)
|
"%s verified: %s, quick: %s, bad: %s, optionals: +%s -%s" %
|
||||||
)
|
(content_inner_path, len(content["files"]), quick_check, bad_files, optional_added, optional_removed)
|
||||||
|
)
|
||||||
|
|
||||||
return bad_files
|
return bad_files
|
||||||
|
|
||||||
|
@ -384,4 +385,4 @@ class SiteStorage:
|
||||||
return False # Some files not deleted
|
return False # Some files not deleted
|
||||||
else:
|
else:
|
||||||
self.log.debug("Site data directory deleted: %s..." % self.directory)
|
self.log.debug("Site data directory deleted: %s..." % self.directory)
|
||||||
return True # All clean
|
return True # All clean
|
||||||
|
|
|
@ -199,12 +199,15 @@ def openLibrary():
|
||||||
dll_path = "src/lib/opensslVerify/libeay32.dll"
|
dll_path = "src/lib/opensslVerify/libeay32.dll"
|
||||||
elif sys.platform == "cygwin":
|
elif sys.platform == "cygwin":
|
||||||
dll_path = "/bin/cygcrypto-1.0.0.dll"
|
dll_path = "/bin/cygcrypto-1.0.0.dll"
|
||||||
|
elif os.path.isfile("../lib/libcrypto.so"): # ZeroBundle
|
||||||
|
dll_path = "../lib/libcrypto.so"
|
||||||
else:
|
else:
|
||||||
dll_path = "/usr/local/ssl/lib/libcrypto.so"
|
dll_path = "/usr/local/ssl/lib/libcrypto.so"
|
||||||
ssl = _OpenSSL(dll_path)
|
ssl = _OpenSSL(dll_path)
|
||||||
assert ssl
|
assert ssl
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
ssl = _OpenSSL(ctypes.util.find_library('ssl') or ctypes.util.find_library('crypto') or ctypes.util.find_library('libcrypto') or 'libeay32')
|
ssl = _OpenSSL(ctypes.util.find_library('ssl') or ctypes.util.find_library('crypto') or ctypes.util.find_library('libcrypto') or 'libeay32')
|
||||||
|
logging.debug("opensslVerify loaded: %s", ssl._lib)
|
||||||
|
|
||||||
openLibrary()
|
openLibrary()
|
||||||
openssl_version = "%.9X" % ssl._lib.SSLeay()
|
openssl_version = "%.9X" % ssl._lib.SSLeay()
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import ctypes
|
import ctypes
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
OpenSSL = None
|
OpenSSL = None
|
||||||
|
|
||||||
|
@ -435,6 +437,8 @@ def openLibrary():
|
||||||
dll_path = "src/lib/opensslVerify/libeay32.dll"
|
dll_path = "src/lib/opensslVerify/libeay32.dll"
|
||||||
elif sys.platform == "cygwin":
|
elif sys.platform == "cygwin":
|
||||||
dll_path = "/bin/cygcrypto-1.0.0.dll"
|
dll_path = "/bin/cygcrypto-1.0.0.dll"
|
||||||
|
elif os.path.isfile("../lib/libcrypto.so"): # ZeroBundle
|
||||||
|
dll_path = "../lib/libcrypto.so"
|
||||||
else:
|
else:
|
||||||
dll_path = "/usr/local/ssl/lib/libcrypto.so"
|
dll_path = "/usr/local/ssl/lib/libcrypto.so"
|
||||||
ssl = _OpenSSL(dll_path)
|
ssl = _OpenSSL(dll_path)
|
||||||
|
@ -442,6 +446,7 @@ def openLibrary():
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
ssl = _OpenSSL(ctypes.util.find_library('ssl') or ctypes.util.find_library('crypto') or ctypes.util.find_library('libcrypto') or 'libeay32')
|
ssl = _OpenSSL(ctypes.util.find_library('ssl') or ctypes.util.find_library('crypto') or ctypes.util.find_library('libcrypto') or 'libeay32')
|
||||||
OpenSSL = ssl
|
OpenSSL = ssl
|
||||||
|
logging.debug("pyelliptic loaded: %s", ssl._lib)
|
||||||
|
|
||||||
|
|
||||||
def closeLibrary():
|
def closeLibrary():
|
||||||
|
|
Loading…
Reference in a new issue