Skip to content

Instantly share code, notes, and snippets.

@kpp
kpp / main.go
Last active July 16, 2021 12:52
Create and parse x509 cert with libp2p ext
package main
import (
"io/ioutil"
"fmt"
"crypto"
"crypto/ecdsa"
"crypto/ed25519"
"crypto/elliptic"
"crypto/rand"
#include <stdio.h>
#include <unistd.h>
void child(int n) {
while (1)
{
sleep(1);
printf("child %d!\n", n);
}
}
type Message =
{ kind: "request", request: string, fields: [string, string][] } |
{ kind: "response", response: string, fields: [string, string][] } |
{ kind: "event", event: string, fields: [string, string][] }
type Enum = { kind: "enum", enum: string, items: string[] }
type SpecItem = Message | Enum
function messageName(msg: Message): string {
switch(msg.kind) {
#![feature(async_await, await_macro)]
use std::io;
use std::net::SocketAddr;
use futures::executor;
use futures::io::AsyncReadExt;
use futures::StreamExt;
use romio::{TcpListener, TcpStream};
> toxic ==> toxic
>
> Sending file [0]: 'large' (70.7 MiB)
> File transfer [0] for 'large' accepted. clock:1556250
> 100.0% [==================================================] 3.0 MiB/s
> File 'large' successfully sent. end=4282650
> Sending file [0]: 'large' (70.7 MiB)
> File transfer [0] for 'large' accepted. clock:9282914
> 100.0% [==================================================] 0.0 Bytes/s
> File 'large' successfully sent. end=12203390
1. Alice creates ToxID
a. Key pair generation: curve25519xsalsa20poly1305, a particular combination of Curve25519, Salsa20, and Poly1305 specified in "Cryptography in NaCl". This function is conjectured to meet the standard notions of privacy and third-party unforgeability.
2. Bob creates ToxID
3. Alice and Bob exchange ToxID in public
a. You can exchange ToxIDs via email, key signing parties, publish on web sites...
b. There are 4 bytes at the end (NoSpam) used to regenerate ToxID in case of receiving a lot of friend requests from spammers.
4. Alice goes online
extern crate common;
use common::measure_and_print;
use std::collections::{BinaryHeap, HashMap};
use std::io;
#[derive(Debug, Eq, PartialEq)]
enum NodeKind {
Leaf(u8),
Branch(Box<Node>, Box<Node>),
@kpp
kpp / Cargo.toml
Created December 11, 2018 10:52
Heapless string for comrade qw1
[package]
name = "stack_string"
version = "0.1.0"
authors = ["Roman Proskuryakov <humbug@deeptown.org>"]
edition = "2018"
[dependencies]
libc = { version = "0.2", default-features = false }
heapless = { version = "0.4" }
language: rust
os:
- linux
- osx
rust:
- 1.26.0
- stable
- beta
- nightly
humbug@home:~/zetox$ git diff | cat
diff --git a/Cargo.toml b/Cargo.toml
index 9206765..b4f0b15 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -33,7 +33,7 @@ bytes = "0.4"
byteorder = "1"
futures = "0.1"
log = "0.4"
-sodiumoxide = "0.0.16"