forked from cwtch.im/cwtch
cwtch peers peer and sendInvite
This commit is contained in:
parent
becfe7c928
commit
3b65cffbdb
|
@ -3,10 +3,8 @@ package testing
|
|||
import (
|
||||
"cwtch.im/cwtch/model"
|
||||
"cwtch.im/cwtch/peer"
|
||||
"cwtch.im/cwtch/protocol"
|
||||
cwtchserver "cwtch.im/cwtch/server"
|
||||
"fmt"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/s-rah/go-ricochet"
|
||||
"github.com/s-rah/go-ricochet/utils"
|
||||
"io/ioutil"
|
||||
|
@ -63,7 +61,9 @@ func serverCheck(serverAddr string) bool {
|
|||
func TestCwtchPeerIntegration(t *testing.T) {
|
||||
// Hide logging "noise"
|
||||
log.SetOutput(ioutil.Discard)
|
||||
// Todo: coung goroutines at beginning middle and end after shutdown
|
||||
|
||||
// ***** Cwtch Server managment *****
|
||||
generatedKey := checkAndGenPrivateKey(keyfile)
|
||||
|
||||
serverKey, err := utils.LoadPrivateKeyFromFile(keyfile)
|
||||
|
@ -86,65 +86,92 @@ func TestCwtchPeerIntegration(t *testing.T) {
|
|||
|
||||
// let tor get established
|
||||
fmt.Printf("Establishing Tor hidden service: %v...\n", serverAddr)
|
||||
time.Sleep(time.Second * 120)
|
||||
} else {
|
||||
fmt.Printf("Found existing cwtch server %v, using for tests...\n", serverAddr)
|
||||
}
|
||||
|
||||
// launch alice
|
||||
// ***** Peer setup *****
|
||||
|
||||
fmt.Println("Creating Alice...")
|
||||
alice := peer.NewCwtchPeer("Alice")
|
||||
alice.Profile.AddContact(alice.Profile.Onion, &alice.Profile.PublicProfile)
|
||||
go alice.Listen()
|
||||
fmt.Println("Alice created:", alice.Profile.Onion)
|
||||
|
||||
fmt.Println("Starting group on ", serverAddr, "...")
|
||||
groupId, invite, err := alice.Profile.StartGroup(serverAddr)
|
||||
fmt.Printf("Started group: %v!\n", groupId)
|
||||
fmt.Println("Creating Bob...")
|
||||
bob := peer.NewCwtchPeer("Bob")
|
||||
bob.Profile.AddContact(bob.Profile.Onion, &bob.Profile.PublicProfile)
|
||||
go bob.Listen()
|
||||
fmt.Println("Bob created:", bob.Profile.Onion)
|
||||
|
||||
fmt.Println("Waiting for alice and bob to connection with onion network...")
|
||||
time.Sleep(time.Second * 60)
|
||||
|
||||
// ***** Peering and group creation / invite *****
|
||||
|
||||
fmt.Println("Creating group on ", serverAddr, "...")
|
||||
groupId, _, err := alice.Profile.StartGroup(serverAddr)
|
||||
fmt.Printf("Created group: %v!\n", groupId)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to start group: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
gci := &protocol.CwtchPeerPacket{}
|
||||
proto.Unmarshal(invite, gci)
|
||||
fmt.Println("Peering Alice peering with bob...")
|
||||
alice.PeerWithOnion(bob.Profile.Onion)
|
||||
|
||||
fmt.Println("Alice joining server/group...")
|
||||
time.Sleep(time.Second * 15)
|
||||
|
||||
// TODO: bob auto accepted!?
|
||||
/*fmt.Println("Bob checking for new peers and accepting...")
|
||||
bpeers := bob.GetPeers()
|
||||
for bpeer, bpeerState := range bpeers {
|
||||
fmt.Printf(" %v: %v\n", bpeer, bpeerState)
|
||||
}
|
||||
time.Sleep(time.Second * 5)*/
|
||||
|
||||
fmt.Println("Alice inviting Bob to group...")
|
||||
err = alice.InviteOnionToGroup(bob.Profile.Onion, groupId)
|
||||
if err != nil {
|
||||
t.Fatalf("Error for Alice inviting Bob to group: %v", err)
|
||||
}
|
||||
|
||||
time.Sleep(time.Second * 10)
|
||||
|
||||
fmt.Println("Bob examining groups and accepting invites...")
|
||||
for _, group := range bob.Profile.Groups {
|
||||
fmt.Printf("Bob group: %v (Accepted: %v)\n", group.GroupID, group.Accepted)
|
||||
if group.Accepted == false {
|
||||
fmt.Printf("Bob received and accepting group invite: %v\n", group.GroupID)
|
||||
bob.AcceptInvite(group.GroupID)
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Second * 3)
|
||||
|
||||
fmt.Println("Alice joining server...")
|
||||
alice.JoinServer(serverAddr)
|
||||
|
||||
// launch bob
|
||||
fmt.Println("Creating Bob...")
|
||||
bob := peer.NewCwtchPeer("Bob")
|
||||
bob.Profile.AddContact(bob.Profile.Onion, &bob.Profile.PublicProfile)
|
||||
fmt.Println("Bob created:", bob.Profile.Onion)
|
||||
|
||||
// Associate peer alice & bob as peers
|
||||
fmt.Println("Peering Alice and Bob...")
|
||||
alice.Profile.AddContact(bob.Profile.Onion, &bob.Profile.PublicProfile)
|
||||
bob.Profile.AddContact(alice.Profile.Onion, &alice.Profile.PublicProfile)
|
||||
|
||||
// TODO: have alice actually send the invite
|
||||
fmt.Printf("Bob processing invite to group %v\n", gci.GetGroupChatInvite().GroupName)
|
||||
bob.Profile.ProcessInvite(gci.GetGroupChatInvite(), alice.Profile.Onion)
|
||||
|
||||
fmt.Println("Bob joining server/group...")
|
||||
fmt.Println("Bob joining server...")
|
||||
bob.JoinServer(serverAddr)
|
||||
|
||||
// Wait for them to join the server
|
||||
time.Sleep(time.Second * 60)
|
||||
time.Sleep(time.Second * 30)
|
||||
|
||||
// ***** Conversation *****
|
||||
|
||||
fmt.Println("Starting conversation in group...")
|
||||
// Conversation
|
||||
fmt.Println("Alice> ", aliceLines[0])
|
||||
err = alice.SendMessageToGroup(groupId, aliceLines[0])
|
||||
if err != nil {
|
||||
t.Errorf("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)
|
||||
|
||||
fmt.Println("Bob> ", bobLines[0])
|
||||
err = bob.SendMessageToGroup(groupId, bobLines[0])
|
||||
if err != nil {
|
||||
t.Errorf("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)
|
||||
|
||||
|
@ -166,7 +193,7 @@ func TestCwtchPeerIntegration(t *testing.T) {
|
|||
|
||||
// Todo: Alice reconects, gets missed messages (from bob)
|
||||
|
||||
// Verify
|
||||
// ***** Verify Test *****
|
||||
|
||||
// final syncing time...
|
||||
time.Sleep(time.Second * 10)
|
||||
|
|
Loading…
Reference in New Issue