WIP fixed redirect returning internal error
Refactors the `check_pubsub_node` function to return an `Option<Status>` to indicate whether a redirect is needed.
This commit is contained in:
parent
786489fcbd
commit
5de6bd7cbf
@ -29,7 +29,7 @@ pub async fn check_pubsub_node(
|
|||||||
db: &Surreal<Client>,
|
db: &Surreal<Client>,
|
||||||
local_addr: &str,
|
local_addr: &str,
|
||||||
id: RecordId,
|
id: RecordId,
|
||||||
) -> Result<String, db::Error> {
|
) -> Result<Option<Status>, db::Error> {
|
||||||
dbg!(&local_addr);
|
dbg!(&local_addr);
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
struct PubSubNode {
|
struct PubSubNode {
|
||||||
@ -44,13 +44,13 @@ pub async fn check_pubsub_node(
|
|||||||
dbg!(&local_addr, &node_endpoint);
|
dbg!(&local_addr, &node_endpoint);
|
||||||
|
|
||||||
if local_addr == node_endpoint {
|
if local_addr == node_endpoint {
|
||||||
return Ok(node_endpoint);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut status = Status::new(tonic::Code::Unavailable, "moved");
|
let mut status = Status::new(tonic::Code::Unavailable, "moved");
|
||||||
status.metadata_mut().insert("location", node_endpoint.parse().unwrap());
|
status.metadata_mut().insert("location", node_endpoint.parse().unwrap());
|
||||||
|
|
||||||
Err(status.into())
|
Ok(Some(status))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait PubkeyGetter {
|
pub trait PubkeyGetter {
|
||||||
|
@ -225,10 +225,12 @@ impl BrainVmCli for VmCliServer {
|
|||||||
|
|
||||||
async fn new_vm(&self, req: Request<NewVmReq>) -> Result<Response<NewVmResp>, Status> {
|
async fn new_vm(&self, req: Request<NewVmReq>) -> Result<Response<NewVmResp>, Status> {
|
||||||
let local_addr = req.local_addr().map(|addr| addr.to_string()).unwrap_or_default();
|
let local_addr = req.local_addr().map(|addr| addr.to_string()).unwrap_or_default();
|
||||||
|
|
||||||
let req = check_sig_from_req(req)?;
|
let req = check_sig_from_req(req)?;
|
||||||
let id = surrealdb::RecordId::from((VM_NODE, req.node_pubkey.clone()));
|
let id = surrealdb::RecordId::from((VM_NODE, req.node_pubkey.clone()));
|
||||||
check_pubsub_node(&self.db, &local_addr, id).await?;
|
if let Some(redirect) = check_pubsub_node(&self.db, &local_addr, id).await? {
|
||||||
|
log::info!("redirect: {redirect}");
|
||||||
|
return Err(redirect);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: make it atleast 1 hour
|
// TODO: make it atleast 1 hour
|
||||||
if req.locked_nano < 100 {
|
if req.locked_nano < 100 {
|
||||||
|
Loading…
Reference in New Issue
Block a user