remove lifetimes backup
This commit is contained in:
parent
c53dedcd8f
commit
984f14dfeb
|
@ -1,161 +0,0 @@
|
||||||
mod error;
|
|
||||||
mod utils;
|
|
||||||
|
|
||||||
use async_std::net::TcpStream;
|
|
||||||
//use futures::io::{self, AsyncRead as Read, AsyncWrite as Write};
|
|
||||||
use kuska_handshake::async_std::{BoxStream, BoxStreamRead, BoxStreamWrite};
|
|
||||||
use kuska_handshake::HandshakeComplete;
|
|
||||||
use kuska_sodiumoxide::crypto::{auth, sign::ed25519};
|
|
||||||
use kuska_ssb::api::{dto::CreateHistoryStreamIn, ApiCaller};
|
|
||||||
use kuska_ssb::discovery;
|
|
||||||
use kuska_ssb::keystore;
|
|
||||||
use kuska_ssb::keystore::OwnedIdentity;
|
|
||||||
use kuska_ssb::rpc::{RpcReader, RpcWriter};
|
|
||||||
|
|
||||||
use crate::error::GolgiError;
|
|
||||||
|
|
||||||
//struct Sbot<R: Read + std::marker::Unpin, W: Write + std::marker::Unpin> {
|
|
||||||
struct Sbot<'a> {
|
|
||||||
id: String,
|
|
||||||
public_key: ed25519::PublicKey,
|
|
||||||
private_key: ed25519::SecretKey,
|
|
||||||
address: String,
|
|
||||||
// aka caps key (scuttleverse identifier)
|
|
||||||
network_id: auth::Key,
|
|
||||||
//socket: TcpStream,
|
|
||||||
//client: ApiCaller<W>,
|
|
||||||
client: ApiCaller<TcpStream>,
|
|
||||||
//rpc_reader: RpcReader<R>,
|
|
||||||
rpc_reader: RpcReader<&'a TcpStream>,
|
|
||||||
}
|
|
||||||
|
|
||||||
//impl<R: Read + std::marker::Unpin, W: Write + std::marker::Unpin> Sbot<R, W> {
|
|
||||||
//impl Sbot<'static> {
|
|
||||||
impl Sbot<'_> {
|
|
||||||
async fn init(
|
|
||||||
ip_port: Option<String>,
|
|
||||||
net_id: Option<String>,
|
|
||||||
) -> Result<Sbot<'static>, GolgiError> {
|
|
||||||
let address;
|
|
||||||
if ip_port.is_none() {
|
|
||||||
// set default
|
|
||||||
address = "127.0.0.1:8008".to_string();
|
|
||||||
} else {
|
|
||||||
address = ip_port.unwrap().to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
let network_id;
|
|
||||||
if net_id.is_none() {
|
|
||||||
network_id = discovery::ssb_net_id();
|
|
||||||
} else {
|
|
||||||
network_id = auth::Key::from_slice(&hex::decode(net_id.unwrap()).unwrap()).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let OwnedIdentity { pk, sk, id } = keystore::from_gosbot_local()
|
|
||||||
.await
|
|
||||||
.expect("couldn't read local secret");
|
|
||||||
|
|
||||||
let socket = TcpStream::connect(&address)
|
|
||||||
.await
|
|
||||||
.map_err(|source| GolgiError::Io {
|
|
||||||
source,
|
|
||||||
context: "socket error; failed to initiate tcp stream connection".to_string(),
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let handshake = kuska_handshake::async_std::handshake_client(
|
|
||||||
&mut &socket,
|
|
||||||
network_id.clone(),
|
|
||||||
pk,
|
|
||||||
sk.clone(),
|
|
||||||
pk,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.map_err(|err| GolgiError::Handshake(err))?;
|
|
||||||
|
|
||||||
let (box_stream_read, box_stream_write) =
|
|
||||||
BoxStream::from_handshake(socket, socket, handshake, 0x8000).split_read_write();
|
|
||||||
|
|
||||||
let rpc_reader = RpcReader::new(box_stream_read);
|
|
||||||
let client = ApiCaller::new(RpcWriter::new(box_stream_write));
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
id,
|
|
||||||
public_key: pk,
|
|
||||||
private_key: sk,
|
|
||||||
address,
|
|
||||||
network_id,
|
|
||||||
client: client,
|
|
||||||
rpc_reader: rpc_reader,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn run() -> Result<(), GolgiError> {
|
|
||||||
let sbot_client = Sbot::init(None, None);
|
|
||||||
/*
|
|
||||||
// read go-sbot id details from `/.ssb-go/secret
|
|
||||||
let OwnedIdentity { pk, sk, id } = keystore::from_gosbot_local()
|
|
||||||
.await
|
|
||||||
.expect("read local secret");
|
|
||||||
println!("connecting with identity {}", id);
|
|
||||||
|
|
||||||
// set the public key, ip and port for the sbot instance
|
|
||||||
let sbot_public_key = "a0SsCiZkBu6qaQ6tWVvzQPDSzvO0JqMAqPXt0LBIl30=".to_string();
|
|
||||||
let server_pk =
|
|
||||||
ed25519::PublicKey::from_slice(&base64::decode(&sbot_public_key)?).expect("bad public key");
|
|
||||||
let server_ipport = "127.0.0.1:8008".to_string();
|
|
||||||
|
|
||||||
// connect to the local go-sbot instance
|
|
||||||
let mut socket = TcpStream::connect(server_ipport)
|
|
||||||
.await
|
|
||||||
.map_err(|source| GolgiError::Io {
|
|
||||||
source,
|
|
||||||
context: "socket error; failed to initiate tcp stream connection".to_string(),
|
|
||||||
})?;
|
|
||||||
|
|
||||||
// initiate secret handshake
|
|
||||||
let handshake = kuska_handshake::async_std::handshake_client(
|
|
||||||
&mut socket,
|
|
||||||
discovery::ssb_net_id(),
|
|
||||||
pk,
|
|
||||||
sk.clone(),
|
|
||||||
server_pk,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.expect("handshake error");
|
|
||||||
|
|
||||||
println!("💃 handshake complete");
|
|
||||||
|
|
||||||
// call `whoami`
|
|
||||||
let (box_stream_read, box_stream_write) =
|
|
||||||
BoxStream::from_handshake(&socket, &socket, handshake, 0x8000).split_read_write();
|
|
||||||
|
|
||||||
let mut rpc_reader = RpcReader::new(box_stream_read);
|
|
||||||
let mut client = ApiCaller::new(RpcWriter::new(box_stream_write));
|
|
||||||
|
|
||||||
let req_id = client.whoami_req_send().await?;
|
|
||||||
let whoami = match utils::get_async(&mut rpc_reader, req_id, utils::whoami_res_parse).await {
|
|
||||||
Ok(res) => {
|
|
||||||
println!("😊 server says hello to {}", res.id);
|
|
||||||
id
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
if !err
|
|
||||||
.to_string()
|
|
||||||
.contains("method:whoami is not in list of allowed methods")
|
|
||||||
{
|
|
||||||
println!("Cannot ask for whoami {}", err);
|
|
||||||
}
|
|
||||||
id
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// call `createhistorystream`
|
|
||||||
let args = CreateHistoryStreamIn::new(whoami.clone());
|
|
||||||
// TODO: this should return an error if the args are wrong but it doesn't?
|
|
||||||
let req_id = client.create_history_stream_req_send(&args).await?;
|
|
||||||
utils::print_source_until_eof(&mut rpc_reader, req_id, utils::feed_res_parse).await?;
|
|
||||||
*/
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
Loading…
Reference in New Issue