Add more information to the Transit docs

Explicitly state that the get_connection_hints method returns a Deferred
Fix documentation example code
This commit is contained in:
Shea Polansky 2020-01-03 17:04:41 -08:00 committed by Brian Warner
parent 5674c7dfa4
commit 9b305169ed

View File

@ -152,12 +152,15 @@ s = TransitSender("tcp:relayhost.example.org:12345")
Next, ask the Transit for its direct and relay hints. This should be Next, ask the Transit for its direct and relay hints. This should be
delivered to the other side via a Wormhole message (i.e. add them to a dict, delivered to the other side via a Wormhole message (i.e. add them to a dict,
serialize it with JSON, send the result as a message with `wormhole.send()`). serialize it with JSON, send the result as a message with `wormhole.send()`).
```python ```python
connection_hints = s.get_connection_hints() connection_hints = yield s.get_connection_hints()
``` ```
The `get_connection_hints` method returns a Deferred, so in the example we are
using `@inlineCallbacks` to `yield` the result.
Then, perform the Wormhole exchange, which ought to give you the direct and Then, perform the Wormhole exchange, which ought to give you the direct and
relay hints of the other side. Tell your Transit instance about their hints. relay hints of the other side. Tell your Transit instance about their hints.
@ -209,7 +212,7 @@ from wormhole.twisted.transit import TransitSender
@inlineCallbacks @inlineCallbacks
def do_transit(): def do_transit():
s = TransitSender(relay) s = TransitSender(relay)
my_connection_hints = s.get_connection_hints() my_connection_hints = yield s.get_connection_hints()
# (send hints via wormhole) # (send hints via wormhole)
s.add_connection_hints(their_connection_hints) s.add_connection_hints(their_connection_hints)
s.set_transit_key(key) s.set_transit_key(key)