71 lines
2.0 KiB
Go
71 lines
2.0 KiB
Go
package meowlib
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"testing"
|
|
)
|
|
|
|
func TestEndToEnd(t *testing.T) {
|
|
//
|
|
// Create my own identity
|
|
//
|
|
fmt.Println("Trying to load identity from file.")
|
|
me, err := LoadIdentity("test.id")
|
|
if err != nil {
|
|
fmt.Println("Failed : creating New identity...")
|
|
me = CreateIdentity("myname")
|
|
|
|
//
|
|
// define my preferences (servers)
|
|
//
|
|
me.MessageServers.Name = "Message Servers"
|
|
me.MessageServers.AddUrls([]string{"http://127.0.0.1/meow/", "mqtt://127.0.0.1", "meow://127.0.0.1"})
|
|
//
|
|
// create an invitation for a friend, I want him/her to know me as Bender
|
|
//
|
|
fmt.Println("Creating an invitation for the first friend...")
|
|
myFirstFriend, invitation := me.InvitePeer("Bender", "myfirstfriend", []int{1, 2})
|
|
// print my invitation
|
|
a, _ := json.Marshal(invitation)
|
|
fmt.Println(string(a))
|
|
// TODO : Convert invitation to QR Code
|
|
|
|
//
|
|
// Simulate peer invitation response : generate the friend's keypair
|
|
fmt.Println("Simulating first friend answer...")
|
|
var receivedContact Contact
|
|
firstFriendContactKp := NewKeyPair()
|
|
firstFriendEncryptionKp := NewKeyPair()
|
|
firstFriendLookupKp := NewKeyPair()
|
|
receivedContact.Name = "I'm the friend"
|
|
receivedContact.ContactPublicKey = firstFriendContactKp.Public
|
|
receivedContact.EncryptionPublicKey = firstFriendEncryptionKp.Public
|
|
receivedContact.LookupPublicKey = firstFriendLookupKp.Public
|
|
var friendsMessageServers ServerList
|
|
friendsMessageServers.AddUrls([]string{"http://myfriend.org/meow/"})
|
|
for _, srv := range friendsMessageServers.Servers {
|
|
receivedContact.PullServers = append(receivedContact.PullServers, srv.ServerData)
|
|
}
|
|
// End simulating concact invitation response
|
|
//
|
|
|
|
//
|
|
// Finalize the contact with the invitation response
|
|
//
|
|
me.FinalizeInvitation(myFirstFriend, &receivedContact)
|
|
err = me.Save("test.id")
|
|
if err != nil {
|
|
fmt.Println(err.Error())
|
|
}
|
|
|
|
a, _ = json.Marshal(me)
|
|
ioutil.WriteFile("id.json", a, 0644)
|
|
fmt.Println(string(a))
|
|
}
|
|
//myFirstFriend.SetComMethod()
|
|
//msg := myFirstFriend.SendText()
|
|
|
|
}
|