key server mostly works
This commit is contained in:
parent
33b7dc5d8e
commit
4183fe6ec8
|
@ -1,4 +1,3 @@
|
||||||
use ed25519_dalek::ed25519::signature::SignerMut;
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use tokio::{io, io::AsyncBufReadExt, select};
|
use tokio::{io, io::AsyncBufReadExt, select};
|
||||||
|
|
||||||
|
@ -7,13 +6,12 @@ use libp2p::{
|
||||||
mdns,
|
mdns,
|
||||||
request_response::{self, ProtocolSupport},
|
request_response::{self, ProtocolSupport},
|
||||||
swarm::SwarmEvent,
|
swarm::SwarmEvent,
|
||||||
Multiaddr,
|
|
||||||
};
|
};
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
use cll2v0::{
|
use cll2v0::{
|
||||||
keys,
|
keys,
|
||||||
messages::MyRequest,
|
messages::{MyRequest, MyResult},
|
||||||
protocol::{mk_swarm, MyBehaviourEvent},
|
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, .. },
|
message: libp2p::request_response::Message::Response { response, .. },
|
||||||
})) => {
|
})) => {
|
||||||
// println!("response : {:?} {:?} {:?}", peer, request_id, "" );
|
// 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 => {
|
e => {
|
||||||
println!("OTHER {:?}", e)
|
println!("OTHER {:?}", e)
|
||||||
|
|
|
@ -11,7 +11,7 @@ use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
use cll2v0::{
|
use cll2v0::{
|
||||||
db, keys,
|
db, keys,
|
||||||
messages::{MyRequest, MyResponse},
|
messages::{MyRequest, MyResponse, MyResult},
|
||||||
protocol::{mk_swarm, MyBehaviourEvent},
|
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()) {
|
if let Some(skey) = keychain.get(&pkey.to_bytes()) {
|
||||||
let _ = swarm.behaviour_mut().req_res.send_response(
|
let _ = swarm.behaviour_mut().req_res.send_response(
|
||||||
channel,
|
channel,
|
||||||
MyResponse {
|
MyResult::Okay(MyResponse {
|
||||||
sig: skey.clone().sign(&body).to_bytes().into(),
|
sig: skey.clone().sign(&body).to_bytes().into(),
|
||||||
},
|
}),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
println!("err0")
|
println!("err0")
|
||||||
|
|
|
@ -7,8 +7,71 @@ pub struct MyRequest {
|
||||||
pub sig: Vec<u8>, // FIXME :: fixed length array not supported by serde [u8; 64],
|
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)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct MyResponse {
|
pub struct MyResponse {
|
||||||
// sig: [u8; 64],
|
// sig: [u8; 64],
|
||||||
pub sig: Vec<u8>, // FIXME :: fixed length array not supported by serde [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,
|
||||||
|
// }
|
||||||
|
|
|
@ -8,12 +8,12 @@ use libp2p::{
|
||||||
};
|
};
|
||||||
use libp2p_identity::ed25519::Keypair;
|
use libp2p_identity::ed25519::Keypair;
|
||||||
|
|
||||||
use crate::messages::{MyRequest, MyResponse};
|
use crate::messages::{MyRequest, MyResult};
|
||||||
|
|
||||||
#[derive(NetworkBehaviour)]
|
#[derive(NetworkBehaviour)]
|
||||||
pub struct MyBehaviour {
|
pub struct MyBehaviour {
|
||||||
pub mdns: mdns::tokio::Behaviour,
|
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(
|
pub fn mk_swarm(
|
||||||
|
@ -33,7 +33,7 @@ pub fn mk_swarm(
|
||||||
let protocol = [(StreamProtocol::new("/sign-me/1"), protocol_support)];
|
let protocol = [(StreamProtocol::new("/sign-me/1"), protocol_support)];
|
||||||
let config = request_response::Config::default();
|
let config = request_response::Config::default();
|
||||||
let req_res =
|
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 })
|
Ok(MyBehaviour { req_res, mdns })
|
||||||
})?
|
})?
|
||||||
.with_swarm_config(|cfg| cfg.with_idle_connection_timeout(Duration::from_secs(u64::MAX)))
|
.with_swarm_config(|cfg| cfg.with_idle_connection_timeout(Duration::from_secs(u64::MAX)))
|
||||||
|
|
Loading…
Reference in New Issue