ACN Process Management #345

Merged
dan merged 14 commits from torrc into master 2020-10-21 23:58:59 +00:00
1 changed files with 14 additions and 15 deletions
Showing only changes of commit 68b2944f23 - Show all commits

29
main.go
View File

@ -22,7 +22,6 @@ import (
mrand "math/rand"
"os"
"os/user"
"path"
"path/filepath"
"runtime"
"time"
@ -75,19 +74,19 @@ func main() {
if os.Getenv("CWTCH_FOLDER") != "" {
the.CwtchDir = os.Getenv("CWTCH_FOLDER")
} else if runtime.GOOS == "android" {
the.CwtchDir = path.Join(androidBaseDir, "files")
the.CwtchDir = filepath.Join(androidBaseDir, "files")
} else {
usr, err := user.Current()
if err != nil {
log.Errorf("\nerror: could not load current user: %v\n", err)
os.Exit(1)
}
the.CwtchDir = path.Join(usr.HomeDir, ".cwtch")
the.CwtchDir = filepath.Join(usr.HomeDir, ".cwtch")
}
if buildVer == "" && os.Getenv("CWTCH_FOLDER") == "" {
log.Infoln("Development build: using dev directory for dev profiles")
the.CwtchDir = path.Join(the.CwtchDir, "dev")
the.CwtchDir = filepath.Join(the.CwtchDir, "dev")
}
the.ACN = nil
@ -136,7 +135,7 @@ func mainUi(flagLocal bool, flagClientUI bool) {
app := gui.NewQGuiApplication(len(os.Args), os.Args)
// our globals
err := ui.InitGlobalSettingsFile(path.Join(the.CwtchDir, "global"), the.AppPassword)
err := ui.InitGlobalSettingsFile(filepath.Join(the.CwtchDir, "global"), the.AppPassword)
if err != nil {
log.Errorf("Could not access global ui config: %v\n", err)
os.Exit(-1)
@ -153,7 +152,7 @@ func mainUi(flagLocal bool, flagClientUI bool) {
if runtime.GOOS == "windows" {
dir = "/" + dir
}
gcd.SetAssetPath("file://" + path.Join(dir, "assets") + "/")
gcd.SetAssetPath("file://" + filepath.Join(dir, "assets") + "/")
}
if buildVer != "" {
@ -216,24 +215,24 @@ func mainUi(flagLocal bool, flagClientUI bool) {
func loadACN() {
torpath := "tor"
if runtime.GOOS == "android" {
torpath = path.Join(androidBaseDir, "lib/libtor.so")
torpath = filepath.Join(androidBaseDir, "lib/libtor.so")
} else if runtime.GOOS == "windows" {
ex, err := os.Executable()
if err != nil {
ex = ""
}
exPath := filepath.Dir(ex)
torpath = path.Join(exPath, "tor-0.3.5.7", "Tor", "tor.exe")
torpath = filepath.Join(exPath, "tor-0.3.5.7", "Tor", "tor.exe")
} else {
dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
if _, err := os.Stat(path.Join(dir, "tor")); os.IsNotExist(err) {
if _, err := os.Stat(path.Join(dir, "deploy", "linux", "tor")); os.IsNotExist(err) {
if _, err := os.Stat(filepath.Join(dir, "tor")); os.IsNotExist(err) {
if _, err := os.Stat(filepath.Join(dir, "deploy", "linux", "tor")); os.IsNotExist(err) {
log.Warnln("Cannot find bundled Tor")
} else {
torpath = path.Join(dir, "deploy", "linux", "tor")
torpath = filepath.Join(dir, "deploy", "linux", "tor")
}
} else {
torpath = path.Join(dir, "tor")
torpath = filepath.Join(dir, "tor")
}
}
@ -251,7 +250,7 @@ func loadACN() {
// generate torrc on the fly
// TODO if we have been configured for it, use system tor (like orbot) - we need a way to config this in the UI first
tor.NewTorrc().WithSocksPort(port).WithOnionTrafficOnly().WithControlPort(controlPort).WithHashedPassword(base64.StdEncoding.EncodeToString(key)).Build(path.Join(the.CwtchDir, "tor", "torrc"))
tor.NewTorrc().WithSocksPort(port).WithOnionTrafficOnly().WithControlPort(controlPort).WithHashedPassword(base64.StdEncoding.EncodeToString(key)).Build(filepath.Join(the.CwtchDir, "tor", "torrc"))
the.ACN, err = tor.NewTorACNWithAuth(the.CwtchDir, torpath, controlPort, tor.HashedPasswordAuthenticator{base64.StdEncoding.EncodeToString(key)})
if err != nil {
@ -263,8 +262,8 @@ func loadACN() {
func loadNetworkingAndFiles(gcd *ui.GrandCentralDispatcher, service bool, clientUI bool) {
if service || clientUI || runtime.GOOS == "android" {
clientIn := path.Join(the.CwtchDir, "clientIn")
serviceIn := path.Join(the.CwtchDir, "serviceIn")
clientIn := filepath.Join(the.CwtchDir, "clientIn")
serviceIn := filepath.Join(the.CwtchDir, "serviceIn")
if service {
loadACN()
serviceBridge := bridge.NewPipeBridgeService(serviceIn, clientIn)