better sketch of transit-client API

This commit is contained in:
Brian Warner 2015-02-15 14:42:59 -08:00
parent 38b9c07566
commit 9dd4c6039f
3 changed files with 41 additions and 24 deletions

View File

@ -12,23 +12,28 @@ APPID = "lothar.com/wormhole/file-xfer"
transit_receiver = TransitReceiver()
direct_hints = transit_receiver.get_direct_hints()
data = json.dumps({"direct_connection_hints": direct_hints,
}).encode("utf-8")
r = Receiver(APPID, data)
mydata = json.dumps({
"transit": {
"direct_connection_hints": direct_hints,
},
}).encode("utf-8")
r = Receiver(APPID, mydata)
r.set_code(r.input_code("Enter receive-text wormhole code: "))
them_bytes = r.get_data()
them_d = json.loads(them_bytes.decode("utf-8"))
print("them: %r" % (them_d,))
data = json.loads(r.get_data().decode("utf-8"))
print("their data: %r" % (data,))
xfer_key = unhexlify(them_d["xfer_key"].encode("ascii"))
filename = os.path.basename(them_d["filename"]) # unicode
filesize = them_d["filesize"]
file_data = data["file"]
xfer_key = unhexlify(file_data["key"].encode("ascii"))
filename = os.path.basename(file_data["filename"]) # unicode
filesize = file_data["filesize"]
# now receive the rest of the owl
transit_receiver.add_sender_direct_hints(them_d["direct_connection_hints"])
transit_receiver.add_sender_relay_hints(them_d["relay_connection_hints"])
transit_receiver.establish_connection(IDS)
tdata = data["transit"]
transit_receiver.set_transit_key(tdata["key"])
transit_receiver.add_sender_direct_hints(tdata["direct_connection_hints"])
transit_receiver.add_sender_relay_hints(tdata["relay_connection_hints"])
transit_receiver.establish_connection()
encrypted = transit_receiver.receive()
decrypted = SecretBox(xfer_key).decrypt(encrypted)

View File

@ -2,7 +2,6 @@ from __future__ import print_function
import os, sys, json
from binascii import hexlify
from nacl.secret import SecretBox
from nacl import utils
from wormhole.blocking.transcribe import Initiator
from wormhole.blocking.transit import TransitSender
@ -11,17 +10,24 @@ APPID = "lothar.com/wormhole/file-xfer"
# we're sending
filename = sys.argv[1]
assert os.path.isfile(filename)
xfer_key = utils.random(SecretBox.KEY_SIZE)
xfer_key = os.urandom(SecretBox.KEY_SIZE)
transit_sender = TransitSender()
transit_key = transit_sender.get_transit_key()
direct_hints = transit_sender.get_direct_hints()
relay_hints = transit_sender.get_relay_hints()
data = json.dumps({"xfer_key": hexlify(xfer_key),
"filename": os.path.basename(filename),
"filesize": os.stat(filename).st_size,
"direct_connection_hints": direct_hints,
"relay_connection_hints": relay_hints,
}).encode("utf-8")
data = json.dumps({
"file": {
"key": hexlify(xfer_key),
"filename": os.path.basename(filename),
"filesize": os.stat(filename).st_size,
},
"transit": {
"key": hexlify(transit_key),
"direct_connection_hints": direct_hints,
"relay_connection_hints": relay_hints,
},
}).encode("utf-8")
i = Initiator(APPID, data)
code = i.get_code()
@ -39,7 +45,7 @@ nonce = utils.random(SecretBox.NONCE_SIZE)
encrypted = box.encrypt(plaintext, nonce)
transit_sender.add_receiver_hints(them_d["direct_connection_hints"])
transit_sender.establish_connection(IDS)
transit_sender.establish_connection()
transit_sender.write(encrypted)
transit_sender.close()

View File

@ -1,7 +1,11 @@
import os
from ..util import ipaddrs
class TransitSender:
def __init__(self, IDS):
pass
def __init__(self):
self.key = os.urandom(32)
def get_transit_key(self):
return self.key
def get_direct_hints(self):
pass
def get_relay_hints(self):
@ -16,10 +20,12 @@ class TransitSender:
pass
class TransitReceiver:
def __init__(self, IDS):
def __init__(self):
pass
def get_direct_hints(self):
pass
def set_transit_key(self, key):
self.key = key
def add_sender_direct_hints(self, hints):
self.sender_direct_hints = hints
def add_sender_relay_hints(self, hints):