Browse Source

pkt: add pkt_totlen() helper.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
92ec2f874b
  1. 5
      pkt.c
  2. 3
      pkt.h
  3. 3
      test-cli/close-channel.c
  4. 3
      test-cli/leak-anchor-sigs.c
  5. 3
      test-cli/open-anchor-scriptsigs.c
  6. 3
      test-cli/open-channel.c
  7. 3
      test-cli/open-commit-sig.c
  8. 3
      test-cli/update-channel-accept.c
  9. 3
      test-cli/update-channel-complete.c
  10. 3
      test-cli/update-channel-signature.c
  11. 3
      test-cli/update-channel.c

5
pkt.c

@ -8,6 +8,11 @@
#include "pkt.h" #include "pkt.h"
#include "protobuf_convert.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) static struct pkt *to_pkt(const tal_t *ctx, Pkt__PktCase type, void *msg)
{ {
struct pkt *ret; struct pkt *ret;

3
pkt.h

@ -20,6 +20,9 @@ struct pkt {
Pkt *pkt_from_file(const char *filename, Pkt__PktCase expect); Pkt *pkt_from_file(const char *filename, Pkt__PktCase expect);
Pkt *any_pkt_from_file(const char *filename); 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 sha256;
struct bitcoin_compressed_pubkey; struct bitcoin_compressed_pubkey;
struct signature; struct signature;

3
test-cli/close-channel.c

@ -98,8 +98,7 @@ int main(int argc, char *argv[])
pkt = close_channel_complete_pkt(ctx, &sig); pkt = close_channel_complete_pkt(ctx, &sig);
else else
pkt = close_channel_pkt(ctx, &sig); pkt = close_channel_pkt(ctx, &sig);
if (!write_all(STDOUT_FILENO, pkt, if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
sizeof(pkt->len) + le32_to_cpu(pkt->len)))
err(1, "Writing out packet"); err(1, "Writing out packet");
tal_free(ctx); tal_free(ctx);

3
test-cli/leak-anchor-sigs.c

@ -28,8 +28,7 @@ int main(int argc, char *argv[])
->open_anchor_scriptsigs; ->open_anchor_scriptsigs;
pkt = leak_anchor_sigs_and_pretend_we_didnt_pkt(ctx, s); pkt = leak_anchor_sigs_and_pretend_we_didnt_pkt(ctx, s);
if (!write_all(STDOUT_FILENO, pkt, if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
sizeof(pkt->len) + le32_to_cpu(pkt->len)))
err(1, "Writing out packet"); err(1, "Writing out packet");
tal_free(ctx); tal_free(ctx);

3
test-cli/open-anchor-scriptsigs.c

@ -95,8 +95,7 @@ int main(int argc, char *argv[])
} }
pkt = open_anchor_sig_pkt(ctx, sigs, o1->anchor->n_inputs); pkt = open_anchor_sig_pkt(ctx, sigs, o1->anchor->n_inputs);
if (!write_all(STDOUT_FILENO, pkt, if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
sizeof(pkt->len) + le32_to_cpu(pkt->len)))
err(1, "Writing out packet"); err(1, "Writing out packet");
tal_free(ctx); tal_free(ctx);

3
test-cli/open-channel.c

@ -174,8 +174,7 @@ int main(int argc, char *argv[])
pkt = openchannel_pkt(ctx, weak_random64(), &revocation_hash, &outkey, pkt = openchannel_pkt(ctx, weak_random64(), &revocation_hash, &outkey,
commit_tx_fee, locktime_seconds, &anchor); commit_tx_fee, locktime_seconds, &anchor);
if (!write_all(STDOUT_FILENO, pkt, if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
sizeof(pkt->len) + le32_to_cpu(pkt->len)))
err(1, "Writing out packet"); err(1, "Writing out packet");
tal_free(ctx); tal_free(ctx);

3
test-cli/open-commit-sig.c

@ -88,8 +88,7 @@ int main(int argc, char *argv[])
privkey, &pubkey1, &sig); privkey, &pubkey1, &sig);
pkt = open_commit_sig_pkt(ctx, &sig); pkt = open_commit_sig_pkt(ctx, &sig);
if (!write_all(STDOUT_FILENO, pkt, if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
sizeof(pkt->len) + le32_to_cpu(pkt->len)))
err(1, "Writing out packet"); err(1, "Writing out packet");
tal_free(ctx); tal_free(ctx);

3
test-cli/update-channel-accept.c

@ -106,8 +106,7 @@ int main(int argc, char *argv[])
privkey, &pubkey1, &sig.sig); privkey, &pubkey1, &sig.sig);
pkt = update_accept_pkt(ctx, &sig.sig, &revocation_hash); pkt = update_accept_pkt(ctx, &sig.sig, &revocation_hash);
if (!write_all(STDOUT_FILENO, pkt, if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
sizeof(pkt->len) + le32_to_cpu(pkt->len)))
err(1, "Writing out packet"); err(1, "Writing out packet");
tal_free(ctx); tal_free(ctx);

3
test-cli/update-channel-complete.c

@ -121,8 +121,7 @@ int main(int argc, char *argv[])
/* Hand over our preimage for previous tx. */ /* Hand over our preimage for previous tx. */
shachain_from_seed(&seed, num_updates, &preimage); shachain_from_seed(&seed, num_updates, &preimage);
pkt = update_complete_pkt(ctx, &preimage); pkt = update_complete_pkt(ctx, &preimage);
if (!write_all(STDOUT_FILENO, pkt, if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
sizeof(pkt->len) + le32_to_cpu(pkt->len)))
err(1, "Writing out packet"); err(1, "Writing out packet");
tal_free(ctx); tal_free(ctx);

3
test-cli/update-channel-signature.c

@ -124,8 +124,7 @@ int main(int argc, char *argv[])
privkey, &pubkey1, &sig.sig); privkey, &pubkey1, &sig.sig);
pkt = update_signature_pkt(ctx, &sig.sig, &preimage); pkt = update_signature_pkt(ctx, &sig.sig, &preimage);
if (!write_all(STDOUT_FILENO, pkt, if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
sizeof(pkt->len) + le32_to_cpu(pkt->len)))
err(1, "Writing out packet"); err(1, "Writing out packet");
tal_free(ctx); tal_free(ctx);

3
test-cli/update-channel.c

@ -63,8 +63,7 @@ int main(int argc, char *argv[])
revocation_hash.u.u8, sizeof(revocation_hash.u.u8)); revocation_hash.u.u8, sizeof(revocation_hash.u.u8));
pkt = update_pkt(ctx, &revocation_hash, this_delta); pkt = update_pkt(ctx, &revocation_hash, this_delta);
if (!write_all(STDOUT_FILENO, pkt, if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
sizeof(pkt->len) + le32_to_cpu(pkt->len)))
err(1, "Writing out packet"); err(1, "Writing out packet");
tal_free(ctx); tal_free(ctx);

Loading…
Cancel
Save