Add add_invitation_bucket for new bridgelines and remove gone bridgelines

This commit is contained in:
onyinyang 2023-03-10 15:21:27 -05:00
parent 514c604ca5
commit 4713042e48
No known key found for this signature in database
GPG Key ID: 156A6435430C2036
1 changed files with 85 additions and 49 deletions

View File

@ -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, BRIDGE_BYTES}; use lox::bridge_table::{BridgeLine, BRIDGE_BYTES, ENC_BUCKET_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;
@ -331,8 +331,8 @@ async fn main() {
let (mut tx, mut rx) = async_channel::bounded(3); let (mut tx, mut rx) = async_channel::bounded(3);
// to populate the bridge db // to populate the bridge db
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 { 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
@ -340,56 +340,92 @@ async fn main() {
} }
}); });
while let resourcediff = rx.recv().await.unwrap() { while let resourcediff = rx.recv().await.unwrap() {
spawn(async move { // spawn(async move {
for new_resource in resourcediff.new.unwrap(){ for new_resource in resourcediff.new {
println!("A NEW RESOURCE: {:?}", new_resource); for pt in new_resource {
match new_resource.0.as_str() { println!("A NEW RESOURCE: {:?}", pt);
"obfs2" => { let mut bucket = [
println!("Obfs2!"); BridgeLine::default(),
let count = 0; BridgeLine::default(),
for resource in new_resource.1 { BridgeLine::default(),
let mut ip_bytes: [u8; 16] = [0; 16]; ];
ip_bytes[..resource.address.len()].copy_from_slice(resource.address.as_bytes()); let mut count = 0;
//let params = resource.params.unwrap(); I guess this should be a cert but I will fix this later for resource in pt.1 {
let infostr: String = format!( let mut ip_bytes: [u8; 16] = [0; 16];
"obfs4 {} fingerprint={} cert={} iat-mode=0", ip_bytes[..resource.address.len()].copy_from_slice(resource.address.as_bytes());
resource.r#type, let infostr: String = format!(
resource.fingerprint, "type={} blocked_in={:?} protocol={} fingerprint={} or_addresses={:?} distribution={} flags={:?} params={:?}",
base64::encode_config("super secret password", base64::STANDARD_NO_PAD), resource.r#type,
); resource.blocked_in,
let mut info_bytes: [u8; BRIDGE_BYTES - 18] = [0; BRIDGE_BYTES-18]; resource.protocol,
resource.fingerprint,
resource.or_addresses,
resource.distribution,
resource.flags,
resource.params,
);
let mut info_bytes: [u8; BRIDGE_BYTES - 18] = [0; BRIDGE_BYTES - 18];
info_bytes[..infostr.len()].copy_from_slice(infostr.as_bytes()); info_bytes[..infostr.len()].copy_from_slice(infostr.as_bytes());
let bline = BridgeLine { let bridgeline = BridgeLine {
addr: ip_bytes, addr: ip_bytes,
port: resource.port, port: resource.port,
info: info_bytes, info: info_bytes,
}; };
println!("Now it's a bridgeline: {:?}", bline);
} println!("Now it's a bridgeline: {:?}", bridgeline);
}, if count < 2 {
"scramblesuit" => println!("Scramblesuit!"), bucket[count] = bridgeline;
"obfs4" => println!("Obfs4!"), count += 1;
"meek" => println!("Meek!"), } else {
"snowflake" => println!("Meek!"), lox_auth.add_openinv_bridges(bucket, &mut bridgedb);
_=> println!("Other unknown"), count = 0;
bucket = [
BridgeLine::default(),
BridgeLine::default(),
BridgeLine::default(),
];
}
} }
} }
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
//add open inv bridges
// users.push(user);
});
} }
for changed_resource in resourcediff.changed {
println!("A NEW CHANGED RESOURCE: {:?}", changed_resource);
}
for gone_resource in resourcediff.gone {
for pt in gone_resource {
println!("A NEW GONE RESOURCE: {:?}", pt);
let mut unreachable_bridge = BridgeLine::default();
for resource in pt.1 {
let mut ip_bytes: [u8; 16] = [0; 16];
ip_bytes[..resource.address.len()].copy_from_slice(resource.address.as_bytes());
let infostr: String = format!(
"type={} blocked_in={:?} protocol={} fingerprint={} or_addresses={:?} distribution={} flags={:?} params={:?}",
resource.r#type,
resource.blocked_in,
resource.protocol,
resource.fingerprint,
resource.or_addresses,
resource.distribution,
resource.flags,
resource.params,
);
let mut info_bytes: [u8; BRIDGE_BYTES - 18] = [0; BRIDGE_BYTES - 18];
info_bytes[..infostr.len()].copy_from_slice(infostr.as_bytes());
let bridgeline = BridgeLine {
addr: ip_bytes,
port: resource.port,
info: info_bytes,
};
println!("Now it's a bridgeline: {:?}", bridgeline);
lox_auth.bridge_unreachable(&unreachable_bridge, &mut bridgedb);
}
}
}
}
// 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