From 1534308210f158a4d926acad8091a859226b2ef6 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Sun, 20 May 2018 11:29:46 -0700 Subject: [PATCH] Fixing go vet issues --- app/app.go | 1 - app/cli/main.go | 6 +++--- model/group.go | 4 ++-- model/message.go | 13 ++++++++++--- model/profile_test | 2 +- peer/connections/peerpeerconnection.go | 6 +++--- peer/connections/peerserverconnection.go | 6 +++--- peer/listen/peer_listen_channel_test.go | 8 ++++++-- peer/test_profile | 2 +- 9 files changed, 29 insertions(+), 19 deletions(-) diff --git a/app/app.go b/app/app.go index b1899ee..a73348b 100644 --- a/app/app.go +++ b/app/app.go @@ -1,7 +1,6 @@ package app import ( - "git.mascherari.press/cwtch/model" "git.mascherari.press/cwtch/peer" "log" ) diff --git a/app/cli/main.go b/app/cli/main.go index 8fe41e8..3697991 100644 --- a/app/cli/main.go +++ b/app/cli/main.go @@ -53,7 +53,7 @@ var usages = map[string]string{ func completer(d prompt.Document) []prompt.Suggest { - s := []prompt.Suggest{} + var s []prompt.Suggest if d.FindStartOfPreviousWord() == 0 { return prompt.FilterHasPrefix(suggestions, d.GetWordBeforeCursor(), true) @@ -305,7 +305,7 @@ func main() { fmt.Printf("Error: group does not exist\n") } else { timeline := group.GetTimeline() - for _, m := range timeline.Messages { + for _, m := range timeline { verified := "not-verified" if m.Verified { verified = "verified" @@ -352,7 +352,7 @@ func main() { totalMessages := 0 for i := 0; i < 100; i++ { found := false - for _, m := range timeline.Messages { + for _, m := range timeline { if m.Message == fmt.Sprintf("this is message %v", i) && m.PeerID == app.Peer.Profile.Onion { found = true latency := m.Received.Sub(m.Timestamp) diff --git a/model/group.go b/model/group.go index a11943b..07448ad 100644 --- a/model/group.go +++ b/model/group.go @@ -90,9 +90,9 @@ func (g *Group) AddMessage(message *protocol.DecryptedGroupMessage, verified boo } // GetTimeline provides a safe copy of the timeline -func (g *Group) GetTimeline() (t Timeline) { +func (g *Group) GetTimeline() (t []Message) { g.lock.Lock() - t = g.Timeline + t = g.Timeline.GetMessages() g.lock.Unlock() return diff --git a/model/message.go b/model/message.go index 1f92f63..d21c31e 100644 --- a/model/message.go +++ b/model/message.go @@ -36,18 +36,25 @@ func compareSignatures(a []byte, b []byte) bool { return true } +func (t *Timeline) GetMessages() (messages []Message) { + t.lock.Lock() + copy(messages[:], t.Messages) + t.lock.Unlock() + return +} + // Len gets the length of the timeline -func (t Timeline) Len() int { +func (t *Timeline) Len() int { return len(t.Messages) } // Swap swaps 2 messages on the timeline. -func (t Timeline) Swap(i, j int) { +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 { +func (t *Timeline) Less(i, j int) bool { if t.Messages[i].Timestamp.Before(t.Messages[j].Timestamp) { return true diff --git a/model/profile_test b/model/profile_test index 8d8a4c6..ea03e7e 100644 --- a/model/profile_test +++ b/model/profile_test @@ -1 +1 @@ -{"Name":"Sarah","Ed25519PublicKey":"57kFKm/7PFfLdt44QNcBxkmIU2tdanullN0WvDOO/FQ=","Trusted":false,"Blocked":false,"Onion":"thrmwavrfuoe7wx7","Contacts":{"thrmwavrfuoe7wx7":{"Name":"Sarah","Ed25519PublicKey":"57kFKm/7PFfLdt44QNcBxkmIU2tdanullN0WvDOO/FQ=","Trusted":false,"Blocked":false,"Onion":"thrmwavrfuoe7wx7"}},"Ed25519PrivateKey":"diZj/+SpkfEn6REh/OUnLohzNBRlUXnKhfxCjpGC6LnnuQUqb/s8V8t23jhA1wHGSYhTa11qe6WU3Ra8M478VA==","OnionPrivateKey":{"N":115526317414135617425575125850363092197768071390300229017881702706301910480774870912224535075135030758413700959706658278491036490782648123350279274716714089785723761985949899401950289873760366537813188975967915448275390012212234547219215257061497408834486190848437014806765167468990582799034285030193834484173,"E":65537,"D":22912417012511020573075140543555845894480818345837044368439604677914952354076502923800212199316494953962819248276044742722835837880782768623936555117992118332152074673728836145747909027351079284225635999348165627201614483800585788303830525435154022352488126513303117823275614249285152465173042638718897652033,"Primes":[11402156153339328374441741694980617047036959691060198184493553742066189291925499966266720635183802563351350181897678783345992456538787170611079594127461721,10131971169356564075007609678604059792569764445254646425006890273240311372317974969782351657027084929890790581133993344651830788464914306688613338559505813],"Precomputed":{"Dp":4911467845778251064444365290588565531499052017617977550822482294559234077102352320791454041705277116184882061049048202600933320843034649531574178589472273,"Dq":3403811728271411130192754356986520354196995648125052265733504785784090444852905304022125462452741640621412884703711361050999564667775734170975172422671765,"Qinv":1754153198344459747541409117109512709100660841746820866017179767764202992075545256290834283674987202721482909528479810051819552048741477845301087087525389,"CRTValues":[]}},"Groups":{}} \ No newline at end of file +{"Name":"Sarah","Ed25519PublicKey":"SgRpJJw2l4dMsGR149urJkwm2hWplFkOjHbyGxs+Eyg=","Trusted":false,"Blocked":false,"Onion":"p6ehgils34x47nyg","Contacts":{"p6ehgils34x47nyg":{"Name":"Sarah","Ed25519PublicKey":"SgRpJJw2l4dMsGR149urJkwm2hWplFkOjHbyGxs+Eyg=","Trusted":false,"Blocked":false,"Onion":"p6ehgils34x47nyg"}},"Ed25519PrivateKey":"QRL3hvZP5wmSdIe24cxN0L/4z/BnCpXa9n9A/JzFFEBKBGkknDaXh0ywZHXj26smTCbaFamUWQ6MdvIbGz4TKA==","OnionPrivateKey":{"N":151025771385966457315600103418087241110098664615614044467509585189952787361645163139595526204706389976899022537376049028041109114981491273832411774529216922191266316467163925107525714054510209765670955357908880636058201272225362200898015155059147874275999278481661208123978874126707190377553876855779404877717,"E":65537,"D":125243750080960236029198010599655514703034199355997493061395523833693090015076261828797126107383425986152630970045178885591440549462579447358251789582806798697737114991639329317994231561839015645204535496591732604621896238281646079430628006514324350534478950620213366125076645317906712748091678643287136521633,"Primes":[12998312283988098720258413423813336955357486672773091346977952106979604643331780603112919326243156235893536425556333045796625578558333990999466915635186681,11618875442160806051497378349343120970680061048618412772214305744446841325704429100064680636090245448365592590278817388980936340830366040119964714124504957],"Precomputed":{"Dp":9178370959398770839028313746644030002640926663654429532387791471301633643277306116701352940484833622662697181217791848273958861390421015632121251428193753,"Dq":3284069284382665842164539672905869552479934248815287214741257604256119271821243643279340587804380833506633461133784172505346060661026603707557965186723985,"Qinv":1616368906391224777304872606094694481250124880102681898802568811243640263040569336684936819346045620346829342124911001383838948453617533259204103210517135,"CRTValues":[]}},"Groups":{}} \ No newline at end of file diff --git a/peer/connections/peerpeerconnection.go b/peer/connections/peerpeerconnection.go index 0e421e0..abc1f19 100644 --- a/peer/connections/peerpeerconnection.go +++ b/peer/connections/peerpeerconnection.go @@ -18,7 +18,7 @@ type PeerPeerConnection struct { connection.AutoConnectionHandler PeerHostname string state ConnectionState - connection connection.Connection + connection *connection.Connection profile *model.Profile } @@ -72,9 +72,9 @@ func (ppc *PeerPeerConnection) Run() error { rc, err := goricochet.Open(ppc.PeerHostname) if err == nil { rc.TraceLog(false) - ppc.connection = *rc + ppc.connection = rc ppc.state = CONNECTED - _, err := connection.HandleOutboundConnection(&ppc.connection).ProcessAuthAsClient(identity.Initialize(ppc.profile.Name, ppc.profile.OnionPrivateKey)) + _, err := connection.HandleOutboundConnection(ppc.connection).ProcessAuthAsClient(identity.Initialize(ppc.profile.Name, ppc.profile.OnionPrivateKey)) if err == nil { ppc.state = AUTHENTICATED go func() { diff --git a/peer/connections/peerserverconnection.go b/peer/connections/peerserverconnection.go index 1084293..dc54e2a 100644 --- a/peer/connections/peerserverconnection.go +++ b/peer/connections/peerserverconnection.go @@ -20,7 +20,7 @@ type PeerServerConnection struct { connection.AutoConnectionHandler Server string state ConnectionState - connection connection.Connection + connection *connection.Connection GroupMessageHandler func(string, *protocol.GroupMessage) } @@ -44,11 +44,11 @@ func (psc *PeerServerConnection) Run() error { rc, err := goricochet.Open(psc.Server) if err == nil { rc.TraceLog(true) - psc.connection = *rc + psc.connection = rc psc.state = CONNECTED pk, err := utils.GeneratePrivateKey() if err == nil { - _, err := connection.HandleOutboundConnection(&psc.connection).ProcessAuthAsClient(identity.Initialize("cwtchpeer", pk)) + _, err := connection.HandleOutboundConnection(psc.connection).ProcessAuthAsClient(identity.Initialize("cwtchpeer", pk)) if err == nil { psc.state = AUTHENTICATED diff --git a/peer/listen/peer_listen_channel_test.go b/peer/listen/peer_listen_channel_test.go index d7c4a02..a70b915 100644 --- a/peer/listen/peer_listen_channel_test.go +++ b/peer/listen/peer_listen_channel_test.go @@ -6,6 +6,7 @@ import ( "github.com/s-rah/go-ricochet/channels" "github.com/s-rah/go-ricochet/wire/control" "testing" + "time" ) type TestHandler struct { @@ -76,8 +77,11 @@ func TestPeerListenChannel(t *testing.T) { pfc.Packet(packet) - if th.Received != true { - t.Errorf("group message should not have been received") + // Wait for goroutine to run + time.Sleep(time.Second * 1) + + if !th.Received { + t.Errorf("group message should have been received") } pfc.Closed(nil) diff --git a/peer/test_profile b/peer/test_profile index 2f5cd78..0d0aea0 100644 --- a/peer/test_profile +++ b/peer/test_profile @@ -1 +1 @@ -{"Profile":{"Name":"alice","Ed25519PublicKey":"0S45Wi1Isv/cFd0kDBMGO7RtQ052ykhaCd6L1zZiGJk=","Trusted":false,"Blocked":false,"Onion":"k5eov6vrcwfwxtll","Contacts":{"k5eov6vrcwfwxtll":{"Name":"alice","Ed25519PublicKey":"0S45Wi1Isv/cFd0kDBMGO7RtQ052ykhaCd6L1zZiGJk=","Trusted":false,"Blocked":false,"Onion":"k5eov6vrcwfwxtll"}},"Ed25519PrivateKey":"2bcZKNNADNvjPbvqi92lX4/m+S9JhtdKT6jvGXCbzFPRLjlaLUiy/9wV3SQMEwY7tG1DTnbKSFoJ3ovXNmIYmQ==","OnionPrivateKey":{"N":129372676647459794327830253373463393606614906660537850553935500200530603388955991892570404489884752658911733140595540603298204271320256261391136774929958682162097800498560829735266250139995081586925851310901551963943491407445610456311068913491697886096166012618097156047960858604885507865489761463667080301053,"E":65537,"D":13830126075226258740265479883645643462592795460026064375556893272577588344645401516690545094467744588985391494621547484119004823609101963277328901920431059810319615003421932162013637268371590049232355377940028961198027904729545745481971750183753640418115007446942300337049266027513914090369018266501543413697,"Primes":[10134035533655370825395777494371157149217307934744138685965355987639016807004540627179525764862351274689439670035451419591678388697397084668693600989506869,12766155814020000856737163927670455275067799350422878241672290736027598052735005956636650394580684371305614873375636621519903205433400104443307931969940137],"Precomputed":{"Dp":3537951584754182896456282543772404528344172079084271375480832888249091422315087500951638761311176849182818555173583296157248600537046939854123771161937793,"Dq":4462515274476771894151268572241672031013446073497989191425767253179978390681695095298671344270395322676355816319978933463531478909223232566210559126895625,"Qinv":2690107827925082851885736485760405702598764576265172898377988691597466473116754634766336624610955703441824524110562956288452424664297519088478250787531223,"CRTValues":[]}},"Groups":{}}} \ No newline at end of file +{"Profile":{"Name":"alice","Ed25519PublicKey":"gWXfzP4wvMJ5j8yv5lkCmntRou/Z3zH3rs7MMthqKTQ=","Trusted":false,"Blocked":false,"Onion":"am6gwjcyctstzlc2","Contacts":{"am6gwjcyctstzlc2":{"Name":"alice","Ed25519PublicKey":"gWXfzP4wvMJ5j8yv5lkCmntRou/Z3zH3rs7MMthqKTQ=","Trusted":false,"Blocked":false,"Onion":"am6gwjcyctstzlc2"}},"Ed25519PrivateKey":"10jFOuAYO4Viw6nfe6Yetjh+oP7apVx7QpKIqRKKGwmBZd/M/jC8wnmPzK/mWQKae1Gi79nfMfeuzswy2GopNA==","OnionPrivateKey":{"N":147880432621871504779615857957362407431209846743533559661945830611220249199723115899614573127370139919927611627709018139426557086534947242067702251560319171966667134304630051790361962997647653664951649912943924083112173778189617381049272838770430351966281298194239296841527739740024573326387864819562137420269,"E":65537,"D":130999990788338985328675072853085004285004178747006795241373989379510853220915287801822232593536488444562879299605944078956134675311242459762920516907790842355984733809116227992469235130987810703943533032505458827231110955929966815957481967581612489200794929349103575491967289603043965454693951743019350429921,"Primes":[11947866823745435455892039576265035645775668999529461749065887228195684195954622809692270909464429145942026225362289090834468485547124190883870378071630407,12377141024703330426235540654219528982015913018918150249718199085745128023134821710912287791906815892120589396719673405276176963231038832685865432874369067],"Precomputed":{"Dp":11122744446397191854973972360460596148502667826270534061251794340287881478849924351772817499387129203702778003808209404167138513690214596487721678388211891,"Dq":5067041422292603496283008922482108771953048603042158951431089025596865661545497451878735393088787561005163701634021048622302331865797517142404589224702413,"Qinv":6439679233885062453326040666151092713878681619523464587705315223851862036675549289934062975420544339668044885799082649238658464851991671641282282423293532,"CRTValues":[]}},"Groups":{}}} \ No newline at end of file