Skip to content
Snippets Groups Projects
Commit 27063854 authored by Jonah Husson's avatar Jonah Husson
Browse files

Fixes from MR

parent 876d0c4f
No related branches found
No related tags found
1 merge request!4Add example E2e client
...@@ -9,7 +9,9 @@ import ( ...@@ -9,7 +9,9 @@ import (
) )
// auth implements the xxdk.AuthCallbacks interface // auth implements the xxdk.AuthCallbacks interface
type auth struct{} type auth struct {
confirmChan chan contact.Contact
}
// Request is called when requests are received // Request is called when requests are received
// Currently confirms all incoming auth requests // Currently confirms all incoming auth requests
...@@ -21,8 +23,11 @@ func (a *auth) Request(partner contact.Contact, receptionID receptionID.Ephemera ...@@ -21,8 +23,11 @@ func (a *auth) Request(partner contact.Contact, receptionID receptionID.Ephemera
} }
} }
// Confirm is called when an e2e request is confirmed.
// Currently passes the confirmed contact over a channel to notify the main thread of the confirmation
func (a *auth) Confirm(partner contact.Contact, receptionID receptionID.EphemeralIdentity, func (a *auth) Confirm(partner contact.Contact, receptionID receptionID.EphemeralIdentity,
round rounds.Round, e2e *xxdk.E2e) { round rounds.Round, e2e *xxdk.E2e) {
a.confirmChan <- partner
} }
func (a *auth) Reset(partner contact.Contact, receptionID receptionID.EphemeralIdentity, func (a *auth) Reset(partner contact.Contact, receptionID receptionID.EphemeralIdentity,
......
...@@ -6,6 +6,8 @@ require ( ...@@ -6,6 +6,8 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/jwalterweatherman v1.1.0
gitlab.com/elixxir/client v1.5.1-0.20220706193049-a0b718049663 gitlab.com/elixxir/client v1.5.1-0.20220706193049-a0b718049663
gitlab.com/elixxir/crypto v0.0.7-0.20220606201132-c370d5039cea gitlab.com/elixxir/crypto v0.0.7-0.20220606201132-c370d5039cea
gitlab.com/elixxir/primitives v0.0.3-0.20220606195757-40f7a589347f
gitlab.com/xx_network/primitives v0.0.4-0.20220630163313-7890038258c6
) )
require ( require (
...@@ -24,10 +26,8 @@ require ( ...@@ -24,10 +26,8 @@ require (
gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f // indirect gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f // indirect
gitlab.com/elixxir/comms v0.0.4-0.20220603231314-e47e4af13326 // indirect gitlab.com/elixxir/comms v0.0.4-0.20220603231314-e47e4af13326 // indirect
gitlab.com/elixxir/ekv v0.1.7 // indirect gitlab.com/elixxir/ekv v0.1.7 // indirect
gitlab.com/elixxir/primitives v0.0.3-0.20220606195757-40f7a589347f // indirect
gitlab.com/xx_network/comms v0.0.4-0.20220630163702-f3d372ef6acd // indirect gitlab.com/xx_network/comms v0.0.4-0.20220630163702-f3d372ef6acd // indirect
gitlab.com/xx_network/crypto v0.0.5-0.20220606200528-3f886fe49e81 // indirect gitlab.com/xx_network/crypto v0.0.5-0.20220606200528-3f886fe49e81 // indirect
gitlab.com/xx_network/primitives v0.0.4-0.20220630163313-7890038258c6 // indirect
gitlab.com/xx_network/ring v0.0.3-0.20220222211904-da613960ad93 // indirect gitlab.com/xx_network/ring v0.0.3-0.20220222211904-da613960ad93 // indirect
golang.org/x/crypto v0.0.0-20220128200615-198e4374d7ed // indirect golang.org/x/crypto v0.0.0-20220128200615-198e4374d7ed // indirect
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
......
...@@ -20,15 +20,16 @@ import ( ...@@ -20,15 +20,16 @@ import (
func main() { func main() {
// Logging // Logging
initLog(1, "client.log") initLog(1, "client2.log")
// Create a new client object------------------------------------------------------- // Create a new client object-------------------------------------------------------
// Path to the recipient contact file // Path to the recipient contact file
recipientContactPath := "recipient.xxc" recipientContactPath := "contact.xxc"
myContactPath := "recipient.xxc"
// You would ideally use a configuration tool to acquire these parameters // You would ideally use a configuration tool to acquire these parameters
statePath := "statePath" statePath := "statePathRecipient"
statePass := "password" statePass := "password"
// The following connects to mainnet. For historical reasons it is called a json file // The following connects to mainnet. For historical reasons it is called a json file
// but it is actually a marshalled file with a cryptographic signature attached. // but it is actually a marshalled file with a cryptographic signature attached.
...@@ -90,11 +91,17 @@ func main() { ...@@ -90,11 +91,17 @@ func main() {
} }
} }
err = ioutil.WriteFile(myContactPath, identity.GetContact().Marshal(), fs.ModePerm)
if err != nil {
jww.FATAL.Panicf("Failed to write contact to file at %s: %+v", myContactPath, err)
}
// Create an E2E client // Create an E2E client
// Pass in auth object which controls auth callbacks for this client // Pass in auth object which controls auth callbacks for this client
params := xxdk.GetDefaultE2EParams() params := xxdk.GetDefaultE2EParams()
jww.INFO.Printf("Using E2E parameters: %+v", params) jww.INFO.Printf("Using E2E parameters: %+v", params)
xxdkClient, err := xxdk.Login(baseClient, &auth{}, identity, params) confirmChan := make(chan contact.Contact)
xxdkClient, err := xxdk.Login(baseClient, &auth{confirmChan: confirmChan}, identity, params)
if err != nil { if err != nil {
jww.FATAL.Panicf("Unable to Login: %+v", err) jww.FATAL.Panicf("Unable to Login: %+v", err)
} }
...@@ -138,6 +145,10 @@ func main() { ...@@ -138,6 +145,10 @@ func main() {
// Connect with the recipient-------------------------------------------------- // Connect with the recipient--------------------------------------------------
if recipientContactPath != "" {
// Wait for 30 seconds to ensure network connectivity
time.Sleep(30 * time.Second)
// Recipient's contact (read from a Client CLI-generated contact file) // Recipient's contact (read from a Client CLI-generated contact file)
contactData, err := ioutil.ReadFile(recipientContactPath) contactData, err := ioutil.ReadFile(recipientContactPath)
if err != nil { if err != nil {
...@@ -160,14 +171,17 @@ func main() { ...@@ -160,14 +171,17 @@ func main() {
if err != nil { if err != nil {
jww.FATAL.Panicf("Failed to send contact request to %s: %+v", recipientContact.ID.String(), err) jww.FATAL.Panicf("Failed to send contact request to %s: %+v", recipientContact.ID.String(), err)
} }
timeout := time.NewTimer(30 * time.Second)
select {
case pc := <-confirmChan:
if !pc.ID.Cmp(recipientContact.ID) {
jww.FATAL.Panicf("Did not receive confirmation for the requested contact")
}
break
case <-timeout.C:
jww.FATAL.Panicf("Timed out waiting to receive confirmation of e2e relationship with partner")
}
} }
// Register a listener for messages--------------------------------------------------
// Listen for all types of messages using catalog.NoType
// Listen for messages from all users using id.ZeroUser
// User-defined behavior for message reception goes in the listener
_ = e2eClient.RegisterListener(&id.ZeroUser, catalog.NoType, listener{name: "e2e Message Listener"})
// Send a message to the recipient---------------------------------------------------- // Send a message to the recipient----------------------------------------------------
...@@ -178,6 +192,14 @@ func main() { ...@@ -178,6 +192,14 @@ func main() {
jww.FATAL.Panicf("Failed to send message: %+v", err) jww.FATAL.Panicf("Failed to send message: %+v", err)
} }
jww.INFO.Printf("Message %v sent in RoundIDs: %+v at %v", messageID, roundIDs, timeSent) jww.INFO.Printf("Message %v sent in RoundIDs: %+v at %v", messageID, roundIDs, timeSent)
}
// Register a listener for messages--------------------------------------------------
// Listen for all types of messages using catalog.NoType
// Listen for messages from all users using id.ZeroUser
// User-defined behavior for message reception goes in the listener
_ = e2eClient.RegisterListener(&id.ZeroUser, catalog.NoType, listener{name: "e2e Message Listener"})
// Keep app running to receive messages----------------------------------------------- // Keep app running to receive messages-----------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment