]> git.bitcoin.ninja Git - ldk-java/commitdiff
[TS] Throw a reasonable error if two `NodeLDKNet`s are on one `PM`
authorMatt Corallo <git@bluematt.me>
Wed, 15 Mar 2023 17:33:37 +0000 (17:33 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 17 Mar 2023 23:18:02 +0000 (23:18 +0000)
node-net/net.mts

index 797bc7a7a47907920d9b00039d643cd82cd21133..9e16ab32601da75ded82e13e98d505ee9f27fac5 100644 (file)
@@ -8,6 +8,12 @@ export class NodeLDKNet {
        private ping_timer;
        private servers: net.Server[];
        public constructor(public peer_manager: ldk.PeerManager) {
+               // @ts-ignore
+               if (peer_manager._node_ldk_net_singleton_check != undefined) {
+                       throw "Only one NdoeLDKNet should exist per PeerManager";
+               }
+               // @ts-ignore
+               peer_manager._node_ldk_net_singleton_check = this;
                this.ping_timer = setInterval(function() {
                        peer_manager.timer_tick_occurred();
                        peer_manager.process_events();
@@ -24,6 +30,8 @@ export class NodeLDKNet {
                        server.close();
                }
                this.peer_manager.disconnect_all_peers();
+               // @ts-ignore
+               delete this.peer_manager._node_ldk_net_singleton_check;
        }
 
        /**