MCPcopy Create free account
hub / github.com/civkit/civkit-node / run

Method run

src/peerhandler.rs:88–118  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

86 }
87
88 pub async fn run(&self) {
89 loop {
90 let one_second = Duration::from_secs(1);
91
92 sleep(one_second);
93
94 let mut local_port = 0;
95 {
96 let mut gateway_receive_lock = self.gateway_receive.lock().unwrap();
97
98 if let Ok(peer) = gateway_receive_lock.try_recv() {
99 local_port = peer.local_port;
100 }
101 }
102 if local_port > 0 {
103 let peer_mngr = self.peer_manager.clone();
104 let secp_ctx = Secp256k1::new();
105 let pubkey = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42;32]).unwrap());
106 let peer_addr = format!("[::1]:{}", local_port).parse().unwrap();
107 println!("[CIVKITD] - NOISE: opening outgoing noise connection!");
108 lightning_net_tokio::connect_outbound(Arc::clone(&peer_mngr), pubkey, peer_addr).await;
109
110 //TODO: the peer key should be read from the Noise connection
111 let secp_ctx = Secp256k1::new();
112 let seckey = SecretKey::from_slice(&[42; 32]).unwrap();
113 let pubkey = PublicKey::from_secret_key(&secp_ctx, &seckey);
114 let nostr_peer = NostrPeer::new(pubkey);
115 log_new_peer_db(nostr_peer);
116 }
117 }
118 }
119}

Callers 1

mainFunction · 0.45

Calls 1

log_new_peer_dbFunction · 0.85

Tested by

no test coverage detected