diff --git a/model/group.go b/model/group.go index cbc3e60..d8cb31a 100644 --- a/model/group.go +++ b/model/group.go @@ -50,7 +50,7 @@ func NewGroup(server string) *Group { // SignGroup adds a signature to the group. func (g *Group) SignGroup(signature []byte) { g.SignedGroupID = signature - copy(g.Timeline.SignedGroupId[:], g.SignedGroupID) + copy(g.Timeline.SignedGroupID[:], g.SignedGroupID) } // Compromised should be called if we detect a a groupkey leak. diff --git a/model/message.go b/model/message.go index 4d659ba..d3fa4e3 100644 --- a/model/message.go +++ b/model/message.go @@ -10,7 +10,7 @@ import ( // in a threadsafe manner. type Timeline struct { Messages []Message - SignedGroupId []byte + SignedGroupID []byte lock sync.Mutex } @@ -37,6 +37,7 @@ func compareSignatures(a []byte, b []byte) bool { return true } +// GetMessages returns a copy of the entire timeline func (t *Timeline) GetMessages() []Message { t.lock.Lock() messages := make([]Message, len(t.Messages)) @@ -62,7 +63,7 @@ func (t *Timeline) Less(i, j int) bool { return true } - if compareSignatures(t.Messages[i].PreviousMessageSig, t.SignedGroupId) { + if compareSignatures(t.Messages[i].PreviousMessageSig, t.SignedGroupID) { return true } diff --git a/model/profile.go b/model/profile.go index 64c6e99..5a6d9a6 100644 --- a/model/profile.go +++ b/model/profile.go @@ -140,6 +140,7 @@ func (p *Profile) IsBlocked(onion string) bool { return false } +// GetContact returns a contact if the profile has it func (p *Profile) GetContact(onion string) (*PublicProfile, bool) { p.lock.Lock() defer p.lock.Unlock() diff --git a/peer/connections/connectionsmanager.go b/peer/connections/connectionsmanager.go index 31863e7..eb148ee 100644 --- a/peer/connections/connectionsmanager.go +++ b/peer/connections/connectionsmanager.go @@ -132,6 +132,7 @@ func (m *Manager) ClosePeerConnection(onion string) { m.lock.Unlock() } +// Shutdown closes all connections under managment (freeing their goroutines) func (m *Manager) Shutdown() { m.breakChannel <- true m.lock.Lock() diff --git a/peer/connections/peerserverconnection.go b/peer/connections/peerserverconnection.go index 529a7e2..838cc5f 100644 --- a/peer/connections/peerserverconnection.go +++ b/peer/connections/peerserverconnection.go @@ -112,6 +112,7 @@ func (psc *PeerServerConnection) SendGroupMessage(gm *protocol.GroupMessage) err return err } +// Close shuts down the connection (freeing the handler goroutines) func (psc *PeerServerConnection) Close() { psc.state = KILLED psc.connection.Conn.Close() diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index add32bf..0d07dbb 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -251,6 +251,7 @@ func (cp *CwtchPeer) Listen() error { return nil } +// Shutdown kills all connections and cleans up all goroutines for the peer func (cp *CwtchPeer) Shutdown() { cp.connectionsManager.Shutdown() cp.app.Shutdown() diff --git a/server/server.go b/server/server.go index 1feee82..2c98538 100644 --- a/server/server.go +++ b/server/server.go @@ -72,6 +72,7 @@ func (s *Server) Run(privateKeyFile string, bufferSize int) { cwtchserver.Run(l) } +// Shutdown kills the app closing all connections and freeing all goroutines func (s *Server) Shutdown() { s.app.Shutdown() } diff --git a/testing/cwtch_peer_server_intergration_test.go b/testing/cwtch_peer_server_intergration_test.go index 6447d56..a347ca0 100644 --- a/testing/cwtch_peer_server_intergration_test.go +++ b/testing/cwtch_peer_server_intergration_test.go @@ -110,8 +110,9 @@ func TestCwtchPeerIntegration(t *testing.T) { numGoRoutinesStart := runtime.NumGoroutine() // ***** Cwtch Server managment ***** - var server *cwtchserver.Server = nil + var server *cwtchserver.Server serverKey := loadPrivateKey(t) + serverOnline := false var serverAddr string @@ -162,8 +163,8 @@ func TestCwtchPeerIntegration(t *testing.T) { // ***** Peering, server joining, group creation / invite ***** fmt.Println("Creating group on ", serverAddr, "...") - groupId, _, err := alice.Profile.StartGroup(serverAddr) - fmt.Printf("Created group: %v!\n", groupId) + groupID, _, err := alice.Profile.StartGroup(serverAddr) + fmt.Printf("Created group: %v!\n", groupID) if err != nil { t.Errorf("Failed to init group: %v", err) return @@ -183,7 +184,7 @@ func TestCwtchPeerIntegration(t *testing.T) { time.Sleep(time.Second * 60) fmt.Println("Alice inviting Bob to group...") - err = alice.InviteOnionToGroup(bob.Profile.Onion, groupId) + err = alice.InviteOnionToGroup(bob.Profile.Onion, groupID) if err != nil { t.Fatalf("Error for Alice inviting Bob to group: %v", err) } @@ -238,29 +239,29 @@ func TestCwtchPeerIntegration(t *testing.T) { fmt.Println("Starting conversation in group...") // Conversation fmt.Println("Alice> ", aliceLines[0]) - err = alice.SendMessageToGroup(groupId, aliceLines[0]) + err = alice.SendMessageToGroup(groupID, aliceLines[0]) if err != nil { t.Fatalf("Alice failed to send a message to the group: %v", err) } time.Sleep(time.Second * 10) fmt.Println("Bob> ", bobLines[0]) - err = bob.SendMessageToGroup(groupId, bobLines[0]) + err = bob.SendMessageToGroup(groupID, bobLines[0]) if err != nil { t.Fatalf("Bob failed to send a message to the group: %v", err) } time.Sleep(time.Second * 10) fmt.Println("Alice> ", aliceLines[1]) - alice.SendMessageToGroup(groupId, aliceLines[1]) + alice.SendMessageToGroup(groupID, aliceLines[1]) time.Sleep(time.Second * 10) fmt.Println("Bob> ", bobLines[1]) - bob.SendMessageToGroup(groupId, bobLines[1]) + bob.SendMessageToGroup(groupID, bobLines[1]) time.Sleep(time.Second * 10) fmt.Println("Alice inviting Carol to group...") - err = alice.InviteOnionToGroup(carol.Profile.Onion, groupId) + err = alice.InviteOnionToGroup(carol.Profile.Onion, groupID) if err != nil { t.Fatalf("Error for Alice inviting Carol to group: %v", err) } @@ -285,11 +286,11 @@ func TestCwtchPeerIntegration(t *testing.T) { numGoRotinesPostCarolConnect := runtime.NumGoroutine() fmt.Println("Bob> ", bobLines[2]) - bob.SendMessageToGroup(groupId, bobLines[2]) + bob.SendMessageToGroup(groupID, bobLines[2]) time.Sleep(time.Second * 10) fmt.Println("Carol> ", carolLines[0]) - carol.SendMessageToGroup(groupId, carolLines[0]) + carol.SendMessageToGroup(groupID, carolLines[0]) time.Sleep(time.Second * 10) // ***** Verify Test ***** @@ -297,7 +298,7 @@ func TestCwtchPeerIntegration(t *testing.T) { // final syncing time... time.Sleep(time.Second * 15) - alicesGroup := alice.Profile.GetGroupByGroupID(groupId) + alicesGroup := alice.Profile.GetGroupByGroupID(groupID) if alicesGroup == nil { t.Error("aliceGroup == nil") return @@ -309,7 +310,7 @@ func TestCwtchPeerIntegration(t *testing.T) { t.Errorf("Alice did not have 4 verified messages") } - bobsGroup := bob.Profile.GetGroupByGroupID(groupId) + bobsGroup := bob.Profile.GetGroupByGroupID(groupID) if bobsGroup == nil { t.Error("bobGroup == nil") return @@ -320,7 +321,7 @@ func TestCwtchPeerIntegration(t *testing.T) { t.Errorf("Bob did not have 5 verified messages") } - carolsGroup := carol.Profile.GetGroupByGroupID(groupId) + carolsGroup := carol.Profile.GetGroupByGroupID(groupID) fmt.Printf("Carol's TimeLine:\n") carolVerified := printAndCountVerifedTimeline(t, carolsGroup.GetTimeline()) if carolVerified != 3 {