3232#define HEADER_LEN crypto_secretstream_xchacha20poly1305_HEADERBYTES
3333#define ABYTES crypto_secretstream_xchacha20poly1305_ABYTES
3434
35- struct pubkey id ;
36- u32 blockheight ;
37- u16 cltv_final ;
38- bool disable_connect ;
39- bool dev_invoice_bpath_scid ;
40- struct short_channel_id * dev_invoice_internal_scid ;
41- struct secret invoicesecret_base ;
42- struct secret offerblinding_base ;
43- struct secret nodealias_base ;
44- static struct gossmap * global_gossmap ;
45-
46- static void init_gossmap (struct plugin * plugin )
35+ struct offers_data * get_offers_data (struct plugin * plugin )
4736{
48- global_gossmap
49- = notleak_with_children (gossmap_load (plugin ,
50- GOSSIP_STORE_FILENAME ,
51- plugin_gossmap_logcb ,
52- plugin ));
53- if (!global_gossmap )
37+ return plugin_get_data (plugin , struct offers_data );
38+ }
39+
40+ static void init_gossmap (struct plugin * plugin ,
41+ struct offers_data * od )
42+ {
43+ od -> global_gossmap_ = gossmap_load (plugin ,
44+ GOSSIP_STORE_FILENAME ,
45+ plugin_gossmap_logcb ,
46+ plugin );
47+ if (!od -> global_gossmap_ )
5448 plugin_err (plugin , "Could not load gossmap %s: %s" ,
5549 GOSSIP_STORE_FILENAME , strerror (errno ));
5650}
5751
5852struct gossmap * get_gossmap (struct plugin * plugin )
5953{
60- if (!global_gossmap )
61- init_gossmap (plugin );
54+ struct offers_data * od = get_offers_data (plugin );
55+ if (!od -> global_gossmap_ )
56+ init_gossmap (plugin , od );
6257 else
63- gossmap_refresh (global_gossmap );
64- return global_gossmap ;
58+ gossmap_refresh (od -> global_gossmap_ );
59+ return od -> global_gossmap_ ;
6560}
6661
6762/* BOLT #12:
@@ -71,6 +66,7 @@ struct gossmap *get_gossmap(struct plugin *plugin)
7166 */
7267bool we_want_blinded_path (struct plugin * plugin , bool for_payment )
7368{
69+ const struct offers_data * od = get_offers_data (plugin );
7470 struct node_id local_nodeid ;
7571 const struct gossmap_node * node ;
7672 const u8 * nannounce ;
@@ -82,7 +78,7 @@ bool we_want_blinded_path(struct plugin *plugin, bool for_payment)
8278 u8 rgb_color [3 ], alias [32 ];
8379 struct tlv_node_ann_tlvs * na_tlvs ;
8480
85- node_id_from_pubkey (& local_nodeid , & id );
81+ node_id_from_pubkey (& local_nodeid , & od -> id );
8682
8783 node = gossmap_find_node (gossmap , & local_nodeid );
8884 if (!node )
@@ -237,6 +233,7 @@ send_onion_reply(struct command *cmd,
237233 struct blinded_path * reply_path ,
238234 struct tlv_onionmsg_tlv * payload )
239235{
236+ const struct offers_data * od = get_offers_data (cmd -> plugin );
240237 struct onion_reply * onion_reply ;
241238
242239 onion_reply = tal (cmd , struct onion_reply );
@@ -253,8 +250,8 @@ send_onion_reply(struct command *cmd,
253250 }
254251
255252 return establish_onion_path (cmd , get_gossmap (cmd -> plugin ),
256- & id , & onion_reply -> reply_path -> first_node_id .pubkey ,
257- disable_connect ,
253+ & od -> id , & onion_reply -> reply_path -> first_node_id .pubkey ,
254+ od -> disable_connect ,
258255 send_onion_reply_after_established ,
259256 send_onion_reply_not_established ,
260257 onion_reply );
@@ -433,8 +430,9 @@ static struct command_result *block_added_notify(struct command *cmd,
433430 const char * buf ,
434431 const jsmntok_t * params )
435432{
433+ struct offers_data * od = get_offers_data (cmd -> plugin );
436434 const char * err = json_scan (cmd , buf , params , "{block_added:{height:%}}" ,
437- JSON_SCAN (json_to_u32 , & blockheight ));
435+ JSON_SCAN (json_to_u32 , & od -> blockheight ));
438436 if (err )
439437 plugin_err (cmd -> plugin , "Failed to parse block_added (%.*s): %s" ,
440438 json_tok_full_len (params ),
@@ -1620,34 +1618,36 @@ static const char *init(struct command *init_cmd,
16201618 const char * buf UNUSED ,
16211619 const jsmntok_t * config UNUSED )
16221620{
1621+ struct offers_data * od = get_offers_data (init_cmd -> plugin );
1622+
16231623 rpc_scan (init_cmd , "getinfo" ,
16241624 take (json_out_obj (NULL , NULL , NULL )),
1625- "{id:%}" , JSON_SCAN (json_to_pubkey , & id ));
1625+ "{id:%}" , JSON_SCAN (json_to_pubkey , & od -> id ));
16261626
16271627 rpc_scan (init_cmd , "getchaininfo" ,
16281628 take (json_out_obj (NULL , "last_height" , NULL )),
1629- "{headercount:%}" , JSON_SCAN (json_to_u32 , & blockheight ));
1629+ "{headercount:%}" , JSON_SCAN (json_to_u32 , & od -> blockheight ));
16301630
16311631 rpc_scan (init_cmd , "listconfigs" ,
16321632 take (json_out_obj (NULL , NULL , NULL )),
16331633 "{configs:"
16341634 "{cltv-final:{value_int:%}}}" ,
1635- JSON_SCAN (json_to_u16 , & cltv_final ));
1635+ JSON_SCAN (json_to_u16 , & od -> cltv_final ));
16361636
16371637 rpc_scan (init_cmd , "makesecret" ,
16381638 take (json_out_obj (NULL , "string" , BOLT12_ID_BASE_STRING )),
16391639 "{secret:%}" ,
1640- JSON_SCAN (json_to_secret , & invoicesecret_base ));
1640+ JSON_SCAN (json_to_secret , & od -> invoicesecret_base ));
16411641
16421642 rpc_scan (init_cmd , "makesecret" ,
16431643 take (json_out_obj (NULL , "string" , "offer-blinded-path" )),
16441644 "{secret:%}" ,
1645- JSON_SCAN (json_to_secret , & offerblinding_base ));
1645+ JSON_SCAN (json_to_secret , & od -> offerblinding_base ));
16461646
16471647 rpc_scan (init_cmd , "makesecret" ,
16481648 take (json_out_obj (NULL , "string" , NODE_ALIAS_BASE_STRING )),
16491649 "{secret:%}" ,
1650- JSON_SCAN (json_to_secret , & nodealias_base ));
1650+ JSON_SCAN (json_to_secret , & od -> nodealias_base ));
16511651
16521652 return NULL ;
16531653}
@@ -1708,22 +1708,28 @@ static bool scid_jsonfmt(struct plugin *plugin, struct json_stream *js, const ch
17081708int main (int argc , char * argv [])
17091709{
17101710 setup_locale ();
1711+ struct offers_data * od = tal (NULL , struct offers_data );
1712+
1713+ od -> disable_connect = false;
1714+ od -> dev_invoice_bpath_scid = false;
1715+ od -> dev_invoice_internal_scid = NULL ;
1716+ od -> global_gossmap_ = NULL ;
17111717
17121718 /* We deal in UTC; mktime() uses local time */
17131719 setenv ("TZ" , "" , 1 );
1714- plugin_main (argv , init , NULL , PLUGIN_RESTARTABLE , true, NULL ,
1720+ plugin_main (argv , init , take ( od ) , PLUGIN_RESTARTABLE , true, NULL ,
17151721 commands , ARRAY_SIZE (commands ),
17161722 notifications , ARRAY_SIZE (notifications ),
17171723 hooks , ARRAY_SIZE (hooks ),
17181724 NULL , 0 ,
17191725 plugin_option ("fetchinvoice-noconnect" , "flag" ,
17201726 "Don't try to connect directly to fetch/pay an invoice." ,
1721- flag_option , flag_jsonfmt , & disable_connect ),
1727+ flag_option , flag_jsonfmt , & od -> disable_connect ),
17221728 plugin_option_dev ("dev-invoice-bpath-scid" , "flag" ,
17231729 "Use short_channel_id instead of pubkey when creating a blinded payment path" ,
1724- flag_option , flag_jsonfmt , & dev_invoice_bpath_scid ),
1730+ flag_option , flag_jsonfmt , & od -> dev_invoice_bpath_scid ),
17251731 plugin_option_dev ("dev-invoice-internal-scid" , "string" ,
17261732 "Use short_channel_id instead of pubkey when creating a blinded payment path" ,
1727- scid_option , scid_jsonfmt , & dev_invoice_internal_scid ),
1733+ scid_option , scid_jsonfmt , & od -> dev_invoice_internal_scid ),
17281734 NULL );
17291735}
0 commit comments