mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
pkt: add pkt_totlen() helper.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
77387bb370
commit
92ec2f874b
5
pkt.c
5
pkt.c
@ -8,6 +8,11 @@
|
||||
#include "pkt.h"
|
||||
#include "protobuf_convert.h"
|
||||
|
||||
size_t pkt_totlen(const struct pkt *pkt)
|
||||
{
|
||||
return sizeof(pkt->len) + le32_to_cpu(pkt->len);
|
||||
}
|
||||
|
||||
static struct pkt *to_pkt(const tal_t *ctx, Pkt__PktCase type, void *msg)
|
||||
{
|
||||
struct pkt *ret;
|
||||
|
3
pkt.h
3
pkt.h
@ -20,6 +20,9 @@ struct pkt {
|
||||
Pkt *pkt_from_file(const char *filename, Pkt__PktCase expect);
|
||||
Pkt *any_pkt_from_file(const char *filename);
|
||||
|
||||
/* Total length of packet, including header. */
|
||||
size_t pkt_totlen(const struct pkt *pkt);
|
||||
|
||||
struct sha256;
|
||||
struct bitcoin_compressed_pubkey;
|
||||
struct signature;
|
||||
|
@ -98,8 +98,7 @@ int main(int argc, char *argv[])
|
||||
pkt = close_channel_complete_pkt(ctx, &sig);
|
||||
else
|
||||
pkt = close_channel_pkt(ctx, &sig);
|
||||
if (!write_all(STDOUT_FILENO, pkt,
|
||||
sizeof(pkt->len) + le32_to_cpu(pkt->len)))
|
||||
if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
|
||||
err(1, "Writing out packet");
|
||||
|
||||
tal_free(ctx);
|
||||
|
@ -28,8 +28,7 @@ int main(int argc, char *argv[])
|
||||
->open_anchor_scriptsigs;
|
||||
|
||||
pkt = leak_anchor_sigs_and_pretend_we_didnt_pkt(ctx, s);
|
||||
if (!write_all(STDOUT_FILENO, pkt,
|
||||
sizeof(pkt->len) + le32_to_cpu(pkt->len)))
|
||||
if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
|
||||
err(1, "Writing out packet");
|
||||
|
||||
tal_free(ctx);
|
||||
|
@ -95,8 +95,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
pkt = open_anchor_sig_pkt(ctx, sigs, o1->anchor->n_inputs);
|
||||
if (!write_all(STDOUT_FILENO, pkt,
|
||||
sizeof(pkt->len) + le32_to_cpu(pkt->len)))
|
||||
if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
|
||||
err(1, "Writing out packet");
|
||||
|
||||
tal_free(ctx);
|
||||
|
@ -174,8 +174,7 @@ int main(int argc, char *argv[])
|
||||
pkt = openchannel_pkt(ctx, weak_random64(), &revocation_hash, &outkey,
|
||||
commit_tx_fee, locktime_seconds, &anchor);
|
||||
|
||||
if (!write_all(STDOUT_FILENO, pkt,
|
||||
sizeof(pkt->len) + le32_to_cpu(pkt->len)))
|
||||
if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
|
||||
err(1, "Writing out packet");
|
||||
|
||||
tal_free(ctx);
|
||||
|
@ -88,8 +88,7 @@ int main(int argc, char *argv[])
|
||||
privkey, &pubkey1, &sig);
|
||||
|
||||
pkt = open_commit_sig_pkt(ctx, &sig);
|
||||
if (!write_all(STDOUT_FILENO, pkt,
|
||||
sizeof(pkt->len) + le32_to_cpu(pkt->len)))
|
||||
if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
|
||||
err(1, "Writing out packet");
|
||||
|
||||
tal_free(ctx);
|
||||
|
@ -106,8 +106,7 @@ int main(int argc, char *argv[])
|
||||
privkey, &pubkey1, &sig.sig);
|
||||
|
||||
pkt = update_accept_pkt(ctx, &sig.sig, &revocation_hash);
|
||||
if (!write_all(STDOUT_FILENO, pkt,
|
||||
sizeof(pkt->len) + le32_to_cpu(pkt->len)))
|
||||
if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
|
||||
err(1, "Writing out packet");
|
||||
|
||||
tal_free(ctx);
|
||||
|
@ -121,8 +121,7 @@ int main(int argc, char *argv[])
|
||||
/* Hand over our preimage for previous tx. */
|
||||
shachain_from_seed(&seed, num_updates, &preimage);
|
||||
pkt = update_complete_pkt(ctx, &preimage);
|
||||
if (!write_all(STDOUT_FILENO, pkt,
|
||||
sizeof(pkt->len) + le32_to_cpu(pkt->len)))
|
||||
if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
|
||||
err(1, "Writing out packet");
|
||||
|
||||
tal_free(ctx);
|
||||
|
@ -124,8 +124,7 @@ int main(int argc, char *argv[])
|
||||
privkey, &pubkey1, &sig.sig);
|
||||
|
||||
pkt = update_signature_pkt(ctx, &sig.sig, &preimage);
|
||||
if (!write_all(STDOUT_FILENO, pkt,
|
||||
sizeof(pkt->len) + le32_to_cpu(pkt->len)))
|
||||
if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
|
||||
err(1, "Writing out packet");
|
||||
|
||||
tal_free(ctx);
|
||||
|
@ -63,8 +63,7 @@ int main(int argc, char *argv[])
|
||||
revocation_hash.u.u8, sizeof(revocation_hash.u.u8));
|
||||
|
||||
pkt = update_pkt(ctx, &revocation_hash, this_delta);
|
||||
if (!write_all(STDOUT_FILENO, pkt,
|
||||
sizeof(pkt->len) + le32_to_cpu(pkt->len)))
|
||||
if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
|
||||
err(1, "Writing out packet");
|
||||
|
||||
tal_free(ctx);
|
||||
|
Loading…
Reference in New Issue
Block a user