[Fix] API
This commit is contained in:
parent
16006dc26e
commit
17da3ec0a3
8 changed files with 19 additions and 28 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use crate::get_public_key;
|
||||
use crate::server::omikron_manager::get_random_omikron;
|
||||
use crate::sql::sql;
|
||||
use crate::sql::user_online_tracker::get_iota_primary_omikron_connection;
|
||||
use crate::transport::omikron_manager::get_random_omikron;
|
||||
use crate::{
|
||||
sql::sql::{get_by_user_id, get_omikron_by_id},
|
||||
util::crypto_helper::public_key_to_base64,
|
||||
|
|
@ -272,10 +272,3 @@ pub async fn handle(path: &str, body_string: Option<String>) -> HttpResponse {
|
|||
.insert_header((header::ACCESS_CONTROL_ALLOW_METHODS, "GET, POST, OPTIONS"))
|
||||
.body(body_bytes)
|
||||
}
|
||||
|
||||
pub fn bad_request() -> (StatusCode, String) {
|
||||
(StatusCode::BAD_REQUEST, "400 Bad Request".to_string())
|
||||
}
|
||||
pub fn not_found() -> (StatusCode, String) {
|
||||
(StatusCode::NOT_FOUND, "404 Not Found".to_string())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
pub mod api;
|
||||
pub mod omikron_connection;
|
||||
pub mod omikron_manager;
|
||||
pub mod server;
|
||||
pub mod short_link;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,39 +0,0 @@
|
|||
use crate::server::omikron_connection::OmikronConnection;
|
||||
use dashmap::DashMap;
|
||||
use once_cell::sync::Lazy;
|
||||
use rand::prelude::IteratorRandom;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub static OMIKRON_CONNECTIONS: Lazy<DashMap<i64, Arc<OmikronConnection>>> =
|
||||
Lazy::new(|| DashMap::new());
|
||||
|
||||
pub async fn add_omikron(conn: Arc<OmikronConnection>) {
|
||||
let id = match conn.clone().get_omikron_id().await {
|
||||
Some(id) => id,
|
||||
_ => {
|
||||
conn.close().await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(old) = OMIKRON_CONNECTIONS.insert(id, conn.clone()) {
|
||||
old.close().await;
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn remove_omikron(omikron_id: i64) {
|
||||
OMIKRON_CONNECTIONS.remove(&omikron_id);
|
||||
}
|
||||
pub async fn get_random_omikron() -> Result<Arc<OmikronConnection>, ()> {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let keys: Vec<_> = OMIKRON_CONNECTIONS.iter().map(|e| *e.key()).collect();
|
||||
|
||||
if let Some(key) = keys.into_iter().choose(&mut rng) {
|
||||
if let Some(entry) = OMIKRON_CONNECTIONS.get(&key) {
|
||||
return Ok(entry.clone());
|
||||
}
|
||||
}
|
||||
|
||||
Err(())
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{
|
||||
log,
|
||||
server::{api, short_link::get_short_link},
|
||||
util::file_util::get_directory,
|
||||
util::file_util::load_file_buf,
|
||||
};
|
||||
|
||||
use actix_web::{App, HttpRequest, HttpResponse, HttpServer, Responder, http::header, web};
|
||||
|
|
@ -10,14 +10,10 @@ use rustls::ServerConfig;
|
|||
use rustls::pki_types::{CertificateDer, PrivateKeyDer};
|
||||
use rustls_pemfile::{certs, pkcs8_private_keys};
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
|
||||
pub async fn start(port: u16) -> anyhow::Result<()> {
|
||||
let mut cert_reader =
|
||||
BufReader::new(File::open(format!("{}/certs/cert.pem", get_directory()))?);
|
||||
let mut cert_reader = load_file_buf("certs", "server_cert.pem")?;
|
||||
|
||||
let mut key_reader = BufReader::new(File::open(format!("{}/certs/key.pem", get_directory()))?);
|
||||
let mut key_reader = load_file_buf("certs", "server_key.pem")?;
|
||||
|
||||
let cert_chain: Vec<CertificateDer<'static>> =
|
||||
certs(&mut cert_reader).collect::<Result<_, _>>()?;
|
||||
|
|
|
|||
Loading…
Reference in a new issue