Skip to content

Instantly share code, notes, and snippets.

@AljoschaMeyer
Created March 12, 2018 09:40
Show Gist options
  • Save AljoschaMeyer/67bfbbd9a2825537fef771ab9a02f769 to your computer and use it in GitHub Desktop.
Save AljoschaMeyer/67bfbbd9a2825537fef771ab9a02f769 to your computer and use it in GitHub Desktop.
#![feature(try_from)]
#![feature(ip_constructors)]
extern crate tokio;
extern crate futures;
extern crate sodiumoxide;
extern crate secret_stream;
extern crate ssb_keyfile;
extern crate ssb_common;
extern crate ssb_client;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
use std::net::{SocketAddr, Ipv6Addr};
use std::convert::TryInto;
use tokio::executor::current_thread;
use tokio::net::TcpStream;
use tokio::io::AsyncRead;
use futures::prelude::*;
use secret_stream::OwningClient;
use sodiumoxide::crypto::box_;
use ssb_keyfile::load_or_create_keys;
use ssb_common::{MAINNET_IDENTIFIER, DEFAULT_TCP_PORT};
use ssb_common::links::MessageId;
use ssb_client::ssb;
use serde_json::Value;
fn main() {
sodiumoxide::init();
let (pk, sk) = load_or_create_keys().unwrap();
let pk = pk.try_into().unwrap();
let sk = sk.try_into().unwrap();
let (ephemeral_pk, ephemeral_sk) = box_::gen_keypair();
let addr = SocketAddr::new(Ipv6Addr::localhost().into(), DEFAULT_TCP_PORT);
let do_stuff = TcpStream::connect(&addr)
.and_then(move |tcp| {
OwningClient::new(tcp,
MAINNET_IDENTIFIER,
pk,
sk,
ephemeral_pk,
ephemeral_sk,
pk)
.map_err(|err| panic!("{:?}", err))
})
.map(|connection| {
println!("{:?}", "yay!");
let (read, write) = connection.unwrap().split();
let (mut client, receive, _) = ssb(read, write);
current_thread::spawn(receive.map_err(|err| panic!("{:?}", err)));
let (req, res) = client
.get::<Value>("%Igm25FZEje8LeruZ0MnCajFz9e1LoMO3EHB5C0fRMmw=.sha256"
.parse::<MessageId>()
.unwrap());
current_thread::spawn(req.map_err(|err| panic!("{:?}", err)));
current_thread::spawn(res.map(|msg| println!("{:?}", msg))
.map_err(|err| panic!("{:?}", err)));
})
.map_err(|err| panic!("{:?}", err));
current_thread::run(|_| current_thread::spawn(do_stuff));
}
@ahdinosaur
Copy link

"yay!"
Object({"author": String("@EMovhfIrFk4NihAKnRNhrfRaqIhBv1Wj8pTxJNgvCCY=.ed25519"), "content": Object({"channel": String("ssbc-grants"), "mentions": Array([Object({"link": String("%uvTmmVVhluZkrTMms6CZ334U5IxcjAEtUQCQ5c5g910=.sha256"), "name": String("rewriting the muxrpc internals")})]), "text": String("## Dev Diary: replication/ebt\n\nI\'ve been working on my grant, getting ebt ready for full deployment.\nI feel the grant process gives me license not to just do the most expedient thing, but _do the right thing_ which has so far involved [rewriting the muxrpc internals](%uvTmmVVhluZkrTMms6CZ334U5IxcjAEtUQCQ5c5g910=.sha256).\n\nAnd, this part is half finished, but rewriting [epidemic-broadcast-trees](https://github.com/dominictarr/epidemic-broadcast-trees). I didn\'t rewrite for the hell of it. Firstly, there where various tests in ssb-ebt that were too complicated, and I didn\'t understand why they weren\'t passing. Secondly, the low level features where provided by the `epidemic-broadcast-trees` module, then that was ment to be glued to ssb in the `ssb-ebt` module... except far too much functionality ended up in ssb-ebt, and it needed it\'s own tests! ebt uses a data structure oriented programming style, with a deterministic simulation for tests, but because of the glue layer I wasn\'t able to test ssb-ebt that way. So, I realized I really needed to just rewrite ebt. EBT is probably the 3rd or 4th time I rewrote scuttlebutt replication (if you include the original [\"insecure\" scuttlebutt](https://github.com/dominictarr/scuttlebutt) module.\n\nThis time the state model encompasses the fact the you may be replicating the multiple peers at one time, and connecting and disconnecting with them. I havn\'t got to this yet, but could also make tests that include randomly connecting and disconnecting to peers."), "type": String("post")}), "hash": String("sha256"), "previous": String("%f/f6vQG3eMTxkoCLPy9lfVzMj84ubl0iADZkXRVQ1mE=.sha256"), "sequence": Number(12194), "signature": String("qNnM/huSmSQhFCiu064lVSCJecjNibaj1NEhOsDJdDdWupCgEla0Pgj23mz4CLI2nhJrB+KRWzWPI2kq9BRWBQ==.sig.ed25519"), "timestamp": Number(1518148461508)})

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment