ACCOUNT CREATION AND LOGIN
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
use crate::ClientEvent;
|
||||
use dashmap::DashMap;
|
||||
use openworm::net::{
|
||||
ClientMsg, ClientRequestMsg, CreateAccount, CreateAccountResp, RecvHandler, RequestId,
|
||||
SERVER_NAME, ServerMsg, ServerRespMsg, SkipServerVerification, recv_uni, send_uni,
|
||||
ClientMsg, ClientRequestMsg, CreateAccount, CreateAccountResp, Login, LoginResp, RecvHandler,
|
||||
RequestId, SERVER_NAME, ServerMsg, ServerRespMsg, SkipServerVerification, recv_uni, send_uni,
|
||||
};
|
||||
use quinn::{
|
||||
ClientConfig, Connection, Endpoint, IdleTimeout, TransportConfig,
|
||||
@@ -10,6 +10,7 @@ use quinn::{
|
||||
};
|
||||
use std::{
|
||||
net::{Ipv6Addr, SocketAddr, SocketAddrV6, ToSocketAddrs},
|
||||
str::FromStr,
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
};
|
||||
@@ -83,7 +84,7 @@ impl RequestMsg for CreateAccount {
|
||||
type Result = CreateAccountResp;
|
||||
|
||||
fn result(msg: ServerMsg) -> Option<Self::Result> {
|
||||
if let ServerMsg::CreateAccount(res) = msg {
|
||||
if let ServerMsg::CreateAccountResp(res) = msg {
|
||||
Some(res)
|
||||
} else {
|
||||
None
|
||||
@@ -91,19 +92,41 @@ impl RequestMsg for CreateAccount {
|
||||
}
|
||||
}
|
||||
|
||||
async fn connection_cert(addr: SocketAddr, cert: CertificateDer) -> NetResult<Connection> {
|
||||
impl RequestMsg for Login {
|
||||
type Result = LoginResp;
|
||||
|
||||
fn result(msg: ServerMsg) -> Option<Self::Result> {
|
||||
if let ServerMsg::LoginResp(res) = msg {
|
||||
Some(res)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn connection_cert(
|
||||
addr: SocketAddr,
|
||||
cert: CertificateDer<'_>,
|
||||
) -> NetResult<(Endpoint, Connection)> {
|
||||
let mut roots = quinn::rustls::RootCertStore::empty();
|
||||
roots.add(cert);
|
||||
roots
|
||||
.add(cert)
|
||||
.map_err(|e| format!("Invalid Certificate: {e:?}"))?;
|
||||
let client_crypto = quinn::rustls::ClientConfig::builder()
|
||||
.with_root_certificates(roots)
|
||||
.with_no_client_auth();
|
||||
let client_config = ClientConfig::new(Arc::new(QuicClientConfig::try_from(client_crypto)?));
|
||||
let mut endpoint = quinn::Endpoint::client(SocketAddr::from_str("[::]:0").unwrap())?;
|
||||
let client_config = ClientConfig::new(Arc::new(
|
||||
QuicClientConfig::try_from(client_crypto).map_err(|e| e.to_string())?,
|
||||
));
|
||||
let mut endpoint = quinn::Endpoint::client(SocketAddr::from_str("[::]:0").unwrap())
|
||||
.map_err(|e| e.to_string())?;
|
||||
endpoint.set_default_client_config(client_config);
|
||||
endpoint
|
||||
.connect(addr, SERVER_NAME)?
|
||||
let conn = endpoint
|
||||
.connect(addr, SERVER_NAME)
|
||||
.map_err(|e| e.to_string())?
|
||||
.await
|
||||
.map_err(|e| format!("failed to connect: {}", e))
|
||||
.map_err(|e| format!("failed to connect: {}", e))?;
|
||||
Ok((endpoint, conn))
|
||||
}
|
||||
|
||||
async fn connection_no_cert(addr: SocketAddr) -> NetResult<(Endpoint, Connection)> {
|
||||
@@ -148,7 +171,7 @@ impl NetHandle {
|
||||
.map_err(|e| e.to_string())?
|
||||
.next()
|
||||
.ok_or("no addresses found".to_string())?;
|
||||
let (endpoint, conn) = connection_cert(addr).await?;
|
||||
let (endpoint, conn) = connection_cert(addr, cert).await?;
|
||||
let conn_ = conn.clone();
|
||||
|
||||
let mut req_id = RequestId::first();
|
||||
|
||||
Reference in New Issue
Block a user