Browse Source

wire: use common/bigsize routines

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
pull/2938/head
Rusty Russell 6 years ago
parent
commit
cc70b9c4ec
  1. 6
      channeld/test/run-commit_tx.c
  2. 6
      channeld/test/run-full_channel.c
  3. 7
      cli/test/run-large-input.c
  4. 1
      closingd/Makefile
  5. 1
      connectd/Makefile
  6. 1
      gossipd/Makefile
  7. 1
      hsmd/Makefile
  8. 6
      lightningd/test/run-find_my_abspath.c
  9. 6
      lightningd/test/run-invoice-select-inchan.c
  10. 6
      lightningd/test/run-jsonrpc.c
  11. 1
      onchaind/Makefile
  12. 1
      openingd/Makefile
  13. 1
      plugins/Makefile
  14. 6
      wallet/test/run-db.c
  15. 6
      wallet/test/run-wallet.c
  16. 37
      wire/fromwire.c
  17. 6
      wire/test/run-peer-wire.c
  18. 4
      wire/test/run-tlvstream.c
  19. 21
      wire/towire.c
  20. 4
      wire/wire.h

6
channeld/test/run-commit_tx.c

@ -20,6 +20,12 @@ static bool print_superverbose;
/*#define DEBUG */
/* AUTOGENERATED MOCKS START */
/* Generated stub for bigsize_get */
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
/* Generated stub for bigsize_put */
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
/* Generated stub for status_fmt */
void status_fmt(enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...)

6
channeld/test/run-full_channel.c

@ -14,6 +14,12 @@
#include <wally_core.h>
/* AUTOGENERATED MOCKS START */
/* Generated stub for bigsize_get */
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
/* Generated stub for bigsize_put */
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
/* Generated stub for status_failed */
void status_failed(enum status_failreason code UNNEEDED,
const char *fmt UNNEEDED, ...)

7
cli/test/run-large-input.c

@ -1,6 +1,7 @@
#include "config.h"
#include <assert.h>
#include <common/amount.h>
#include <common/bigsize.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/stat.h>
@ -26,6 +27,12 @@ int test_printf(const char *format, ...);
#undef main
/* AUTOGENERATED MOCKS START */
/* Generated stub for bigsize_get */
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
/* Generated stub for bigsize_put */
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
/* Generated stub for version_and_exit */
char *version_and_exit(const void *unused UNNEEDED)
{ fprintf(stderr, "version_and_exit called!\n"); abort(); }

1
closingd/Makefile

@ -44,6 +44,7 @@ $(LIGHTNINGD_CLOSING_OBJS): $(LIGHTNINGD_HEADERS)
CLOSINGD_COMMON_OBJS := \
common/amount.o \
common/base32.o \
common/bigsize.o \
common/bip32.o \
common/close_tx.o \
common/crypto_state.o \

1
connectd/Makefile

@ -41,6 +41,7 @@ CONNECTD_COMMON_OBJS := \
common/base32.o \
common/bech32.o \
common/bech32_util.o \
common/bigsize.o \
common/bip32.o \
common/crypto_state.o \
common/cryptomsg.o \

1
gossipd/Makefile

@ -40,6 +40,7 @@ GOSSIPD_COMMON_OBJS := \
common/base32.o \
common/bech32.o \
common/bech32_util.o \
common/bigsize.o \
common/bip32.o \
common/crypto_state.o \
common/cryptomsg.o \

1
hsmd/Makefile

@ -14,6 +14,7 @@ LIGHTNINGD_HSM_OBJS := $(LIGHTNINGD_HSM_SRC:.c=.o)
# Common source we use.
HSMD_COMMON_OBJS := \
common/amount.o \
common/bigsize.o \
common/bip32.o \
common/daemon.o \
common/daemon_conn.o \

6
lightningd/test/run-find_my_abspath.c

@ -18,6 +18,12 @@ char *add_plugin_dir(struct plugins *plugins UNNEEDED, const char *dir UNNEEDED,
/* Generated stub for begin_topology */
void begin_topology(struct chain_topology *topo UNNEEDED)
{ fprintf(stderr, "begin_topology called!\n"); abort(); }
/* Generated stub for bigsize_get */
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
/* Generated stub for bigsize_put */
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
/* Generated stub for channel_notify_new_block */
void channel_notify_new_block(struct lightningd *ld UNNEEDED,
u32 block_height UNNEEDED)

6
lightningd/test/run-invoice-select-inchan.c

@ -6,6 +6,12 @@
bool deprecated_apis = false;
/* AUTOGENERATED MOCKS START */
/* Generated stub for bigsize_get */
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
/* Generated stub for bigsize_put */
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
/* Generated stub for bitcoind_gettxout */
void bitcoind_gettxout(struct bitcoind *bitcoind UNNEEDED,
const struct bitcoin_txid *txid UNNEEDED, const u32 outnum UNNEEDED,

6
lightningd/test/run-jsonrpc.c

@ -3,6 +3,12 @@
#include "../json.c"
/* AUTOGENERATED MOCKS START */
/* Generated stub for bigsize_get */
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
/* Generated stub for bigsize_put */
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
/* Generated stub for db_begin_transaction_ */
void db_begin_transaction_(struct db *db UNNEEDED, const char *location UNNEEDED)
{ fprintf(stderr, "db_begin_transaction_ called!\n"); abort(); }

1
onchaind/Makefile

@ -48,6 +48,7 @@ $(LIGHTNINGD_ONCHAIN_OBJS): $(LIGHTNINGD_HEADERS)
# Common source we use.
ONCHAIND_COMMON_OBJS := \
common/amount.o \
common/bigsize.o \
common/bip32.o \
common/daemon.o \
common/daemon_conn.o \

1
openingd/Makefile

@ -37,6 +37,7 @@ LIGHTNINGD_HEADERS_NOGEN += $(LIGHTNINGD_OPENING_HEADERS_NOGEN)
OPENINGD_COMMON_OBJS := \
common/amount.o \
common/base32.o \
common/bigsize.o \
common/bip32.o \
common/channel_config.o \
common/crypto_state.o \

1
plugins/Makefile

@ -21,6 +21,7 @@ PLUGIN_COMMON_OBJS := \
common/amount.o \
common/bech32.o \
common/bech32_util.o \
common/bigsize.o \
common/bolt11.o \
common/daemon.o \
common/hash_u5.o \

6
wallet/test/run-db.c

@ -18,6 +18,12 @@ static void db_log_(struct log *log UNUSED, enum log_level level UNUSED, bool ca
#include <unistd.h>
/* AUTOGENERATED MOCKS START */
/* Generated stub for bigsize_get */
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
/* Generated stub for bigsize_put */
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */
static char *db_err;

6
wallet/test/run-wallet.c

@ -35,6 +35,12 @@ const struct chainparams *get_chainparams(const struct lightningd *ld)
}
/* AUTOGENERATED MOCKS START */
/* Generated stub for bigsize_get */
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
/* Generated stub for bigsize_put */
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
/* Generated stub for bitcoind_gettxout */
void bitcoind_gettxout(struct bitcoind *bitcoind UNNEEDED,
const struct bitcoin_txid *txid UNNEEDED, const u32 outnum UNNEEDED,

37
wire/fromwire.c

@ -163,37 +163,18 @@ bool fromwire_bool(const u8 **cursor, size_t *max)
return ret;
}
u64 fromwire_bigsize(const u8 **cursor, size_t *max)
bigsize_t fromwire_bigsize(const u8 **cursor, size_t *max)
{
u8 flag = fromwire_u8(cursor, max);
u64 ret;
bigsize_t v;
size_t len = bigsize_get(*cursor, *max, &v);
switch(flag) {
case 0xff:
ret = fromwire_u64(cursor, max);
if ((ret >> 32) == 0) {
SUPERVERBOSE("not minimal encoded");
fromwire_fail(cursor, max);
}
break;
case 0xfe:
ret = fromwire_u32(cursor, max);
if ((ret >> 16) == 0) {
SUPERVERBOSE("not minimal encoded");
fromwire_fail(cursor, max);
}
break;
case 0xfd:
ret = fromwire_u16(cursor, max);
if (ret < 0xfd) {
SUPERVERBOSE("not minimal encoded");
fromwire_fail(cursor, max);
}
break;
default:
ret = flag;
if (len == 0) {
fromwire_fail(cursor, max);
return 0;
}
return ret;
assert(len <= *max);
fromwire(cursor, max, NULL, len);
return v;
}
void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey)

6
wire/test/run-peer-wire.c

@ -12,6 +12,12 @@
secp256k1_context *secp256k1_ctx;
/* AUTOGENERATED MOCKS START */
/* Generated stub for bigsize_get */
size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNNEEDED)
{ fprintf(stderr, "bigsize_get called!\n"); abort(); }
/* Generated stub for bigsize_put */
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */
/* memsetting pubkeys doesn't work */

4
wire/test/run-tlvstream.c

@ -1,9 +1,13 @@
#include <ccan/array_size/array_size.h>
#include <ccan/str/hex/hex.h>
#include <common/utils.h>
#include <stdio.h>
#include <wally_core.h>
#include <common/bigsize.c>
static const char *reason;
#undef SUPERVERBOSE
#define SUPERVERBOSE(r) do { reason = (r); } while(0)
#include <wire/tlvstream.c>

21
wire/towire.c

@ -87,20 +87,13 @@ void towire_bool(u8 **pptr, bool v)
towire(pptr, &val, sizeof(val));
}
void towire_bigsize(u8 **pptr, const u64 val)
{
if (val < 0xfd) {
towire_u8(pptr, val);
} else if (val <= 0xffff) {
towire_u8(pptr, 0xfd);
towire_u16(pptr, val);
} else if (val <= 0xffffffff) {
towire_u8(pptr, 0xfe);
towire_u32(pptr, val);
} else {
towire_u8(pptr, 0xff);
towire_u64(pptr, val);
}
void towire_bigsize(u8 **pptr, const bigsize_t val)
{
u8 buf[BIGSIZE_MAX_LEN];
size_t len;
len = bigsize_put(buf, val);
towire(pptr, buf, len);
}
void towire_pubkey(u8 **pptr, const struct pubkey *pubkey)

4
wire/wire.h

@ -79,7 +79,7 @@ void towire_tu64(u8 **pptr, u64 v);
void towire_double(u8 **pptr, const double *v);
void towire_pad(u8 **pptr, size_t num);
void towire_bool(u8 **pptr, bool v);
void towire_bigsize(u8 **pptr, const u64 val);
void towire_bigsize(u8 **pptr, const bigsize_t val);
void towire_u8_array(u8 **pptr, const u8 *arr, size_t num);
@ -99,7 +99,7 @@ u32 fromwire_tu32(const u8 **cursor, size_t *max);
u64 fromwire_tu64(const u8 **cursor, size_t *max);
void fromwire_double(const u8 **cursor, size_t *max, double *v);
bool fromwire_bool(const u8 **cursor, size_t *max);
u64 fromwire_bigsize(const u8 **cursor, size_t *max);
bigsize_t fromwire_bigsize(const u8 **cursor, size_t *max);
void fromwire_secret(const u8 **cursor, size_t *max, struct secret *secret);
void fromwire_privkey(const u8 **cursor, size_t *max, struct privkey *privkey);
void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey);

Loading…
Cancel
Save