This commit is contained in:
2025-11-15 02:23:32 -05:00
parent 2e00389033
commit b7f2d8b7c3
2 changed files with 13 additions and 9 deletions

View File

@@ -9,9 +9,9 @@ use std::{
};
use tokio::sync::mpsc::UnboundedSender;
pub fn connect(handle: AppHandle) {
pub fn connect(handle: AppHandle, ip: String) {
std::thread::spawn(|| {
connect_the(handle).unwrap();
connect_the(handle, ip).unwrap();
});
}
@@ -22,7 +22,7 @@ pub enum NetCmd {
pub type NetSender = UnboundedSender<NetCmd>;
#[tokio::main]
async fn connect_the(handle: AppHandle) -> anyhow::Result<()> {
async fn connect_the(handle: AppHandle, ip: String) -> anyhow::Result<()> {
let dirs = directories_next::ProjectDirs::from("", "", "openworm").unwrap();
let mut roots = quinn::rustls::RootCertStore::empty();
match fs::read(dirs.data_local_dir().join("cert.der")) {
@@ -43,7 +43,8 @@ async fn connect_the(handle: AppHandle) -> anyhow::Result<()> {
quinn::ClientConfig::new(Arc::new(QuicClientConfig::try_from(client_crypto)?));
let mut endpoint = quinn::Endpoint::client(SocketAddr::from_str("[::]:0").unwrap())?;
endpoint.set_default_client_config(client_config);
let remote = SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 4433);
let remote = SocketAddr::from_str(&ip).unwrap();
// let remote = SocketAddr::new(IpAddr::V6(Ipv6Addr::LOCALHOST), 4433);
let host = "localhost";
let conn = endpoint
.connect(remote, host)?
@@ -64,7 +65,9 @@ async fn connect_the(handle: AppHandle) -> anyhow::Result<()> {
drop(recv);
send.write_all(content.as_bytes()).await.expect("failed to send");
send.write_all(content.as_bytes())
.await
.expect("failed to send");
send.finish().unwrap();
send.stopped().await.unwrap();
}