better sketch of transit-client API
This commit is contained in:
parent
38b9c07566
commit
9dd4c6039f
|
@ -12,23 +12,28 @@ APPID = "lothar.com/wormhole/file-xfer"
|
||||||
transit_receiver = TransitReceiver()
|
transit_receiver = TransitReceiver()
|
||||||
direct_hints = transit_receiver.get_direct_hints()
|
direct_hints = transit_receiver.get_direct_hints()
|
||||||
|
|
||||||
data = json.dumps({"direct_connection_hints": direct_hints,
|
mydata = json.dumps({
|
||||||
}).encode("utf-8")
|
"transit": {
|
||||||
r = Receiver(APPID, data)
|
"direct_connection_hints": direct_hints,
|
||||||
|
},
|
||||||
|
}).encode("utf-8")
|
||||||
|
r = Receiver(APPID, mydata)
|
||||||
r.set_code(r.input_code("Enter receive-text wormhole code: "))
|
r.set_code(r.input_code("Enter receive-text wormhole code: "))
|
||||||
|
|
||||||
them_bytes = r.get_data()
|
data = json.loads(r.get_data().decode("utf-8"))
|
||||||
them_d = json.loads(them_bytes.decode("utf-8"))
|
print("their data: %r" % (data,))
|
||||||
print("them: %r" % (them_d,))
|
|
||||||
|
|
||||||
xfer_key = unhexlify(them_d["xfer_key"].encode("ascii"))
|
file_data = data["file"]
|
||||||
filename = os.path.basename(them_d["filename"]) # unicode
|
xfer_key = unhexlify(file_data["key"].encode("ascii"))
|
||||||
filesize = them_d["filesize"]
|
filename = os.path.basename(file_data["filename"]) # unicode
|
||||||
|
filesize = file_data["filesize"]
|
||||||
|
|
||||||
# now receive the rest of the owl
|
# now receive the rest of the owl
|
||||||
transit_receiver.add_sender_direct_hints(them_d["direct_connection_hints"])
|
tdata = data["transit"]
|
||||||
transit_receiver.add_sender_relay_hints(them_d["relay_connection_hints"])
|
transit_receiver.set_transit_key(tdata["key"])
|
||||||
transit_receiver.establish_connection(IDS)
|
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()
|
encrypted = transit_receiver.receive()
|
||||||
|
|
||||||
decrypted = SecretBox(xfer_key).decrypt(encrypted)
|
decrypted = SecretBox(xfer_key).decrypt(encrypted)
|
||||||
|
|
|
@ -2,7 +2,6 @@ from __future__ import print_function
|
||||||
import os, sys, json
|
import os, sys, json
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
from nacl.secret import SecretBox
|
from nacl.secret import SecretBox
|
||||||
from nacl import utils
|
|
||||||
from wormhole.blocking.transcribe import Initiator
|
from wormhole.blocking.transcribe import Initiator
|
||||||
from wormhole.blocking.transit import TransitSender
|
from wormhole.blocking.transit import TransitSender
|
||||||
|
|
||||||
|
@ -11,17 +10,24 @@ APPID = "lothar.com/wormhole/file-xfer"
|
||||||
# we're sending
|
# we're sending
|
||||||
filename = sys.argv[1]
|
filename = sys.argv[1]
|
||||||
assert os.path.isfile(filename)
|
assert os.path.isfile(filename)
|
||||||
xfer_key = utils.random(SecretBox.KEY_SIZE)
|
xfer_key = os.urandom(SecretBox.KEY_SIZE)
|
||||||
transit_sender = TransitSender()
|
transit_sender = TransitSender()
|
||||||
|
transit_key = transit_sender.get_transit_key()
|
||||||
direct_hints = transit_sender.get_direct_hints()
|
direct_hints = transit_sender.get_direct_hints()
|
||||||
relay_hints = transit_sender.get_relay_hints()
|
relay_hints = transit_sender.get_relay_hints()
|
||||||
|
|
||||||
data = json.dumps({"xfer_key": hexlify(xfer_key),
|
data = json.dumps({
|
||||||
"filename": os.path.basename(filename),
|
"file": {
|
||||||
"filesize": os.stat(filename).st_size,
|
"key": hexlify(xfer_key),
|
||||||
"direct_connection_hints": direct_hints,
|
"filename": os.path.basename(filename),
|
||||||
"relay_connection_hints": relay_hints,
|
"filesize": os.stat(filename).st_size,
|
||||||
}).encode("utf-8")
|
},
|
||||||
|
"transit": {
|
||||||
|
"key": hexlify(transit_key),
|
||||||
|
"direct_connection_hints": direct_hints,
|
||||||
|
"relay_connection_hints": relay_hints,
|
||||||
|
},
|
||||||
|
}).encode("utf-8")
|
||||||
|
|
||||||
i = Initiator(APPID, data)
|
i = Initiator(APPID, data)
|
||||||
code = i.get_code()
|
code = i.get_code()
|
||||||
|
@ -39,7 +45,7 @@ nonce = utils.random(SecretBox.NONCE_SIZE)
|
||||||
encrypted = box.encrypt(plaintext, nonce)
|
encrypted = box.encrypt(plaintext, nonce)
|
||||||
|
|
||||||
transit_sender.add_receiver_hints(them_d["direct_connection_hints"])
|
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.write(encrypted)
|
||||||
transit_sender.close()
|
transit_sender.close()
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
|
import os
|
||||||
|
from ..util import ipaddrs
|
||||||
|
|
||||||
class TransitSender:
|
class TransitSender:
|
||||||
def __init__(self, IDS):
|
def __init__(self):
|
||||||
pass
|
self.key = os.urandom(32)
|
||||||
|
def get_transit_key(self):
|
||||||
|
return self.key
|
||||||
def get_direct_hints(self):
|
def get_direct_hints(self):
|
||||||
pass
|
pass
|
||||||
def get_relay_hints(self):
|
def get_relay_hints(self):
|
||||||
|
@ -16,10 +20,12 @@ class TransitSender:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class TransitReceiver:
|
class TransitReceiver:
|
||||||
def __init__(self, IDS):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
def get_direct_hints(self):
|
def get_direct_hints(self):
|
||||||
pass
|
pass
|
||||||
|
def set_transit_key(self, key):
|
||||||
|
self.key = key
|
||||||
def add_sender_direct_hints(self, hints):
|
def add_sender_direct_hints(self, hints):
|
||||||
self.sender_direct_hints = hints
|
self.sender_direct_hints = hints
|
||||||
def add_sender_relay_hints(self, hints):
|
def add_sender_relay_hints(self, hints):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user