diff --git a/src/wormhole/_allocator.py b/src/wormhole/_allocator.py index 040b913..b671692 100644 --- a/src/wormhole/_allocator.py +++ b/src/wormhole/_allocator.py @@ -10,8 +10,7 @@ from . import _interfaces class Allocator(object): _timing = attrib(validator=provides(_interfaces.ITiming)) m = MethodicalMachine() - @m.setTrace() - def set_trace(): pass # pragma: no cover + set_trace = m.setTrace def wire(self, rendezvous_connector, code): self._RC = _interfaces.IRendezvousConnector(rendezvous_connector) diff --git a/src/wormhole/_boss.py b/src/wormhole/_boss.py index a48ad11..c8a7ab0 100644 --- a/src/wormhole/_boss.py +++ b/src/wormhole/_boss.py @@ -38,8 +38,7 @@ class Boss(object): _tor_manager = attrib() # TODO: ITorManager or None _timing = attrib(validator=provides(_interfaces.ITiming)) m = MethodicalMachine() - @m.setTrace() - def set_trace(): pass # pragma: no cover + set_trace = m.setTrace def __attrs_post_init__(self): self._build_workers() @@ -92,9 +91,22 @@ class Boss(object): "RC": self._RC, "L": self._L, "C": self._C, "T": self._T} for machine in which.split(): - def tracer(old_state, input, new_state, machine=machine): - print("%s.%s[%s].%s -> [%s]" % (client_name, machine, - old_state, input, new_state)) + def tracer(old_state, input, new_state, output, machine=machine): + if output is None: + if new_state: + print("%s.%s[%s].%s -> [%s]" % + (client_name, machine, old_state, input, + new_state)) + else: + # the RendezvousConnector emits message events as if + # they were state transitions, except that old_state + # and new_state are empty strings. "input" is one of + # R.connected, R.rx(type phase+side), R.tx(type + # phase), R.lost . + print("%s.%s.%s" % (client_name, machine, input)) + else: + if new_state: + print(" %s.%s.%s()" % (client_name, machine, output)) names[machine].set_trace(tracer) def serialize(self): diff --git a/src/wormhole/_code.py b/src/wormhole/_code.py index e026460..7ff9603 100644 --- a/src/wormhole/_code.py +++ b/src/wormhole/_code.py @@ -13,8 +13,7 @@ def first(outputs): class Code(object): _timing = attrib(validator=provides(_interfaces.ITiming)) m = MethodicalMachine() - @m.setTrace() - def set_trace(): pass # pragma: no cover + set_trace = m.setTrace def wire(self, boss, allocator, nameplate, key, input): self._B = _interfaces.IBoss(boss) diff --git a/src/wormhole/_input.py b/src/wormhole/_input.py index 8a8da3a..dab364f 100644 --- a/src/wormhole/_input.py +++ b/src/wormhole/_input.py @@ -13,8 +13,7 @@ def first(outputs): class Input(object): _timing = attrib(validator=provides(_interfaces.ITiming)) m = MethodicalMachine() - @m.setTrace() - def set_trace(): pass # pragma: no cover + set_trace = m.setTrace def __attrs_post_init__(self): self._all_nameplates = set() diff --git a/src/wormhole/_key.py b/src/wormhole/_key.py index 330833f..454808b 100644 --- a/src/wormhole/_key.py +++ b/src/wormhole/_key.py @@ -64,8 +64,7 @@ class Key(object): _side = attrib(validator=instance_of(type(u""))) _timing = attrib(validator=provides(_interfaces.ITiming)) m = MethodicalMachine() - @m.setTrace() - def _set_trace(): pass # pragma: no cover + set_trace = m.setTrace def __attrs_post_init__(self): self._SK = _SortedKey(self._appid, self._versions, self._side, @@ -114,8 +113,7 @@ class _SortedKey(object): _side = attrib(validator=instance_of(type(u""))) _timing = attrib(validator=provides(_interfaces.ITiming)) m = MethodicalMachine() - @m.setTrace() - def set_trace(): pass # pragma: no cover + set_trace = m.setTrace def wire(self, boss, mailbox, receive): self._B = _interfaces.IBoss(boss) diff --git a/src/wormhole/_lister.py b/src/wormhole/_lister.py index a58ecf6..dfca877 100644 --- a/src/wormhole/_lister.py +++ b/src/wormhole/_lister.py @@ -10,8 +10,7 @@ from . import _interfaces class Lister(object): _timing = attrib(validator=provides(_interfaces.ITiming)) m = MethodicalMachine() - @m.setTrace() - def set_trace(): pass # pragma: no cover + set_trace = m.setTrace def wire(self, rendezvous_connector, input): self._RC = _interfaces.IRendezvousConnector(rendezvous_connector) diff --git a/src/wormhole/_mailbox.py b/src/wormhole/_mailbox.py index 061a39c..3c5413d 100644 --- a/src/wormhole/_mailbox.py +++ b/src/wormhole/_mailbox.py @@ -10,8 +10,7 @@ from . import _interfaces class Mailbox(object): _side = attrib(validator=instance_of(type(u""))) m = MethodicalMachine() - @m.setTrace() - def set_trace(): pass # pragma: no cover + set_trace = m.setTrace def __attrs_post_init__(self): self._mailbox = None diff --git a/src/wormhole/_nameplate.py b/src/wormhole/_nameplate.py index 599573b..00f2f7e 100644 --- a/src/wormhole/_nameplate.py +++ b/src/wormhole/_nameplate.py @@ -7,8 +7,7 @@ from ._wordlist import PGPWordList @implementer(_interfaces.INameplate) class Nameplate(object): m = MethodicalMachine() - @m.setTrace() - def set_trace(): pass # pragma: no cover + set_trace = m.setTrace def __init__(self): self._nameplate = None diff --git a/src/wormhole/_order.py b/src/wormhole/_order.py index 81cb088..26671a1 100644 --- a/src/wormhole/_order.py +++ b/src/wormhole/_order.py @@ -11,8 +11,7 @@ class Order(object): _side = attrib(validator=instance_of(type(u""))) _timing = attrib(validator=provides(_interfaces.ITiming)) m = MethodicalMachine() - @m.setTrace() - def set_trace(): pass # pragma: no cover + set_trace = m.setTrace def __attrs_post_init__(self): self._key = None diff --git a/src/wormhole/_receive.py b/src/wormhole/_receive.py index 389c0f4..7a78518 100644 --- a/src/wormhole/_receive.py +++ b/src/wormhole/_receive.py @@ -12,8 +12,7 @@ class Receive(object): _side = attrib(validator=instance_of(type(u""))) _timing = attrib(validator=provides(_interfaces.ITiming)) m = MethodicalMachine() - @m.setTrace() - def set_trace(): pass # pragma: no cover + set_trace = m.setTrace def __attrs_post_init__(self): self._key = None diff --git a/src/wormhole/_rendezvous.py b/src/wormhole/_rendezvous.py index 9af0edb..c4e5c45 100644 --- a/src/wormhole/_rendezvous.py +++ b/src/wormhole/_rendezvous.py @@ -86,7 +86,7 @@ class RendezvousConnector(object): self._trace = f def _debug(self, what): if self._trace: - self._trace(old_state="", input=what, new_state="") + self._trace(old_state="", input=what, new_state="", output=None) def _make_endpoint(self, hostname, port): if self._tor_manager: diff --git a/src/wormhole/_send.py b/src/wormhole/_send.py index ccd4699..3c8c722 100644 --- a/src/wormhole/_send.py +++ b/src/wormhole/_send.py @@ -12,8 +12,7 @@ class Send(object): _side = attrib(validator=instance_of(type(u""))) _timing = attrib(validator=provides(_interfaces.ITiming)) m = MethodicalMachine() - @m.setTrace() - def set_trace(): pass # pragma: no cover + set_trace = m.setTrace def __attrs_post_init__(self): self._queue = [] diff --git a/src/wormhole/_terminator.py b/src/wormhole/_terminator.py index 1468c07..3a14042 100644 --- a/src/wormhole/_terminator.py +++ b/src/wormhole/_terminator.py @@ -6,8 +6,7 @@ from . import _interfaces @implementer(_interfaces.ITerminator) class Terminator(object): m = MethodicalMachine() - @m.setTrace() - def set_trace(): pass # pragma: no cover + set_trace = m.setTrace def __init__(self): self._mood = None