Skip to content

Commit

Permalink
fix for windows defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Feb 8, 2022
1 parent e68f5bd commit 43cc8bb
Show file tree
Hide file tree
Showing 20 changed files with 434 additions and 174 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions applications/launchpad/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tor-hash-passwd = "1.0.1"
thiserror = "1.0.30"
tokio = { version = "1.9", features= ["sync"] }
futures = "0.3"
regex= "1.5.4"

[features]
default = [ "custom-protocol" ]
Expand Down
5 changes: 0 additions & 5 deletions applications/launchpad/backend/assets/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ use_libtor = false
base_node_identity_file = "/var/tari/base_node/config/igor/base_node_id.json"
base_node_tor_identity_file = "/var/tari/base_node/config/igor/tari_base_node_tor.json"


[mempool.dibbler]

[mempool.igor]

[wallet]
config = "dibbler"
wallet_db_file = "wallet/wallet.dat"
Expand Down
22 changes: 15 additions & 7 deletions applications/launchpad/backend/src/commands/create_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

use std::path::Path;
use std::{
env,
path::{Path, PathBuf},
str::FromStr,
};

use log::*;
use tauri::{
Expand All @@ -38,15 +42,19 @@ use crate::{commands::AppState, docker::create_workspace_folders, error::Launche
/// Create a new workspace environment by creating a folder hierarchy (if required) at the `root_folder`, and copying
/// the default config files into it.
#[tauri::command]
pub fn create_new_workspace(app: AppHandle<Wry>, root_path: String) -> Result<(), String> {
pub fn create_new_workspace(app: AppHandle<Wry>, root_path: Option<String>) -> Result<(), String> {
let config = app.config();
let package_info = &app.state::<AppState>().package_info;
let path = Path::new(&root_path);
let path = root_path
.as_ref()
.map(|r| PathBuf::from_str(r.as_str()).unwrap())
.unwrap_or_else(|| env::temp_dir().join("tari"));
debug!("Creating workspace at {:?}", path);
let _ = create_workspace_folders(root_path.as_str()).map_err(|e| e.chained_message());
copy_config_file(path, config.as_ref(), package_info, "log4rs.yml").map_err(|e| e.chained_message())?;
copy_config_file(path, config.as_ref(), package_info, "config.toml").map_err(|e| e.chained_message())?;
info!("Workspace at {} complete!", root_path);
create_workspace_folders(&path).map_err(|e| e.chained_message())?;
dbg!("hello");
copy_config_file(path.as_path(), config.as_ref(), package_info, "log4rs.yml").map_err(|e| e.chained_message())?;
copy_config_file(path.as_path(), config.as_ref(), package_info, "config.toml").map_err(|e| e.chained_message())?;
info!("Workspace at {:?} complete!", path);
Ok(())
}

Expand Down
3 changes: 2 additions & 1 deletion applications/launchpad/backend/src/commands/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ async fn create_default_workspace_impl(app: AppHandle<Wry>, settings: ServiceSet
}; // drop read-only lock
if should_create_workspace {
let package_info = &state.package_info;
let _ = create_workspace_folders(&config.data_directory).map_err(|e| e.chained_message());
dbg!(&config);
create_workspace_folders(&config.data_directory)?;
copy_config_file(&config.data_directory, app_config.as_ref(), package_info, "log4rs.yml")?;
copy_config_file(&config.data_directory, app_config.as_ref(), package_info, "config.toml")?;
// Only get a write-lock if we need one
Expand Down
12 changes: 7 additions & 5 deletions applications/launchpad/backend/src/docker/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ use crate::docker::{DockerWrapperError, ImageType};
pub fn create_workspace_folders<P: AsRef<Path>>(root: P) -> Result<(), DockerWrapperError> {
if !root.as_ref().exists() {
info!("Creating new workspace at {}", root.as_ref().to_str().unwrap_or("???"));
fs::create_dir(&root)?
fs::create_dir_all(&root)?;
}
let make_subfolder = |folder: &str| -> Result<(), std::io::Error> {
let p = root.as_ref().join(folder);
let p_str = p.as_path().to_str().unwrap_or("???");
match p.exists() {
true => {
debug!("{} already exists", p_str);
info!("{} already exists", p_str);
Ok(())
},
false => {
info!("Creating new data folder, {}", p_str);
fs::create_dir(&p)?;
fs::create_dir_all(&p)?;
#[cfg(any(target_os = "linux", target_os = "macos"))]
{
use std::os::unix::fs::PermissionsExt;
Expand All @@ -64,9 +64,11 @@ pub fn create_workspace_folders<P: AsRef<Path>>(root: P) -> Result<(), DockerWra
},
}
};
let _ = make_subfolder("config")?;
info!("Making config folder");
make_subfolder("config")?;
for image in ImageType::iter() {
let _ = make_subfolder(image.data_folder())?;
debug!("Making folder for image:{:?}", image);
make_subfolder(image.data_folder())?;
}
Ok(())
}
2 changes: 1 addition & 1 deletion applications/launchpad/backend/src/docker/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl TryFrom<&str> for TariNetwork {

//------------------------------------------- ImageType ----------------------------------------------

#[derive(Clone, Copy, EnumIter, PartialEq, Eq, Hash, Serialize)]
#[derive(Debug, Clone, Copy, EnumIter, PartialEq, Eq, Hash, Serialize)]
pub enum ImageType {
Tor,
BaseNode,
Expand Down
30 changes: 27 additions & 3 deletions applications/launchpad/backend/src/docker/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

use std::{collections::HashMap, path::PathBuf, time::Duration};
use std::{collections::HashMap, ffi::OsStr, path, path::PathBuf, time::Duration};

use bollard::models::{Mount, MountTypeEnum, PortBinding, PortMap};
use config::ConfigError;
use regex::Regex;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use tor_hash_passwd::EncryptedKey;
Expand Down Expand Up @@ -109,7 +110,7 @@ impl MmProxyConfig {
pub struct LaunchpadConfig {
/// The directory to use for config, id files and logs
pub data_directory: PathBuf,
/// The Tri network to use. Default = dibbler
/// The Tari network to use. Default = dibbler
pub tari_network: TariNetwork,
/// The tor control password to share among containers.
pub tor_control_password: String,
Expand Down Expand Up @@ -184,10 +185,33 @@ impl LaunchpadConfig {
fn build_mounts(&self, blockchain: bool, general: bool, volume_name: String) -> Vec<Mount> {
let mut mounts = Vec::with_capacity(2);
if general {
#[cfg(not(target_os = "linux"))]
#[cfg(target_os = "windows")]
let host = format!(
"//{}",
self.data_directory
.iter()
.filter_map(|part| {
dbg!(part);
if part == OsStr::new(&path::MAIN_SEPARATOR.to_string()) {
None
} else {
let drive = Regex::new(r"(?P<letter>[A-Za-z]):").unwrap();
let part = part.to_string_lossy().to_string();
if drive.is_match(part.as_str()) {
Some(drive.replace(part.as_str(), "$letter").to_lowercase())
} else {
Some(part)
}
}
})
.collect::<Vec<String>>()
.join("/")
);
#[cfg(target_os = "macos")]
let host = format!("/host_mnt{}", self.data_directory.to_string_lossy());
#[cfg(target_os = "linux")]
let host = self.data_directory.to_string_lossy().to_string();
dbg!(&host);
let mount = Mount {
target: Some("/var/tari".to_string()),
source: Some(host),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const imageNames = [

async function getWorkspaceFolder(fn) {
const options = {
defaultPath: "/tmp",
//defaultPath: "/tmp",
directory: true,
multiple: false
}
Expand Down Expand Up @@ -148,7 +148,7 @@ export default {
},
data() {
const options = {
root_folder: "/tmp/tari",
root_folder: null,
tari_network: "dibbler",
has_base_node: true,
has_wallet: false,
Expand Down
20 changes: 12 additions & 8 deletions applications/launchpad/gui-vue/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ library.add(

import store from "./store";

createApp(App)
.use(store)
.component('vue-fontawesome', FontAwesomeIcon)
.use(Oruga, {
iconComponent: 'vue-fontawesome',
iconPack: 'fas'
})
.mount('#app')
console.log(store);
store.dispatch("initState").then(()=> {
createApp(App)
.use(store)
.component('vue-fontawesome', FontAwesomeIcon)
.use(Oruga, {
iconComponent: 'vue-fontawesome',
iconPack: 'fas'
})
.mount('#app')
})

57 changes: 33 additions & 24 deletions applications/launchpad/gui-vue/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,43 @@ import {createStore} from 'vuex'
import {invoke} from '@tauri-apps/api/tauri'
import {listen} from "@tauri-apps/api/event";
import CBuffer from 'CBuffer';
import {cacheDir, sep} from "@tauri-apps/api/path";

const settings = {
walletPassword: "tari",
moneroMiningAddress: "5AJ8FwQge4UjT9Gbj4zn7yYcnpVQzzkqr636pKto59jQcu85CFsuYVeFgbhUdRpiPjUCkA4sQtWApUzCyTMmSigFG2hDo48",
numMiningThreads: 1,
tariNetwork: "dibbler",
rootFolder: "/tmp/dibbler",
dockerRegistry: "quay.io/tarilabs",
dockerTag: "latest",
monerodUrl: "http://monero-stagenet.exan.tech:38081",
moneroUseAuth: false,
moneroUsername: "",
moneroPassword: ""
};
async function createDefaultSettings() {
return {
walletPassword: "tari",
moneroMiningAddress: "5AJ8FwQge4UjT9Gbj4zn7yYcnpVQzzkqr636pKto59jQcu85CFsuYVeFgbhUdRpiPjUCkA4sQtWApUzCyTMmSigFG2hDo48",
numMiningThreads: 1,
tariNetwork: "dibbler",
rootFolder: await cacheDir() + "tari" + sep + "tmp" + sep + "dibbler",
dockerRegistry: "quay.io/tarilabs",
dockerTag: "latest",
monerodUrl: "http://monero-stagenet.exan.tech:38081",
moneroUseAuth: false,
moneroUsername: "",
moneroPassword: ""
};
}

function handleSystemEvent(commit, payload) {
if (payload.Type === "container") {
return commit('updateContainerStatus', {status: payload.Action, id: payload.Actor.ID});
}
}

export const store = createStore({
state() {
return {
settings,
subscribedToEvents: false,
unsubscribeSystemEvents: () => {},
containers: {}
}
},
const store = createStore({

state: {
settings: {},
subscribedToEvents: false,
unsubscribeSystemEvents: () => {},
containers: {}
},
mutations: {
init(state, settings) {
// work around to get async settings from tauri
state.settings = settings;
},
setNetwork(state, network) {
state.settings.tariNetwork = network;
},
Expand Down Expand Up @@ -147,6 +153,9 @@ export const store = createStore({
},
},
actions: {
async initState({commit}) {
commit("init", await createDefaultSettings());
},
async startContainer({state, commit}, type) {
console.log(`Starting container ${type}`);
try {
Expand All @@ -161,7 +170,7 @@ export const store = createStore({
commit('unsubscribeSystemEvents', eventsUnsubscribe);
}

const settings = Object.assign({}, this.state.settings);
const settings = Object.assign({}, state.settings);
console.log(settings);
let record = await invoke("start_service", {serviceName: type, settings});
console.log(`Got ${JSON.stringify(record)} as response`)
Expand All @@ -185,7 +194,7 @@ export const store = createStore({
async stopContainer({state}, type) {
console.log(`Stopping container ${type}`);
try {
await invoke("stop_service", {serviceName: type, settings});
await invoke("stop_service", {serviceName: type, settings: state.settings});
let service = state.containers[type];
if (service.listeners) {
if (typeof (service.listeners.statsUnsubscribe) === 'function') {
Expand Down
8 changes: 4 additions & 4 deletions applications/tari_merge_mining_proxy/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ mod test {
let cfg = get_config("config_b");
let config = <MergeMiningProxyConfig as DefaultConfigLoader>::load_from(&cfg).expect("Failed to load config");
assert_eq!(&config.monerod_url, &["http://network.b.org".to_string()]);
assert_eq!(config.proxy_submit_to_origin, false);
assert!(!config.proxy_submit_to_origin);
assert_eq!(config.monerod_username.as_str(), "cmot");
assert_eq!(config.monerod_password.as_str(), "password_dibbler");
assert_eq!(
Expand All @@ -116,7 +116,7 @@ mod test {
let cfg = get_config("config_a");
let config = <MergeMiningProxyConfig as DefaultConfigLoader>::load_from(&cfg).expect("Failed to load config");
assert_eq!(&config.monerod_url, &["http://network.a.org".to_string()]);
assert_eq!(config.proxy_submit_to_origin, true);
assert!(config.proxy_submit_to_origin);
assert_eq!(config.monerod_username.as_str(), "cmot");
assert_eq!(config.monerod_password.as_str(), "password_igor");
assert_eq!(
Expand All @@ -133,7 +133,7 @@ mod test {
fn default_config() {
let config = MergeMiningProxyConfig::default();
assert_eq!(&config.grpc_base_node_address.to_string(), "/ip4/127.0.0.1/tcp/18142");
assert_eq!(config.monerod_use_auth, false);
assert_eq!(config.proxy_submit_to_origin, true);
assert!(!config.monerod_use_auth);
assert!(config.proxy_submit_to_origin);
}
}
2 changes: 1 addition & 1 deletion applications/tari_mining_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,6 @@ mine_on_tip_only = false
config.base_node_addr.to_string(),
"/dns4/my_base_node/tcp/1234".to_string()
);
assert_eq!(config.mine_on_tip_only, false);
assert!(!config.mine_on_tip_only);
}
}
Loading

0 comments on commit 43cc8bb

Please sign in to comment.