[WIP] Progress on bridgedb update through channel update
This commit is contained in:
parent
4713042e48
commit
54687d9aca
|
@ -322,13 +322,15 @@ async fn main() {
|
||||||
let rtype: ResourceInfo = serde_json::from_reader(reader).unwrap();
|
let rtype: ResourceInfo = serde_json::from_reader(reader).unwrap();
|
||||||
|
|
||||||
// pass in distribution of open invite vs. hot spare buckets?
|
// pass in distribution of open invite vs. hot spare buckets?
|
||||||
let num_buckets = 5;
|
let bridgedb = BridgeDb::new();
|
||||||
let hot_spare_buckets = 5;
|
let lox_auth = BridgeAuth::new(bridgedb.pubkey);
|
||||||
let mut bridgedb = BridgeDb::new();
|
|
||||||
let mut lox_auth = BridgeAuth::new(bridgedb.pubkey);
|
|
||||||
|
|
||||||
|
let context = LoxServerContext {
|
||||||
|
db: Arc::new(Mutex::new(bridgedb)),
|
||||||
|
ba: Arc::new(Mutex::new(lox_auth)),
|
||||||
|
};
|
||||||
//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) = async_channel::bounded(3);
|
let (tx, 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
|
||||||
|
@ -340,6 +342,8 @@ async fn main() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let context_clone = context.clone();
|
||||||
|
let _ = spawn(async move {
|
||||||
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 {
|
for new_resource in resourcediff.new {
|
||||||
|
@ -379,7 +383,9 @@ async fn main() {
|
||||||
bucket[count] = bridgeline;
|
bucket[count] = bridgeline;
|
||||||
count += 1;
|
count += 1;
|
||||||
} else {
|
} else {
|
||||||
lox_auth.add_openinv_bridges(bucket, &mut bridgedb);
|
let mut ba_obj = context_clone.ba.lock().unwrap();
|
||||||
|
let mut db_obj = context_clone.db.lock().unwrap();
|
||||||
|
ba_obj.add_openinv_bridges(bucket, &mut db_obj);
|
||||||
count = 0;
|
count = 0;
|
||||||
bucket = [
|
bucket = [
|
||||||
BridgeLine::default(),
|
BridgeLine::default(),
|
||||||
|
@ -421,31 +427,32 @@ async fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("Now it's a bridgeline: {:?}", bridgeline);
|
println!("Now it's a bridgeline: {:?}", bridgeline);
|
||||||
lox_auth.bridge_unreachable(&unreachable_bridge, &mut bridgedb);
|
let mut ba_obj = context_clone.ba.lock().unwrap();
|
||||||
|
let mut db_obj = context_clone.db.lock().unwrap();
|
||||||
|
ba_obj.bridge_unreachable(&unreachable_bridge, &mut db_obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Create the encrypted bridge table
|
||||||
|
let mut ba_obj = context_clone.ba.lock().unwrap();
|
||||||
|
ba_obj.enc_bridge_table();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
// 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
|
||||||
for _ in 0..num_buckets {
|
/* for _ in 0..num_buckets {
|
||||||
let bucket = [random(), random(), random()];
|
let bucket = [random(), random(), random()];
|
||||||
lox_auth.add_openinv_bridges(bucket, &mut bridgedb);
|
lox_auth.add_openinv_bridges(bucket, &mut bridgedb);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Create the encrypted bridge table
|
|
||||||
lox_auth.enc_bridge_table();
|
|
||||||
|
|
||||||
let context = LoxServerContext {
|
|
||||||
db: Arc::new(Mutex::new(bridgedb)),
|
|
||||||
ba: Arc::new(Mutex::new(lox_auth)),
|
|
||||||
};
|
|
||||||
|
|
||||||
let new_service = make_service_fn(move |_conn: &AddrStream| {
|
let new_service = make_service_fn(move |_conn: &AddrStream| {
|
||||||
let context = context.clone();
|
let context = context.clone();
|
||||||
let service = service_fn(move |req| {
|
let service = service_fn(move |req| {
|
||||||
// let addr = conn.remote_addr();
|
|
||||||
handle(context.clone(), req)
|
handle(context.clone(), req)
|
||||||
});
|
});
|
||||||
async move { Ok::<_, Infallible>(service) }
|
async move { Ok::<_, Infallible>(service) }
|
||||||
|
|
Loading…
Reference in New Issue