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
a66425cb
Commit
a66425cb
authored
2 years ago
by
Jonah Husson
Browse files
Options
Downloads
Patches
Plain Diff
Fixes from latest comments
parent
68478757
No related branches found
Branches containing commit
No related tags found
1 merge request
!4
Add example E2e client
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
e2eClient/README.md
+26
-0
26 additions, 0 deletions
e2eClient/README.md
e2eClient/main.go
+9
-12
9 additions, 12 deletions
e2eClient/main.go
e2eClient/utils.go
+12
-0
12 additions, 0 deletions
e2eClient/utils.go
with
47 additions
and
12 deletions
e2eClient/README.md
+
26
−
0
View file @
a66425cb
# xxdk E2E client example
# xxdk E2E client example
This mini-repository contains example logic for running an e2e client.
This is provided by the xx network team as a springboard to help consumers
better understand our API and how it may be used.
`main.go`
contains the crux of the logic. We avoid complicating our example by
avoiding the usage of CLI flags for basic variables you may change in the code.
This file initiates an xxdk E2E client, using the authentication callbacks in
`auth.go`
. With that established, it registers a generic message listener
and establishes authentication with a partner. Finally, it sends a test message
and listens for incoming messages until stopped by the user.
`utils.go`
contains utility functions for running the program. In this case,
we provide a tool initializing a log and one which writes a contact to a file.
`listener.go`
contains logic for handling the reception of a message via the
e2e client. In this example, it is very basic. We invite consumers
to use this as a basis to implement more complex message listeners.
## Build Instructions
In these instructions we will go over building a connection client using our
example. In order to build a client which successfully sends a message through
the connection, we must first go over how to build and run a connection server.
### Building a Client
This diff is collapsed.
Click to expand it.
e2eClient/main.go
+
9
−
12
View file @
a66425cb
...
@@ -91,16 +91,13 @@ func main() {
...
@@ -91,16 +91,13 @@ func main() {
}
}
}
}
err
=
ioutil
.
WriteFile
(
myContactPath
,
identity
.
GetContact
()
.
Marshal
(),
fs
.
ModePerm
)
writeContact
(
myContactPath
,
identity
.
GetContact
())
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
)
confirmChan
:=
make
(
chan
contact
.
Contact
)
confirmChan
:=
make
(
chan
contact
.
Contact
,
5
)
xxdkClient
,
err
:=
xxdk
.
Login
(
baseClient
,
&
auth
{
confirmChan
:
confirmChan
},
identity
,
params
)
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
)
...
@@ -143,6 +140,13 @@ func main() {
...
@@ -143,6 +140,13 @@ func main() {
// Wait until connected or crash on timeout
// Wait until connected or crash on timeout
waitUntilConnected
(
connected
)
waitUntilConnected
(
connected
)
// 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"
})
// Connect with the recipient--------------------------------------------------
// Connect with the recipient--------------------------------------------------
if
recipientContactPath
!=
""
{
if
recipientContactPath
!=
""
{
...
@@ -194,13 +198,6 @@ func main() {
...
@@ -194,13 +198,6 @@ func main() {
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-----------------------------------------------
// Wait until the user terminates the program
// Wait until the user terminates the program
...
...
This diff is collapsed.
Click to expand it.
e2eClient/utils.go
+
12
−
0
View file @
a66425cb
...
@@ -2,6 +2,8 @@ package main
...
@@ -2,6 +2,8 @@ package main
import
(
import
(
jww
"github.com/spf13/jwalterweatherman"
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/crypto/contact"
"gitlab.com/xx_network/primitives/utils"
"io/ioutil"
"io/ioutil"
"log"
"log"
"os"
"os"
...
@@ -36,3 +38,13 @@ func initLog(threshold uint, logPath string) {
...
@@ -36,3 +38,13 @@ func initLog(threshold uint, logPath string) {
jww
.
SetLogThreshold
(
jww
.
LevelInfo
)
jww
.
SetLogThreshold
(
jww
.
LevelInfo
)
}
}
}
}
func
writeContact
(
outfilePath
string
,
c
contact
.
Contact
)
{
err
:=
utils
.
WriteFileDef
(
outfilePath
,
c
.
Marshal
())
if
err
!=
nil
{
jww
.
ERROR
.
Printf
(
"could not write contact file: %+v"
,
err
)
}
else
{
jww
.
INFO
.
Printf
(
"contact written to %s successfully"
,
outfilePath
)
}
}
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