Surfacing some error codes

This commit is contained in:
Sarah Jamie Lewis 2018-05-16 13:18:47 -07:00
vanhempi 4d3bf6967c
commit bd1ad4fc67
10 muutettua tiedostoa jossa 39 lisäystä ja 28 poistoa

Näytä tiedosto

@ -42,11 +42,3 @@ func (app *Application) SetProfile(filename string) error {
func (app *Application) PeerRequest(onion string) {
app.Peer.PeerWithOnion(onion)
}
func (app *Application) SendMessageToPeer(onion string) {
}
func (app *Application) GetNewMessages() []model.Message {
return nil
}

Näytä tiedosto

@ -273,14 +273,18 @@ func main() {
case "new-group":
if len(commands) == 2 {
fmt.Printf("Setting up a new group on server:%v\n", commands[1])
id, _ := app.Peer.Profile.StartGroup(commands[1])
fmt.Printf("New Group [%v] created for server %v\n", id, commands[1])
app.Peer.Save(profilefile)
group := app.Peer.Profile.GetGroupByGroupId(id)
if group == nil {
fmt.Printf("Error: group does not exist\n")
id, _ ,err:= app.Peer.Profile.StartGroup(commands[1])
if err == nil {
fmt.Printf("New Group [%v] created for server %v\n", id, commands[1])
app.Peer.Save(profilefile)
group := app.Peer.Profile.GetGroupByGroupId(id)
if group == nil {
fmt.Printf("Error: group does not exist\n")
} else {
app.Peer.JoinServer(group.GroupServer)
}
} else {
app.Peer.JoinServer(group.GroupServer)
fmt.Printf("Error creating new group: %v", err)
}
} else {
fmt.Printf("Error creating a new group, usage: %s\n", usages["new-group"])
@ -373,6 +377,8 @@ func main() {
}
}
}
app.Peer.Save(profilefile)
if profilefile != "" {
app.Peer.Save(profilefile)
}
}
}

Näytä tiedosto

@ -10,6 +10,7 @@ import (
"io"
"sync"
"time"
"errors"
)
//Group defines and encapsulates Cwtch's conception of group chat. Which are sessions
@ -45,11 +46,18 @@ func NewGroup(server string) *Group {
return group
}
// SignGroup adds a signature to the group.
func (g *Group) SignGroup(signature []byte) {
g.SignedGroupID = signature
}
func (g *Group) Invite() []byte {
// Invite generates a invitation that can be sent to a cwtch peer
func (g *Group) Invite() ([]byte, error) {
if g.SignedGroupID == nil {
return nil, errors.New("group isn't signed")
}
gci := &protocol.GroupChatInvite{
GroupName: g.GroupID,
GroupSharedKey: g.GroupKey[:],
@ -61,10 +69,11 @@ func (g *Group) Invite() []byte {
GroupChatInvite: gci,
}
invite, err := proto.Marshal(cp)
utils.CheckError(err)
return invite
return invite, err
}
// AddMessage takes a DecryptedGroupMessage and adds it to the Groups Timeline
func (g *Group) AddMessage(message *protocol.DecryptedGroupMessage, verified bool) *Message {
g.lock.Lock()
timelineMessage := &Message{
@ -81,6 +90,7 @@ func (g *Group) AddMessage(message *protocol.DecryptedGroupMessage, verified boo
return timelineMessage
}
// GetTimeline provides a safe copy of the timeline
func (g *Group) GetTimeline() (t Timeline) {
g.lock.Lock()
t = g.Timeline

Näytä tiedosto

@ -16,7 +16,7 @@ func TestTranscriptConsistency(t *testing.T) {
sarah.AddContact(alice.Onion, &alice.PublicProfile)
alice.AddContact(sarah.Onion, &sarah.PublicProfile)
gid, invite := alice.StartGroup("aaa.onion")
gid, invite,_ := alice.StartGroup("aaa.onion")
gci := &protocol.CwtchPeerPacket{}
proto.Unmarshal(invite, gci)
sarah.ProcessInvite(gci.GetGroupChatInvite(), alice.Onion)

Näytä tiedosto

@ -104,12 +104,12 @@ func (p *Profile) SignMessage(message string) []byte {
//StartGroup when given a server, creates a new Group under this profile and returns the group id an a precomputed
// invite which can be sent on the wire.
func (p *Profile) StartGroup(server string) (groupID string, invite []byte) {
func (p *Profile) StartGroup(server string) (groupID string, invite []byte, err error) {
group := NewGroup(server)
groupID = group.GroupID
signedGroupId := p.SignMessage(groupID + server)
group.SignGroup(signedGroupId)
invite = group.Invite()
invite, err = group.Invite()
p.Groups[group.GroupID] = group
return
}

Näytä tiedosto

@ -1 +1 @@
{"Name":"Sarah","Ed25519PublicKey":"FH0bgqmhOuDPu/uXhm5ZT2BuA323JzPBd0Kf3B1YxZA=","Trusted":false,"Blocked":false,"Onion":"y6rv5psc5wruugyx","Contacts":{"y6rv5psc5wruugyx":{"Name":"Sarah","Ed25519PublicKey":"FH0bgqmhOuDPu/uXhm5ZT2BuA323JzPBd0Kf3B1YxZA=","Trusted":false,"Blocked":false,"Onion":"y6rv5psc5wruugyx"}},"Ed25519PrivateKey":"JMnZpsSi1hY6ziZqEaO2kk0ID9+XKm3nOiVoMJazbNIUfRuCqaE64M+7+5eGbllPYG4DfbcnM8F3Qp/cHVjFkA==","OnionPrivateKey":{"N":134057991576218556828017459230656270170181976065106440664426101908559409913157558701412664226096530310039819285641603796528668425856812146294423697678905284504161436672881228795123245277153307076066056625279711139065658846052615035565877781519956303024388960852968254724005382280308994893755778995867984769237,"E":65537,"D":119111293612512116271655044493966989822690945058076323906946181761988105028352909702660473288151745730711181119106925691927679973719306212959462470296819405321699089033715265196316348982251250275981258387949939751153694376595038421083397851309304042337114325061140172676796510776973712466297887452957497017473,"Primes":[11012092321802935235393019477644583097314933484252577291348472528127020714587871982369210353940819563472891086714033880185118457292396210254630513786328037,12173707562439882498035952564416877264727009547626505009495704590991075365448508893781170020376584913732483057163277808299913173595097515219539586115287601],"Precomputed":{"Dp":1484196888452100751243214383417529067528004142185376431854998822664235072889431515331297359603876576653738300028152971049562099779723449733420073062157797,"Dq":716821604337328632069224116851316498536422629114708986246607626480225824118677934923806935145539789463870059929400019259797746874337874959674737366966673,"Qinv":7022175560771039220943597791205895336996303269499099474897105311693825279448116080639519964317539885032301904250731793359527590562893328519648160444244943,"CRTValues":[]}},"Groups":{}}
{"Name":"Sarah","Ed25519PublicKey":"kt15QiBG1J5c/id40gVquRLy+9W80Pjo6GGupFX8SZg=","Trusted":false,"Blocked":false,"Onion":"c27gxmufdf7nlx42","Contacts":{"c27gxmufdf7nlx42":{"Name":"Sarah","Ed25519PublicKey":"kt15QiBG1J5c/id40gVquRLy+9W80Pjo6GGupFX8SZg=","Trusted":false,"Blocked":false,"Onion":"c27gxmufdf7nlx42"}},"Ed25519PrivateKey":"u5yr0+3ALkNUjsUEKpkS7XUir6CfiWjA+taMZq1j0HGS3XlCIEbUnlz+J3jSBWq5EvL71bzQ+OjoYa6kVfxJmA==","OnionPrivateKey":{"N":144983829191233247655266694233137145819597408562346928188863035707031200862163675503272451103113131843230802493116072128238601984611336245323267523366222203161150760005269917335298087279274255607542117827432707159523825155764216110649157897893395661131095379161623185618508372444555805823157700912547742897509,"E":65537,"D":110012677447103745558215320162956453979626158206767938598104428073835460696622326610956188426487525114546356671501123805868096466007555123726761534239877668156343381545220529056421907169124878216082199536352041119544096845173248537114532660978043529615659228326205308510959117986237470324931784765184852195841,"Primes":[13248368879651663441865660834404482695394663552933885883086531548794851607132827182384075868330839844484127087259737850183704901175666156837593492818358913,10943522973149980466244221046433018406848697119237814681483123960590595104315012043140302716278381470709492608332245501082916813931717759085319177194072293],"Precomputed":{"Dp":8401596945346945760522738757323110690194815324526377942032124413681780179807550399424211928585349264943540379840425481658985907163310208650490915895201409,"Dq":10070706173774742846318705026326736654363869619623000800162460992465611650536923818938792694489360002723492061103158920461887377332222989310398699613569433,"Qinv":8720528109273545534841434252402387798923580372660317915320553246728526976024152225431503920682105988836370044356429305972844849937961351483405213229018548,"CRTValues":[]}},"Groups":{}}

Näytä tiedosto

@ -43,7 +43,7 @@ func TestProfileGroup(t *testing.T) {
sarah.AddContact(alice.Onion, &alice.PublicProfile)
alice.AddContact(sarah.Onion, &sarah.PublicProfile)
gid, invite := alice.StartGroup("aaa.onion")
gid, invite,_ := alice.StartGroup("aaa.onion")
gci := &protocol.CwtchPeerPacket{}
proto.Unmarshal(invite, gci)
sarah.ProcessInvite(gci.GetGroupChatInvite(), alice.Onion)
@ -52,7 +52,7 @@ func TestProfileGroup(t *testing.T) {
c, _ := sarah.EncryptMessageToGroup("Hello World", group.GroupID)
alice.AttemptDecryption(c)
gid2, invite2 := alice.StartGroup("bbb.onion")
gid2, invite2 ,_:= alice.StartGroup("bbb.onion")
gci2 := &protocol.CwtchPeerPacket{}
proto.Unmarshal(invite2, gci2)
sarah.ProcessInvite(gci2.GetGroupChatInvite(), alice.Onion)

Näytä tiedosto

@ -100,7 +100,7 @@ func TestPeerPeerConnection(t *testing.T) {
t.Errorf("should have received an identity packet")
}
_, invite := profile.StartGroup("aaa.onion")
_, invite,_ := profile.StartGroup("aaa.onion")
ppc.SendGroupInvite(invite)
time.Sleep(time.Second * 3)
if tp.ReceivedGroupInvite == false {

Näytä tiedosto

@ -91,7 +91,10 @@ func (cp *CwtchPeer) InviteOnionToGroup(onion string, groupid string) error {
group := cp.Profile.GetGroupByGroupId(groupid)
if group != nil {
fmt.Printf("Constructing invite for group: %v\n", group)
invite := group.Invite()
invite, err := group.Invite()
if err != nil {
return err
}
ppc := cp.connectionsManager.GetPeerPeerConnectionForOnion(onion)
if ppc == nil {
return errors.New("peer connection not setup for onion. peers must be trusted before sending")

Näytä tiedosto

@ -1 +1 @@
{"Profile":{"Name":"alice","Ed25519PublicKey":"W6naGYWbCXL80XXDgpKE7V+siJo6o9bbGyTvUnUKILE=","Trusted":false,"Blocked":false,"Onion":"ycnqegkvvkz5gsvs","Contacts":{"ycnqegkvvkz5gsvs":{"Name":"alice","Ed25519PublicKey":"W6naGYWbCXL80XXDgpKE7V+siJo6o9bbGyTvUnUKILE=","Trusted":false,"Blocked":false,"Onion":"ycnqegkvvkz5gsvs"}},"Ed25519PrivateKey":"KvmZ7aWoB5RVmkloWri+316/wfA/CyGn0pcYS34WN7xbqdoZhZsJcvzRdcOCkoTtX6yImjqj1tsbJO9SdQogsQ==","OnionPrivateKey":{"N":138578445730948217399235853380745007937830927545752074120752000142489179414948896312808960302192046016583916437398543221534462954288785032720766262144773721364963084161409242148120269561063898622509706451288561156808651123385134272354840396173775759747294322189173896763873375202344132814058552323894612271379,"E":65537,"D":66260191577658320344575654997009713119915009011301814160670837488213389782059578785391177198063535925899470611750930777881256864604625902701343234975183920374575910046121511808611558969522048550963186520107773724296757371157728176877458332331908465537431591104876047516596838295433500859876997952335609406401,"Primes":[13275044288223673053268894137348396823019805659935753695111177485542609507887379320301691989583038422110723796993226398199751492392227091252491529012654327,10439019465560768307866940717986678867283694780656194070584524560148251882718648675994212565947390303977286149767780033032504469772695284927646948863796677],"Precomputed":{"Dp":5339834254331941789069908406682918611600288643166857483719438803635721376427469881773550883155897567537160699091130724771378745478796566513544740952921149,"Dq":6887615251084321564924765912178799470531367716104711656104878564862147484026383377308478349087250013492864037140982596218296928108413824489317205789392741,"Qinv":2094027238282876917718460475743388991144681081516298156361631729627217848136364125434066438976020876853031955793909233935538173930073006469995174800032241,"CRTValues":[]}},"Groups":{}}}
{"Profile":{"Name":"alice","Ed25519PublicKey":"/WIV95f8Corc4xS/Xp2lVsAjHuFP+T/IfAHP0W+TFc4=","Trusted":false,"Blocked":false,"Onion":"3r2nnz6k5uswkkqo","Contacts":{"3r2nnz6k5uswkkqo":{"Name":"alice","Ed25519PublicKey":"/WIV95f8Corc4xS/Xp2lVsAjHuFP+T/IfAHP0W+TFc4=","Trusted":false,"Blocked":false,"Onion":"3r2nnz6k5uswkkqo"}},"Ed25519PrivateKey":"hbOI9I+178MieEzHMe9jHbjw+9sO6SfquTludlISEd39YhX3l/wKitzjFL9enaVWwCMe4U/5P8h8Ac/Rb5MVzg==","OnionPrivateKey":{"N":130269025238092543507621713123709118014305981271637731491846807701026648665684664051832359307951319412301949886948642224152289779779325223257036298459799604792870723010336882108168182356061346752681059256446240403001412808193121911471377179009684049120483546399757136077849905221337094699790526750420132078753,"E":65537,"D":88290424691786236744457958916778485496123458140036998297219151082048334230013296425748657029473148079033645270282203798043798273314891859051086230754953351912669951165279170788120887160917925887800573610002558140382981117459828870692574727288633691427897040218206982631374868810780080016589748542727301979785,"Primes":[12884100328921389071983729873399702090258766052630626372371737584623900431811369576553518181772382574151671174790990476473529160298530692435837356984629647,10110835984851276122611693957975561424333331770264913531572029296384234947637618589542094789542370984086862838029253422898636836751501457892114271684757199],"Precomputed":{"Dp":8858077004143307579007932933085795455740718690196847019032390132108331258015421676005133317580908708456688584978446509436566777617699863279887081053655837,"Dq":9222973234148328259791755621949357051276305596685491565748188891716775770018037360880197609112745810316017428064525811796791238150636436756433394721426901,"Qinv":8953138537673943698274239645780397108345765090740203906412441783445824154548616018858987264413473443339625049275120780708904111729185063018076548957031915,"CRTValues":[]}},"Groups":{}}}