This commit is contained in:
j 2016-02-23 14:37:06 +05:30
parent edcd933f2b
commit 3a419b12c2

View file

@ -31,7 +31,7 @@ import library
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
ENCODING='base64' DEBUG_NODES=False
class Node(Thread): class Node(Thread):
host = None host = None
@ -185,10 +185,12 @@ class Node(Thread):
logger.debug('version does not match local: %s remote %s', settings.NODE_PROTOCOL, version) logger.debug('version does not match local: %s remote %s', settings.NODE_PROTOCOL, version)
return False return False
c = r.read() c = r.read()
logger.debug('can connect to: %s', url) if DEBUG_NODES:
logger.debug('can connect to: %s', url)
return True return True
except: except:
logger.debug('can not connect to: %s', url) if DEBUG_NODES:
logger.debug('can not connect to: %s', url)
pass pass
return False return False
@ -202,13 +204,16 @@ class Node(Thread):
with db.session(): with db.session():
u = user.models.User.get_or_create(self.user_id) u = user.models.User.get_or_create(self.user_id)
if u.peered or u.queued: if u.peered or u.queued:
logger.debug('go online peered=%s queued=%s %s (%s)', u.peered, u.queued, u.id, u.nickname) if DEBUG_NODES:
logger.debug('go online peered=%s queued=%s %s (%s)', u.peered, u.queued, u.id, u.nickname)
try: try:
self.online = self.can_connect() self.online = self.can_connect()
if self.online: if self.online:
logger.debug('connected to %s', self.url) if DEBUG_NODES:
logger.debug('connected to %s', self.url)
if u.queued: if u.queued:
logger.debug('queued peering event pending=%s peered=%s', u.pending, u.peered) if DEBUG_NODES:
logger.debug('queued peering event pending=%s peered=%s', u.pending, u.peered)
if u.pending == 'sent': if u.pending == 'sent':
self.peering('requestPeering') self.peering('requestPeering')
elif u.pending == '' and u.peered: elif u.pending == '' and u.peered:
@ -217,7 +222,8 @@ class Node(Thread):
#fixme, what about cancel/reject peering here? #fixme, what about cancel/reject peering here?
self.peering('removePeering') self.peering('removePeering')
except: except:
logger.debug('failed to connect to %s', self.user_id) if DEBUG_NODES:
logger.debug('failed to connect to %s', self.user_id)
self.online = False self.online = False
def trigger_status(self): def trigger_status(self):
@ -238,7 +244,8 @@ class Node(Thread):
changes = self.request('pullChanges', from_revision) changes = self.request('pullChanges', from_revision)
except: except:
self.online = False self.online = False
logger.debug('%s went offline', u.name, exc_info=True) if DEBUG_NODES:
logger.debug('%s went offline', u.name, exc_info=True)
return False return False
if not changes: if not changes:
return False return False
@ -275,7 +282,8 @@ class Node(Thread):
self.resolve() self.resolve()
url = '%s/get/%s' % (self.url, item.id) url = '%s/get/%s' % (self.url, item.id)
t1 = datetime.utcnow() t1 = datetime.utcnow()
logger.debug('download %s', url) if DEBUG_NODES:
logger.debug('download %s', url)
self._opener.addheaders = list(zip(self.headers.keys(), self.headers.values())) self._opener.addheaders = list(zip(self.headers.keys(), self.headers.values()))
try: try:
r = self._opener.open(url, timeout=self.TIMEOUT*5) r = self._opener.open(url, timeout=self.TIMEOUT*5)
@ -340,7 +348,8 @@ class Node(Thread):
def download_preview(self, item_id): def download_preview(self, item_id):
from item.icons import icons from item.icons import icons
self.resolve() self.resolve()
logger.debug('download preview for %s from %s', item_id, self.url) if DEBUG_NODES:
logger.debug('download preview for %s from %s', item_id, self.url)
url = '%s/preview/%s' % (self.url, item_id) url = '%s/preview/%s' % (self.url, item_id)
self._opener.addheaders = list(zip(self.headers.keys(), self.headers.values())) self._opener.addheaders = list(zip(self.headers.keys(), self.headers.values()))
try: try: