From 82997cb31173f9a82555ff7d5eb7ef9746256329 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Tue, 31 Mar 2015 09:49:07 +1300 Subject: [PATCH] Fix timestamps in detail view - Fix a crash when connection timestamps don't exist yet - Fix display of response timestamps - Get rid of those colossal ternaries. I want a device that pokes people in the eye every time they try to use a ternary operator. --- libmproxy/console/flowdetailview.py | 74 +++++++++++++++++++++++++---- test/tools/testpatt | 12 ++--- 2 files changed, 70 insertions(+), 16 deletions(-) diff --git a/libmproxy/console/flowdetailview.py b/libmproxy/console/flowdetailview.py index 99f2a2629..48845a62e 100644 --- a/libmproxy/console/flowdetailview.py +++ b/libmproxy/console/flowdetailview.py @@ -1,8 +1,17 @@ from __future__ import absolute_import import urwid -from . import common, signals, searchable +from . import common, searchable from .. import utils + +def maybe_timestamp(base, attr): + if base and getattr(base, attr): + return utils.format_timestamp_with_milli(getattr(base, attr)) + else: + return "active" + pass + + def flowdetails(state, flow): text = [] @@ -81,16 +90,61 @@ def flowdetails(state, flow): parts = [] - parts.append(["Client conn. established", utils.format_timestamp_with_milli(cc.timestamp_start) if (cc and cc.timestamp_start) else "active"]) - parts.append(["Server conn. initiated", utils.format_timestamp_with_milli(sc.timestamp_start) if sc else "active" ]) - parts.append(["Server conn. TCP handshake", utils.format_timestamp_with_milli(sc.timestamp_tcp_setup) if (sc and sc.timestamp_tcp_setup) else "active"]) + parts.append( + [ + "Client conn. established", + maybe_timestamp(cc, "timestamp_start") + ] + ) + parts.append( + [ + "Server conn. initiated", + maybe_timestamp(sc, "timestamp_start") + ] + ) + parts.append( + [ + "Server conn. TCP handshake", + maybe_timestamp(sc, "timestamp_tcp_setup") + ] + ) if sc.ssl_established: - parts.append(["Server conn. SSL handshake", utils.format_timestamp_with_milli(sc.timestamp_ssl_setup) if sc.timestamp_ssl_setup else "active"]) - parts.append(["Client conn. SSL handshake", utils.format_timestamp_with_milli(cc.timestamp_ssl_setup) if (cc and cc.timestamp_ssl_setup) else "active"]) - parts.append(["First request byte", utils.format_timestamp_with_milli(req.timestamp_start)]) - parts.append(["Request complete", utils.format_timestamp_with_milli(req.timestamp_end) if req.timestamp_end else "active"]) - parts.append(["First response byte", utils.format_timestamp_with_milli(resp.timestamp_start) if resp else "active"]) - parts.append(["Response complete", utils.format_timestamp_with_milli(resp.timestamp_end) if (resp and resp.timestamp_end) else "active"]) + parts.append( + [ + "Server conn. SSL handshake", + maybe_timestamp(sc, "timestamp_ssl_setup") + ] + ) + parts.append( + [ + "Client conn. SSL handshake", + maybe_timestamp(cc, "timestamp_ssl_setup") + ] + ) + parts.append( + [ + "First request byte", + maybe_timestamp(req, "timestamp_start") + ] + ) + parts.append( + [ + "Request complete", + maybe_timestamp(req, "timestamp_end") + ] + ) + parts.append( + [ + "First response byte", + maybe_timestamp(resp, "timestamp_start") + ] + ) + parts.append( + [ + "Response complete", + maybe_timestamp(resp, "timestamp_end") + ] + ) # sort operations by timestamp parts = sorted(parts, key=lambda p: p[1]) diff --git a/test/tools/testpatt b/test/tools/testpatt index 5ee1ea025..b41011c0b 100755 --- a/test/tools/testpatt +++ b/test/tools/testpatt @@ -1,9 +1,9 @@ #!/bin/bash # Generate a test pattern with pathoc -PATHOD=http://localhost:9999 -pathoc localhost:8080 "get:'$PATHOD/p/200:p0,1:b@2048b':b@2048b" -pathoc localhost:8080 "get:'$PATHOD/p/300:p0,1:b@2048b':b@2048b" -pathoc localhost:8080 "get:'$PATHOD/p/400:p0,1:b@2048b':b@2048b" -pathoc localhost:8080 "get:'$PATHOD/p/500:p0,1:b@2048b':b@2048b" -pathoc localhost:8080 "get:'$PATHOD/p/600:p0,1:b@2048b':b@2048b" +PATHOD=localhost:9999 +pathoc -s -c $PATHOD localhost:8080 "get:'/p/200:p0,1:b@2048b':b@2048b" +pathoc -s -c $PATHOD localhost:8080 "get:'/p/300:p0,1:b@2048b':b@2048b" +pathoc -s -c $PATHOD localhost:8080 "get:'/p/400:p0,1:b@2048b':b@2048b" +pathoc -s -c $PATHOD localhost:8080 "get:'/p/500:p0,1:b@2048b':b@2048b" +pathoc -s -c $PATHOD localhost:8080 "get:'/p/600:p0,1:b@2048b':b@2048b"