key server mostly works

This commit is contained in:
waalge 2025-03-07 14:26:02 +00:00
parent 33b7dc5d8e
commit 4183fe6ec8
4 changed files with 78 additions and 10 deletions

View File

@ -1,4 +1,3 @@
use ed25519_dalek::ed25519::signature::SignerMut;
use std::error::Error;
use tokio::{io, io::AsyncBufReadExt, select};
@ -7,13 +6,12 @@ use libp2p::{
mdns,
request_response::{self, ProtocolSupport},
swarm::SwarmEvent,
Multiaddr,
};
use tracing_subscriber::EnvFilter;
use cll2v0::{
keys,
messages::MyRequest,
messages::{MyRequest, MyResult},
protocol::{mk_swarm, MyBehaviourEvent},
};
@ -148,7 +146,14 @@ pub async fn start(params: ClientParams) -> Result<(), Box<dyn Error>> {
message: libp2p::request_response::Message::Response { response, .. },
})) => {
// println!("response : {:?} {:?} {:?}", peer, request_id, "" );
println!("RESSIG : {}", hex::encode(response.sig.clone()),);
match response {
MyResult::Okay(response) => {
println!("OKAY : {}", hex::encode(response.sig.clone()),);
}
MyResult::Fail(response) => {
println!("FAIL : {}", response);
}
}
}
e => {
println!("OTHER {:?}", e)

View File

@ -11,7 +11,7 @@ use tracing_subscriber::EnvFilter;
use cll2v0::{
db, keys,
messages::{MyRequest, MyResponse},
messages::{MyRequest, MyResponse, MyResult},
protocol::{mk_swarm, MyBehaviourEvent},
};
@ -106,9 +106,9 @@ pub async fn start(params: ServerParams) -> Result<(), Box<dyn Error>> {
if let Some(skey) = keychain.get(&pkey.to_bytes()) {
let _ = swarm.behaviour_mut().req_res.send_response(
channel,
MyResponse {
MyResult::Okay(MyResponse {
sig: skey.clone().sign(&body).to_bytes().into(),
},
}),
);
} else {
println!("err0")

View File

@ -7,8 +7,71 @@ pub struct MyRequest {
pub sig: Vec<u8>, // FIXME :: fixed length array not supported by serde [u8; 64],
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum MyResult {
Okay(MyResponse),
Fail(i64),
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct MyResponse {
// sig: [u8; 64],
pub sig: Vec<u8>, // FIXME :: fixed length array not supported by serde [u8; 64],
}
// type TestnetMagic = i64;
//
// pub enum NetworkId {
// Mainnet,
// Testnet(TestnetMagic),
// }
//
// type Version = i64;
//
// type Blake2b224Hash = [u8; 24];
// type ScriptHash = Blake2b224Hash;
//
// type TokenName = Vec<u8>;
// type Currency = (ScriptHash, TokenName);
//
// pub struct Init {
// version: Version,
// network_id: NetworkId,
// currencies: Vec<Currency>,
// routing: bool,
// htlc: bool,
// }
//
// type Positive = i64;
// type Natural = i64;
// type Amount = Natural;
// type Markdown = String;
// type Milliseconds = Natural;
//
// type ChannelId = Vec<u8>;
//
// // type ChannelMessage<msg> = (ChannelId, msg)
//
// type VerificationKey = [u8; 32];
//
// pub struct Open {
// currency: Currency,
// funding_amount: Amount,
// gift_amount: Amount,
// respond_period: Milliseconds,
// minimum_depth: Positive,
// max_htlc_amount: Amount,
// max_total_htlc_amount: Amount,
// max_htlc_count: Positive,
// verification_key: VerificationKey,
// }
//
// pub struct Accept {
// respond_period: Milliseconds,
// minimum_depth: Positive,
// min_htlc_amount: Amount,
// max_htlc_amount: Amount,
// max_total_htlc_amount: Amount,
// max_htlc_count: Positive,
// verification_key: VerificationKey,
// }

View File

@ -8,12 +8,12 @@ use libp2p::{
};
use libp2p_identity::ed25519::Keypair;
use crate::messages::{MyRequest, MyResponse};
use crate::messages::{MyRequest, MyResult};
#[derive(NetworkBehaviour)]
pub struct MyBehaviour {
pub mdns: mdns::tokio::Behaviour,
pub req_res: request_response::cbor::Behaviour<MyRequest, MyResponse>,
pub req_res: request_response::cbor::Behaviour<MyRequest, MyResult>,
}
pub fn mk_swarm(
@ -33,7 +33,7 @@ pub fn mk_swarm(
let protocol = [(StreamProtocol::new("/sign-me/1"), protocol_support)];
let config = request_response::Config::default();
let req_res =
request_response::cbor::Behaviour::<MyRequest, MyResponse>::new(protocol, config);
request_response::cbor::Behaviour::<MyRequest, MyResult>::new(protocol, config);
Ok(MyBehaviour { req_res, mdns })
})?
.with_swarm_config(|cfg| cfg.with_idle_connection_timeout(Duration::from_secs(u64::MAX)))