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