Skip to content

Commit

Permalink
Fixed: warning if bandwidth data cannot be persisted displays fpid ye…
Browse files Browse the repository at this point in the history
…t not fp.
  • Loading branch information
ralphwetzel committed Dec 1, 2019
1 parent 6fea48c commit 342115f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion theonionbox/stamp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__title__ = 'The Onion Box'
__description__ = 'Dashboard to monitor Tor node operations.'
__version__ = '19.2b6'
__stamp__ = '20191129|205240'
__stamp__ = '20191201|213412'
2 changes: 0 additions & 2 deletions theonionbox/tob/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,6 @@ def _run(self, icon=None):
try:
self.server.run(self.box)
except KeyboardInterrupt:
# SIGINT consumed before ...
# ... so this never emits!!
self.log.notice("Received SIGINT signal.")
except Exception as exc:
self.log.error(exc)
14 changes: 10 additions & 4 deletions theonionbox/tob/persistor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def __init__(self, storage: Storage, fingerprint: str):

self.path = None
self.fp = None
self.fpid = None

log = logging.getLogger('theonionbox')

if len(fingerprint) == 0:
Expand Down Expand Up @@ -105,7 +107,8 @@ def __init__(self, storage: Storage, fingerprint: str):

if fpid is not None:
self.path = path
self.fp = fpid
self.fp = fingerprint
self.fpid = fpid

conn.close()

Expand All @@ -129,17 +132,20 @@ def open_connection(self, path: Optional[str] = None) -> Optional[Connection]:
def persist(self, interval: str, timestamp: float,
read: Optional[int] = 0, write: Optional[int] = 0, connection: Optional[Connection] = None) -> bool:

if self.fpid is None:
return False

if connection is None:
connection = self.open_connection()
if connection is None:
return False

try:
connection.execute("INSERT INTO bandwidth(fp, interval, timestamp, read, write) VALUES(?, ?, ?, ?, ?)",
(self.fp, interval, timestamp, read, write))
(self.fpid, interval, timestamp, read, write))
except Exception as e:
log = logging.getLogger('theonionbox')
log.warning(f'Failed to open persist bandwidth data for fingerprint {self.fp}: {e}')
log.warning(f'Failed to open persist bandwidth data for fingerprint {self.fp[:6]}: {e}')
return False

return True
Expand Down Expand Up @@ -168,7 +174,7 @@ def get(self, interval: str, js_timestamp: Optional[int] = int(time()*1000), lim

try:
cur.execute(sql, {'jsts': js_timestamp,
'fp': self.fp,
'fp': self.fpid,
'interval': interval,
'limit': limit,
'offset': offset}
Expand Down

0 comments on commit 342115f

Please sign in to comment.