diff --git a/.gitignore b/.gitignore index e95809b..54fedbb 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ *.test */*test_* */*_test* +.* diff --git a/app/cli/main.go b/app/cli/main.go index b54287d..6852011 100644 --- a/app/cli/main.go +++ b/app/cli/main.go @@ -250,7 +250,7 @@ func main() { fmt.Printf("Error: %v\n", err) } else { app.Peer.Save(profilefile) - group := app.Peer.Profile.GetGroupByGroupId(groupID) + group := app.Peer.Profile.GetGroupByGroupID(groupID) if group == nil { fmt.Printf("Error: group does not exist\n") } else { @@ -277,7 +277,7 @@ func main() { 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) + group := app.Peer.Profile.GetGroupByGroupID(id) if group == nil { fmt.Printf("Error: group does not exist\n") } else { @@ -301,7 +301,7 @@ func main() { } case "timeline": if len(commands) == 2 { - group := app.Peer.Profile.GetGroupByGroupId(commands[1]) + group := app.Peer.Profile.GetGroupByGroupID(commands[1]) if group == nil { fmt.Printf("Error: group does not exist\n") } else { @@ -334,7 +334,7 @@ func main() { } case "sendlots": if len(commands) == 2 { - group := app.Peer.Profile.GetGroupByGroupId(commands[1]) + group := app.Peer.Profile.GetGroupByGroupID(commands[1]) if group == nil { fmt.Printf("Error: group does not exist\n") } else { diff --git a/model/message.go b/model/message.go index 1dfc634..1f92f63 100644 --- a/model/message.go +++ b/model/message.go @@ -6,6 +6,8 @@ import ( "time" ) +// Timeline encapsulates a collection of ordered messages, and a mechanism to access them +// in a threadsafe manner. type Timeline struct { Messages []Message lock sync.Mutex @@ -34,12 +36,17 @@ func compareSignatures(a []byte, b []byte) bool { return true } +// Len gets the length of the timeline func (t Timeline) Len() int { return len(t.Messages) } + +// Swap swaps 2 messages on the timeline. func (t Timeline) Swap(i, j int) { t.Messages[i], t.Messages[j] = t.Messages[j], t.Messages[i] } + +// Less checks 2 messages (i andj) in the timeline and returns true if i cccured before j, else false func (t Timeline) Less(i, j int) bool { if t.Messages[i].Timestamp.Before(t.Messages[j].Timestamp) { @@ -57,6 +64,7 @@ func (t Timeline) Less(i, j int) bool { return false } +// Insert inserts a message into the timeline in a thread safe way. func (t *Timeline) Insert(mi *Message) { t.lock.Lock() diff --git a/model/message_test.go b/model/message_test.go index 6e869e3..7b48085 100644 --- a/model/message_test.go +++ b/model/message_test.go @@ -21,7 +21,7 @@ func TestTranscriptConsistency(t *testing.T) { proto.Unmarshal(invite, gci) sarah.ProcessInvite(gci.GetGroupChatInvite(), alice.Onion) - group := alice.GetGroupByGroupId(gid) + group := alice.GetGroupByGroupID(gid) t.Logf("group: %v, sarah %v", group, sarah) diff --git a/model/profile.go b/model/profile.go index 590d961..2422397 100644 --- a/model/profile.go +++ b/model/profile.go @@ -80,7 +80,7 @@ func (p *Profile) AddContact(onion string, profile *PublicProfile) { p.Contacts[onion] = profile } -// VerifyMessage confirms the authenticity of a message given an onion, message and signature. +// VerifyGroupMessage confirms the authenticity of a message given an onion, message and signature. func (p *Profile) VerifyGroupMessage(onion string, groupID string, message string, timestamp int32, signature []byte) bool { if onion == p.Onion { @@ -107,14 +107,15 @@ func (p *Profile) SignMessage(message string) []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) + signedGroupID := p.SignMessage(groupID + server) + group.SignGroup(signedGroupID) invite, err = group.Invite() p.Groups[group.GroupID] = group return } -func (p *Profile) GetGroupByGroupId(groupID string) *Group { +// GetGroupByGroupID a pointer to a Group by the group Id, returns nil if no group found. +func (p *Profile) GetGroupByGroupID(groupID string) *Group { return p.Groups[groupID] } diff --git a/model/profile_test b/model/profile_test index d71af12..864609b 100644 --- a/model/profile_test +++ b/model/profile_test @@ -1 +1 @@ -{"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":{}} \ No newline at end of file +{"Name":"Sarah","Ed25519PublicKey":"hkfbKr6SljTDaW9N8hCgJLh4ENpLqjLFgpUWZTurpag=","Trusted":false,"Blocked":false,"Onion":"owjekmmpj3ul3gfz","Contacts":{"owjekmmpj3ul3gfz":{"Name":"Sarah","Ed25519PublicKey":"hkfbKr6SljTDaW9N8hCgJLh4ENpLqjLFgpUWZTurpag=","Trusted":false,"Blocked":false,"Onion":"owjekmmpj3ul3gfz"}},"Ed25519PrivateKey":"V2kCSvs/zrKhuUZUEM4fzXu/y6sIaF2Qpz9ldIyeto+GR9sqvpKWNMNpb03yEKAkuHgQ2kuqMsWClRZlO6ulqA==","OnionPrivateKey":{"N":154552290328420627595829708318053000227886131468989692989624020047013814443612876624924003554522692413957181345653068356278670975716107206352364806129405828764966426939741017013826498996451649729462665263223045560347290965899936752732687160190028906071717682111902486370328224252220595900689133553343977971221,"E":65537,"D":147425674502665906803077562529610499553630796478079415555279393521813153027182492061081893925736394956414440572859629953961290813538801623588478048357108256862763483195055449738743289919744325795735243060276681914199738214331673267262302372485022069058706717424527999434240341330101621889282035926454638330913,"Primes":[12023851229241952371916616433226927134047042939386147016983881750452924185418883493919153456117039577010798472989975972000325916048411130307466298630615433,12853809264751226235922963581062329700363294705890811085720976326030808993421083144923264023939317664751296612868402325363336832100976595908571056262619437],"Precomputed":{"Dp":2926842831684344205398260249313657454101537696446697336801255253749416353052282655270950075307614513512264339832599702173141879224259620699681246655388681,"Dq":12844983389033481981828077740069488941150691927891130195554239308244346591957727349852974769303352190364098414177905688278310813860218795783208502323137649,"Qinv":5576087614201436790737269005844816983805544009730952472017948942072576857626128347301588121845450868691821943357914869501149940762854671411061246602467131,"CRTValues":[]}},"Groups":{}} \ No newline at end of file diff --git a/model/profile_test.go b/model/profile_test.go index 40894af..be9d2cf 100644 --- a/model/profile_test.go +++ b/model/profile_test.go @@ -48,7 +48,7 @@ func TestProfileGroup(t *testing.T) { proto.Unmarshal(invite, gci) sarah.ProcessInvite(gci.GetGroupChatInvite(), alice.Onion) - group := alice.GetGroupByGroupId(gid) + group := alice.GetGroupByGroupID(gid) c, _ := sarah.EncryptMessageToGroup("Hello World", group.GroupID) alice.AttemptDecryption(c) @@ -56,7 +56,7 @@ func TestProfileGroup(t *testing.T) { gci2 := &protocol.CwtchPeerPacket{} proto.Unmarshal(invite2, gci2) sarah.ProcessInvite(gci2.GetGroupChatInvite(), alice.Onion) - group2 := alice.GetGroupByGroupId(gid2) + group2 := alice.GetGroupByGroupID(gid2) c2, _ := sarah.EncryptMessageToGroup("Hello World", group2.GroupID) alice.AttemptDecryption(c2) diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index 01d3073..4afea94 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -88,7 +88,7 @@ func (cp *CwtchPeer) PeerWithOnion(onion string) { // InviteOnionToGroup kicks off the invite process func (cp *CwtchPeer) InviteOnionToGroup(onion string, groupid string) error { - group := cp.Profile.GetGroupByGroupId(groupid) + group := cp.Profile.GetGroupByGroupID(groupid) if group != nil { fmt.Printf("Constructing invite for group: %v\n", group) invite, err := group.Invite() @@ -119,7 +119,7 @@ func (cp *CwtchPeer) JoinServer(onion string) { } func (cp *CwtchPeer) SendMessageToGroup(groupid string, message string) error { - group := cp.Profile.GetGroupByGroupId(groupid) + group := cp.Profile.GetGroupByGroupID(groupid) if group == nil { return errors.New("group does not exit") } @@ -166,7 +166,7 @@ func (cp *CwtchPeer) BlockPeer(peer string) error { } func (cp *CwtchPeer) AcceptInvite(groupID string) error { - g := cp.Profile.GetGroupByGroupId(groupID) + g := cp.Profile.GetGroupByGroupID(groupID) if g == nil { return errors.New("group invite does not exit") } @@ -175,7 +175,7 @@ func (cp *CwtchPeer) AcceptInvite(groupID string) error { } func (cp *CwtchPeer) RejectInvite(groupID string) error { - g := cp.Profile.GetGroupByGroupId(groupID) + g := cp.Profile.GetGroupByGroupID(groupID) if g == nil { return errors.New("group invite does not exit") } diff --git a/peer/test_profile b/peer/test_profile index 7a41cd3..514ed0c 100644 --- a/peer/test_profile +++ b/peer/test_profile @@ -1 +1 @@ -{"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":{}}} \ No newline at end of file +{"Profile":{"Name":"alice","Ed25519PublicKey":"EPP2ByelMR8QbCRZ56TvNZIn3zQa2lgF2stgkpPJ+aM=","Trusted":false,"Blocked":false,"Onion":"7isshkc2i3djqbvm","Contacts":{"7isshkc2i3djqbvm":{"Name":"alice","Ed25519PublicKey":"EPP2ByelMR8QbCRZ56TvNZIn3zQa2lgF2stgkpPJ+aM=","Trusted":false,"Blocked":false,"Onion":"7isshkc2i3djqbvm"}},"Ed25519PrivateKey":"sJ5CAaTezNmdt8oAHbXF42fw5tD9yY67fqjaell9UWUQ8/YHJ6UxHxBsJFnnpO81kiffNBraWAXay2CSk8n5ow==","OnionPrivateKey":{"N":109264965121269102864268122399717914981859407652105503986871936893865494823555161493388959985138872973433399135905775525157924873337104893694978392209273343269778013691805532688273390165440742501637993188808873815612746664566611221222356706841643278718951875953660024258163364129880350927070816248541790972927,"E":65537,"D":80405289727992508412576998321119304909137336967485422597538381381211395377505756646499982806709071621981057114718828085688866485594832807547304925783551650481916788738771615371037649919470056628797374101427393208956491043600211579247644280949777877409955527302067923539607079105105839036975582591395024605569,"Primes":[10488093793005778253652455285384166778311422933955447489461025546115184116803524144032108593418314278741083466541849319796911230734922592676584779174557633,10418000380024719809017535929593675542117900930084020826809324556106965859207771141464817326453354343332212022219319386849128962897507240725843863893136319],"Precomputed":{"Dp":9125571392626584881181988155369659004831656468299456523666570940325711336992650827244807182545623618973294513215677766189774770132863741126339226129832001,"Dq":3288798844352524957333472707743161165309325302386564946302975658655370503092139968960520098066640951053605360753398825007577843254749642238384175352626719,"Qinv":9470686814605331096328774018187602768490278876204799167115558347990281971237179616039742279558354704162800553043867292124027611347849132182052052306560962,"CRTValues":[]}},"Groups":{}}} \ No newline at end of file