@@ -139,7 +139,7 @@ struct NodeMonitors {
139
139
}
140
140
};
141
141
142
- LDKCResult_NoneChannelMonitorUpdateErrZ add_channel_monitor (const void *this_arg, LDKOutPoint funding_txo_arg, LDKChannelMonitor monitor_arg) {
142
+ LDKChannelMonitorUpdateStatus add_channel_monitor (const void *this_arg, LDKOutPoint funding_txo_arg, LDKChannelMonitor monitor_arg) {
143
143
// First bind the args to C++ objects so they auto-free
144
144
LDK::ChannelMonitor mon (std::move (monitor_arg));
145
145
LDK::OutPoint funding_txo (std::move (funding_txo_arg));
@@ -148,10 +148,10 @@ LDKCResult_NoneChannelMonitorUpdateErrZ add_channel_monitor(const void *this_arg
148
148
std::unique_lock<std::mutex> l (arg->mut );
149
149
150
150
arg->mons .push_back (std::make_pair (std::move (funding_txo), std::move (mon)));
151
- return CResult_NoneChannelMonitorUpdateErrZ_ok ();
151
+ return ChannelMonitorUpdateStatus_completed ();
152
152
}
153
153
static std::atomic_int mons_updated (0 );
154
- LDKCResult_NoneChannelMonitorUpdateErrZ update_channel_monitor (const void *this_arg, LDKOutPoint funding_txo_arg, LDKChannelMonitorUpdate monitor_arg) {
154
+ LDKChannelMonitorUpdateStatus update_channel_monitor (const void *this_arg, LDKOutPoint funding_txo_arg, LDKChannelMonitorUpdate monitor_arg) {
155
155
// First bind the args to C++ objects so they auto-free
156
156
LDK::ChannelMonitorUpdate update (std::move (monitor_arg));
157
157
LDK::OutPoint funding_txo (std::move (funding_txo_arg));
@@ -174,7 +174,7 @@ LDKCResult_NoneChannelMonitorUpdateErrZ update_channel_monitor(const void *this_
174
174
assert (updated);
175
175
176
176
mons_updated += 1 ;
177
- return CResult_NoneChannelMonitorUpdateErrZ_ok ();
177
+ return ChannelMonitorUpdateStatus_completed ();
178
178
}
179
179
LDKCVec_C3Tuple_OutPointCVec_MonitorEventZPublicKeyZZ monitors_pending_monitor_events (const void *this_arg) {
180
180
NodeMonitors* arg = (NodeMonitors*) this_arg;
@@ -369,6 +369,47 @@ class PeersConnection {
369
369
};
370
370
#endif // !REAL_NET
371
371
372
+ struct CustomOnionMsgQueue {
373
+ std::mutex mtx;
374
+ std::vector<LDK::CustomOnionMessageContents> msgs;
375
+ };
376
+
377
+ uint64_t custom_onion_msg_type_id (const void *this_arg) {
378
+ return 8888 ;
379
+ }
380
+ LDKCVec_u8Z custom_onion_msg_bytes (const void *this_arg) {
381
+ uint8_t *bytes = (uint8_t *) malloc (1024 );
382
+ memset (bytes, 43 , 1024 );
383
+ return LDKCVec_u8Z {
384
+ .data = bytes, .datalen = 1024
385
+ };
386
+ }
387
+
388
+ void handle_custom_onion_message (const void * this_arg, struct LDKCustomOnionMessageContents msg) {
389
+ CustomOnionMsgQueue* arg = (CustomOnionMsgQueue*) this_arg;
390
+ std::unique_lock<std::mutex> lck (arg->mtx );
391
+ arg->msgs .push_back (std::move (msg));
392
+ }
393
+
394
+ LDKCustomOnionMessageContents build_custom_onion_message () {
395
+ return LDKCustomOnionMessageContents {
396
+ .this_arg = NULL ,
397
+ .tlv_type = custom_onion_msg_type_id,
398
+ .write = custom_onion_msg_bytes,
399
+ .free = NULL ,
400
+ };
401
+ }
402
+
403
+ LDKCResult_COption_CustomOnionMessageContentsZDecodeErrorZ read_custom_onion_message (const void * this_arg, uint64_t type, LDKu8slice buf) {
404
+ assert (type == 8888 );
405
+ assert (buf.datalen == 1024 );
406
+ uint8_t cmp[1024 ];
407
+ memset (cmp, 43 , 1024 );
408
+ assert (!memcmp (cmp, buf.data , 1024 ));
409
+ return CResult_COption_CustomOnionMessageContentsZDecodeErrorZ_ok (COption_CustomOnionMessageContentsZ_some (build_custom_onion_message ()));
410
+ }
411
+
412
+
372
413
struct CustomMsgQueue {
373
414
std::vector<LDK::Type> msgs;
374
415
};
@@ -534,16 +575,18 @@ int main() {
534
575
node_secret1 = *node_secret1_res->contents .result ;
535
576
536
577
LDK::ChannelManager cm1 = ChannelManager_new (fee_est, mon1, broadcast, logger1, KeysManager_as_KeysInterface (&keys1), UserConfig_default (), ChainParameters_new (network, BestBlock_new (chain_tip, 0 )));
537
- LDK::OnionMessenger om1 = OnionMessenger_new (KeysManager_as_KeysInterface (&keys1), logger1);
578
+
579
+ LDK::IgnoringMessageHandler ignoring_handler1 = IgnoringMessageHandler_new ();
580
+ LDK::CustomMessageHandler custom_msg_handler1 = IgnoringMessageHandler_as_CustomMessageHandler (&ignoring_handler1);
581
+ LDK::CustomOnionMessageHandler custom_onion_msg_handler1 = IgnoringMessageHandler_as_CustomOnionMessageHandler (&ignoring_handler1);
582
+
583
+ LDK::OnionMessenger om1 = OnionMessenger_new (KeysManager_as_KeysInterface (&keys1), logger1, std::move (custom_onion_msg_handler1));
538
584
539
585
LDK::CVec_ChannelDetailsZ channels = ChannelManager_list_channels (&cm1);
540
586
assert (channels->datalen == 0 );
541
587
542
588
LDK::MessageHandler msg_handler1 = MessageHandler_new (ChannelManager_as_ChannelMessageHandler (&cm1), P2PGossipSync_as_RoutingMessageHandler (&graph_msg_handler1), OnionMessenger_as_OnionMessageHandler (&om1));
543
589
544
- LDK::IgnoringMessageHandler ignoring_handler1 = IgnoringMessageHandler_new ();
545
- LDK::CustomMessageHandler custom_msg_handler1 = IgnoringMessageHandler_as_CustomMessageHandler (&ignoring_handler1);
546
-
547
590
random_bytes = keys_source1->get_secure_random_bytes (keys_source1->this_arg );
548
591
LDK::PeerManager net1 = PeerManager_new (std::move (msg_handler1), node_secret1, 0xdeadbeef , &random_bytes.data , logger1, std::move (custom_msg_handler1));
549
592
@@ -567,7 +610,12 @@ int main() {
567
610
UserConfig_set_channel_handshake_config (&config2, std::move (handshake_config2));
568
611
569
612
LDK::ChannelManager cm2 = ChannelManager_new (fee_est, mon2, broadcast, logger2, KeysManager_as_KeysInterface (&keys2), std::move (config2), ChainParameters_new (network, BestBlock_new (chain_tip, 0 )));
570
- LDK::OnionMessenger om2 = OnionMessenger_new (KeysManager_as_KeysInterface (&keys2), logger2);
613
+
614
+ LDK::IgnoringMessageHandler ignoring_handler2 = IgnoringMessageHandler_new ();
615
+ LDK::CustomMessageHandler custom_msg_handler2 = IgnoringMessageHandler_as_CustomMessageHandler (&ignoring_handler2);
616
+ LDK::CustomOnionMessageHandler custom_onion_msg_handler2 = IgnoringMessageHandler_as_CustomOnionMessageHandler (&ignoring_handler2);
617
+
618
+ LDK::OnionMessenger om2 = OnionMessenger_new (KeysManager_as_KeysInterface (&keys2), logger2, std::move (custom_onion_msg_handler2));
571
619
572
620
LDK::CVec_ChannelDetailsZ channels2 = ChannelManager_list_channels (&cm2);
573
621
assert (channels2->datalen == 0 );
@@ -580,9 +628,6 @@ int main() {
580
628
581
629
LDK::MessageHandler msg_handler2 = MessageHandler_new (ChannelManager_as_ChannelMessageHandler (&cm2), std::move (net_msgs2), OnionMessenger_as_OnionMessageHandler (&om1));
582
630
583
- LDK::IgnoringMessageHandler ignoring_handler2 = IgnoringMessageHandler_new ();
584
- LDK::CustomMessageHandler custom_msg_handler2 = IgnoringMessageHandler_as_CustomMessageHandler (&ignoring_handler2);
585
-
586
631
random_bytes = keys_source2->get_secure_random_bytes (keys_source2->this_arg );
587
632
LDK::PeerManager net2 = PeerManager_new (std::move (msg_handler2), node_secret2, 0xdeadbeef , &random_bytes.data , logger2, std::move (custom_msg_handler2));
588
633
@@ -702,7 +747,7 @@ int main() {
702
747
.some = 5000 ,
703
748
};
704
749
LDK::CResult_InvoiceSignOrCreationErrorZ invoice = create_invoice_from_channelmanager (&cm2,
705
- KeysManager_as_KeysInterface (&keys2),
750
+ KeysManager_as_KeysInterface (&keys2), logger2,
706
751
LDKCurrency_Bitcoin, min_value,
707
752
LDKStr {
708
753
.chars = (const uint8_t *)" Invoice Description" ,
@@ -823,7 +868,13 @@ int main() {
823
868
assert (cm1_read->result_ok );
824
869
LDK::ChannelManager cm1 (std::move (cm1_read->contents .result ->b ));
825
870
826
- LDK::OnionMessenger om1 = OnionMessenger_new (KeysManager_as_KeysInterface (&keys1), logger1);
871
+ LDKCustomOnionMessageHandler custom_onion_msg_handler1 = {
872
+ .this_arg = NULL ,
873
+ .handle_custom_message = NULL , // We only create custom messages, not handle them
874
+ .read_custom_message = NULL , // We only create custom messages, not handle them
875
+ .free = NULL ,
876
+ };
877
+ LDK::OnionMessenger om1 = OnionMessenger_new (KeysManager_as_KeysInterface (&keys1), logger1, custom_onion_msg_handler1);
827
878
828
879
LDK::CVec_ChannelMonitorZ mons_list2 = LDKCVec_ChannelMonitorZ { .data = (LDKChannelMonitor*)malloc (sizeof (LDKChannelMonitor)), .datalen = 1 };
829
880
assert (mons2.mons .size () == 1 );
@@ -838,7 +889,14 @@ int main() {
838
889
assert (cm2_read->result_ok );
839
890
LDK::ChannelManager cm2 (std::move (cm2_read->contents .result ->b ));
840
891
841
- LDK::OnionMessenger om2 = OnionMessenger_new (KeysManager_as_KeysInterface (&keys2), logger2);
892
+ CustomOnionMsgQueue peer_2_custom_onion_messages;
893
+ LDKCustomOnionMessageHandler custom_onion_msg_handler2 = {
894
+ .this_arg = &peer_2_custom_onion_messages,
895
+ .handle_custom_message = handle_custom_onion_message,
896
+ .read_custom_message = read_custom_onion_message,
897
+ .free = NULL ,
898
+ };
899
+ LDK::OnionMessenger om2 = OnionMessenger_new (KeysManager_as_KeysInterface (&keys2), logger2, custom_onion_msg_handler2);
842
900
843
901
// Attempt to close the channel...
844
902
uint8_t chan_id[32 ];
@@ -911,7 +969,7 @@ int main() {
911
969
LDK::InvoicePayer payer = InvoicePayer_new (ChannelManager_as_Payer (&cm1), sending_router, logger1, handler1, Retry_attempts (0 ));
912
970
913
971
LDK::CResult_InvoiceSignOrCreationErrorZ invoice_res2 = create_invoice_from_channelmanager (&cm2,
914
- KeysManager_as_KeysInterface (&keys2),
972
+ KeysManager_as_KeysInterface (&keys2), logger1,
915
973
LDKCurrency_Bitcoin, COption_u64Z_some (10000 ),
916
974
LDKStr {
917
975
.chars = (const uint8_t *)" Invoice 2 Description" ,
@@ -991,8 +1049,23 @@ int main() {
991
1049
LDK::CVec_ChannelDetailsZ chans_after_close2 = ChannelManager_list_channels (&cm2);
992
1050
assert (chans_after_close2->datalen == 0 );
993
1051
1052
+ assert (OnionMessenger_send_custom_onion_message (&om1,
1053
+ LDKCVec_PublicKeyZ { .data = NULL , .datalen = 0 , },
1054
+ Destination_node (ChannelManager_get_our_node_id (&cm2)),
1055
+ build_custom_onion_message (), LDKBlindedRoute { .inner = NULL , .is_owned = true })
1056
+ .result_ok );
1057
+ PeerManager_process_events (&net1);
1058
+ while (true ) {
1059
+ std::this_thread::yield ();
1060
+ std::unique_lock<std::mutex> lck (peer_2_custom_onion_messages.mtx );
1061
+ if (peer_2_custom_onion_messages.msgs .size () != 0 ) break ;
1062
+ }
1063
+
994
1064
conn.stop ();
995
1065
1066
+ std::unique_lock<std::mutex> lck (peer_2_custom_onion_messages.mtx );
1067
+ assert (peer_2_custom_onion_messages.msgs .size () == 1 );
1068
+ assert (peer_2_custom_onion_messages.msgs [0 ].tlv_type () == 8888 );
996
1069
assert (peer_2_custom_messages.msgs .size () != 0 );
997
1070
998
1071
// Few extra random tests:
0 commit comments