From da4cc4995fd967171738a326a9e51ab0e90032f9 Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Fri, 21 May 2021 19:19:15 +0200 Subject: [PATCH] Add contact info on session info pop-up --- Cargo.lock | 5 +++-- Cargo.toml | 3 ++- src/frontend/index.css | 13 ++++++++++--- src/frontend/index.js | 43 ++++++++++++++++++++++++++++-------------- src/session_manager.rs | 6 +++--- 5 files changed, 47 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2b73c23..717c981 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -395,8 +395,9 @@ dependencies = [ [[package]] name = "async-psec" -version = "0.1.0" -source = "git+https://forge.chapril.org/hardcoresushi/async-psec#9d2713aea1e982d7c0f10a466268f623a87ec5d9" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58ab60657d7b3949c3bdb06570fc4855a4e83dbe6c9da73902c67355dd8f37a8" dependencies = [ "aes-gcm", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 83a0e11..00f0c62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,12 +3,13 @@ name = "aira" version = "0.0.2" authors = ["Hardcore Sushi "] edition = "2018" +exclude = ["src/frontend"] [dependencies] rand = "0.8" rand-7 = { package = "rand", version = "0.7.3" } tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros", "net", "io-util"] } -async-psec = { version = "0.1", git = "https://forge.chapril.org/hardcoresushi/async-psec", features = ["split"] } +async-psec = { version = "0.2", features = ["split"] } lazy_static = "1.4" socket2 = "0.4" rusqlite = { version = "0.25.1", features = ["bundled"] } diff --git a/src/frontend/index.css b/src/frontend/index.css index 8b6e584..c70c700 100644 --- a/src/frontend/index.css +++ b/src/frontend/index.css @@ -194,12 +194,19 @@ label { #session_info .name button::after { content: url("/static/imgs/icons/refresh"); } -#session_info p:first-of-type, #session_info pre { - display: inline-block; +#session_info .session_field { + display: flex; + gap: .3em; } -#session_info p, #session_info pre { +#session_info .session_field p { margin-top: 0; } +#session_info .session_field p:first-child { + color: #34db4a; +} +#session_info .session_field p:last-child { + font-weight: bold; +} .button_row { display: flex; gap: 15px; diff --git a/src/frontend/index.js b/src/frontend/index.js index d9d4754..c6e29ab 100644 --- a/src/frontend/index.js +++ b/src/frontend/index.js @@ -771,6 +771,17 @@ function beautifyFingerprint(f) { } return f; } +function generateSessionField(name, value) { + let div = document.createElement("div"); + div.classList.add("session_field"); + let pName = document.createElement("p"); + pName.textContent = name+':'; + div.appendChild(pName); + let pValue = document.createElement("p"); + pValue.textContent = value; + div.appendChild(pValue); + return div; +} function showSessionInfoPopup() { let session = sessionsData.get(currentSessionId); if (typeof session !== "undefined") { @@ -790,25 +801,29 @@ function showSessionInfoPopup() { nameDiv.appendChild(button); } mainDiv.appendChild(nameDiv); - let pFingerprint = document.createElement("p"); - pFingerprint.textContent = "Fingerprint:"; - mainDiv.appendChild(pFingerprint); - let pre = document.createElement("pre"); - pre.textContent = ' '+beautifyFingerprint(session.fingerprint); - mainDiv.appendChild(pre); if (session.isOnline) { - let pIp = document.createElement("p"); - pIp.textContent = "IP: "+session.ip; - mainDiv.appendChild(pIp); - let pConnection = document.createElement("p"); - pConnection.textContent = "Connection: "; + mainDiv.appendChild(generateSessionField("Peer IP", session.ip)); + let connection; if (session.outgoing) { - pConnection.textContent += "outgoing"; + connection = generateSessionField("Connection", "outgoing"); } else { - pConnection.textContent += "incomming"; + connection = generateSessionField("Connection", "incoming"); } - mainDiv.appendChild(pConnection); + mainDiv.appendChild(connection); } + if (session.isContact) { + mainDiv.appendChild(generateSessionField("Is contact", "yes")); + let isVerified; + if (session.isVerified) { + isVerified = generateSessionField("Is verified", "yes"); + } else { + isVerified = generateSessionField("Is verified", "no"); + } + mainDiv.appendChild(isVerified); + } else { + mainDiv.appendChild(generateSessionField("Is contact", "no")); + } + mainDiv.appendChild(generateSessionField("Fingerprint", beautifyFingerprint(session.fingerprint))); showPopup(mainDiv); } } diff --git a/src/session_manager.rs b/src/session_manager.rs index 4cc21b3..94daa5f 100644 --- a/src/session_manager.rs +++ b/src/session_manager.rs @@ -79,7 +79,7 @@ impl SessionManager { pub async fn connect_to(session_manager: Arc, ip: IpAddr) -> io::Result<()> { let stream = TcpStream::connect(SocketAddr::new(ip, constants::PORT)).await?; - SessionManager::handle_new_session(session_manager, Session::new(stream), true); + SessionManager::handle_new_session(session_manager, Session::from(stream), true); Ok(()) } @@ -448,7 +448,7 @@ impl SessionManager { } }; if let Some(mut session) = session { - let ip = session.get_addr().unwrap().ip(); + let ip = session.peer_addr().unwrap().ip(); let mut is_contact = false; let session_data = { let mut sessions = session_manager.sessions.write().unwrap(); @@ -531,7 +531,7 @@ impl SessionManager { client = server_v4.accept() => client, _ = receiver.recv() => break }).unwrap(); - SessionManager::handle_new_session(session_manager.clone(), Session::new(stream), false); + SessionManager::handle_new_session(session_manager.clone(), Session::from(stream), false); } }); Ok(())