MCPcopy Create free account
hub / github.com/ElementsProject/lightning / main

Function main

common/test/run-onion-test-vector.c:133–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131}
132
133int main(int argc, char *argv[])
134{
135 char *json;
136 size_t i;
137 jsmn_parser parser;
138 jsmntok_t toks[5000];
139 const jsmntok_t *t, *generate_tok;
140 struct sphinx_path *sp;
141 struct secret session_key;
142 struct onionpacket *op;
143 u8 *assoc_data, *expected, *actual;
144 struct secret *unused_path_secrets;
145 u8 *payloads[5];
146
147 common_setup(argv[0]);
148
149 if (argv[1])
150 json = grab_file_str(tmpctx, argv[1]);
151 else {
152 char *dir = getenv("BOLTDIR");
153 json = grab_file_str(tmpctx,
154 path_join(tmpctx,
155 dir ? dir : ".tmp.lightningrfc",
156 "bolt04/onion-test.json"));
157 if (!json) {
158 printf("test file not found, skipping\n");
159 goto out;
160 }
161 }
162
163 jsmn_init(&parser);
164 if (jsmn_parse(&parser, json, strlen(json), toks, ARRAY_SIZE(toks)) < 0)
165 abort();
166
167 generate_tok = json_get_member(json, toks, "generate");
168 json_to_secret(json, json_get_member(json, generate_tok, "session_key"), &session_key);
169 assoc_data = json_tok_bin_from_hex(tmpctx, json, json_get_member(json, generate_tok, "associated_data"));
170 sp = sphinx_path_new_with_key(tmpctx, assoc_data, tal_bytelen(assoc_data),
171 &session_key);
172 json_for_each_arr(i, t, json_get_member(json, generate_tok, "hops")) {
173 struct pubkey k;
174 const u8 *cursor;
175 size_t max, len;
176
177 json_to_pubkey(json, json_get_member(json, t, "pubkey"), &k);
178 payloads[i] = json_tok_bin_from_hex(NULL, json, json_get_member(json, t, "payload"));
179 /* First byte(s) are length: check and remove them for our API. */
180 cursor = payloads[i];
181 max = tal_bytelen(payloads[i]);
182 len = fromwire_bigsize(&cursor, &max);
183 assert(len == max);
184 sphinx_add_hop(sp, &k, take(tal_dup_arr(NULL, u8, cursor, max, 0)));
185 }
186 assert(i == ARRAY_SIZE(payloads));
187
188 op = create_onionpacket(tmpctx, sp, ROUTING_INFO_SIZE, &unused_path_secrets);
189
190 expected = json_tok_bin_from_hex(tmpctx, json, json_get_member(json, toks, "onion"));

Callers

nothing calls this directly

Calls 15

common_setupFunction · 0.85
grab_file_strFunction · 0.85
path_joinFunction · 0.85
abortFunction · 0.85
json_get_memberFunction · 0.85
json_to_secretFunction · 0.85
sphinx_path_new_with_keyFunction · 0.85
tal_bytelenFunction · 0.85
sphinx_add_hopFunction · 0.85
create_onionpacketFunction · 0.85
serialize_onionpacketFunction · 0.85
parse_onionpacketFunction · 0.85

Tested by

no test coverage detected