Add parsing resource into Lox BridgeLine
This commit is contained in:
parent
a9661cb8ab
commit
514c604ca5
|
@ -6,10 +6,11 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
async-channel = "1.8.0"
|
||||||
base64 = "0.13"
|
base64 = "0.13"
|
||||||
hyper = { version = "0.14.24", features = ["server"] }
|
hyper = { version = "0.14.24", features = ["server"] }
|
||||||
hex_fmt = "0.3"
|
hex_fmt = "0.3"
|
||||||
tokio = { version = "1", features = ["full", "macros", "signal", "sync"] }
|
tokio = { version = "1", features = ["full", "macros", "signal"] }
|
||||||
rand = "0.7"
|
rand = "0.7"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_with = "1.9.1"
|
serde_with = "1.9.1"
|
||||||
|
|
|
@ -6,7 +6,7 @@ use hyper::{
|
||||||
service::{make_service_fn, service_fn},
|
service::{make_service_fn, service_fn},
|
||||||
Body, Method, Request, Response, Server, StatusCode,
|
Body, Method, Request, Response, Server, StatusCode,
|
||||||
};
|
};
|
||||||
use lox::bridge_table::{BridgeLine, ENC_BUCKET_BYTES};
|
use lox::bridge_table::{BridgeLine, ENC_BUCKET_BYTES, BRIDGE_BYTES};
|
||||||
use lox::proto;
|
use lox::proto;
|
||||||
use lox::{BridgeAuth, BridgeDb, OPENINV_LENGTH};
|
use lox::{BridgeAuth, BridgeDb, OPENINV_LENGTH};
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
|
@ -328,26 +328,68 @@ async fn main() {
|
||||||
let mut lox_auth = BridgeAuth::new(bridgedb.pubkey);
|
let mut lox_auth = BridgeAuth::new(bridgedb.pubkey);
|
||||||
|
|
||||||
//Sender is resource stream and receiver is bridgedb function (add_openinv_bridges)
|
//Sender is resource stream and receiver is bridgedb function (add_openinv_bridges)
|
||||||
let (mut tx, mut rx) = mpsc::channel(100);
|
let (mut tx, mut rx) = async_channel::bounded(3);
|
||||||
// to populate the bridge db
|
// to populate the bridge db
|
||||||
spawn(async move {
|
let rstream = start_stream(rtype.endpoint, rtype.name, rtype.token, rtype.types)
|
||||||
let rstream = start_stream(rtype.endpoint, rtype.name, rtype.token, rtype.types)
|
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
spawn(async move {
|
||||||
for diff in rstream {
|
for diff in rstream {
|
||||||
println!("Received diff: {:?}", diff); //send this through a channel
|
println!("Received diff: {:?}", diff); //send this through a channel
|
||||||
tx.send(diff).await.expect("can not add to bridgedb)")
|
tx.send(diff).await.expect("can not add to bridgedb)")
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
while let resourcediff = rx.recv().await.unwrap() {
|
||||||
spawn(async move {
|
spawn(async move {
|
||||||
while let Some(resourcediff) = rx.recv().await {
|
for new_resource in resourcediff.new.unwrap(){
|
||||||
println!("received: {:?}", resourcediff);
|
println!("A NEW RESOURCE: {:?}", new_resource);
|
||||||
|
match new_resource.0.as_str() {
|
||||||
|
"obfs2" => {
|
||||||
|
println!("Obfs2!");
|
||||||
|
let count = 0;
|
||||||
|
for resource in new_resource.1 {
|
||||||
|
let mut ip_bytes: [u8; 16] = [0; 16];
|
||||||
|
ip_bytes[..resource.address.len()].copy_from_slice(resource.address.as_bytes());
|
||||||
|
//let params = resource.params.unwrap(); I guess this should be a cert but I will fix this later
|
||||||
|
let infostr: String = format!(
|
||||||
|
"obfs4 {} fingerprint={} cert={} iat-mode=0",
|
||||||
|
resource.r#type,
|
||||||
|
resource.fingerprint,
|
||||||
|
base64::encode_config("super secret password", base64::STANDARD_NO_PAD),
|
||||||
|
);
|
||||||
|
let mut info_bytes: [u8; BRIDGE_BYTES - 18] = [0; BRIDGE_BYTES-18];
|
||||||
|
|
||||||
|
info_bytes[..infostr.len()].copy_from_slice(infostr.as_bytes());
|
||||||
|
let bline = BridgeLine {
|
||||||
|
addr: ip_bytes,
|
||||||
|
port: resource.port,
|
||||||
|
info: info_bytes,
|
||||||
|
};
|
||||||
|
println!("Now it's a bridgeline: {:?}", bline);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"scramblesuit" => println!("Scramblesuit!"),
|
||||||
|
"obfs4" => println!("Obfs4!"),
|
||||||
|
"meek" => println!("Meek!"),
|
||||||
|
"snowflake" => println!("Meek!"),
|
||||||
|
_=> println!("Other unknown"),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
for changed_resource in resourcediff.changed{
|
||||||
|
println!("A NEW CHANGED RESOURCE: {:?}", changed_resource);
|
||||||
|
}
|
||||||
|
for gone_resource in resourcediff.gone{
|
||||||
|
println!("A NEW GONE RESOURCE: {:?}", gone_resource);
|
||||||
|
}
|
||||||
//parse resource diff into Bridgeline
|
//parse resource diff into Bridgeline
|
||||||
//add open inv bridges
|
//add open inv bridges
|
||||||
// users.push(user);
|
// users.push(user);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
// let new_bridgedb = task::spawn(load_bridges());
|
// let new_bridgedb = task::spawn(load_bridges());
|
||||||
// Create and initialize a new db and lox_auth
|
// Create and initialize a new db and lox_auth
|
||||||
// Make 3 x num_buckets open invitation bridges, in sets of 3
|
// Make 3 x num_buckets open invitation bridges, in sets of 3
|
||||||
|
|
Loading…
Reference in New Issue