more work on identity->chat hello/handshake

This commit is contained in:
sam 2024-01-18 21:44:53 +01:00
parent 1e53661b0a
commit 041531e88a
12 changed files with 96 additions and 40 deletions

View file

@ -1,5 +1,5 @@
mod node;
mod account;
mod node;
use std::sync::Arc;

View file

@ -2,9 +2,8 @@ use std::sync::Arc;
use axum::{Extension, Json, extract::Path};
use eyre::{Context, Result};
use foxchat::http::ApiError;
use foxchat::{http::ApiError, s2s::http::NodeResponse};
use rsa::pkcs1::EncodeRsaPublicKey;
use serde::Serialize;
use crate::{app_state::AppState, model::{instance::Instance, chat_instance::ChatInstance}};
@ -19,19 +18,13 @@ pub async fn get_node(
.wrap_err("serializing public key")?;
Ok(Json(NodeResponse {
software: NODE_SOFTWARE,
software: NODE_SOFTWARE.into(),
public_key,
}))
}
const NODE_SOFTWARE: &str = "foxchat_ident";
#[derive(Serialize)]
pub struct NodeResponse {
pub software: &'static str,
pub public_key: String,
}
pub async fn get_chat_node(
Extension(state): Extension<Arc<AppState>>,
Path(domain): Path<String>,

View file

@ -4,11 +4,10 @@ mod db;
mod http;
mod model;
use std::net::{Ipv4Addr, SocketAddrV4};
use crate::config::Config;
use clap::{Parser, Subcommand};
use color_eyre::eyre::Result;
use std::net::{Ipv4Addr, SocketAddrV4};
use tokio::net::TcpListener;
use tracing::info;

View file

@ -1,7 +1,11 @@
use std::sync::Arc;
use eyre::Result;
use foxchat::{fed::{self, request::is_valid_domain}, FoxError};
use foxchat::{
fed::{self, request::is_valid_domain},
s2s::http::{HelloRequest, HelloResponse},
FoxError,
};
use serde::{Deserialize, Serialize};
use ulid::Ulid;
@ -47,9 +51,9 @@ impl ChatInstance {
let resp: HelloResponse = fed::post(
&current_instance.private_key,
state.config.domain.clone(),
domain.clone(),
"/_fox/chat/hello".into(),
&state.config.domain,
&domain,
"/_fox/chat/hello",
None,
&HelloRequest {
host: state.config.domain.clone(),
@ -78,14 +82,3 @@ impl ChatInstance {
Ok(instance)
}
}
#[derive(Serialize, Debug)]
struct HelloRequest {
pub host: String,
}
#[derive(Deserialize, Debug)]
struct HelloResponse {
pub public_key: String,
pub host: String,
}