Allow Caching of Tor Data Directories
continuous-integration/drone/pr Build is pending
Details
continuous-integration/drone/pr Build is pending
Details
- Also deletes unused data directories on startup.
This commit is contained in:
parent
4cf95d6507
commit
799fc6e621
|
@ -110,7 +110,7 @@ func (sf *ServersFunctionality) Enable() {
|
||||||
|
|
||||||
func (sf *ServersFunctionality) LoadServers(password string) ([]string, error) {
|
func (sf *ServersFunctionality) LoadServers(password string) ([]string, error) {
|
||||||
servers, err := appServers.LoadServers(password)
|
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 {
|
for _, onion := range servers {
|
||||||
server := appServers.GetServer(onion)
|
server := appServers.GetServer(onion)
|
||||||
server.SetMonitorLogging(false)
|
server.SetMonitorLogging(false)
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -5,7 +5,7 @@ go 1.15
|
||||||
require (
|
require (
|
||||||
cwtch.im/cwtch v0.14.12
|
cwtch.im/cwtch v0.14.12
|
||||||
git.openprivacy.ca/cwtch.im/server v1.4.2
|
git.openprivacy.ca/cwtch.im/server v1.4.2
|
||||||
git.openprivacy.ca/openprivacy/connectivity v1.7.0
|
git.openprivacy.ca/openprivacy/connectivity v1.8.0
|
||||||
git.openprivacy.ca/openprivacy/log v1.0.3
|
git.openprivacy.ca/openprivacy/log v1.0.3
|
||||||
github.com/mutecomm/go-sqlcipher/v4 v4.4.2
|
github.com/mutecomm/go-sqlcipher/v4 v4.4.2
|
||||||
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect
|
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/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.5.0/go.mod h1:UjQiGBnWbotmBzIw59B8H6efwDadjkKzm3RPT1UaIRw=
|
||||||
git.openprivacy.ca/openprivacy/connectivity v1.6.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.7.0/go.mod h1:UjQiGBnWbotmBzIw59B8H6efwDadjkKzm3RPT1UaIRw=
|
||||||
|
git.openprivacy.ca/openprivacy/connectivity v1.8.0 h1:/jnc/2LuUpli2NgeLw6zOAVESHrz5mr10kDCQHyZ7R4=
|
||||||
|
git.openprivacy.ca/openprivacy/connectivity v1.8.0/go.mod h1:UjQiGBnWbotmBzIw59B8H6efwDadjkKzm3RPT1UaIRw=
|
||||||
git.openprivacy.ca/openprivacy/log v1.0.2/go.mod h1:gGYK8xHtndRLDymFtmjkG26GaMQNgyhioNS82m812Iw=
|
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 h1:E/PMm4LY+Q9s3aDpfySfEDq/vYQontlvNj/scrPaga0=
|
||||||
git.openprivacy.ca/openprivacy/log v1.0.3/go.mod h1:gGYK8xHtndRLDymFtmjkG26GaMQNgyhioNS82m812Iw=
|
git.openprivacy.ca/openprivacy/log v1.0.3/go.mod h1:gGYK8xHtndRLDymFtmjkG26GaMQNgyhioNS82m812Iw=
|
||||||
|
|
33
lib.go
33
lib.go
|
@ -10,6 +10,8 @@ import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
constants2 "cwtch.im/cwtch/model/constants"
|
constants2 "cwtch.im/cwtch/model/constants"
|
||||||
|
@ -195,6 +197,8 @@ func _startCwtch(appDir string, torPath string) {
|
||||||
event.FileDownloaded,
|
event.FileDownloaded,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Settings may have changed...
|
||||||
|
settings = utils.ReadGlobalSettings()
|
||||||
settingsJson, _ := json.Marshal(settings)
|
settingsJson, _ := json.Marshal(settings)
|
||||||
|
|
||||||
application.LoadProfiles(constants.DefactoPasswordForUnencryptedProfiles)
|
application.LoadProfiles(constants.DefactoPasswordForUnencryptedProfiles)
|
||||||
|
@ -260,7 +264,32 @@ func buildACN(settings utils.GlobalSettings, torPath string, appDir string) conn
|
||||||
return &connectivity.ErrorACN{}
|
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 := filepath.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 {
|
if err != nil {
|
||||||
log.Errorf("Error connecting to Tor replacing with ErrorACN: %v\n", err)
|
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)))
|
eventHandler.Push(event.NewEventList(utils.CwtchStartError, event.Error, fmt.Sprintf("Error connecting to Tor: %v", err)))
|
||||||
|
@ -296,7 +325,7 @@ func ReconnectCwtchForeground() {
|
||||||
profile := application.GetPeer(profileOnion)
|
profile := application.GetPeer(profileOnion)
|
||||||
conversations, _ := profile.FetchConversations()
|
conversations, _ := profile.FetchConversations()
|
||||||
for _, conversation := range conversations {
|
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)
|
totalMessages, _ := profile.GetChannelMessageCount(conversation.ID, 0)
|
||||||
eventHandler.Push(event.NewEvent(event.MessageCounterResync, map[event.Field]string{
|
eventHandler.Push(event.NewEvent(event.MessageCounterResync, map[event.Field]string{
|
||||||
event.Identity: profileOnion,
|
event.Identity: profileOnion,
|
||||||
|
|
|
@ -46,6 +46,8 @@ type GlobalSettings struct {
|
||||||
UseExternalTor bool
|
UseExternalTor bool
|
||||||
CustomSocksPort int
|
CustomSocksPort int
|
||||||
CustomControlPort int
|
CustomControlPort int
|
||||||
|
UseTorCache bool
|
||||||
|
TorCacheDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
var DefaultGlobalSettings = GlobalSettings{
|
var DefaultGlobalSettings = GlobalSettings{
|
||||||
|
@ -66,6 +68,8 @@ var DefaultGlobalSettings = GlobalSettings{
|
||||||
UseCustomTorrc: false,
|
UseCustomTorrc: false,
|
||||||
CustomSocksPort: -1,
|
CustomSocksPort: -1,
|
||||||
CustomControlPort: -1,
|
CustomControlPort: -1,
|
||||||
|
UseTorCache: false,
|
||||||
|
TorCacheDir: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitGlobalSettingsFile(directory string, password string) error {
|
func InitGlobalSettingsFile(directory string, password string) error {
|
||||||
|
|
Reference in New Issue