Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xxdk Examples
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
elixxir
xxdk Examples
Commits
27063854
Commit
27063854
authored
2 years ago
by
Jonah Husson
Browse files
Options
Downloads
Patches
Plain Diff
Fixes from MR
parent
876d0c4f
No related branches found
No related tags found
1 merge request
!4
Add example E2e client
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
e2eClient/auth.go
+6
-1
6 additions, 1 deletion
e2eClient/auth.go
e2eClient/go.mod
+2
-2
2 additions, 2 deletions
e2eClient/go.mod
e2eClient/main.go
+54
-32
54 additions, 32 deletions
e2eClient/main.go
with
62 additions
and
35 deletions
e2eClient/auth.go
+
6
−
1
View file @
27063854
...
@@ -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
,
...
...
This diff is collapsed.
Click to expand it.
e2eClient/go.mod
+
2
−
2
View file @
27063854
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
e2eClient/main.go
+
54
−
32
View file @
27063854
...
@@ -20,15 +20,16 @@ import (
...
@@ -20,15 +20,16 @@ import (
func
main
()
{
func
main
()
{
// Logging
// Logging
initLog
(
1
,
"client.log"
)
initLog
(
1
,
"client
2
.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
:=
"statePath
Recipient
"
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-----------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment