Merge pull request 'Allow Caching of Tor Data Directories' (#62) from custom_tor_config into trunk
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Reviewed-on: #62
This commit is contained in:
commit
2aea700ebd
|
@ -110,7 +110,7 @@ func (sf *ServersFunctionality) Enable() {
|
|||
|
||||
func (sf *ServersFunctionality) LoadServers(password string) ([]string, error) {
|
||||
servers, err := appServers.LoadServers(password)
|
||||
// server:1.3/libcwtch-go:1.4 accidentely enabled monitor logging by default. make sure it's turned off
|
||||
// server:1.3/libcwtch-go:1.4 accidentally enabled monitor logging by default. make sure it's turned off
|
||||
for _, onion := range servers {
|
||||
server := appServers.GetServer(onion)
|
||||
server.SetMonitorLogging(false)
|
||||
|
|
2
go.mod
2
go.mod
|
@ -5,7 +5,7 @@ go 1.15
|
|||
require (
|
||||
cwtch.im/cwtch v0.14.12
|
||||
git.openprivacy.ca/cwtch.im/server v1.4.2
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.7.0
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.8.1
|
||||
git.openprivacy.ca/openprivacy/log v1.0.3
|
||||
github.com/mutecomm/go-sqlcipher/v4 v4.4.2
|
||||
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect
|
||||
|
|
3
go.sum
3
go.sum
|
@ -25,8 +25,9 @@ git.openprivacy.ca/openprivacy/bine v0.0.4 h1:CO7EkGyz+jegZ4ap8g5NWRuDHA/56KKvGy
|
|||
git.openprivacy.ca/openprivacy/bine v0.0.4/go.mod h1:13ZqhKyqakDsN/ZkQkIGNULsmLyqtXc46XBcnuXm/mU=
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.5.0/go.mod h1:UjQiGBnWbotmBzIw59B8H6efwDadjkKzm3RPT1UaIRw=
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.6.0/go.mod h1:UjQiGBnWbotmBzIw59B8H6efwDadjkKzm3RPT1UaIRw=
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.7.0 h1:h3NZsxY0/viqyrLInu/S/3t23ehAYmhJm7rsHPvm8NU=
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.7.0/go.mod h1:UjQiGBnWbotmBzIw59B8H6efwDadjkKzm3RPT1UaIRw=
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.8.1 h1:OjWy+JTAvlrstY8PnGPBp7Ho04JaKHaQ+YdoLwSdaCo=
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.8.1/go.mod h1:UjQiGBnWbotmBzIw59B8H6efwDadjkKzm3RPT1UaIRw=
|
||||
git.openprivacy.ca/openprivacy/log v1.0.2/go.mod h1:gGYK8xHtndRLDymFtmjkG26GaMQNgyhioNS82m812Iw=
|
||||
git.openprivacy.ca/openprivacy/log v1.0.3 h1:E/PMm4LY+Q9s3aDpfySfEDq/vYQontlvNj/scrPaga0=
|
||||
git.openprivacy.ca/openprivacy/log v1.0.3/go.mod h1:gGYK8xHtndRLDymFtmjkG26GaMQNgyhioNS82m812Iw=
|
||||
|
|
42
lib.go
42
lib.go
|
@ -10,6 +10,8 @@ import (
|
|||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
path "path/filepath"
|
||||
"strconv"
|
||||
|
||||
constants2 "cwtch.im/cwtch/model/constants"
|
||||
|
@ -41,7 +43,6 @@ import (
|
|||
"encoding/base64"
|
||||
mrand "math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"git.openprivacy.ca/openprivacy/connectivity/tor"
|
||||
|
@ -140,7 +141,7 @@ func _startCwtch(appDir string, torPath string) {
|
|||
if appDir == "~" {
|
||||
appDir = homeDir
|
||||
} else if strings.HasPrefix(appDir, "~/") {
|
||||
appDir = filepath.Join(homeDir, appDir[2:])
|
||||
appDir = path.Join(homeDir, appDir[2:])
|
||||
}
|
||||
|
||||
// Ensure that the application directory exists...and then initialize settings..
|
||||
|
@ -159,7 +160,7 @@ func _startCwtch(appDir string, torPath string) {
|
|||
log.Infof("Loading Cwtch Directory %v and tor path: %v", appDir, torPath)
|
||||
|
||||
log.Infof("making directory %v", appDir)
|
||||
err = os.MkdirAll(filepath.Join(appDir, "tor"), 0700)
|
||||
err = os.MkdirAll(path.Join(appDir, "tor"), 0700)
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("error creating tor data directory: %v. Aborting app start up", err)
|
||||
|
@ -195,6 +196,8 @@ func _startCwtch(appDir string, torPath string) {
|
|||
event.FileDownloaded,
|
||||
}
|
||||
|
||||
// Settings may have changed...
|
||||
settings = utils.ReadGlobalSettings()
|
||||
settingsJson, _ := json.Marshal(settings)
|
||||
|
||||
application.LoadProfiles(constants.DefactoPasswordForUnencryptedProfiles)
|
||||
|
@ -227,7 +230,7 @@ func buildACN(settings utils.GlobalSettings, torPath string, appDir string) conn
|
|||
}
|
||||
|
||||
log.Infof("making directory %v", appDir)
|
||||
err = os.MkdirAll(filepath.Join(appDir, "tor"), 0700)
|
||||
err = os.MkdirAll(path.Join(appDir, "tor"), 0700)
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("error creating tor data directory: %v. Aborting app start up", err)
|
||||
|
@ -252,7 +255,7 @@ func buildACN(settings utils.GlobalSettings, torPath string, appDir string) conn
|
|||
utils.WriteGlobalSettings(settings)
|
||||
}
|
||||
|
||||
err = torrc.Build(filepath.Join(appDir, "tor", "torrc"))
|
||||
err = torrc.Build(path.Join(appDir, "tor", "torrc"))
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("error constructing torrc: %v", err)
|
||||
|
@ -260,7 +263,32 @@ func buildACN(settings utils.GlobalSettings, torPath string, appDir string) conn
|
|||
return &connectivity.ErrorACN{}
|
||||
}
|
||||
|
||||
acn, err := tor.NewTorACNWithAuth(appDir, torPath, controlPort, tor.HashedPasswordAuthenticator{Password: base64.StdEncoding.EncodeToString(key)})
|
||||
dataDir := settings.TorCacheDir
|
||||
if !settings.UseTorCache {
|
||||
|
||||
// purge data dir directories if we are not using them for a cache
|
||||
torDir := path.Join(appDir, "tor")
|
||||
files, err := path.Glob(path.Join(torDir, "data-dir-*"))
|
||||
if err != nil {
|
||||
log.Errorf("could not construct filesystem glob: %v", err)
|
||||
}
|
||||
for _, f := range files {
|
||||
if err := os.RemoveAll(f); err != nil {
|
||||
log.Errorf("could not remove data-dir: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if dataDir, err = ioutil.TempDir(torDir, "data-dir-"); err != nil {
|
||||
eventHandler.Push(event.NewEventList(utils.CwtchStartError, event.Error, fmt.Sprintf("Error connecting to Tor: %v", err)))
|
||||
return &connectivity.ErrorACN{}
|
||||
}
|
||||
}
|
||||
|
||||
// Persist Current Data Dir as Tor Cache...
|
||||
settings.TorCacheDir = dataDir
|
||||
utils.WriteGlobalSettings(settings)
|
||||
|
||||
acn, err := tor.NewTorACNWithAuth(appDir, torPath, dataDir, controlPort, tor.HashedPasswordAuthenticator{Password: base64.StdEncoding.EncodeToString(key)})
|
||||
if err != nil {
|
||||
log.Errorf("Error connecting to Tor replacing with ErrorACN: %v\n", err)
|
||||
eventHandler.Push(event.NewEventList(utils.CwtchStartError, event.Error, fmt.Sprintf("Error connecting to Tor: %v", err)))
|
||||
|
@ -296,7 +324,7 @@ func ReconnectCwtchForeground() {
|
|||
profile := application.GetPeer(profileOnion)
|
||||
conversations, _ := profile.FetchConversations()
|
||||
for _, conversation := range conversations {
|
||||
if (conversation.IsGroup() && groupHandler != nil) || conversation.IsServer() == false {
|
||||
if (conversation.IsGroup() && groupHandler != nil) || !conversation.IsServer() {
|
||||
totalMessages, _ := profile.GetChannelMessageCount(conversation.ID, 0)
|
||||
eventHandler.Push(event.NewEvent(event.MessageCounterResync, map[event.Field]string{
|
||||
event.Identity: profileOnion,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
path "path/filepath"
|
||||
"sync"
|
||||
|
||||
"cwtch.im/cwtch/event"
|
||||
|
@ -9,7 +10,6 @@ import (
|
|||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"git.openprivacy.ca/openprivacy/log"
|
||||
)
|
||||
|
@ -46,6 +46,8 @@ type GlobalSettings struct {
|
|||
UseExternalTor bool
|
||||
CustomSocksPort int
|
||||
CustomControlPort int
|
||||
UseTorCache bool
|
||||
TorCacheDir string
|
||||
}
|
||||
|
||||
var DefaultGlobalSettings = GlobalSettings{
|
||||
|
@ -66,6 +68,8 @@ var DefaultGlobalSettings = GlobalSettings{
|
|||
UseCustomTorrc: false,
|
||||
CustomSocksPort: -1,
|
||||
CustomControlPort: -1,
|
||||
UseTorCache: false,
|
||||
TorCacheDir: "",
|
||||
}
|
||||
|
||||
func InitGlobalSettingsFile(directory string, password string) error {
|
||||
|
|
Reference in New Issue