2017-01-10 05:52:20 +01:00
|
|
|
#ifndef LIGHTNING_WIRE_WIRE_IO_H
|
|
|
|
#define LIGHTNING_WIRE_WIRE_IO_H
|
|
|
|
#include "config.h"
|
2017-09-29 02:56:32 +02:00
|
|
|
#include <ccan/endian/endian.h>
|
2017-09-29 12:22:51 +02:00
|
|
|
#include <ccan/io/io.h>
|
2017-01-10 05:52:20 +01:00
|
|
|
#include <ccan/short_types/short_types.h>
|
|
|
|
|
2019-04-08 11:58:44 +02:00
|
|
|
/* We don't allow > 128M msgs: enough for more than 1M channels in gossip_getchannels_entry. */
|
|
|
|
#define WIRE_LEN_LIMIT (1 << 27)
|
2017-09-28 05:42:19 +02:00
|
|
|
|
2017-09-29 02:56:32 +02:00
|
|
|
typedef be32 wire_len_t;
|
|
|
|
#define wirelen_to_cpu be32_to_cpu
|
|
|
|
#define cpu_to_wirelen cpu_to_be32
|
2017-09-28 05:42:19 +02:00
|
|
|
|
2017-01-10 05:52:20 +01:00
|
|
|
/* Read message into *data, allocating off ctx. */
|
|
|
|
struct io_plan *io_read_wire_(struct io_conn *conn,
|
|
|
|
const tal_t *ctx,
|
|
|
|
u8 **data,
|
|
|
|
struct io_plan *(*next)(struct io_conn *, void *),
|
|
|
|
void *next_arg);
|
|
|
|
|
|
|
|
#define io_read_wire(conn, ctx, data, next, arg) \
|
|
|
|
io_read_wire_((conn), (ctx), (data), \
|
|
|
|
typesafe_cb_preargs(struct io_plan *, void *, \
|
|
|
|
(next), (arg), struct io_conn *), \
|
|
|
|
(arg))
|
|
|
|
|
2017-03-10 11:45:42 +01:00
|
|
|
/* Write message from data (tal_count(data) gives length). data can be take() */
|
2017-01-10 05:52:20 +01:00
|
|
|
struct io_plan *io_write_wire_(struct io_conn *conn,
|
|
|
|
const u8 *data,
|
|
|
|
struct io_plan *(*next)(struct io_conn *, void *),
|
|
|
|
void *next_arg);
|
|
|
|
|
|
|
|
#define io_write_wire(conn, data, next, arg) \
|
|
|
|
io_write_wire_((conn), (data), \
|
|
|
|
typesafe_cb_preargs(struct io_plan *, void *, \
|
|
|
|
(next), (arg), struct io_conn *), \
|
|
|
|
(arg))
|
|
|
|
#endif /* LIGHTNING_WIRE_WIRE_IO_H */
|