Преглед на файлове

Merge branch 'lint' of dan/cwtch into master

profile-password-2
Sarah Jamie Lewis Gogs преди 1 година
родител
ревизия
0aebd647de
променени са 8 файла, в които са добавени 24 реда и са изтрити 17 реда
  1. +1
    -1
      model/group.go
  2. +3
    -2
      model/message.go
  3. +1
    -0
      model/profile.go
  4. +1
    -0
      peer/connections/connectionsmanager.go
  5. +1
    -0
      peer/connections/peerserverconnection.go
  6. +1
    -0
      peer/cwtch_peer.go
  7. +1
    -0
      server/server.go
  8. +15
    -14
      testing/cwtch_peer_server_intergration_test.go

+ 1
- 1
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.


+ 3
- 2
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
}



+ 1
- 0
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()


+ 1
- 0
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()


+ 1
- 0
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()


+ 1
- 0
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()


+ 1
- 0
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()
}

+ 15
- 14
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 {


Loading…
Отказ
Запис