1
0

Trampoline routing:

- add support for trampoline forwarding
 - add regtest with trampoline payment
This commit is contained in:
ThomasV
2021-02-09 15:09:27 +01:00
parent ded449233e
commit cf818fe08c
5 changed files with 166 additions and 16 deletions

View File

@@ -349,7 +349,8 @@ class ProcessedOnionPacket(NamedTuple):
def process_onion_packet(
onion_packet: OnionPacket,
associated_data: bytes,
our_onion_private_key: bytes) -> ProcessedOnionPacket:
our_onion_private_key: bytes,
is_trampoline=False) -> ProcessedOnionPacket:
if not ecc.ECPubkey.is_pubkey_bytes(onion_packet.public_key):
raise InvalidOnionPubkey()
shared_secret = get_ecdh(our_onion_private_key, onion_packet.public_key)
@@ -362,8 +363,9 @@ def process_onion_packet(
raise InvalidOnionMac()
# peel an onion layer off
rho_key = get_bolt04_onion_key(b'rho', shared_secret)
stream_bytes = generate_cipher_stream(rho_key, 2 * HOPS_DATA_SIZE)
padded_header = onion_packet.hops_data + bytes(HOPS_DATA_SIZE)
data_size = TRAMPOLINE_HOPS_DATA_SIZE if is_trampoline else HOPS_DATA_SIZE
stream_bytes = generate_cipher_stream(rho_key, 2 * data_size)
padded_header = onion_packet.hops_data + bytes(data_size)
next_hops_data = xor_bytes(padded_header, stream_bytes)
next_hops_data_fd = io.BytesIO(next_hops_data)
hop_data = OnionHopsDataSingle.from_fd(next_hops_data_fd)
@@ -386,7 +388,7 @@ def process_onion_packet(
next_public_key = next_public_key_int.get_public_key_bytes()
next_onion_packet = OnionPacket(
public_key=next_public_key,
hops_data=next_hops_data_fd.read(HOPS_DATA_SIZE),
hops_data=next_hops_data_fd.read(data_size),
hmac=hop_data.hmac)
if hop_data.hmac == bytes(PER_HOP_HMAC_SIZE):
# we are the destination / exit node