forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connectd_gossipd_wiregen.c
164 lines (136 loc) · 4.56 KB
/
connectd_gossipd_wiregen.c
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* This file was generated by generate-wire.py */
/* Do not modify this file! Modify the .csv file it was generated from. */
/* Original template can be found at tools/gen/impl_template */
#include <connectd/connectd_gossipd_wiregen.h>
#include <assert.h>
#include <ccan/array_size/array_size.h>
#include <ccan/mem/mem.h>
#include <ccan/tal/str/str.h>
#include <common/utils.h>
#include <stdio.h>
#ifndef SUPERVERBOSE
#define SUPERVERBOSE(...)
#endif
const char *connectd_gossipd_wire_name(int e)
{
static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)];
switch ((enum connectd_gossipd_wire)e) {
case WIRE_GOSSIPD_NEW_PEER: return "WIRE_GOSSIPD_NEW_PEER";
case WIRE_GOSSIPD_NEW_PEER_REPLY: return "WIRE_GOSSIPD_NEW_PEER_REPLY";
case WIRE_GOSSIPD_GET_ADDRS: return "WIRE_GOSSIPD_GET_ADDRS";
case WIRE_GOSSIPD_GET_ADDRS_REPLY: return "WIRE_GOSSIPD_GET_ADDRS_REPLY";
}
snprintf(invalidbuf, sizeof(invalidbuf), "INVALID %i", e);
return invalidbuf;
}
bool connectd_gossipd_wire_is_defined(u16 type)
{
switch ((enum connectd_gossipd_wire)type) {
case WIRE_GOSSIPD_NEW_PEER:;
case WIRE_GOSSIPD_NEW_PEER_REPLY:;
case WIRE_GOSSIPD_GET_ADDRS:;
case WIRE_GOSSIPD_GET_ADDRS_REPLY:;
return true;
}
return false;
}
/* WIRE: GOSSIPD_NEW_PEER */
/* Communication between gossipd and connectd. */
u8 *towire_gossipd_new_peer(const tal_t *ctx, const struct node_id *id, bool gossip_queries_feature, bool initial_routing_sync)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_GOSSIPD_NEW_PEER);
towire_node_id(&p, id);
/* Did we negotiate LOCAL_GOSSIP_QUERIES? */
towire_bool(&p, gossip_queries_feature);
/* Did they offer LOCAL_INITIAL_ROUTING_SYNC? */
towire_bool(&p, initial_routing_sync);
return memcheck(p, tal_count(p));
}
bool fromwire_gossipd_new_peer(const void *p, struct node_id *id, bool *gossip_queries_feature, bool *initial_routing_sync)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_NEW_PEER)
return false;
fromwire_node_id(&cursor, &plen, id);
/* Did we negotiate LOCAL_GOSSIP_QUERIES? */
*gossip_queries_feature = fromwire_bool(&cursor, &plen);
/* Did they offer LOCAL_INITIAL_ROUTING_SYNC? */
*initial_routing_sync = fromwire_bool(&cursor, &plen);
return cursor != NULL;
}
/* WIRE: GOSSIPD_NEW_PEER_REPLY */
/* if success: + gossip fd and gossip_store fd */
u8 *towire_gossipd_new_peer_reply(const tal_t *ctx, bool success, const struct gossip_state *gs)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_GOSSIPD_NEW_PEER_REPLY);
towire_bool(&p, success);
if (!gs)
towire_bool(&p, false);
else {
towire_bool(&p, true);
towire_gossip_state(&p, gs);
}
return memcheck(p, tal_count(p));
}
bool fromwire_gossipd_new_peer_reply(const tal_t *ctx, const void *p, bool *success, struct gossip_state **gs)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_NEW_PEER_REPLY)
return false;
*success = fromwire_bool(&cursor, &plen);
if (!fromwire_bool(&cursor, &plen))
*gs = NULL;
else {
*gs = tal(ctx, struct gossip_state);
fromwire_gossip_state(&cursor, &plen, *gs);
}
return cursor != NULL;
}
/* WIRE: GOSSIPD_GET_ADDRS */
/* Connectd asks gossipd for any known addresses for that node. */
u8 *towire_gossipd_get_addrs(const tal_t *ctx, const struct node_id *id)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_GOSSIPD_GET_ADDRS);
towire_node_id(&p, id);
return memcheck(p, tal_count(p));
}
bool fromwire_gossipd_get_addrs(const void *p, struct node_id *id)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_GET_ADDRS)
return false;
fromwire_node_id(&cursor, &plen, id);
return cursor != NULL;
}
/* WIRE: GOSSIPD_GET_ADDRS_REPLY */
u8 *towire_gossipd_get_addrs_reply(const tal_t *ctx, const struct wireaddr *addrs)
{
u16 num = tal_count(addrs);
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_GOSSIPD_GET_ADDRS_REPLY);
towire_u16(&p, num);
for (size_t i = 0; i < num; i++)
towire_wireaddr(&p, addrs + i);
return memcheck(p, tal_count(p));
}
bool fromwire_gossipd_get_addrs_reply(const tal_t *ctx, const void *p, struct wireaddr **addrs)
{
u16 num;
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_GOSSIPD_GET_ADDRS_REPLY)
return false;
num = fromwire_u16(&cursor, &plen);
// 2nd case addrs
*addrs = num ? tal_arr(ctx, struct wireaddr, num) : NULL;
for (size_t i = 0; i < num; i++)
fromwire_wireaddr(&cursor, &plen, *addrs + i);
return cursor != NULL;
}
// SHA256STAMP:6bfe0677cb910aba63f79cfc4164ce26034da95e16341eab3aac6fddcc04e3e9