Additional Tapir Improvements

This commit is contained in:
Sarah Jamie Lewis 2019-07-30 16:47:12 -07:00
父節點 29c5214552
當前提交 821e64c360
共有 4 個文件被更改,包括 20 次插入13 次删除

2
go.mod
查看文件

@ -1,7 +1,7 @@
module cwtch.im/cwtch
require (
cwtch.im/tapir v0.1.5
cwtch.im/tapir v0.1.6
git.openprivacy.ca/openprivacy/libricochet-go v1.0.4
github.com/c-bata/go-prompt v0.2.3
github.com/golang/protobuf v1.3.2

4
go.sum
查看文件

@ -1,5 +1,5 @@
cwtch.im/tapir v0.1.5 h1:SSHJ104t46pWg08FLmGR28y6pEQTbq8gwkaBzmAbCbA=
cwtch.im/tapir v0.1.5/go.mod h1:EuRYdVrwijeaGBQ4OijDDRHf7R2MDSypqHkSl5DxI34=
cwtch.im/tapir v0.1.6 h1:5wd0z8TOUftEBIlCosLechh5KSAo9HfiQNcqknSzRWA=
cwtch.im/tapir v0.1.6/go.mod h1:EuRYdVrwijeaGBQ4OijDDRHf7R2MDSypqHkSl5DxI34=
git.openprivacy.ca/openprivacy/libricochet-go v1.0.4 h1:GWLMJ5jBSIC/gFXzdbbeVz7fIAn2FTgW8+wBci6/3Ek=
git.openprivacy.ca/openprivacy/libricochet-go v1.0.4/go.mod h1:yMSG1gBaP4f1U+RMZXN85d29D39OK5s8aTpyVRoH5FY=
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI=

查看文件

@ -8,6 +8,7 @@ import (
"errors"
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
"git.openprivacy.ca/openprivacy/libricochet-go/identity"
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"github.com/golang/protobuf/proto"
"golang.org/x/crypto/ed25519"
"sync"
@ -114,7 +115,7 @@ func (e *engine) eventHandler() {
if !ok {
context = event.ContextRaw
}
err := e.sendMessageToPeer(ev.EventID, ev.Data[event.RemotePeer], context, []byte(ev.Data[event.GroupInvite]))
err := e.sendMessageToPeer(ev.EventID, ev.Data[event.RemotePeer], context, []byte(ev.Data[event.Data]))
if err != nil {
e.eventManager.Publish(event.NewEvent(event.SendMessageToPeerError, map[event.Field]string{event.RemotePeer: ev.Data[event.RemotePeer], event.Signature: ev.EventID, event.Error: "peer is offline or the connection has yet to finalize"}))
}
@ -163,8 +164,9 @@ func (e *engine) Shutdown() {
// needs to be run in a goroutine as will block on Open.
func (e *engine) peerWithOnion(onion string) {
e.ignoreOnShutdown(e.peerConnecting)(onion)
_, err := e.service.Connect(onion, e.createPeerTemplate())
if err != nil {
connected, err := e.service.Connect(onion, e.createPeerTemplate())
// Only issue a disconnected error if we are disconnected (Connect will fail if a connection already exists)
if !connected && err != nil {
e.ignoreOnShutdown(e.peerDisconnected)(onion)
}
}
@ -256,11 +258,12 @@ func (e *engine) sendMessageToGroup(server string, ct []byte, sig []byte) {
}
}
func (e *engine) handlePeerMessage(hostname string, message []byte) {
cpp := &protocol.CwtchPeerPacket{}
err := proto.Unmarshal(message, cpp)
if err == nil {
if cpp.GetGroupChatInvite() != nil {
func (e *engine) handlePeerMessage(hostname string, context string, message []byte) {
log.Debugf("New message from peer: %v %v", hostname, context)
if context == event.ContextInvite {
cpp := &protocol.CwtchPeerPacket{}
err := proto.Unmarshal(message, cpp)
if err == nil && cpp.GetGroupChatInvite() != nil {
marshal, _ := proto.Marshal(cpp.GetGroupChatInvite())
e.eventManager.Publish(event.NewEvent(event.NewGroupInvite, map[event.Field]string{event.TimestampReceived: time.Now().Format(time.RFC3339Nano), event.RemotePeer: hostname, event.GroupInvite: string(marshal)}))
}

查看文件

@ -12,7 +12,7 @@ import (
type PeerApp struct {
applications.AuthApp
connection *tapir.Connection
MessageHandler func(string, []byte)
MessageHandler func(string, string, []byte)
OnAcknowledgement func(string, string)
OnAuth func(string)
OnClose func(string)
@ -66,7 +66,11 @@ func (pa PeerApp) listen() {
if peerMessage.Context == event.ContextAck {
pa.OnAcknowledgement(pa.connection.Hostname, peerMessage.ID)
} else {
pa.MessageHandler(pa.connection.Hostname, peerMessage.Data)
pa.MessageHandler(pa.connection.Hostname, peerMessage.Context, peerMessage.Data)
// Acknowledge the message
// TODO Should this be in the ui?
pa.SendMessage(PeerMessage{peerMessage.ID, event.ContextAck, []byte{}})
}
} else {
log.Errorf("Error unmarshalling PeerMessage package: %x %v", message, err)