return '%04d:%02d:%02d %02d:%02d:%02d (%.1f %s ago)' % \
(YY, MM, DD, hh, mm, ss, ago, unit)
def xlate_bytes(b):
- """Translate a number of bytes into something a human might want to read."""
+ """Translate a raw byte count into something a human might want to read."""
suff = 'B'
b = int(b)
for s in 'KMG':
('ip-bytes-in', xlate_bytes),
('ip-bytes-out', xlate_bytes)]
+def format_stat(format, dict):
+ if callable(format): return format(dict)
+ else: return format % dict
+
## How to lay out the stats dialog. Format is (LABEL, FORMAT): LABEL is
## the label to give the entry box; FORMAT is the format string to write into
## the entry.
-statslayout = \
- [('Start time', '%(start-time)s'),
- ('Private key', '%(current-key)s'),
- ('Diffie-Hellman group',
+cryptolayout = \
+ [('Diffie-Hellman group',
'%(kx-group)s '
'(%(kx-group-order-bits)s-bit order, '
'%(kx-group-elt-bits)s-bit elements)'),
('Cipher',
'%(cipher)s (%(cipher-keysz)s-bit key, %(cipher-blksz)s-bit block)'),
('Mac', '%(mac)s (%(mac-keysz)s-bit key, %(mac-tagsz)s-bit tag)'),
- ('Hash', '%(hash)s (%(hash-sz)s-bit output)'),
- ('Last key-exchange', '%(last-keyexch-time)s'),
+ ('Hash', '%(hash)s (%(hash-sz)s-bit output)')]
+
+statslayout = \
+ [('Start time', '%(start-time)s'),
+ ('Private key', '%(current-key)s')] + \
+ cryptolayout + \
+ [('Last key-exchange', '%(last-keyexch-time)s'),
('Last packet', '%(last-packet-time)s'),
('Packets in/out',
'%(packets-in)s (%(bytes-in)s) / %(packets-out)s (%(bytes-out)s)'),
stat[s] = trans(stat[s])
stat.update(me.peer.__dict__)
for label, format in statslayout:
- me.e[label].set_text(format % stat)
+ me.e[label].set_text(format_stat(format, stat))
GL.timeout_add(1000, lambda: me.cr.switch() and False)
me.cr.parent.switch()
me.cr = None