Autodownloads Experiment Moved to Cwtch + Better Build Dirs
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
This commit is contained in:
parent
6dee3bc1bd
commit
7e3e1f977a
12
.drone.yml
12
.drone.yml
|
@ -17,6 +17,8 @@ steps:
|
||||||
- git fetch --tags
|
- git fetch --tags
|
||||||
- go mod download
|
- go mod download
|
||||||
- echo `git describe --tags` > VERSION
|
- echo `git describe --tags` > VERSION
|
||||||
|
- echo `git log -1 --format=%cd --date=format:%G-%m-%d-%H-%M` > COMMIT_DATE
|
||||||
|
- export GOSUMDB="off"
|
||||||
|
|
||||||
- name: build-linux
|
- name: build-linux
|
||||||
image: golang:1.19.1
|
image: golang:1.19.1
|
||||||
|
@ -68,9 +70,9 @@ steps:
|
||||||
- echo $BUILDFILES_KEY > ~/id_rsab64
|
- echo $BUILDFILES_KEY > ~/id_rsab64
|
||||||
- base64 -d ~/id_rsab64 > ~/id_rsa
|
- base64 -d ~/id_rsab64 > ~/id_rsa
|
||||||
- chmod 400 ~/id_rsa
|
- chmod 400 ~/id_rsa
|
||||||
- export DIR=libCwtch-autobindings-`cat VERSION`
|
- export DIR=libCwtch-autobindings-`cat VERSION`-`cat COMMIT_DATE`
|
||||||
- mkdir -p $DIR
|
- mkdir -p $DIR
|
||||||
- mv libCwtch.so libCwtch.dll cwtch.aar cwtch-sources.jar libCwtch.h $DIR/
|
- mv windows android linux $DIR/
|
||||||
- cd $DIR
|
- cd $DIR
|
||||||
- find . -type f -exec sha256sum {} \; > ./../sha256s.txt
|
- find . -type f -exec sha256sum {} \; > ./../sha256s.txt
|
||||||
- mv ./../sha256s.txt .
|
- mv ./../sha256s.txt .
|
||||||
|
@ -136,6 +138,7 @@ steps:
|
||||||
- export PATH=$PATH:/usr/local/go/bin/
|
- export PATH=$PATH:/usr/local/go/bin/
|
||||||
- git fetch --tags
|
- git fetch --tags
|
||||||
- echo `git describe --tags` > VERSION
|
- echo `git describe --tags` > VERSION
|
||||||
|
- echo `git log -1 --format=%cd --date=format:%G-%m-%d-%H-%M` > COMMIT_DATE
|
||||||
- name: build-macos-x64
|
- name: build-macos-x64
|
||||||
commands:
|
commands:
|
||||||
- export PATH=$PATH:/usr/local/go/bin/
|
- export PATH=$PATH:/usr/local/go/bin/
|
||||||
|
@ -163,10 +166,9 @@ steps:
|
||||||
- echo $BUILDFILES_KEY > ~/id_rsab64
|
- echo $BUILDFILES_KEY > ~/id_rsab64
|
||||||
- base64 -d ~/id_rsab64 > ~/id_rsa
|
- base64 -d ~/id_rsab64 > ~/id_rsa
|
||||||
- chmod 400 ~/id_rsa
|
- chmod 400 ~/id_rsa
|
||||||
- export DIR=libCwtch-autobindings-`cat VERSION`
|
- export DIR=libCwtch-autobindings-`cat VERSION`-`cat COMMIT_DATE`
|
||||||
- mkdir -p $DIR
|
- mkdir -p $DIR
|
||||||
- mv libCwtch.x64.dylib $DIR/
|
- mv macos $DIR/
|
||||||
- mv libCwtch.arm64.dylib $DIR/
|
|
||||||
- cd $DIR
|
- cd $DIR
|
||||||
- find . -type f -exec shasum -a 512 {} \; > ./../sha512s.txt
|
- find . -type f -exec shasum -a 512 {} \; > ./../sha512s.txt
|
||||||
- mv ./../sha512s.txt .
|
- mv ./../sha512s.txt .
|
||||||
|
|
16
Makefile
16
Makefile
|
@ -17,18 +17,29 @@ windows: libCwtch.dll
|
||||||
libCwtch.so: lib.go
|
libCwtch.so: lib.go
|
||||||
./switch-ffi.sh
|
./switch-ffi.sh
|
||||||
go build -trimpath -ldflags "-buildid=autobindings-$(shell git describe --tags) -X main.buildVer=autobindings-$(shell git describe --tags) -X main.buildDate=$(shell git log -1 --format=%cd --date=format:%G-%m-%d-%H-%M)" -buildmode c-shared -o libCwtch.so
|
go build -trimpath -ldflags "-buildid=autobindings-$(shell git describe --tags) -X main.buildVer=autobindings-$(shell git describe --tags) -X main.buildDate=$(shell git log -1 --format=%cd --date=format:%G-%m-%d-%H-%M)" -buildmode c-shared -o libCwtch.so
|
||||||
|
mkdir -p build/linux
|
||||||
|
mv libCwtch.so build/linux/
|
||||||
|
mv libCwtch.h build/linux/
|
||||||
|
|
||||||
libCwtch.x64.dylib: lib.go
|
libCwtch.x64.dylib: lib.go
|
||||||
./switch-ffi.sh
|
./switch-ffi.sh
|
||||||
go build -trimpath -ldflags "-buildid=autobindings-$(shell git describe --tags) -X main.buildVer=autobindings-$(shell git describe --tags) -X main.buildDate=$(shell git log -1 --format=%cd --date=format:%G-%m-%d-%H-%M)" -buildmode c-shared -o libCwtch.x64.dylib
|
go build -trimpath -ldflags "-buildid=autobindings-$(shell git describe --tags) -X main.buildVer=autobindings-$(shell git describe --tags) -X main.buildDate=$(shell git log -1 --format=%cd --date=format:%G-%m-%d-%H-%M)" -buildmode c-shared -o libCwtch.x64.dylib
|
||||||
|
mkdir -p build/macos
|
||||||
|
mv libCwtch.x64.dylib build/macos/
|
||||||
|
|
||||||
libCwtch.arm64.dylib: lib.go
|
libCwtch.arm64.dylib: lib.go
|
||||||
./switch-ffi.sh
|
./switch-ffi.sh
|
||||||
env GOARCH=arm64 GOOS=darwin CGO_ENABLED=1 go build -trimpath -ldflags "-buildid=$(shell git describe --tags) -X main.buildVer=$(shell git describe --tags) -X main.buildDate=$(shell git log -1 --format=%cd --date=format:%G-%m-%d-%H-%M)" -buildmode c-shared -o libCwtch.arm64.dylib
|
env GOARCH=arm64 GOOS=darwin CGO_ENABLED=1 go build -trimpath -ldflags "-buildid=$(shell git describe --tags) -X main.buildVer=$(shell git describe --tags) -X main.buildDate=$(shell git log -1 --format=%cd --date=format:%G-%m-%d-%H-%M)" -buildmode c-shared -o libCwtch.arm64.dylib
|
||||||
|
mkdir -p build/macos
|
||||||
|
mv libCwtch.arm64.dylib build/macos/
|
||||||
|
mv libCwtch.h build/macos/
|
||||||
|
|
||||||
cwtch.aar: lib.go
|
cwtch.aar: lib.go
|
||||||
./switch-gomobile.sh
|
./switch-gomobile.sh
|
||||||
gomobile bind -trimpath -target android/arm,android/arm64,android/amd64 -ldflags="-buildid=$(shell git describe --tags) -X cwtch.buildVer=$(shell git describe --tags) -X cwtch.buildDate=$(shell git log -1 --format=%cd --date=format:%G-%m-%d-%H-%M)"
|
gomobile bind -trimpath -target android/arm,android/arm64,android/amd64 -ldflags="-buildid=$(shell git describe --tags) -X cwtch.buildVer=$(shell git describe --tags) -X cwtch.buildDate=$(shell git log -1 --format=%cd --date=format:%G-%m-%d-%H-%M)"
|
||||||
|
mkdir -p build/android
|
||||||
|
mv cwtch.aar build/android/
|
||||||
|
mv cwtch-sources.jar build/android/
|
||||||
|
|
||||||
libCwtch.dll: lib.go
|
libCwtch.dll: lib.go
|
||||||
./switch-ffi.sh
|
./switch-ffi.sh
|
||||||
|
@ -37,9 +48,12 @@ libCwtch.dll: lib.go
|
||||||
# note: the above documentation also references an ability to set an optional timestamp - this behaviour seems to no longer be supported in more recent versions of mingw32-gcc (the help docs no longer reference that functionality)
|
# note: the above documentation also references an ability to set an optional timestamp - this behaviour seems to no longer be supported in more recent versions of mingw32-gcc (the help docs no longer reference that functionality)
|
||||||
# these flags have to be passed through to the underlying gcc process using the -extldflags option in the underlying go linker, note that the whole flag is quoted...this is necessary.
|
# these flags have to be passed through to the underlying gcc process using the -extldflags option in the underlying go linker, note that the whole flag is quoted...this is necessary.
|
||||||
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc-win32 go build -trimpath -ldflags "-buildid=$(shell git describe --tags) -X main.buildVer=$(shell git describe --tags) -X main.buildDate=$(shell git log -1 --format=%cd --date=format:%G-%m-%d-%H-%M) '-extldflags=-Xlinker --no-insert-timestamp'" -buildmode c-shared -o libCwtch.dll
|
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc-win32 go build -trimpath -ldflags "-buildid=$(shell git describe --tags) -X main.buildVer=$(shell git describe --tags) -X main.buildDate=$(shell git log -1 --format=%cd --date=format:%G-%m-%d-%H-%M) '-extldflags=-Xlinker --no-insert-timestamp'" -buildmode c-shared -o libCwtch.dll
|
||||||
|
mkdir -p build/windows
|
||||||
|
mv libCwtch.dll build/windows/
|
||||||
|
mv libCwtch.h build/windows/
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f cwtch.aar cwtch_go.apk libCwtch.h libCwtch.so cwtch-sources.jar libCwtch.dll libCwtch.dylib
|
rm -f cwtch.aar cwtch_go.apk libCwtch.h libCwtch.so cwtch-sources.jar libCwtch.dll libCwtch.dylib build
|
||||||
|
|
||||||
# iOS - for testing purposes only for now, not officially supported
|
# iOS - for testing purposes only for now, not officially supported
|
||||||
|
|
||||||
|
|
|
@ -405,7 +405,7 @@ func c_{{FNAME}}({{C_ARGS}}) {
|
||||||
func {{FNAME}}({{GO_ARGS_SPEC}}) {
|
func {{FNAME}}({{GO_ARGS_SPEC}}) {
|
||||||
cwtchProfile := application.GetPeer(profile)
|
cwtchProfile := application.GetPeer(profile)
|
||||||
if cwtchProfile != nil {
|
if cwtchProfile != nil {
|
||||||
functionality, _ := {{EXPERIMENT}}.FunctionalityGate(application.ReadSettings().Experiments)
|
functionality := {{EXPERIMENT}}.FunctionalityGate()
|
||||||
if functionality != nil {
|
if functionality != nil {
|
||||||
functionality.{{LIBNAME}}(cwtchProfile, {{GO_ARG}})
|
functionality.{{LIBNAME}}(cwtchProfile, {{GO_ARG}})
|
||||||
}
|
}
|
||||||
|
@ -439,7 +439,7 @@ func c_{{FNAME}}({{C_ARGS}}) *C.char {
|
||||||
func {{FNAME}}({{GO_ARGS_SPEC}}) string {
|
func {{FNAME}}({{GO_ARGS_SPEC}}) string {
|
||||||
cwtchProfile := application.GetPeer(profile)
|
cwtchProfile := application.GetPeer(profile)
|
||||||
if cwtchProfile != nil {
|
if cwtchProfile != nil {
|
||||||
functionality, _ := {{EXPERIMENT}}.FunctionalityGate(application.ReadSettings().Experiments)
|
functionality := {{EXPERIMENT}}.FunctionalityGate()
|
||||||
if functionality != nil {
|
if functionality != nil {
|
||||||
return functionality.{{LIBNAME}}(cwtchProfile, {{GO_ARG}})
|
return functionality.{{LIBNAME}}(cwtchProfile, {{GO_ARG}})
|
||||||
}
|
}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module git.openprivacy.ca/cwtch.im/cwtch-autobindings
|
||||||
go 1.19
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
cwtch.im/cwtch v0.19.1
|
cwtch.im/cwtch v0.19.2
|
||||||
git.openprivacy.ca/cwtch.im/server v1.4.5
|
git.openprivacy.ca/cwtch.im/server v1.4.5
|
||||||
git.openprivacy.ca/openprivacy/connectivity v1.8.6
|
git.openprivacy.ca/openprivacy/connectivity v1.8.6
|
||||||
git.openprivacy.ca/openprivacy/log v1.0.3
|
git.openprivacy.ca/openprivacy/log v1.0.3
|
||||||
|
|
6
go.sum
6
go.sum
|
@ -1,8 +1,6 @@
|
||||||
cwtch.im/cwtch v0.18.0/go.mod h1:StheazFFY7PKqBbEyDVLhzWW6WOat41zV0ckC240c5Y=
|
cwtch.im/cwtch v0.18.0/go.mod h1:StheazFFY7PKqBbEyDVLhzWW6WOat41zV0ckC240c5Y=
|
||||||
cwtch.im/cwtch v0.19.0 h1:s5YkU3od1ZJB+8OXoJAy8vjgi6lkIVhbdkXIE8V+iZY=
|
cwtch.im/cwtch v0.19.2 h1:H7DrSKQ9J7aNkKQkdyGGWckEV+dPKbL5PMRq0GoAn6I=
|
||||||
cwtch.im/cwtch v0.19.0/go.mod h1:h8S7EgEM+8pE1k+XLB5jAFdIPlOzwoXEY0GH5mQye5A=
|
cwtch.im/cwtch v0.19.2/go.mod h1:h8S7EgEM+8pE1k+XLB5jAFdIPlOzwoXEY0GH5mQye5A=
|
||||||
cwtch.im/cwtch v0.19.1 h1:PRZtIZa1AIZ4jtIItUCN4ROcNLpPE4Ds8VksbbVa3ks=
|
|
||||||
cwtch.im/cwtch v0.19.1/go.mod h1:h8S7EgEM+8pE1k+XLB5jAFdIPlOzwoXEY0GH5mQye5A=
|
|
||||||
filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
|
filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
|
||||||
filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek=
|
filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek=
|
||||||
filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
|
filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"cwtch.im/cwtch/event"
|
"cwtch.im/cwtch/event"
|
||||||
"cwtch.im/cwtch/model/attr"
|
"cwtch.im/cwtch/model/attr"
|
||||||
"cwtch.im/cwtch/model/constants"
|
"cwtch.im/cwtch/model/constants"
|
||||||
|
"cwtch.im/cwtch/settings"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.openprivacy.ca/cwtch.im/cwtch-autobindings/utils"
|
"git.openprivacy.ca/cwtch.im/cwtch-autobindings/utils"
|
||||||
|
@ -149,7 +150,7 @@ func _startCwtch(appDir string, torPath string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("Loading Cwtch Directory %v and tor path: %v", appDir, torPath)
|
log.Infof("Loading Cwtch Directory %v and tor path: %v", appDir, torPath)
|
||||||
app.InitGlobalSettingsFile(appDir, app.DefactoPasswordForUnencryptedProfiles)
|
settings.InitGlobalSettingsFile(appDir, app.DefactoPasswordForUnencryptedProfiles)
|
||||||
|
|
||||||
log.Infof("making directory %v", appDir)
|
log.Infof("making directory %v", appDir)
|
||||||
err = os.MkdirAll(path.Join(appDir, "tor"), 0700)
|
err = os.MkdirAll(path.Join(appDir, "tor"), 0700)
|
||||||
|
@ -164,17 +165,17 @@ func _startCwtch(appDir string, torPath string) {
|
||||||
globalAppDir = appDir
|
globalAppDir = appDir
|
||||||
globalTorPath = torPath
|
globalTorPath = torPath
|
||||||
settingsFile := app.LoadAppSettings(appDir)
|
settingsFile := app.LoadAppSettings(appDir)
|
||||||
newACN, settings := buildACN(settingsFile.ReadGlobalSettings(), globalTorPath, globalAppDir)
|
newACN, globalSettings := buildACN(settingsFile.ReadGlobalSettings(), globalTorPath, globalAppDir)
|
||||||
globalACN = connectivity.NewProxyACN(newACN)
|
globalACN = connectivity.NewProxyACN(newACN)
|
||||||
settingsFile.WriteGlobalSettings(settings)
|
settingsFile.WriteGlobalSettings(globalSettings)
|
||||||
application = app.NewApp(&globalACN, appDir, settingsFile)
|
application = app.NewApp(&globalACN, appDir, settingsFile)
|
||||||
|
|
||||||
// Subscribe to all App Events...
|
// Subscribe to all App Events...
|
||||||
eventHandler.HandleApp(application)
|
eventHandler.HandleApp(application)
|
||||||
|
|
||||||
// Settings may have changed...
|
// Settings may have changed...
|
||||||
settings = settings
|
globalSettings = settingsFile.ReadGlobalSettings()
|
||||||
settingsJson, _ := json.Marshal(settings)
|
settingsJson, _ := json.Marshal(globalSettings)
|
||||||
|
|
||||||
// FIXME: This code exists to allow the Splash Screen test in the new UI integration tests to pass
|
// FIXME: This code exists to allow the Splash Screen test in the new UI integration tests to pass
|
||||||
// it doesn't actually fix the problem in theory, and we should get around to ensuring that application
|
// it doesn't actually fix the problem in theory, and we should get around to ensuring that application
|
||||||
|
@ -184,10 +185,10 @@ func _startCwtch(appDir string, torPath string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Send global settings to the UI...
|
// Send global settings to the UI...
|
||||||
application.UpdateSettings(application.ReadSettings())
|
application.UpdateSettings(globalSettings)
|
||||||
application.GetPrimaryBus().Publish(event.NewEvent(app.UpdateGlobalSettings, map[event.Field]string{event.Data: string(settingsJson)}))
|
application.GetPrimaryBus().Publish(event.NewEvent(settings.UpdateGlobalSettings, map[event.Field]string{event.Data: string(settingsJson)}))
|
||||||
log.Infof("libcwtch-go application launched")
|
log.Infof("libcwtch-go application launched")
|
||||||
application.GetPrimaryBus().Publish(event.NewEvent(app.CwtchStarted, map[event.Field]string{}))
|
application.GetPrimaryBus().Publish(event.NewEvent(settings.CwtchStarted, map[event.Field]string{}))
|
||||||
application.QueryACNVersion()
|
application.QueryACNVersion()
|
||||||
application.LoadProfiles(app.DefactoPasswordForUnencryptedProfiles)
|
application.LoadProfiles(app.DefactoPasswordForUnencryptedProfiles)
|
||||||
|
|
||||||
|
@ -233,8 +234,8 @@ func ReconnectCwtchForeground() {
|
||||||
// TODO: Need To Repopulate UI
|
// TODO: Need To Repopulate UI
|
||||||
|
|
||||||
settingsJson, _ := json.Marshal(application.ReadSettings())
|
settingsJson, _ := json.Marshal(application.ReadSettings())
|
||||||
application.GetPrimaryBus().Publish(event.NewEvent(app.UpdateGlobalSettings, map[event.Field]string{event.Data: string(settingsJson)}))
|
application.GetPrimaryBus().Publish(event.NewEvent(settings.UpdateGlobalSettings, map[event.Field]string{event.Data: string(settingsJson)}))
|
||||||
application.GetPrimaryBus().Publish(event.NewEvent(app.CwtchStarted, map[event.Field]string{}))
|
application.GetPrimaryBus().Publish(event.NewEvent(settings.CwtchStarted, map[event.Field]string{}))
|
||||||
application.QueryACNStatus()
|
application.QueryACNStatus()
|
||||||
application.QueryACNVersion()
|
application.QueryACNVersion()
|
||||||
}
|
}
|
||||||
|
@ -397,7 +398,7 @@ const (
|
||||||
UpdateGlobalSettings = event.Type("UpdateGlobalSettings")
|
UpdateGlobalSettings = event.Type("UpdateGlobalSettings")
|
||||||
)
|
)
|
||||||
|
|
||||||
func buildACN(settings app.GlobalSettings, torPath string, appDir string) (connectivity.ACN, app.GlobalSettings) {
|
func buildACN(globalSettings settings.GlobalSettings, torPath string, appDir string) (connectivity.ACN, settings.GlobalSettings) {
|
||||||
|
|
||||||
mrand.Seed(int64(time.Now().Nanosecond()))
|
mrand.Seed(int64(time.Now().Nanosecond()))
|
||||||
socksPort := mrand.Intn(1000) + 9600
|
socksPort := mrand.Intn(1000) + 9600
|
||||||
|
@ -416,24 +417,24 @@ func buildACN(settings app.GlobalSettings, torPath string, appDir string) (conne
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("error creating tor data directory: %v. Aborting app start up", err)
|
log.Errorf("error creating tor data directory: %v. Aborting app start up", err)
|
||||||
eventHandler.Push(event.NewEventList(CwtchStartError, event.Error, fmt.Sprintf("Error connecting to Tor: %v", err)))
|
eventHandler.Push(event.NewEventList(CwtchStartError, event.Error, fmt.Sprintf("Error connecting to Tor: %v", err)))
|
||||||
return &connectivity.ErrorACN{}, settings
|
return &connectivity.ErrorACN{}, globalSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
if settings.AllowAdvancedTorConfig {
|
if globalSettings.AllowAdvancedTorConfig {
|
||||||
controlPort = settings.CustomControlPort
|
controlPort = globalSettings.CustomControlPort
|
||||||
socksPort = settings.CustomSocksPort
|
socksPort = globalSettings.CustomSocksPort
|
||||||
}
|
}
|
||||||
|
|
||||||
torrc := tor.NewTorrc().WithSocksPort(socksPort).WithOnionTrafficOnly().WithControlPort(controlPort).WithHashedPassword(base64.StdEncoding.EncodeToString(key))
|
torrc := tor.NewTorrc().WithSocksPort(socksPort).WithOnionTrafficOnly().WithControlPort(controlPort).WithHashedPassword(base64.StdEncoding.EncodeToString(key))
|
||||||
// torrc.WithLog(path.Join(appDir, "tor", "tor.log"), tor.TorLogLevelNotice)
|
// torrc.WithLog(path.Join(appDir, "tor", "tor.log"), tor.TorLogLevelNotice)
|
||||||
if settings.UseCustomTorrc {
|
if globalSettings.UseCustomTorrc {
|
||||||
customTorrc := settings.CustomTorrc
|
customTorrc := globalSettings.CustomTorrc
|
||||||
torrc.WithCustom(strings.Split(customTorrc, "\n"))
|
torrc.WithCustom(strings.Split(customTorrc, "\n"))
|
||||||
} else {
|
} else {
|
||||||
// Fallback to showing the freshly generated torrc for this session.
|
// Fallback to showing the freshly generated torrc for this session.
|
||||||
settings.CustomTorrc = torrc.Preview()
|
globalSettings.CustomTorrc = torrc.Preview()
|
||||||
settings.CustomControlPort = controlPort
|
globalSettings.CustomControlPort = controlPort
|
||||||
settings.CustomSocksPort = socksPort
|
globalSettings.CustomSocksPort = socksPort
|
||||||
}
|
}
|
||||||
|
|
||||||
err = torrc.Build(path.Join(appDir, "tor", "torrc"))
|
err = torrc.Build(path.Join(appDir, "tor", "torrc"))
|
||||||
|
@ -441,11 +442,11 @@ func buildACN(settings app.GlobalSettings, torPath string, appDir string) (conne
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("error constructing torrc: %v", err)
|
log.Errorf("error constructing torrc: %v", err)
|
||||||
eventHandler.Push(event.NewEventList(CwtchStartError, event.Error, fmt.Sprintf("Error connecting to Tor: %v", err)))
|
eventHandler.Push(event.NewEventList(CwtchStartError, event.Error, fmt.Sprintf("Error connecting to Tor: %v", err)))
|
||||||
return &connectivity.ErrorACN{}, settings
|
return &connectivity.ErrorACN{}, globalSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
dataDir := settings.TorCacheDir
|
dataDir := globalSettings.TorCacheDir
|
||||||
if !settings.UseTorCache {
|
if !globalSettings.UseTorCache {
|
||||||
|
|
||||||
// purge data dir directories if we are not using them for a cache
|
// purge data dir directories if we are not using them for a cache
|
||||||
torDir := path.Join(appDir, "tor")
|
torDir := path.Join(appDir, "tor")
|
||||||
|
@ -461,12 +462,12 @@ func buildACN(settings app.GlobalSettings, torPath string, appDir string) (conne
|
||||||
|
|
||||||
if dataDir, err = os.MkdirTemp(torDir, "data-dir-"); err != nil {
|
if dataDir, err = os.MkdirTemp(torDir, "data-dir-"); err != nil {
|
||||||
eventHandler.Push(event.NewEventList(CwtchStartError, event.Error, fmt.Sprintf("Error connecting to Tor: %v", err)))
|
eventHandler.Push(event.NewEventList(CwtchStartError, event.Error, fmt.Sprintf("Error connecting to Tor: %v", err)))
|
||||||
return &connectivity.ErrorACN{}, settings
|
return &connectivity.ErrorACN{}, globalSettings
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Persist Current Data Dir as Tor Cache...
|
// Persist Current Data Dir as Tor Cache...
|
||||||
settings.TorCacheDir = dataDir
|
globalSettings.TorCacheDir = dataDir
|
||||||
|
|
||||||
acn, err := tor.NewTorACNWithAuth(appDir, torPath, dataDir, controlPort, tor.HashedPasswordAuthenticator{Password: base64.StdEncoding.EncodeToString(key)})
|
acn, err := tor.NewTorACNWithAuth(appDir, torPath, dataDir, controlPort, tor.HashedPasswordAuthenticator{Password: base64.StdEncoding.EncodeToString(key)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -474,7 +475,7 @@ func buildACN(settings app.GlobalSettings, torPath string, appDir string) (conne
|
||||||
eventHandler.Push(event.NewEventList(CwtchStartError, event.Error, fmt.Sprintf("Error connecting to Tor: %v", err)))
|
eventHandler.Push(event.NewEventList(CwtchStartError, event.Error, fmt.Sprintf("Error connecting to Tor: %v", err)))
|
||||||
acn = &connectivity.ErrorACN{}
|
acn = &connectivity.ErrorACN{}
|
||||||
}
|
}
|
||||||
return acn, settings
|
return acn, globalSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -485,7 +486,7 @@ func c_UpdateSettings(json_ptr *C.char, json_len C.int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateSettings(settingsJson string) {
|
func UpdateSettings(settingsJson string) {
|
||||||
var newSettings app.GlobalSettings
|
var newSettings settings.GlobalSettings
|
||||||
json.Unmarshal([]byte(settingsJson), &newSettings)
|
json.Unmarshal([]byte(settingsJson), &newSettings)
|
||||||
application.UpdateSettings(newSettings)
|
application.UpdateSettings(newSettings)
|
||||||
{{EXPERIMENT_UPDATESETTINGS}}
|
{{EXPERIMENT_UPDATESETTINGS}}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"cwtch.im/cwtch/settings"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.openprivacy.ca/cwtch.im/cwtch-autobindings/experiments/servers"
|
"git.openprivacy.ca/cwtch.im/cwtch-autobindings/experiments/servers"
|
||||||
|
@ -66,8 +67,8 @@ func (eh *EventHandler) HandleApp(application app.Application) {
|
||||||
application.GetPrimaryBus().Subscribe(event.AppError, eh.appBusQueue)
|
application.GetPrimaryBus().Subscribe(event.AppError, eh.appBusQueue)
|
||||||
application.GetPrimaryBus().Subscribe(event.ACNStatus, eh.appBusQueue)
|
application.GetPrimaryBus().Subscribe(event.ACNStatus, eh.appBusQueue)
|
||||||
application.GetPrimaryBus().Subscribe(event.ACNVersion, eh.appBusQueue)
|
application.GetPrimaryBus().Subscribe(event.ACNVersion, eh.appBusQueue)
|
||||||
application.GetPrimaryBus().Subscribe(app.UpdateGlobalSettings, eh.appBusQueue)
|
application.GetPrimaryBus().Subscribe(settings.UpdateGlobalSettings, eh.appBusQueue)
|
||||||
application.GetPrimaryBus().Subscribe(app.CwtchStarted, eh.appBusQueue)
|
application.GetPrimaryBus().Subscribe(settings.CwtchStarted, eh.appBusQueue)
|
||||||
application.GetPrimaryBus().Subscribe(servers.NewServer, eh.appBusQueue)
|
application.GetPrimaryBus().Subscribe(servers.NewServer, eh.appBusQueue)
|
||||||
application.GetPrimaryBus().Subscribe(servers.ServerIntentUpdate, eh.appBusQueue)
|
application.GetPrimaryBus().Subscribe(servers.ServerIntentUpdate, eh.appBusQueue)
|
||||||
application.GetPrimaryBus().Subscribe(servers.ServerDeleted, eh.appBusQueue)
|
application.GetPrimaryBus().Subscribe(servers.ServerDeleted, eh.appBusQueue)
|
||||||
|
@ -393,10 +394,6 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ci.Accepted {
|
|
||||||
handleImagePreviews(profile, &ev.Event, ci.ID, ci.ID, eh.app.ReadSettings())
|
|
||||||
}
|
|
||||||
|
|
||||||
ev.Event.Data["notification"] = string(determineNotification(ci, eh.app.ReadSettings()))
|
ev.Event.Data["notification"] = string(determineNotification(ci, eh.app.ReadSettings()))
|
||||||
case event.NewMessageFromGroup:
|
case event.NewMessageFromGroup:
|
||||||
// only needs contact nickname and picture, for displaying on popup notifications
|
// only needs contact nickname and picture, for displaying on popup notifications
|
||||||
|
@ -417,10 +414,6 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID])
|
conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID])
|
||||||
profile.SetConversationAttribute(conversationID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False)
|
profile.SetConversationAttribute(conversationID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False)
|
||||||
|
|
||||||
if ci != nil && ci.Accepted {
|
|
||||||
handleImagePreviews(profile, &ev.Event, conversationID, ci.ID, eh.app.ReadSettings())
|
|
||||||
}
|
|
||||||
|
|
||||||
gci, _ := profile.GetConversationInfo(conversationID)
|
gci, _ := profile.GetConversationInfo(conversationID)
|
||||||
groupServer := gci.Attributes[attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.GroupServer)).ToString()]
|
groupServer := gci.Attributes[attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.GroupServer)).ToString()]
|
||||||
state := profile.GetPeerState(groupServer)
|
state := profile.GetPeerState(groupServer)
|
||||||
|
@ -550,7 +543,6 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
onion := ev.Event.Data[event.RemotePeer]
|
onion := ev.Event.Data[event.RemotePeer]
|
||||||
scope := ev.Event.Data[event.Scope]
|
scope := ev.Event.Data[event.Scope]
|
||||||
path := ev.Event.Data[event.Path]
|
path := ev.Event.Data[event.Path]
|
||||||
val := ev.Event.Data[event.Data]
|
|
||||||
exists, _ := strconv.ParseBool(ev.Event.Data[event.Exists])
|
exists, _ := strconv.ParseBool(ev.Event.Data[event.Exists])
|
||||||
|
|
||||||
conversation, err := profile.FetchConversationInfo(onion)
|
conversation, err := profile.FetchConversationInfo(onion)
|
||||||
|
@ -558,36 +550,6 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
|
|
||||||
if exists && attr.IntoScope(scope) == attr.PublicScope {
|
if exists && attr.IntoScope(scope) == attr.PublicScope {
|
||||||
zone, path := attr.ParseZone(path)
|
zone, path := attr.ParseZone(path)
|
||||||
|
|
||||||
// auto download profile images from contacts...
|
|
||||||
settings := eh.app.ReadSettings()
|
|
||||||
if settings.ExperimentsEnabled && zone == attr.ProfileZone && path == constants.CustomProfileImageKey {
|
|
||||||
fileKey := val
|
|
||||||
fsf, err := filesharing.FunctionalityGate(settings.Experiments)
|
|
||||||
imagePreviewsEnabled := settings.Experiments["filesharing-images"]
|
|
||||||
if err == nil && imagePreviewsEnabled && conversation.Accepted {
|
|
||||||
|
|
||||||
basepath := settings.DownloadPath
|
|
||||||
fp, mp := filesharing.GenerateDownloadPath(basepath, fileKey, true)
|
|
||||||
|
|
||||||
if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True {
|
|
||||||
if _, err := os.Stat(fp); err == nil {
|
|
||||||
// file is marked as completed downloaded and exists...
|
|
||||||
return ""
|
|
||||||
} else {
|
|
||||||
// the user probably deleted the file, mark completed as false...
|
|
||||||
profile.SetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey), event.False)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debugf("Downloading Profile Image %v %v %v", fp, mp, fileKey)
|
|
||||||
ev.Event.Data[event.FilePath] = fp
|
|
||||||
fsf.DownloadFile(profile, conversation.ID, fp, mp, val, constants.ImagePreviewMaxSizeInBytes)
|
|
||||||
} else {
|
|
||||||
// if image previews are disabled then ignore this event...
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if val, err := profile.GetConversationAttribute(conversation.ID, attr.LocalScope.ConstructScopedZonedPath(zone.ConstructZonedPath(path))); err == nil || val != "" {
|
if val, err := profile.GetConversationAttribute(conversation.ID, attr.LocalScope.ConstructScopedZonedPath(zone.ConstructZonedPath(path))); err == nil || val != "" {
|
||||||
// we have a locally set override, don't pass this remote set public scope update to UI
|
// we have a locally set override, don't pass this remote set public scope update to UI
|
||||||
return ""
|
return ""
|
||||||
|
@ -623,24 +585,6 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
} else {
|
} else {
|
||||||
profile.AllowUnknownConnections()
|
profile.AllowUnknownConnections()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that the Peer Engine is Activated, Share Files
|
|
||||||
key, exists := profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey)
|
|
||||||
if exists {
|
|
||||||
serializedManifest, _ := profile.GetScopedZonedAttribute(attr.ConversationScope, attr.FilesharingZone, fmt.Sprintf("%s.manifest", key))
|
|
||||||
// reset the share timestamp, currently file shares are hardcoded to expire after 30 days...
|
|
||||||
// we reset the profile image here so that it is always available.
|
|
||||||
profile.SetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.ts", key), strconv.FormatInt(time.Now().Unix(), 10))
|
|
||||||
log.Infof("Custom Profile Image: %v %s", key, serializedManifest)
|
|
||||||
|
|
||||||
}
|
|
||||||
// If file sharing is enabled then reshare all active files...
|
|
||||||
fsf, err := filesharing.FunctionalityGate(settings.Experiments)
|
|
||||||
if err == nil {
|
|
||||||
fsf.ReShareFiles(profile)
|
|
||||||
info, _ := fsf.GetFileShareInfo(profile, key)
|
|
||||||
log.Infof("Custom Profile Image: %v %v", key, info)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -718,46 +662,3 @@ func getLastMessageTime(conversationMessages []model.ConversationMessage) int {
|
||||||
}
|
}
|
||||||
return int(time.Unix())
|
return int(time.Unix())
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleImagePreviews checks settings and, if appropriate, auto-downloads any images
|
|
||||||
func handleImagePreviews(profile peer.CwtchPeer, ev *event.Event, conversationID, senderID int, settings app.GlobalSettings) {
|
|
||||||
fh, err := filesharing.PreviewFunctionalityGate(settings.Experiments)
|
|
||||||
|
|
||||||
// Short-circuit if file sharing is disabled
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Short-circuit failures
|
|
||||||
// Don't autodownload images if the download path does not exist.
|
|
||||||
if settings.DownloadPath == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't autodownload images if the download path does not exist.
|
|
||||||
if _, err := os.Stat(settings.DownloadPath); os.IsNotExist(err) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now look at the image preview experiment
|
|
||||||
imagePreviewsEnabled := settings.Experiments["filesharing-images"]
|
|
||||||
if imagePreviewsEnabled {
|
|
||||||
var cm model.MessageWrapper
|
|
||||||
err := json.Unmarshal([]byte(ev.Data[event.Data]), &cm)
|
|
||||||
if err == nil && cm.Overlay == model.OverlayFileSharing {
|
|
||||||
var fm filesharing.OverlayMessage
|
|
||||||
err = json.Unmarshal([]byte(cm.Data), &fm)
|
|
||||||
if err == nil {
|
|
||||||
if fm.ShouldAutoDL() {
|
|
||||||
basepath := settings.DownloadPath
|
|
||||||
fp, mp := filesharing.GenerateDownloadPath(basepath, fm.Name, false)
|
|
||||||
log.Debugf("autodownloading file!")
|
|
||||||
ev.Data["Auto"] = constants.True
|
|
||||||
mID, _ := strconv.Atoi(ev.Data["Index"])
|
|
||||||
profile.UpdateMessageAttribute(conversationID, 0, mID, constants.AttrDownloaded, constants.True)
|
|
||||||
fh.DownloadFile(profile, senderID, fp, mp, fm.FileKey(), constants.ImagePreviewMaxSizeInBytes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cwtch.im/cwtch/app"
|
|
||||||
"cwtch.im/cwtch/model"
|
"cwtch.im/cwtch/model"
|
||||||
"cwtch.im/cwtch/model/attr"
|
"cwtch.im/cwtch/model/attr"
|
||||||
|
"cwtch.im/cwtch/settings"
|
||||||
"git.openprivacy.ca/cwtch.im/cwtch-autobindings/constants"
|
"git.openprivacy.ca/cwtch.im/cwtch-autobindings/constants"
|
||||||
)
|
)
|
||||||
|
|
||||||
func determineNotification(ci *model.Conversation, settings app.GlobalSettings) constants.NotificationType {
|
func determineNotification(ci *model.Conversation, gsettings settings.GlobalSettings) constants.NotificationType {
|
||||||
switch settings.NotificationPolicy {
|
switch gsettings.NotificationPolicy {
|
||||||
case app.NotificationPolicyMute:
|
case settings.NotificationPolicyMute:
|
||||||
return constants.NotificationNone
|
return constants.NotificationNone
|
||||||
case app.NotificationPolicyOptIn:
|
case settings.NotificationPolicyOptIn:
|
||||||
if ci != nil {
|
if ci != nil {
|
||||||
if policy, exists := ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.ConversationNotificationPolicy); exists {
|
if policy, exists := ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.ConversationNotificationPolicy); exists {
|
||||||
switch policy {
|
switch policy {
|
||||||
|
@ -20,12 +20,12 @@ func determineNotification(ci *model.Conversation, settings app.GlobalSettings)
|
||||||
case constants.ConversationNotificationPolicyNever:
|
case constants.ConversationNotificationPolicyNever:
|
||||||
return constants.NotificationNone
|
return constants.NotificationNone
|
||||||
case constants.ConversationNotificationPolicyOptIn:
|
case constants.ConversationNotificationPolicyOptIn:
|
||||||
return notificationContentToNotificationType(settings.NotificationContent)
|
return notificationContentToNotificationType(gsettings.NotificationContent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return constants.NotificationNone
|
return constants.NotificationNone
|
||||||
case app.NotificationPolicyDefaultAll:
|
case settings.NotificationPolicyDefaultAll:
|
||||||
if ci != nil {
|
if ci != nil {
|
||||||
if policy, exists := ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.ConversationNotificationPolicy); exists {
|
if policy, exists := ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.ConversationNotificationPolicy); exists {
|
||||||
switch policy {
|
switch policy {
|
||||||
|
@ -34,11 +34,11 @@ func determineNotification(ci *model.Conversation, settings app.GlobalSettings)
|
||||||
case constants.ConversationNotificationPolicyDefault:
|
case constants.ConversationNotificationPolicyDefault:
|
||||||
fallthrough
|
fallthrough
|
||||||
case constants.ConversationNotificationPolicyOptIn:
|
case constants.ConversationNotificationPolicyOptIn:
|
||||||
return notificationContentToNotificationType(settings.NotificationContent)
|
return notificationContentToNotificationType(gsettings.NotificationContent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return notificationContentToNotificationType(settings.NotificationContent)
|
return notificationContentToNotificationType(gsettings.NotificationContent)
|
||||||
}
|
}
|
||||||
return constants.NotificationNone
|
return constants.NotificationNone
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue