Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production node epic #50

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/backend/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ pub async fn write_file<'a>(
trace!("Check catalog at {path:?}");

if path.exists() {
if name.is_some() {
// Is a named catalog, so the old one must be versioned
}
return Err(anyhow!("This file already exists for this public key."));
}

Expand Down
5 changes: 4 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct SysCfgFile {
pub struct SysCfg {
pub http_port: u16,
pub private_key: SecretKey,
pub public_key: PublicKey,
pub drive_redundancy: usize,
pub volumes: Vec<Volume>,
/// Total allocated capacity for the node in megabytes
Expand Down Expand Up @@ -83,7 +84,8 @@ pub fn init_sys_cfg() -> Result<SysCfg> {
.unwrap_or_else(|| SecretKey::new(&mut rand::thread_rng()));

let secp = Secp256k1::new();
info!("Node Public Key: {}", private_key.public_key(&secp));
let public_key = private_key.public_key(&secp);
info!("Node Public Key: {public_key}");

let drive_redundancy = sys_cfg.drive_redundancy.unwrap_or(1);

Expand Down Expand Up @@ -115,6 +117,7 @@ pub fn init_sys_cfg() -> Result<SysCfg> {
let config = SysCfg {
http_port,
private_key,
public_key,
drive_redundancy,
volumes,
capacity,
Expand Down
14 changes: 4 additions & 10 deletions src/frontend/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ use bytes::BytesMut;
use futures_util::{stream, StreamExt};
use log::{debug, info, trace};
use percent_encoding::{percent_decode_str, utf8_percent_encode, FORM};
use secp256k1::PublicKey;
use tower_http::cors::CorsLayer;

use crate::{
backend::fs::{delete_file, read_file, write_file, FileStream},
config::{node_shared_secret, SYS_CFG},
config::SYS_CFG,
prelude::*,
};

Expand Down Expand Up @@ -127,13 +126,8 @@ async fn remove_file(
Ok((StatusCode::OK, blake3_hash))
}

async fn key(Path(pk): Path<String>) -> Result<impl IntoResponse, AppError> {
let pk = PublicKey::from_str(&pk)?;

let ss = node_shared_secret(&pk)?;
let ss = ss.display_secret();

Ok(ss.to_string())
async fn id() -> Result<impl IntoResponse, AppError> {
Ok(SYS_CFG.public_key.to_string())
}

pub async fn start() -> Result<()> {
Expand All @@ -143,7 +137,7 @@ pub async fn start() -> Result<()> {
.route("/store_named/:pk/:name", post(post_file_named))
.route("/retrieve/:pk/:blake3_hash", get(get_file))
.route("/retrieve_named/:pk/:name", get(get_file_named))
.route("/key/:pk", get(key))
.route("/id", get(id))
// .route("/catalog/:blake3_hash", get(get_catalog))
// .route("/raw/:bao_hash", get(get_raw))
.layer(CorsLayer::permissive());
Expand Down