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 be861baf36
commit b2642d353c
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},
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::{BridgeAuth, BridgeDb, OPENINV_LENGTH};
use rand::RngCore;
@ -341,54 +341,90 @@ async fn main() {
});
while let resourcediff = rx.recv().await.unwrap() {
spawn(async move {
for new_resource in resourcediff.new.unwrap(){
println!("A NEW RESOURCE: {:?}", new_resource);
match new_resource.0.as_str() {
"obfs2" => {
println!("Obfs2!");
let count = 0;
for resource in new_resource.1 {
// spawn(async move {
for new_resource in resourcediff.new {
for pt in new_resource {
println!("A NEW RESOURCE: {:?}", pt);
let mut bucket = [
BridgeLine::default(),
BridgeLine::default(),
BridgeLine::default(),
];
let mut count = 0;
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 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",
"type={} blocked_in={:?} protocol={} fingerprint={} or_addresses={:?} distribution={} flags={:?} params={:?}",
resource.r#type,
resource.blocked_in,
resource.protocol,
resource.fingerprint,
base64::encode_config("super secret password", base64::STANDARD_NO_PAD),
resource.or_addresses,
resource.distribution,
resource.flags,
resource.params,
);
let mut info_bytes: [u8; BRIDGE_BYTES - 18] = [0; BRIDGE_BYTES-18];
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 {
let bridgeline = 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"),
}
println!("Now it's a bridgeline: {:?}", bridgeline);
if count < 2 {
bucket[count] = bridgeline;
count += 1;
} else {
lox_auth.add_openinv_bridges(bucket, &mut bridgedb);
count = 0;
bucket = [
BridgeLine::default(),
BridgeLine::default(),
BridgeLine::default(),
];
}
for changed_resource in resourcediff.changed{
}
}
}
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);
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);
}
}
}
//parse resource diff into Bridgeline
//add open inv bridges
// users.push(user);
});
}
// let new_bridgedb = task::spawn(load_bridges());
// Create and initialize a new db and lox_auth