add mutex on StartCwtch and ReconnectCwtchForeground #54

Merged
sarah merged 2 commits from fixReconnect into trunk 2021-06-16 19:03:23 +00:00
1 changed files with 7 additions and 0 deletions
Showing only changes of commit 9b18bef47a - Show all commits

7
lib.go
View File

@ -15,6 +15,7 @@ import (
"git.openprivacy.ca/openprivacy/connectivity"
"runtime"
"strings"
"sync"
"encoding/json"
"fmt"
@ -42,6 +43,7 @@ var eventHandler *utils.EventHandler
var acnQueue event.Queue
var contactEventsQueue event.Queue
var globalACN connectivity.ACN
var startLock sync.Mutex
// ChatMessage API currently not officially documented, see
// https://git.openprivacy.ca/cwtch.im/secure-development-handbook/issues/3
@ -87,6 +89,8 @@ func StartCwtch(appDir string, torPath string) int {
}
func _startCwtch(appDir string, torPath string) {
startLock.Lock()
defer startLock.Unlock()
// Exclude Tapir wire Messages (We need a TRACE level)
log.ExcludeFromPattern("service.go")
@ -161,10 +165,13 @@ func c_ReconnectCwtchForeground() {
// Like StartCwtch, but StartCwtch has already been called so we don't need to restart Tor etc (probably)
// Do need to re-send initial state tho, eg profiles that are already loaded
func ReconnectCwtchForeground() {
startLock.Lock()
defer startLock.Unlock()
peerList := application.ListPeers()
for onion := range peerList {
eventHandler.Push(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: onion, event.Created: event.False}))
}
application.GetPrimaryBus().Publish(event.NewEvent(utils.CwtchStarted, map[event.Field]string{}))
}
//export c_SendAppEvent