mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 18:11:28 +01:00
sphinx: Migrate sphinx compression to new interface
It also removes the duplicate compression code and serialization code.
This commit is contained in:
parent
6dd14a2039
commit
ef86ee0bae
@ -149,30 +149,6 @@ u8 *serialize_onionpacket(
|
||||
return dst;
|
||||
}
|
||||
|
||||
u8 *serialize_compressed_onion(const tal_t *ctx,
|
||||
const struct sphinx_path *sp,
|
||||
const struct onionpacket *packet)
|
||||
{
|
||||
u8 *dst;
|
||||
u8 der[PUBKEY_CMPR_LEN];
|
||||
size_t payloads_size = sphinx_path_payloads_size(sp);
|
||||
size_t max_prefill = ROUTING_INFO_SIZE - payloads_size;
|
||||
size_t rv_onion_size = TOTAL_PACKET_SIZE - max_prefill;
|
||||
int p = 0;
|
||||
|
||||
assert(sp->rendezvous_id != NULL);
|
||||
|
||||
dst = tal_arr(ctx, u8, rv_onion_size);
|
||||
|
||||
pubkey_to_der(der, &packet->ephemeralkey);
|
||||
write_buffer(dst, &packet->version, 1, &p);
|
||||
write_buffer(dst, der, sizeof(der), &p);
|
||||
write_buffer(dst, packet->routinginfo, ROUTING_INFO_SIZE - max_prefill, &p);
|
||||
write_buffer(dst, packet->mac, sizeof(packet->mac), &p);
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
enum onion_type parse_onionpacket(const u8 *src,
|
||||
const size_t srclen,
|
||||
struct onionpacket *dest)
|
||||
@ -810,7 +786,7 @@ sphinx_compress(const tal_t *ctx, const struct onionpacket *packet,
|
||||
size_t payloads_size = sphinx_path_payloads_size(path);
|
||||
|
||||
/* We can't compress an onion that doesn't have a rendez-vous node. */
|
||||
if (path->rendezvous_id)
|
||||
if (path->rendezvous_id == NULL)
|
||||
return NULL;
|
||||
|
||||
res = tal(ctx, struct sphinx_compressed_onion);
|
||||
|
@ -234,15 +234,6 @@ void sphinx_add_hop(struct sphinx_path *path, const struct pubkey *pubkey,
|
||||
*/
|
||||
size_t sphinx_path_payloads_size(const struct sphinx_path *path);
|
||||
|
||||
/**
|
||||
* Compress a rendez-vous onion by removing the unused blinded middle
|
||||
* part. This middle part can be regenerated by the node processing this
|
||||
* onion.
|
||||
*/
|
||||
u8 *serialize_compressed_onion(const tal_t *ctx,
|
||||
const struct sphinx_path *sp,
|
||||
const struct onionpacket *packet);
|
||||
|
||||
/**
|
||||
* Set the rendez-vous node_id and make the onion generated from the
|
||||
* sphinx_path compressible. To unset pass in a NULL rendezvous_id.
|
||||
|
@ -32,7 +32,9 @@ static void do_generate(int argc, char **argv,
|
||||
struct secret session_key;
|
||||
struct secret *shared_secrets;
|
||||
struct sphinx_path *sp;
|
||||
|
||||
struct sphinx_compressed_onion *comp;
|
||||
u8 *serialized;
|
||||
struct onionpacket *packet;
|
||||
const u8* tmp_assocdata =tal_dup_arr(ctx, u8, assocdata,
|
||||
ASSOC_DATA_SIZE, 0);
|
||||
memset(&session_key, 'A', sizeof(struct secret));
|
||||
@ -93,13 +95,17 @@ static void do_generate(int argc, char **argv,
|
||||
}
|
||||
}
|
||||
|
||||
struct onionpacket *res = create_onionpacket(ctx, sp, &shared_secrets);
|
||||
packet = create_onionpacket(ctx, sp, &shared_secrets);
|
||||
|
||||
if (rvnode_id != NULL)
|
||||
printf("Rendezvous onion: %s\n",
|
||||
tal_hex(ctx, serialize_compressed_onion(ctx, sp, res)));
|
||||
if (rvnode_id != NULL) {
|
||||
comp = sphinx_compress(ctx, packet, sp);
|
||||
serialized = sphinx_compressed_onion_serialize(ctx, comp);
|
||||
printf("Rendezvous onion: %s\n", tal_hex(ctx, serialized));
|
||||
} else {
|
||||
assert(sphinx_compress(ctx, packet, sp) == NULL);
|
||||
}
|
||||
|
||||
u8 *serialized = serialize_onionpacket(ctx, res);
|
||||
serialized = serialize_onionpacket(ctx, packet);
|
||||
if (!serialized)
|
||||
errx(1, "Error serializing message.");
|
||||
printf("%s\n", tal_hex(ctx, serialized));
|
||||
|
Loading…
Reference in New Issue
Block a user