Redirect to pubsub node and some bug fixes #8

Merged
ghe0 merged 7 commits from pubsub_redirect into surreal_brain 2025-06-19 17:39:56 +00:00
3 changed files with 24 additions and 6 deletions
Showing only changes of commit 420653bcb6 - Show all commits

@ -1,3 +1,4 @@
use crate::constants::{STAGING_BRAIN_URLS, TESTNET_BRAIN_URLS};
use crate::{general, utils::block_on}; use crate::{general, utils::block_on};
use ed25519_dalek::SigningKey; use ed25519_dalek::SigningKey;
use log::{debug, info, warn}; use log::{debug, info, warn};
@ -5,6 +6,7 @@ use openssl::bn::BigNum;
use openssl::hash::{Hasher, MessageDigest}; use openssl::hash::{Hasher, MessageDigest};
use openssl::pkey::{PKey, Private}; use openssl::pkey::{PKey, Private};
use openssl::rsa::Rsa; use openssl::rsa::Rsa;
use rand::Rng;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{fs::File, io::Write, path::Path}; use std::{fs::File, io::Write, path::Path};
@ -309,15 +311,19 @@ impl Config {
pub fn get_brain_info() -> (String, String) { pub fn get_brain_info() -> (String, String) {
match Self::init_config().network.as_str() { match Self::init_config().network.as_str() {
"localhost" => ("https://localhost:31337".to_string(), "staging-brain".to_string()),
"staging" => { "staging" => {
let url1 = "https://149.22.95.1:47855".to_string(); // staging brain 2 let url = STAGING_BRAIN_URLS
let url2 = "https://149.36.48.99:48843".to_string(); // staging brain 3 [rand::thread_rng().gen_range(0..STAGING_BRAIN_URLS.len())]
.to_string();
let url = if rand::random::<bool>() { url1 } else { url2 };
(url, "staging-brain".to_string()) (url, "staging-brain".to_string())
} }
"localhost" => ("https://localhost:31337".to_string(), "staging-brain".to_string()), _ => {
_ => ("https://173.234.17.2:39477".to_string(), "testnet-brain".to_string()), let url = TESTNET_BRAIN_URLS
[rand::thread_rng().gen_range(0..TESTNET_BRAIN_URLS.len())]
.to_string();
(url, "testnet-brain".to_string())
}
} }
} }

@ -1,2 +1,13 @@
pub const HRATLS_APP_PORT: u32 = 34500; pub const HRATLS_APP_PORT: u32 = 34500;
pub const MAX_REDIRECTS: u16 = 3; pub const MAX_REDIRECTS: u16 = 3;
pub const STAGING_BRAIN_URLS: [&str; 3] = [
"https://184.107.169.199:49092", // staging brain 1
"https://149.22.95.1:47855", // staging brain 2
"https://149.36.48.99:48843", // staging brain 3
];
pub const TESTNET_BRAIN_URLS: [&str; 3] = [
"https://184.107.169.199:45223", // testnet brain 1
"https://149.22.95.1:44522", // testnet brain 2
"https://149.36.48.99:48638", // testnet brain 3
];

@ -91,6 +91,7 @@ impl crate::HumanOutput for VmNodeListResp {
async fn client() -> Result<BrainVmCliClient<Channel>, Error> { async fn client() -> Result<BrainVmCliClient<Channel>, Error> {
let default_brain_url = Config::get_brain_info().0; let default_brain_url = Config::get_brain_info().0;
info!("brain_url: {default_brain_url}");
Ok(BrainVmCliClient::new(Config::connect_brain_channel(default_brain_url).await?)) Ok(BrainVmCliClient::new(Config::connect_brain_channel(default_brain_url).await?))
} }