Compare commits
1 Commits
trunk
...
beta_fixes
Author | SHA1 | Date |
---|---|---|
Sarah Jamie Lewis | d372a15ff9 |
|
@ -1,5 +0,0 @@
|
||||||
package constants
|
|
||||||
|
|
||||||
// We offer "un-passworded" profiles but our storage encrypts everything with a password. We need an agreed upon
|
|
||||||
// password to use in that case, that the app case use behind the scenes to password and unlock with
|
|
||||||
const DefactoPasswordForUnencryptedProfiles = "be gay do crime"
|
|
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module git.openprivacy.ca/flutter/libcwtch-go
|
||||||
go 1.15
|
go 1.15
|
||||||
|
|
||||||
require (
|
require (
|
||||||
cwtch.im/cwtch v0.8.11
|
cwtch.im/cwtch v0.8.10
|
||||||
git.openprivacy.ca/openprivacy/connectivity v1.4.4
|
git.openprivacy.ca/openprivacy/connectivity v1.4.4
|
||||||
git.openprivacy.ca/openprivacy/log v1.0.2
|
git.openprivacy.ca/openprivacy/log v1.0.2
|
||||||
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
|
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -1,5 +1,5 @@
|
||||||
cwtch.im/cwtch v0.8.11 h1:nUrd6srjLxInSJ0q1JdmRBhN4RRlZRL+2vIyE/AXkfY=
|
cwtch.im/cwtch v0.8.10 h1:y1PAEz9j2wLWahmBLNu7rPAlNpA+9FLwMAzIT/yfXjM=
|
||||||
cwtch.im/cwtch v0.8.11/go.mod h1:D9dtO+WnKqdmufKSfFeFlUYaxLTfE/RtqVe1OD0kiKc=
|
cwtch.im/cwtch v0.8.10/go.mod h1:D9dtO+WnKqdmufKSfFeFlUYaxLTfE/RtqVe1OD0kiKc=
|
||||||
git.openprivacy.ca/cwtch.im/tapir v0.4.3 h1:sctSfUXHDIqaHfJPDl+5lHtmoEJolQiHTcHZGAe5Qc4=
|
git.openprivacy.ca/cwtch.im/tapir v0.4.3 h1:sctSfUXHDIqaHfJPDl+5lHtmoEJolQiHTcHZGAe5Qc4=
|
||||||
git.openprivacy.ca/cwtch.im/tapir v0.4.3/go.mod h1:10qEaib5x021zgyZ/97JKWsEpedH5+Vfy2CvB2V+08E=
|
git.openprivacy.ca/cwtch.im/tapir v0.4.3/go.mod h1:10qEaib5x021zgyZ/97JKWsEpedH5+Vfy2CvB2V+08E=
|
||||||
git.openprivacy.ca/openprivacy/bine v0.0.4 h1:CO7EkGyz+jegZ4ap8g5NWRuDHA/56KKvGySR6OBPW+c=
|
git.openprivacy.ca/openprivacy/bine v0.0.4 h1:CO7EkGyz+jegZ4ap8g5NWRuDHA/56KKvGySR6OBPW+c=
|
||||||
|
|
188
lib.go
188
lib.go
|
@ -18,7 +18,6 @@ import (
|
||||||
"git.openprivacy.ca/flutter/libcwtch-go/utils"
|
"git.openprivacy.ca/flutter/libcwtch-go/utils"
|
||||||
"git.openprivacy.ca/openprivacy/connectivity"
|
"git.openprivacy.ca/openprivacy/connectivity"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
@ -68,10 +67,9 @@ func c_StartCwtch(dir_c *C.char, len C.int, tor_c *C.char, torLen C.int) int8 {
|
||||||
// message: CwtchStarted when start up is complete and app is safe to use
|
// message: CwtchStarted when start up is complete and app is safe to use
|
||||||
// CwtchStartError message when start up fails (includes event.Error data field)
|
// CwtchStartError message when start up fails (includes event.Error data field)
|
||||||
func StartCwtch(appDir string, torPath string) int {
|
func StartCwtch(appDir string, torPath string) int {
|
||||||
log.SetLevel(log.LevelInfo)
|
eventHandler = utils.NewEventHandler()
|
||||||
|
log.SetLevel(log.LevelDebug)
|
||||||
|
|
||||||
|
|
||||||
log.Infof("StartCwtch(...)")
|
|
||||||
// Quick hack check that we're being called with the correct params
|
// Quick hack check that we're being called with the correct params
|
||||||
// On android a stale worker could be calling us with "last apps" directory. Best to abort fast so the app can make a new worker
|
// On android a stale worker could be calling us with "last apps" directory. Best to abort fast so the app can make a new worker
|
||||||
if runtime.GOOS == "android" {
|
if runtime.GOOS == "android" {
|
||||||
|
@ -88,21 +86,12 @@ func StartCwtch(appDir string, torPath string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func _startCwtch(appDir string, torPath string) {
|
func _startCwtch(appDir string, torPath string) {
|
||||||
log.Infof("application: %v eventHandler: %v acn: %v", application, eventHandler, globalACN)
|
// Exclude Tapir wire Messages (We need a TRACE level)
|
||||||
|
|
||||||
if application != nil {
|
|
||||||
log.Infof("_startCwtch detected existing application; resuming instead of relaunching")
|
|
||||||
ReconnectCwtchForeground()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exclude Tapir wire Messages
|
|
||||||
//(We need a TRACE level)
|
|
||||||
log.ExcludeFromPattern("service.go")
|
log.ExcludeFromPattern("service.go")
|
||||||
|
|
||||||
// Ensure that the application directory exists...and then initialize settings..
|
// Ensure that the application directory exists...and then initialize settings..
|
||||||
os.MkdirAll(path.Join(appDir), 0700)
|
os.MkdirAll(path.Join(appDir), 0700)
|
||||||
utils.InitGlobalSettingsFile(appDir, constants.DefactoPasswordForUnencryptedProfiles)
|
utils.InitGlobalSettingsFile(appDir, "be gay do crime")
|
||||||
|
|
||||||
log.Infof("Loading Cwtch Directory %v and tor path: %v", appDir, torPath)
|
log.Infof("Loading Cwtch Directory %v and tor path: %v", appDir, torPath)
|
||||||
|
|
||||||
|
@ -117,9 +106,6 @@ func _startCwtch(appDir string, torPath string) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("Creating new EventHandler()")
|
|
||||||
eventHandler = utils.NewEventHandler()
|
|
||||||
|
|
||||||
log.Infof("making directory %v", appDir)
|
log.Infof("making directory %v", appDir)
|
||||||
os.MkdirAll(path.Join(appDir, "/.tor", "tor"), 0700)
|
os.MkdirAll(path.Join(appDir, "/.tor", "tor"), 0700)
|
||||||
tor.NewTorrc().WithSocksPort(port).WithOnionTrafficOnly().WithControlPort(controlPort).WithHashedPassword(base64.StdEncoding.EncodeToString(key)).Build(filepath.Join(appDir, ".tor", "tor", "torrc"))
|
tor.NewTorrc().WithSocksPort(port).WithOnionTrafficOnly().WithControlPort(controlPort).WithHashedPassword(base64.StdEncoding.EncodeToString(key)).Build(filepath.Join(appDir, ".tor", "tor", "torrc"))
|
||||||
|
@ -157,14 +143,13 @@ func _startCwtch(appDir string, torPath string) {
|
||||||
settings := utils.ReadGlobalSettings()
|
settings := utils.ReadGlobalSettings()
|
||||||
settingsJson, _ := json.Marshal(settings)
|
settingsJson, _ := json.Marshal(settings)
|
||||||
|
|
||||||
newApp.LoadProfiles(constants.DefactoPasswordForUnencryptedProfiles)
|
newApp.LoadProfiles("be gay do crime")
|
||||||
application = newApp
|
application = newApp
|
||||||
|
|
||||||
// Send global settings to the UI...
|
// Send global settings to the UI...
|
||||||
application.GetPrimaryBus().Publish(event.NewEvent(utils.UpdateGlobalSettings, map[event.Field]string{event.Data: string(settingsJson)}))
|
application.GetPrimaryBus().Publish(event.NewEvent(utils.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(utils.CwtchStarted, map[event.Field]string{}))
|
application.GetPrimaryBus().Publish(event.NewEvent(utils.CwtchStarted, map[event.Field]string{}))
|
||||||
application.QueryACNVersion()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//export c_ReconnectCwtchForeground
|
//export c_ReconnectCwtchForeground
|
||||||
|
@ -175,46 +160,15 @@ func c_ReconnectCwtchForeground() {
|
||||||
// Like StartCwtch, but StartCwtch has already been called so we don't need to restart Tor etc (probably)
|
// 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
|
// Do need to re-send initial state tho, eg profiles that are already loaded
|
||||||
func ReconnectCwtchForeground() {
|
func ReconnectCwtchForeground() {
|
||||||
log.Infof("Reconnecting cwtchforeground")
|
|
||||||
if application == nil {
|
if application == nil {
|
||||||
log.Errorf("ReconnectCwtchForeground: Application is nil, presuming stale thread, EXITING Reconnect\n")
|
log.Errorf("ReconnectCwtchForeground: Application is nil, presuming stale thread, EXITING Reconnect\n")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// populate profile list
|
|
||||||
peerList := application.ListPeers()
|
peerList := application.ListPeers()
|
||||||
for onion := range peerList {
|
for onion := range peerList {
|
||||||
eventHandler.Push(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: onion, event.Created: event.False, "Reload": event.True}))
|
eventHandler.Push(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: onion, event.Created: event.False}))
|
||||||
}
|
}
|
||||||
|
|
||||||
for onion := range peerList {
|
|
||||||
// fix peerpeercontact message counts
|
|
||||||
contactList := application.GetPeer(onion).GetContacts()
|
|
||||||
for _, handle := range contactList {
|
|
||||||
totalMessages := application.GetPeer(onion).GetContact(handle).Timeline.Len() + len(application.GetPeer(onion).GetContact(handle).UnacknowledgedMessages)
|
|
||||||
eventHandler.Push(event.NewEvent(event.MessageCounterResync, map[event.Field]string{
|
|
||||||
event.Identity: onion,
|
|
||||||
event.RemotePeer: handle,
|
|
||||||
event.Data: strconv.Itoa(totalMessages),
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
// fix peergroupcontact message counts
|
|
||||||
groupList := application.GetPeer(onion).GetGroups()
|
|
||||||
for _, groupID := range groupList {
|
|
||||||
totalMessages := application.GetPeer(onion).GetGroup(groupID).Timeline.Len() + len(application.GetPeer(onion).GetGroup(groupID).UnacknowledgedMessages)
|
|
||||||
eventHandler.Push(event.NewEvent(event.MessageCounterResync, map[event.Field]string{
|
|
||||||
event.Identity: onion,
|
|
||||||
event.GroupID: groupID,
|
|
||||||
event.Data: strconv.Itoa(totalMessages),
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
application.GetPrimaryBus().Publish(event.NewEvent(utils.CwtchStarted, map[event.Field]string{}))
|
application.GetPrimaryBus().Publish(event.NewEvent(utils.CwtchStarted, map[event.Field]string{}))
|
||||||
application.QueryACNStatus()
|
|
||||||
application.QueryACNVersion()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//export c_SendAppEvent
|
//export c_SendAppEvent
|
||||||
|
@ -347,18 +301,10 @@ func c_GetAppBusEvent() *C.char {
|
||||||
|
|
||||||
// GetAppBusEvent blocks until an event
|
// GetAppBusEvent blocks until an event
|
||||||
func GetAppBusEvent() string {
|
func GetAppBusEvent() string {
|
||||||
log.Debugf("appbusevent called")
|
|
||||||
for eventHandler == nil {
|
|
||||||
log.Debugf("waiting for eventHandler != nil")
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
}
|
|
||||||
|
|
||||||
var json = ""
|
var json = ""
|
||||||
for json == "" {
|
for json == "" {
|
||||||
log.Debugf("waiting for json != ''")
|
|
||||||
json = eventHandler.GetNextEvent()
|
json = eventHandler.GetNextEvent()
|
||||||
}
|
}
|
||||||
log.Debugf("appbusevent: %v", json)
|
|
||||||
return json
|
return json
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,17 +314,35 @@ type Profile struct {
|
||||||
ImagePath string `json:"imagePath"`
|
ImagePath string `json:"imagePath"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//export c_GetProfiles
|
||||||
|
func c_GetProfiles() *C.char {
|
||||||
|
return C.CString(GetProfiles())
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetProfiles() string {
|
||||||
|
peerList := application.ListPeers()
|
||||||
|
profiles := make([]Profile, len(peerList))
|
||||||
|
i := 0
|
||||||
|
for onion := range peerList {
|
||||||
|
name, _ := application.GetPeer(onion).GetAttribute(attr.GetPublicScope(constants.Name))
|
||||||
|
profiles[i] = Profile{
|
||||||
|
Name: name,
|
||||||
|
Onion: onion,
|
||||||
|
ImagePath: "",
|
||||||
|
}
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
jsonBytes, _ := json.Marshal(profiles)
|
||||||
|
return string(jsonBytes)
|
||||||
|
}
|
||||||
|
|
||||||
//export c_CreateProfile
|
//export c_CreateProfile
|
||||||
func c_CreateProfile(nick_ptr *C.char, nick_len C.int, pass_ptr *C.char, pass_len C.int) {
|
func c_CreateProfile(nick_ptr *C.char, nick_len C.int, pass_ptr *C.char, pass_len C.int) {
|
||||||
CreateProfile(C.GoStringN(nick_ptr, nick_len), C.GoStringN(pass_ptr, pass_len))
|
CreateProfile(C.GoStringN(nick_ptr, nick_len), C.GoStringN(pass_ptr, pass_len))
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateProfile(nick, pass string) {
|
func CreateProfile(nick, pass string) {
|
||||||
if pass == constants.DefactoPasswordForUnencryptedProfiles {
|
application.CreatePeer(nick, pass)
|
||||||
application.CreateTaggedPeer(nick, pass, constants.ProfileTypeV1DefaultPassword)
|
|
||||||
} else {
|
|
||||||
application.CreateTaggedPeer(nick, pass, constants.ProfileTypeV1Password)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//export c_LoadProfiles
|
//export c_LoadProfiles
|
||||||
|
@ -464,6 +428,36 @@ func BlockContact(profile, handle string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//export c_DebugResetContact
|
||||||
|
func c_DebugResetContact(profilePtr *C.char, profileLen C.int, handlePtr *C.char, handleLen C.int) {
|
||||||
|
DebugResetContact(C.GoStringN(profilePtr, profileLen), C.GoStringN(handlePtr, handleLen))
|
||||||
|
}
|
||||||
|
|
||||||
|
func DebugResetContact(profile, handle string) {
|
||||||
|
err := application.GetPeer(profile).SetContactAuthorization(handle, model.AuthUnknown)
|
||||||
|
if err == nil {
|
||||||
|
application.GetPrimaryBus().Publish(event.NewEvent(event.PeerStateChange, map[event.Field]string{
|
||||||
|
ProfileOnion: profile,
|
||||||
|
event.RemotePeer: handle,
|
||||||
|
"authorization": string(model.AuthUnknown),
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
|
log.Errorf("error resetting contact: %s", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//export c_NumMessages
|
||||||
|
func c_NumMessages(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int) (n int) {
|
||||||
|
profile := C.GoStringN(profile_ptr, profile_len)
|
||||||
|
handle := C.GoStringN(handle_ptr, handle_len)
|
||||||
|
return (NumMessages(profile, handle))
|
||||||
|
}
|
||||||
|
|
||||||
|
func NumMessages(profile, handle string) (n int) {
|
||||||
|
n = len(application.GetPeer(profile).GetContact(handle).Timeline.Messages)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
//export c_UpdateMessageFlags
|
//export c_UpdateMessageFlags
|
||||||
func c_UpdateMessageFlags(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, mIdx C.int, message_flags C.ulong) {
|
func c_UpdateMessageFlags(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, mIdx C.int, message_flags C.ulong) {
|
||||||
profile := C.GoStringN(profile_ptr, profile_len)
|
profile := C.GoStringN(profile_ptr, profile_len)
|
||||||
|
@ -519,19 +513,24 @@ func GetMessage(profileOnion, handle string, message_index int) string {
|
||||||
if message_index < len(profile.GetContact(handle).Timeline.Messages) {
|
if message_index < len(profile.GetContact(handle).Timeline.Messages) {
|
||||||
message.Message = profile.GetContact(handle).Timeline.Messages[message_index]
|
message.Message = profile.GetContact(handle).Timeline.Messages[message_index]
|
||||||
message.ContactImage = ph.GetProfilePic(handle)
|
message.ContactImage = ph.GetProfilePic(handle)
|
||||||
} else {
|
|
||||||
log.Errorf("peerpeercontact getmessage out of range; sending counter resync just in case")
|
|
||||||
eventHandler.Push(event.NewEvent(event.MessageCounterResync, map[event.Field]string{
|
|
||||||
event.Identity: profileOnion,
|
|
||||||
event.RemotePeer: handle,
|
|
||||||
event.Data: strconv.Itoa(len(profile.GetContact(handle).Timeline.Messages)),
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bytes, _ := json.Marshal(message)
|
bytes, _ := json.Marshal(message)
|
||||||
return string(bytes)
|
return string(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//export c_GetMessages
|
||||||
|
func c_GetMessages(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, start C.int, end C.int) *C.char {
|
||||||
|
profile := C.GoStringN(profile_ptr, profile_len)
|
||||||
|
handle := C.GoStringN(handle_ptr, handle_len)
|
||||||
|
return C.CString(GetMessages(profile, handle, int(start), int(end)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMessages(profile, handle string, start, end int) string {
|
||||||
|
messages := application.GetPeer(profile).GetContact(handle).Timeline.Messages[start:end]
|
||||||
|
bytes, _ := json.Marshal(messages)
|
||||||
|
return string(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
//export c_SendMessage
|
//export c_SendMessage
|
||||||
func c_SendMessage(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, msg_ptr *C.char, msg_len C.int) {
|
func c_SendMessage(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, msg_ptr *C.char, msg_len C.int) {
|
||||||
|
@ -598,6 +597,15 @@ func ResetTor() {
|
||||||
globalACN.Restart()
|
globalACN.Restart()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//export c_QueryACNVersion
|
||||||
|
func c_QueryACNVersion() {
|
||||||
|
QueryACNVersion()
|
||||||
|
}
|
||||||
|
|
||||||
|
func QueryACNVersion() {
|
||||||
|
application.QueryACNVersion()
|
||||||
|
}
|
||||||
|
|
||||||
//export c_CreateGroup
|
//export c_CreateGroup
|
||||||
func c_CreateGroup(profile_ptr *C.char, profile_len C.int, server_ptr *C.char, server_len C.int, name_ptr *C.char, name_len C.int) {
|
func c_CreateGroup(profile_ptr *C.char, profile_len C.int, server_ptr *C.char, server_len C.int, name_ptr *C.char, name_len C.int) {
|
||||||
profile := C.GoStringN(profile_ptr, profile_len)
|
profile := C.GoStringN(profile_ptr, profile_len)
|
||||||
|
@ -631,12 +639,6 @@ func c_DeleteProfile(profile_ptr *C.char, profile_len C.int, password_ptr *C.cha
|
||||||
|
|
||||||
// DeleteProfile deletes a profile given the right password
|
// DeleteProfile deletes a profile given the right password
|
||||||
func DeleteProfile(profile string, password string) {
|
func DeleteProfile(profile string, password string) {
|
||||||
|
|
||||||
// allow a blank password to delete "unencrypted" accounts...
|
|
||||||
if password == "" {
|
|
||||||
password = constants.DefactoPasswordForUnencryptedProfiles
|
|
||||||
}
|
|
||||||
|
|
||||||
application.DeletePeer(profile, password)
|
application.DeletePeer(profile, password)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -728,15 +730,31 @@ func ShutdownCwtch() {
|
||||||
eventHandler.Push(event.NewEvent(event.Shutdown, map[event.Field]string{}))
|
eventHandler.Push(event.NewEvent(event.Shutdown, map[event.Field]string{}))
|
||||||
|
|
||||||
// Allow for the shutdown events to go through and then purge everything else...
|
// Allow for the shutdown events to go through and then purge everything else...
|
||||||
log.Infof("Shutting Down Application...")
|
log.Debugf("Shutting Down Application...")
|
||||||
application.Shutdown()
|
application.Shutdown()
|
||||||
log.Infof("Shutting Down ACN...")
|
log.Debugf("Shutting Down ACN...")
|
||||||
globalACN.Close()
|
globalACN.Close()
|
||||||
log.Infof("Library Shutdown Complete!")
|
log.Debugf("Library Shutdown Complete!")
|
||||||
// do not remove - important for state checks elsewhere
|
}
|
||||||
application = nil
|
}
|
||||||
globalACN = nil
|
|
||||||
eventHandler = nil
|
//export c_ResyncConversation
|
||||||
|
func c_ResyncConversation(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int) {
|
||||||
|
profile := C.GoStringN(profile_ptr, profile_len)
|
||||||
|
name := C.GoStringN(handle_ptr, handle_len)
|
||||||
|
ResyncConversation(profile, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResyncConversation forces the protocol engine to retry connecting to the underlying contact, in the case of
|
||||||
|
// a group it will create completely refresh cached server state and so may cause older messages to appear (bandwidth intensive)
|
||||||
|
func ResyncConversation(profileOnion string, handle string) {
|
||||||
|
profile := application.GetPeer(profileOnion)
|
||||||
|
ph := utils.NewPeerHelper(profile)
|
||||||
|
if ph.IsPeer(handle) {
|
||||||
|
profile.PeerWithOnion(handle)
|
||||||
|
} else if ph.IsGroup(handle) {
|
||||||
|
group := profile.GetGroup(handle)
|
||||||
|
profile.ResyncServer(group.GroupServer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,6 @@ func (eh *EventHandler) GetNextEvent() string {
|
||||||
// handleAppBusEvent enriches AppBus events so they are usable with out further data fetches
|
// handleAppBusEvent enriches AppBus events so they are usable with out further data fetches
|
||||||
func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
||||||
log.Debugf("New AppBus Event to Handle: %v", e)
|
log.Debugf("New AppBus Event to Handle: %v", e)
|
||||||
if eh.app != nil {
|
|
||||||
switch e.EventType {
|
switch e.EventType {
|
||||||
case event.ACNStatus:
|
case event.ACNStatus:
|
||||||
if e.Data[event.Progress] == "100" {
|
if e.Data[event.Progress] == "100" {
|
||||||
|
@ -78,19 +77,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
||||||
onion := e.Data[event.Identity]
|
onion := e.Data[event.Identity]
|
||||||
profile := eh.app.GetPeer(e.Data[event.Identity])
|
profile := eh.app.GetPeer(e.Data[event.Identity])
|
||||||
log.Debug("New Peer Event: %v", e)
|
log.Debug("New Peer Event: %v", e)
|
||||||
|
|
||||||
if e.Data["Reload"] != event.True {
|
|
||||||
eh.startHandlingPeer(onion)
|
eh.startHandlingPeer(onion)
|
||||||
}
|
|
||||||
|
|
||||||
tag,isTagged := profile.GetAttribute(app.AttributeTag)
|
|
||||||
if isTagged {
|
|
||||||
e.Data[app.AttributeTag] = tag
|
|
||||||
} else {
|
|
||||||
// Assume encrypted for non-tagged profiles - this isn't always true, but all post-beta profiles
|
|
||||||
// are tagged on creation.
|
|
||||||
e.Data[app.AttributeTag] = constants.ProfileTypeV1Password
|
|
||||||
}
|
|
||||||
|
|
||||||
if e.Data[event.Created] == event.True {
|
if e.Data[event.Created] == event.True {
|
||||||
name, _ := profile.GetAttribute(attr.GetLocalScope(constants.Name))
|
name, _ := profile.GetAttribute(attr.GetLocalScope(constants.Name))
|
||||||
|
@ -219,8 +206,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
||||||
serversListBytes, _ := json.Marshal(servers)
|
serversListBytes, _ := json.Marshal(servers)
|
||||||
e.Data[groups.ServerList] = string(serversListBytes)
|
e.Data[groups.ServerList] = string(serversListBytes)
|
||||||
|
|
||||||
log.Debugf("contactsJson %v", e.Data["ContactsJson"])
|
log.Infof("contactsJson %v", e.Data["ContactsJson"])
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
json, _ := json.Marshal(e)
|
json, _ := json.Marshal(e)
|
||||||
|
@ -229,9 +215,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
||||||
|
|
||||||
// handleProfileEvent enriches Profile events so they are usable with out further data fetches
|
// handleProfileEvent enriches Profile events so they are usable with out further data fetches
|
||||||
func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
if eh.app == nil {
|
|
||||||
log.Errorf("eh.app == nil in handleProfileEvent... this shouldnt happen?")
|
|
||||||
} else {
|
|
||||||
peer := eh.app.GetPeer(ev.Profile)
|
peer := eh.app.GetPeer(ev.Profile)
|
||||||
ph := NewPeerHelper(peer)
|
ph := NewPeerHelper(peer)
|
||||||
log.Debugf("New Profile Event to Handle: %v", ev)
|
log.Debugf("New Profile Event to Handle: %v", ev)
|
||||||
|
@ -319,7 +303,6 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
json, _ := json.Marshal(unwrap(ev))
|
json, _ := json.Marshal(unwrap(ev))
|
||||||
return string(json)
|
return string(json)
|
||||||
|
@ -356,19 +339,17 @@ func (eh *EventHandler) startHandlingPeer(onion string) {
|
||||||
eventBus.Subscribe(event.ChangePasswordError, q)
|
eventBus.Subscribe(event.ChangePasswordError, q)
|
||||||
eventBus.Subscribe(event.NewRetValMessageFromPeer, q)
|
eventBus.Subscribe(event.NewRetValMessageFromPeer, q)
|
||||||
eventBus.Subscribe(event.SetAttribute, q)
|
eventBus.Subscribe(event.SetAttribute, q)
|
||||||
|
|
||||||
go eh.forwardProfileMessages(onion, q)
|
go eh.forwardProfileMessages(onion, q)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (eh *EventHandler) forwardProfileMessages(onion string, q event.Queue) {
|
func (eh *EventHandler) forwardProfileMessages(onion string, q event.Queue) {
|
||||||
log.Infof("Launching Forwarding Goroutine for %v", onion)
|
|
||||||
// TODO: graceful shutdown, via an injected event of special QUIT type exiting loop/go routine
|
// TODO: graceful shutdown, via an injected event of special QUIT type exiting loop/go routine
|
||||||
for {
|
for {
|
||||||
e := q.Next()
|
e := q.Next()
|
||||||
ev := EventProfileEnvelope{Event: e, Profile: onion}
|
ev := EventProfileEnvelope{Event: e, Profile: onion}
|
||||||
eh.profileEvents <- ev
|
eh.profileEvents <- ev
|
||||||
if ev.Event.EventType == event.Shutdown {
|
if e.EventType == event.Shutdown {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -286,7 +286,7 @@ func EnrichNewPeer(handle string, ph *PeerHelper, ev *EventProfileEnvelope) erro
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// could be a server?
|
// could be a server?
|
||||||
log.Debugf("sorry, unable to handle AddContact(%v)", handle)
|
log.Infof("sorry, unable to handle AddContact(%v)", handle)
|
||||||
return errors.New("not a peer or group")
|
return errors.New("not a peer or group")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -31,8 +31,6 @@ type GlobalSettings struct {
|
||||||
BlockUnknownConnections bool
|
BlockUnknownConnections bool
|
||||||
StateRootPane int
|
StateRootPane int
|
||||||
FirstTime bool
|
FirstTime bool
|
||||||
UIColumnModePortrait string
|
|
||||||
UIColumnModeLandscape string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var DefaultGlobalSettings = GlobalSettings{
|
var DefaultGlobalSettings = GlobalSettings{
|
||||||
|
@ -44,8 +42,6 @@ var DefaultGlobalSettings = GlobalSettings{
|
||||||
StateRootPane: 0,
|
StateRootPane: 0,
|
||||||
FirstTime: true,
|
FirstTime: true,
|
||||||
BlockUnknownConnections: false,
|
BlockUnknownConnections: false,
|
||||||
UIColumnModePortrait: "DualpaneMode.Single",
|
|
||||||
UIColumnModeLandscape: "DualpaneMode.CopyPortrait",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitGlobalSettingsFile(directory string, password string) error {
|
func InitGlobalSettingsFile(directory string, password string) error {
|
||||||
|
|
Loading…
Reference in New Issue