forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_peer_msg.h
60 lines (53 loc) · 2.2 KB
/
read_peer_msg.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef LIGHTNING_COMMON_READ_PEER_MSG_H
#define LIGHTNING_COMMON_READ_PEER_MSG_H
#include "config.h"
#include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>
#include <ccan/typesafe_cb/typesafe_cb.h>
struct crypto_state;
struct channel_id;
/**
* read_peer_msg - read & decode in a peer message, handling common ones.
* @ctx: context to allocate return packet from.
* @cs: the cryptostate (updated)
* @chanid: the channel id (for identifying errors)
* @send_reply: the way to send a reply packet (eg. sync_crypto_write_arg)
* @io_error: what to do if there's an IO error (eg. status_fail_io)
* (MUST NOT RETURN!)
* @err_pkt: what to do if there's an error packet (eg. status_fail_errorpkt)
* (MUST NOT RETURN!)
*
* This returns NULL if it handled the message, so it's normally called in
* a loop.
*/
#define read_peer_msg(ctx, cs, chanid, send_reply, io_error, err_pkt, arg) \
read_peer_msg_((ctx), PEER_FD, GOSSIP_FD, (cs), (chanid), \
typesafe_cb_preargs(bool, void *, (send_reply), (arg), \
struct crypto_state *, int, \
const u8 *), \
typesafe_cb_preargs(void, void *, (io_error), (arg), \
const char *), \
typesafe_cb_preargs(void, void *, (err_pkt), (arg), \
const char *, \
const struct channel_id *), \
arg)
/* Helper: sync_crypto_write, with extra args it ignores */
bool sync_crypto_write_arg(struct crypto_state *cs, int fd, const u8 *TAKES,
void *unused);
/* Helper: calls status_fatal_connection_lost. */
/* FIXME: Remove what_i_was_doing arg */
void status_fail_io(const char *what_i_was_doing, void *unused);
/* Helper: calls status_fatal_received_errmsg() */
void status_fail_errpkt(const char *desc, const struct channel_id *c,
void *unused);
u8 *read_peer_msg_(const tal_t *ctx,
int peer_fd, int gossip_fd,
struct crypto_state *cs,
const struct channel_id *channel,
bool (*send_reply)(struct crypto_state *cs, int fd,
const u8 *TAKES, void *arg),
void (*io_error)(const char *what_i_was_doing, void *arg),
void (*err_pkt)(const char *desc, const struct channel_id *,
void *arg),
void *arg);
#endif /* LIGHTNING_COMMON_READ_PEER_MSG_H */