initial commit

This commit is contained in:
erinn 2018-10-24 17:13:03 -07:00
parent 50590096ed
commit 5c73cd8b3f
23 changed files with 262 additions and 88 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
deploy
moc*
rcc*
*.qmlc

22
gcd.go
View File

@ -1,12 +1,11 @@
package main
import (
"github.com/therecipe/qt/core"
"log"
"fmt"
"strings"
"cwtch.im/cwtch/model"
"encoding/base32"
"github.com/therecipe/qt/core"
"log"
"strings"
)
type GrandCentralDispatcher struct {
@ -27,6 +26,7 @@ type GrandCentralDispatcher struct {
// profile-area stuff
_ func(name, onion, image string) `signal:"UpdateMyProfile"`
_ func(status int, str string) `signal:"TorStatus"`
// other stuff i can't ontologize atm
_ func(str string) `signal:"InvokePopup"`
@ -57,11 +57,12 @@ func (this *GrandCentralDispatcher) sendMessage(message string) {
gcd.MarkTrusted(gcd.currentOpenConversation)
}
log.Printf("SENDING MESSAGE %v to %v...\n", message, gcd.currentOpenConversation)
connection := peer.PeerWithOnion(gcd.currentOpenConversation)
select { // fancy trick to do a non-blocking send. this means the user can only send a limited number of messages
// before the channel buffer fills. TODO: stop the user from sending if the buffer is full
case outgoingMessages <- Message{gcd.currentOpenConversation, message, true}:
default:
}
fmt.Printf("sending data, connection state: %v\n", connection.GetState())
go connection.SendPacket([]byte(message))
DeliverMessageToUI(gcd.currentOpenConversation, message, true)
}
@ -99,6 +100,11 @@ func (this *GrandCentralDispatcher) importString(str string) {
onion := str
name := onion
if strings.Contains(str, " ") {// usually people prepend spaces and we don't want it going into the name (use ~ for that)
parts := strings.Split(strings.TrimSpace(str), " ")
str = parts[len(parts) - 1]
}
if strings.Contains(str, "~") {
parts := strings.Split(str, "~")
onion = parts[len(parts)-1]

80
main.go
View File

@ -1,26 +1,31 @@
package main
import (
"os"
libpeer "cwtch.im/cwtch/peer"
"cwtch.im/cwtch/peer/connections"
"encoding/base32"
"fmt"
"github.com/sethvargo/go-diceware/diceware"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/quick"
"github.com/therecipe/qt/quickcontrols2"
"github.com/therecipe/qt/widgets"
"time"
"github.com/sethvargo/go-diceware/diceware"
libpeer "cwtch.im/cwtch/peer"
"path"
"os"
"os/user"
"fmt"
"encoding/base32"
"path"
"strings"
"cwtch.im/cwtch/peer/connections"
"time"
"strconv"
"git.openprivacy.ca/openprivacy/asaur"
)
var gcd *GrandCentralDispatcher
type ContactManager map[string]*Contact
var contactMgr ContactManager
var peer libpeer.CwtchPeer
var outgoingMessages chan Message
type Contact struct {
Messages []Message
@ -77,8 +82,12 @@ func main() {
view.SetSource(core.NewQUrl3("qrc:/qml/main.qml", 0))
}
outgoingMessages = make(chan Message, 1000)
go postmanPat()
initialize(view)
view.Show()
go torStatusPoller()
go presencePoller()
go ricochetListener()
go alice()
@ -128,6 +137,37 @@ func presencePoller() { // TODO: make this subscribe-able in ricochet
}
}
func torStatusPoller() {
for {
time.Sleep(time.Second)
//todo: this should use a config manager
//todo: also, try dialing the proxy to differentiate tor not running vs control port not configured
rawStatus, err := asaur.GetInfo("localhost:9051", "tcp4", "", "status/bootstrap-phase")
if err != nil {
gcd.TorStatus(0, "can't find tor. is it running? is the controlport configured?")
continue
}
status := asaur.ParseBootstrapPhase(rawStatus)
progress, _ := strconv.Atoi(status["PROGRESS"])
if status["TAG"] == "done" {
gcd.TorStatus(3, "tor appears to be running just fine!")
continue
}
if progress == 0 {
gcd.TorStatus(1, "tor is trying to start up")
continue
}
gcd.TorStatus(2, status["SUMMARY"])
//qCwtchApp.SetTorStatusProgress(progress)
//qCwtchApp.SetTorStatusSummary(status["SUMMARY"])
//if status["TAG"] == "done" {
}
}
func ricochetListener() {
processData := func(onion string, data []byte) []byte {
/* _, exists := peer.GetProfile().GetCustomAttribute(onion + "_name")
@ -159,6 +199,30 @@ func ricochetListener() {
}
}
func postmanPat() {
postOffice := make(map[string]chan Message)
for {
m := <-outgoingMessages
_, found := postOffice[m.With]
if !found {
postOffice[m.With] = make(chan Message, 100)
go andHisBlackAndWhiteCat(postOffice[m.With])
}
postOffice[m.With] <- m
}
}
func andHisBlackAndWhiteCat(incomingMessages chan Message) {
for {
m := <-incomingMessages
connection := peer.PeerWithOnion(m.With)
connection.SendPacket([]byte(m.Message))
}
}
func initialize(view *quick.QQuickView) {
//TODO: this section is ported over and has a lot of printf errors, need to show them in the ui
var dirname, filename string

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

View File

@ -18,7 +18,7 @@ Item {
Rectangle { // THE LEFT PANE WITH TOOLS AND CONTACTS
color: "#FFEEEE"
color: "#D2C0DD"
Layout.fillHeight: true
Layout.minimumWidth: 200
Layout.maximumWidth: 200

Binary file not shown.

View File

@ -10,22 +10,22 @@ RowLayout { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
anchors.right: parent.right
property alias nick: cn.text
property alias image: img.source
property alias image: imgProfile.source
property string onion
property string badge
property bool isActive
property bool isHover
property bool isTrusted
property int status
property alias status: imgProfile.status
Rectangle { // CONTACT ENTRY BACKGROUND COLOR
id: root
anchors.left: parent.left
anchors.right: parent.right
height: childrenRect.height
height: childrenRect.height + 3
width: parent.width
color: isHover ? "#EEEEFF" : (isActive ? "#EEEEFF" : "#FFEEEE")
color: isHover ? "#D2D2F3" : (isActive ? "#D2D2F3" : "#D2C0DD")
RowLayout {
@ -34,39 +34,8 @@ RowLayout { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
anchors.right: parent.right
Item { // PROFILE IMAGE
ContactPicture {
id: imgProfile
implicitWidth: 48
implicitHeight: 48
anchors.left: parent.left
Image {
id: img
anchors.fill: parent
fillMode: Image.PreserveAspectFit
}
Rectangle { // PRESENCE INDICATOR
color: "#FFFFFF"
width: 8
height: 8
radius: 2
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins: 4
Rectangle { //-2:WtfCodeError,-1:Untrusted,0:Disconnected,1:Connecting,2:Connected,3:Authenticated,4:Failed,5:Killed
color: status==3?"green":(status==4?"red":(status==-1?"blue":"orange"))
width: 5
height: 5
radius: 2
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins: 1.5
}
}
}
Label { // CONTACT NAME
@ -77,6 +46,7 @@ RowLayout { // LOTS OF NESTING TO DEAL WITH QT WEIRDNESS, SORRY
anchors.left: imgProfile.right
font.pixelSize: 16
font.italic: !isTrusted
textFormat: Text.PlainText
}
Rectangle { // UNREAD MESSAGES?

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,67 @@
import QtGraphicalEffects 1.0
import QtQuick 2.7
import QtQuick.Controls 2.4
import QtQuick.Controls.Material 2.0
import QtQuick.Layouts 1.3
import CustomQmlTypes 1.0
Item {
id: imgProfile
implicitWidth: 48
implicitHeight: 48
anchors.left: parent.left
anchors.margins: 5
property alias source: img.source
property int status
Rectangle {
width: 48
height: 48
color: "#FFFFFF"
radius: width / 2
Image { // PROFILE IMAGE
id: img
anchors.fill: parent
fillMode: Image.PreserveAspectFit
visible: false
}
Image { // CIRCLE MASK
id: mask
fillMode: Image.PreserveAspectFit
visible: false
source: "qrc:/qml/images/extra/clipcircle.png"
}
OpacityMask {
anchors.fill: img
source: img
maskSource: mask
}
Rectangle { // PRESENCE INDICATOR
color: "#FFFFFF"
width: 8
height: 8
radius: 2
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins: 4
Rectangle { //-2:WtfCodeError,-1:Untrusted,0:Disconnected,1:Connecting,2:Connected,3:Authenticated,4:Failed,5:Killed
color: status == 3 ? "green" : status == -1 ? "blue" : status == 1 ? "orange" : status == 2 ? "orange" : "red"
width: 5
height: 5
radius: 2
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins: 1.5
}
}
}
}

Binary file not shown.

View File

@ -23,12 +23,74 @@ ColumnLayout {
implicitHeight: 96
anchors.horizontalCenter: parent.horizontalCenter
Rectangle { // WHITE CIRCLE BORDER
width: 96
height: 96
color: "#FFFFFF"
radius: width / 2
Image {
Image { // ACTUAL IMAGE
id: imgProfileImg
anchors.fill: parent
fillMode: Image.PreserveAspectFit
source: "qrc:/qml/images/extra/robot.png"
visible: false
}
Image { // INNER CIRCLE MASK
id: mask
fillMode: Image.PreserveAspectFit
visible: false
source: "qrc:/qml/images/extra/clipcircle.png"
}
OpacityMask { // WE PUT IT ALL TOGETHER ANNND
anchors.fill: imgProfileImg
source: imgProfileImg
maskSource: mask
}
Rectangle { // TOR STATUS INDICATOR
color: "#FFFFFF"
width: 12
height: 12
radius: 3
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins: 8
Rectangle { //0: no tor, 1: progress 0%, 2: progress 1-99%, 3: DONE
id: rectTorStatus
color: code == 3 ? "green": code == 2 ? "orange" : code == 1 ? "yellow" : "red"
width: 8
height: 8
radius: 2
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.margins: 2
property int code
property string message
property bool hovered
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: rectTorStatus.hovered = true
onExited: rectTorStatus.hovered = false
}
ToolTip.visible: hovered
ToolTip.delay: 400
ToolTip.timeout: 5000
ToolTip.text: message
}
}
}
}
@ -38,7 +100,6 @@ ColumnLayout {
width: parent.width
onUpdated: {
console.log("sending updatenick ["+nick+"]")
gcd.updateNick(lblNick.text)
}
}
@ -136,5 +197,10 @@ ColumnLayout {
onion = _onion
image = _image
}
onTorStatus: function(code, str) {
rectTorStatus.code = code
rectTorStatus.message = str
}
}
}

Binary file not shown.