3030#define HEADER_LEN crypto_secretstream_xchacha20poly1305_HEADERBYTES
3131#define ABYTES crypto_secretstream_xchacha20poly1305_ABYTES
3232
33- struct pubkey id ;
34- u32 blockheight ;
35- u16 cltv_final ;
36- bool disable_connect ;
37- bool dev_invoice_bpath_scid ;
38- struct short_channel_id * dev_invoice_internal_scid ;
39- struct secret invoicesecret_base ;
40- struct secret offerblinding_base ;
41- struct secret nodealias_base ;
42- static struct gossmap * global_gossmap ;
43-
44- static void init_gossmap (struct plugin * plugin )
33+ struct offers_data * get_offers_data (struct plugin * plugin )
4534{
46- global_gossmap
47- = notleak_with_children (gossmap_load (plugin ,
48- GOSSIP_STORE_FILENAME ,
49- plugin_gossmap_logcb ,
50- plugin ));
51- if (!global_gossmap )
35+ return plugin_get_data (plugin , struct offers_data );
36+ }
37+
38+ static void init_gossmap (struct plugin * plugin ,
39+ struct offers_data * od )
40+ {
41+ od -> global_gossmap_ = gossmap_load (plugin ,
42+ GOSSIP_STORE_FILENAME ,
43+ plugin_gossmap_logcb ,
44+ plugin );
45+ if (!od -> global_gossmap_ )
5246 plugin_err (plugin , "Could not load gossmap %s: %s" ,
5347 GOSSIP_STORE_FILENAME , strerror (errno ));
5448}
5549
5650struct gossmap * get_gossmap (struct plugin * plugin )
5751{
58- if (!global_gossmap )
59- init_gossmap (plugin );
52+ struct offers_data * od = get_offers_data (plugin );
53+ if (!od -> global_gossmap_ )
54+ init_gossmap (plugin , od );
6055 else
61- gossmap_refresh (global_gossmap );
62- return global_gossmap ;
56+ gossmap_refresh (od -> global_gossmap_ );
57+ return od -> global_gossmap_ ;
6358}
6459
6560/* BOLT #12:
@@ -69,6 +64,7 @@ struct gossmap *get_gossmap(struct plugin *plugin)
6964 */
7065bool we_want_blinded_path (struct plugin * plugin , bool for_payment )
7166{
67+ const struct offers_data * od = get_offers_data (plugin );
7268 struct node_id local_nodeid ;
7369 const struct gossmap_node * node ;
7470 const u8 * nannounce ;
@@ -80,7 +76,7 @@ bool we_want_blinded_path(struct plugin *plugin, bool for_payment)
8076 u8 rgb_color [3 ], alias [32 ];
8177 struct tlv_node_ann_tlvs * na_tlvs ;
8278
83- node_id_from_pubkey (& local_nodeid , & id );
79+ node_id_from_pubkey (& local_nodeid , & od -> id );
8480
8581 node = gossmap_find_node (gossmap , & local_nodeid );
8682 if (!node )
@@ -235,6 +231,7 @@ send_onion_reply(struct command *cmd,
235231 struct blinded_path * reply_path ,
236232 struct tlv_onionmsg_tlv * payload )
237233{
234+ const struct offers_data * od = get_offers_data (cmd -> plugin );
238235 struct onion_reply * onion_reply ;
239236
240237 onion_reply = tal (cmd , struct onion_reply );
@@ -251,8 +248,8 @@ send_onion_reply(struct command *cmd,
251248 }
252249
253250 return establish_onion_path (cmd , get_gossmap (cmd -> plugin ),
254- & id , & onion_reply -> reply_path -> first_node_id .pubkey ,
255- disable_connect ,
251+ & od -> id , & onion_reply -> reply_path -> first_node_id .pubkey ,
252+ od -> disable_connect ,
256253 send_onion_reply_after_established ,
257254 send_onion_reply_not_established ,
258255 onion_reply );
@@ -425,8 +422,9 @@ static struct command_result *block_added_notify(struct command *cmd,
425422 const char * buf ,
426423 const jsmntok_t * params )
427424{
425+ struct offers_data * od = get_offers_data (cmd -> plugin );
428426 const char * err = json_scan (cmd , buf , params , "{block_added:{height:%}}" ,
429- JSON_SCAN (json_to_u32 , & blockheight ));
427+ JSON_SCAN (json_to_u32 , & od -> blockheight ));
430428 if (err )
431429 plugin_err (cmd -> plugin , "Failed to parse block_added (%.*s): %s" ,
432430 json_tok_full_len (params ),
@@ -1515,34 +1513,36 @@ static const char *init(struct command *init_cmd,
15151513 const char * buf UNUSED ,
15161514 const jsmntok_t * config UNUSED )
15171515{
1516+ struct offers_data * od = get_offers_data (init_cmd -> plugin );
1517+
15181518 rpc_scan (init_cmd , "getinfo" ,
15191519 take (json_out_obj (NULL , NULL , NULL )),
1520- "{id:%}" , JSON_SCAN (json_to_pubkey , & id ));
1520+ "{id:%}" , JSON_SCAN (json_to_pubkey , & od -> id ));
15211521
15221522 rpc_scan (init_cmd , "getchaininfo" ,
15231523 take (json_out_obj (NULL , "last_height" , NULL )),
1524- "{headercount:%}" , JSON_SCAN (json_to_u32 , & blockheight ));
1524+ "{headercount:%}" , JSON_SCAN (json_to_u32 , & od -> blockheight ));
15251525
15261526 rpc_scan (init_cmd , "listconfigs" ,
15271527 take (json_out_obj (NULL , NULL , NULL )),
15281528 "{configs:"
15291529 "{cltv-final:{value_int:%}}}" ,
1530- JSON_SCAN (json_to_u16 , & cltv_final ));
1530+ JSON_SCAN (json_to_u16 , & od -> cltv_final ));
15311531
15321532 rpc_scan (init_cmd , "makesecret" ,
15331533 take (json_out_obj (NULL , "string" , BOLT12_ID_BASE_STRING )),
15341534 "{secret:%}" ,
1535- JSON_SCAN (json_to_secret , & invoicesecret_base ));
1535+ JSON_SCAN (json_to_secret , & od -> invoicesecret_base ));
15361536
15371537 rpc_scan (init_cmd , "makesecret" ,
15381538 take (json_out_obj (NULL , "string" , "offer-blinded-path" )),
15391539 "{secret:%}" ,
1540- JSON_SCAN (json_to_secret , & offerblinding_base ));
1540+ JSON_SCAN (json_to_secret , & od -> offerblinding_base ));
15411541
15421542 rpc_scan (init_cmd , "makesecret" ,
15431543 take (json_out_obj (NULL , "string" , NODE_ALIAS_BASE_STRING )),
15441544 "{secret:%}" ,
1545- JSON_SCAN (json_to_secret , & nodealias_base ));
1545+ JSON_SCAN (json_to_secret , & od -> nodealias_base ));
15461546
15471547 return NULL ;
15481548}
@@ -1599,22 +1599,27 @@ static bool scid_jsonfmt(struct plugin *plugin, struct json_stream *js, const ch
15991599int main (int argc , char * argv [])
16001600{
16011601 setup_locale ();
1602+ struct offers_data * od = tal (NULL , struct offers_data );
1603+
1604+ od -> disable_connect = false;
1605+ od -> dev_invoice_bpath_scid = false;
1606+ od -> dev_invoice_internal_scid = NULL ;
16021607
16031608 /* We deal in UTC; mktime() uses local time */
16041609 setenv ("TZ" , "" , 1 );
1605- plugin_main (argv , init , NULL , PLUGIN_RESTARTABLE , true, NULL ,
1610+ plugin_main (argv , init , take ( od ) , PLUGIN_RESTARTABLE , true, NULL ,
16061611 commands , ARRAY_SIZE (commands ),
16071612 notifications , ARRAY_SIZE (notifications ),
16081613 hooks , ARRAY_SIZE (hooks ),
16091614 NULL , 0 ,
16101615 plugin_option ("fetchinvoice-noconnect" , "flag" ,
16111616 "Don't try to connect directly to fetch/pay an invoice." ,
1612- flag_option , flag_jsonfmt , & disable_connect ),
1617+ flag_option , flag_jsonfmt , & od -> disable_connect ),
16131618 plugin_option_dev ("dev-invoice-bpath-scid" , "flag" ,
16141619 "Use short_channel_id instead of pubkey when creating a blinded payment path" ,
1615- flag_option , flag_jsonfmt , & dev_invoice_bpath_scid ),
1620+ flag_option , flag_jsonfmt , & od -> dev_invoice_bpath_scid ),
16161621 plugin_option_dev ("dev-invoice-internal-scid" , "string" ,
16171622 "Use short_channel_id instead of pubkey when creating a blinded payment path" ,
1618- scid_option , scid_jsonfmt , & dev_invoice_internal_scid ),
1623+ scid_option , scid_jsonfmt , & od -> dev_invoice_internal_scid ),
16191624 NULL );
16201625}
0 commit comments