From f667c1ec70aa329c1ab4d7f006020cc5c0ff57fd Mon Sep 17 00:00:00 2001 From: erinn Date: Mon, 28 Jan 2019 11:57:44 -0800 Subject: [PATCH 1/3] add storage eventbus calls --- go/characters/presencepoller.go | 8 ++++++-- go/gothings/gcd.go | 19 +++++++++++++------ go/gothings/uistate.go | 11 +++++++---- main.go | 2 -- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/go/characters/presencepoller.go b/go/characters/presencepoller.go index 87bfafa..ddd2672 100644 --- a/go/characters/presencepoller.go +++ b/go/characters/presencepoller.go @@ -26,8 +26,12 @@ func PresencePoller(getContact func(string) *gobjects.Contact, addContact func(c 0, c.Trusted, }) - c.SetAttribute("name", c.Name) - the.CwtchApp.EventBus().Publish(event.NewEvent(event.RequestProfileSave, map[event.Field]string{})) + + the.CwtchApp.EventBus().Publish(event.NewEvent(event.SetPeerAttribute, map[event.Field]string{ + event.RemotePeer: contacts[i], + event.Key: "name", + event.Data: c.Name, + })) } cxnState, found := the.Peer.GetPeers()[contacts[i]] diff --git a/go/gothings/gcd.go b/go/gothings/gcd.go index 5f87c74..5a94aa8 100644 --- a/go/gothings/gcd.go +++ b/go/gothings/gcd.go @@ -68,8 +68,11 @@ func (this *GrandCentralDispatcher) sendMessage(message string, mID uint) { if len(this.CurrentOpenConversation()) == 32 { // SEND TO GROUP if !the.Peer.GetGroup(this.CurrentOpenConversation()).Accepted { - the.Peer.GetGroup(this.CurrentOpenConversation()).Accepted = true - the.CwtchApp.EventBus().Publish(event.NewEvent(event.RequestProfileSave, map[event.Field]string{})) + err := the.Peer.AcceptInvite(this.CurrentOpenConversation()) + if err != nil { + log.Errorf("tried to mark a nonexistent group as existed. bad!") + return + } c := this.UIState.GetContact(this.CurrentOpenConversation()) c.Trusted = true this.UIState.UpdateContact(c.Handle) @@ -211,7 +214,6 @@ func (this *GrandCentralDispatcher) importString(str string) { } the.Peer.JoinServer(group.GroupServer) - the.CwtchApp.EventBus().Publish(event.NewEvent(event.RequestProfileSave, map[event.Field]string{})) this.UIState.AddContact(&gobjects.Contact{ groupID, groupID[:12], @@ -285,7 +287,9 @@ func (this *GrandCentralDispatcher) popup(str string) { func (this *GrandCentralDispatcher) updateNick(nick string) { the.Peer.GetProfile().Name = nick - the.CwtchApp.EventBus().Publish(event.NewEvent(event.RequestProfileSave, map[event.Field]string{})) + the.CwtchApp.EventBus().Publish(event.NewEvent(event.SetProfileName, map[event.Field]string{ + event.ProfileName: nick, + })) } func (this *GrandCentralDispatcher) createGroup(server, groupName string) { @@ -304,8 +308,11 @@ func (this *GrandCentralDispatcher) createGroup(server, groupName string) { }) group := the.Peer.GetGroup(groupID) - group.SetAttribute("nick", groupName) - the.CwtchApp.EventBus().Publish(event.NewEvent(event.RequestProfileSave, map[event.Field]string{})) + the.CwtchApp.EventBus().Publish(event.NewEvent(event.SetGroupAttribute, map[event.Field]string{ + event.GroupID: groupID, + event.Key: "nick", + event.Data: groupName, + })) the.Peer.JoinServer(server) group.NewMessage = make(chan model.Message) diff --git a/go/gothings/uistate.go b/go/gothings/uistate.go index dab29b6..3e00ec5 100644 --- a/go/gothings/uistate.go +++ b/go/gothings/uistate.go @@ -46,7 +46,13 @@ func (this *InterfaceState) AddContact(c *gobjects.Contact) { if c.Trusted { the.Peer.GetProfile().TrustPeer(c.Handle) } - the.CwtchApp.EventBus().Publish(event.NewEvent(event.RequestProfileSave, map[event.Field]string{})) + + the.CwtchApp.EventBus().Publish(event.NewEvent(event.SetPeerAttribute, map[event.Field]string{ + event.RemotePeer: c.Handle, + event.Key: "name", + event.Data: c.DisplayName, + })) + go the.Peer.PeerWithOnion(c.Handle) } @@ -54,8 +60,6 @@ func (this *InterfaceState) AddContact(c *gobjects.Contact) { this.contacts[c.Handle] = c this.parentGcd.AddContact(c.Handle, c.DisplayName, c.Image, c.Server, c.Badge, c.Status, c.Trusted) } - - the.CwtchApp.EventBus().Publish(event.NewEvent(event.RequestProfileSave, map[event.Field]string{})) } func (this *InterfaceState) GetContact(handle string) *gobjects.Contact { @@ -99,7 +103,6 @@ func (this *InterfaceState) AddMessage(m *gobjects.Message) { c.Badge++ this.UpdateContact(c.Handle) } - the.CwtchApp.EventBus().Publish(event.NewEvent(event.RequestProfileSave, map[event.Field]string{})) } func (this *InterfaceState) GetMessages(handle string) []*gobjects.Message { diff --git a/main.go b/main.go index c37e2bc..68b1c88 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( libapp "cwtch.im/cwtch/app" - "cwtch.im/cwtch/event" "cwtch.im/cwtch/model" "cwtch.im/ui/go/characters" "cwtch.im/ui/go/cwutil" @@ -127,7 +126,6 @@ func loadCwtchData(gcd *gothings.GrandCentralDispatcher) { log.Errorf("couldn't create one. is your cwtch folder writable?") os.Exit(1) } - the.CwtchApp.EventBus().Publish(event.NewEvent(event.RequestProfileSave, map[event.Field]string{})) } else { the.Peer = the.CwtchApp.PrimaryIdentity() } From d019f3538facd4f472b07523cb32ffc03519ef7c Mon Sep 17 00:00:00 2001 From: erinn Date: Mon, 28 Jan 2019 14:00:46 -0800 Subject: [PATCH 2/3] disable network access manager --- main.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/main.go b/main.go index 68b1c88..b8e8543 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,8 @@ import ( "git.openprivacy.ca/openprivacy/libricochet-go/connectivity" "git.openprivacy.ca/openprivacy/libricochet-go/log" "github.com/therecipe/qt/core" + "github.com/therecipe/qt/network" + "github.com/therecipe/qt/qml" "github.com/therecipe/qt/quick" "github.com/therecipe/qt/quickcontrols2" "github.com/therecipe/qt/widgets" @@ -63,6 +65,21 @@ func main() { go characters.GroupPoller(gcd.UIState.GetContact, gcd.UIState.UpdateContact) // here we go! + factory := qml.NewQQmlNetworkAccessManagerFactory() + factory.Create(nil) + factory.ConnectCreate(func(parent *core.QObject) *network.QNetworkAccessManager { + nam := network.NewQNetworkAccessManager(parent) + nam.SetNetworkAccessible(network.QNetworkAccessManager__NotAccessible) + proxy := network.NewQNetworkProxy() + proxy.SetHostName("0.0.0.0") + nam.SetProxy(proxy) + //nam.ConnectCreateRequest(func(op network.QNetworkAccessManager__Operation, originalReq *network.QNetworkRequest, outgoingData *core.QIODevice) *network.QNetworkReply { + // log.Errorf("network access request detected - possible remote content insertion bug!!!") + // return nil + //}) + return nam + }) + view.Engine().SetNetworkAccessManagerFactory(factory) view.Show() widgets.QApplication_Exec() } From 6ba5b7b638f391cc78898d13817b06fa31c0e372 Mon Sep 17 00:00:00 2001 From: erinn Date: Mon, 28 Jan 2019 14:02:36 -0800 Subject: [PATCH 3/3] tidy nam --- main.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index b8e8543..6e5a1f1 100644 --- a/main.go +++ b/main.go @@ -64,9 +64,8 @@ func main() { go characters.PresencePoller(gcd.UIState.GetContact, gcd.UIState.AddContact, gcd.UIState.UpdateContact) go characters.GroupPoller(gcd.UIState.GetContact, gcd.UIState.UpdateContact) - // here we go! + // prevent qt from initiating network connections (possible deanon attempts!) factory := qml.NewQQmlNetworkAccessManagerFactory() - factory.Create(nil) factory.ConnectCreate(func(parent *core.QObject) *network.QNetworkAccessManager { nam := network.NewQNetworkAccessManager(parent) nam.SetNetworkAccessible(network.QNetworkAccessManager__NotAccessible) @@ -80,6 +79,8 @@ func main() { return nam }) view.Engine().SetNetworkAccessManagerFactory(factory) + + // here we go! view.Show() widgets.QApplication_Exec() }