Skip to content
Snippets Groups Projects
Commit fad440d1 authored by Josh Brooks's avatar Josh Brooks
Browse files

Add README's for restlike connection client & server

parent d3bb271a
No related branches found
No related tags found
1 merge request!6Rest connect
...@@ -6,7 +6,7 @@ help consumers better understand our API and how it may be used. ...@@ -6,7 +6,7 @@ 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 `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. avoiding the usage of CLI flags for basic variables you may change in the code.
This file initiates an xxdk E2E client. With that established, a connection This file initiates an xxdk E2E object. With that established, a connection
client is built on top. Using a precanned contact object created in client is built on top. Using a precanned contact object created in
`connectServer` this connection client contacts the server with a simple `connectServer` this connection client contacts the server with a simple
message. message.
......
...@@ -6,7 +6,7 @@ to help consumers better understand our API and how it may be used. ...@@ -6,7 +6,7 @@ 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 `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. avoiding the usage of CLI flags for basic variables you may change in the code.
This file initiates an xxdk E2E client. With that client established, a This file initiates an xxdk E2E object. With that client established, a
connection server is built on top. This program creates contact file connection server is built on top. This program creates contact file
`connectServer.xxc` which may be used by a client to contact the server. `connectServer.xxc` which may be used by a client to contact the server.
......
# xxdk Restlike Connect Client Example
This mini-repository contains the example logic for running a basic REST-like
connection 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 object. With that client established, a
REST-like client is built on top. Using a precanned contact object created
in `restConnectServer` this REST-like client contacts the server with a simple
request.
`utils.go` contains utility functions for running the program. In this case,
we provide a tool initializing a log.
## Build Instructions
In these instructions we will go over building a REST-like client using our
example. In order to build a client which successfully sends a request and
receives a response, we must first go over how to build and run a REST-like
connect server.
### Building a Server
In order to run a server, the following commands may be run:
```bash
cd restConnectServer/
go build -o server .
./server
```
This will initialize the server. You may verify its functionality by checking
the `server.log` file. It is a long-running process which may be
stopped by a user inputted kill signal. This will create a file
`restConnectServer.xxc`, which is the contact file for the server.
A REST-like client may parse this file in order to send a request to this
server.
### Building a Client
Please follow the steps above before continuing to these instructions.
In order to run the client, you must first move the aforementioned
`restConnectServer.xxc` file to the path where you will run the client.
```bash
cd restConnectServer/
cp restConnectServer.xxc /path/to/restConnectClient
```
Once the contact object is local to the client, you may build and run
the client:
```bash
cd restConnectClient/
go build -o client .
./client
```
This is a long-running process which may be stopped by a user inputted kill
signal. We recommend allowing the process to run for a long enough time to
complete its requests to the server and receive the server's responses. We go
into detail on what this entails below.
Once the REST-like client has set up and sent its request, you can verify
by checking the server's log for the string `Request received:`
```bash
grep "Request received: " restConnectServer/server.log
INFO 2022/07/12 14:51:56.184948 Request received: headers:{headers:"This is a header"} method:1 uri:"handleClient"
INFO 2022/07/12 14:52:05.677718 Request received: headers:{headers:"This is a header"} method:1 uri:"handleClient"
```
By default, the client sends two requests, synchronous and asynchronous. Both
requests should be received by the server in order to accomplish a successful
client-server request.
In order to verify the response, look at the client log for the string
`Response: `:
```bash
grep "Response: " restConnectClient/client.log
INFO 2022/07/12 14:52:00.881453 Response: content:"This is content" headers:{headers:"this is a response"}
INFO 2022/07/12 14:52:09.540666 Response: content:"This is content" headers:{headers:"this is a response"}
```
As by default, there are two requests received by the server, the client will
receive two responses.
# xxdk Restlike Connect Server Example
This mini-respository contains the example logic for running a basic REST-like
connect server. 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 object. With that client established, a
REST-like server is built on top. This program creates contact file
`restConnectServer.xxc` which may be used by a client to contact the server.
`utils.go` contains utility functions for running the program. In this case,
we provide a tool initializing a log. It also contains a utility to write the
contact file to disk.
`endpoints.go` contains a simple example of request handling by the server.
This prints out the request and builds a response to return the to requester.
This endpoint may be modified for more complex request handling, or more
endpoints with various request handling may be put here.
## Build Instructions
In these instructions we will go over building a REST-like server using our
example. This will not include instructions on running a client which sends
requests. That documentation may be found in the `README.md` for
`restConnectClient`.
In order to run a server, the following commands may be run:
```bash
cd restConnectServer/
go build -o server .
./server
```
This will initialize the server. You may verify its functionality by checking
the `server.log` file. It is a long-running process which may be stopped by a
user inputted kill signal. This will create a file `restConnectServer.xxc`,
which is the contact file for the server. A REST-like client may parse this
file in order to send a request to this server.
...@@ -3,9 +3,10 @@ module restConnectServer ...@@ -3,9 +3,10 @@ module restConnectServer
go 1.18 go 1.18
require ( require (
github.com/pkg/errors v0.9.1
github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/jwalterweatherman v1.1.0
gitlab.com/elixxir/client v1.5.1-0.20220707223957-5b095fc07bc2 gitlab.com/elixxir/client v1.5.1-0.20220712214129-83531d271630
gitlab.com/elixxir/crypto v0.0.7-0.20220606201132-c370d5039cea gitlab.com/elixxir/crypto v0.0.7-0.20220629210331-d568778d08c6
gitlab.com/xx_network/primitives v0.0.4-0.20220630163313-7890038258c6 gitlab.com/xx_network/primitives v0.0.4-0.20220630163313-7890038258c6
) )
...@@ -17,7 +18,6 @@ require ( ...@@ -17,7 +18,6 @@ require (
github.com/golang/protobuf v1.5.2 // indirect github.com/golang/protobuf v1.5.2 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 // indirect github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 // indirect
github.com/ttacon/libphonenumber v1.2.1 // indirect github.com/ttacon/libphonenumber v1.2.1 // indirect
......
...@@ -101,14 +101,14 @@ github.com/zeebo/pcg v0.0.0-20181207190024-3cdc6b625a05/go.mod h1:Gr+78ptB0MwXxm ...@@ -101,14 +101,14 @@ github.com/zeebo/pcg v0.0.0-20181207190024-3cdc6b625a05/go.mod h1:Gr+78ptB0MwXxm
github.com/zeebo/pcg v1.0.0/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4= github.com/zeebo/pcg v1.0.0/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f h1:yXGvNBqzZwAhDYlSnxPRbgor6JWoOt1Z7s3z1O9JR40= gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f h1:yXGvNBqzZwAhDYlSnxPRbgor6JWoOt1Z7s3z1O9JR40=
gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k= gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k=
gitlab.com/elixxir/client v1.5.1-0.20220707223957-5b095fc07bc2 h1:x3+i6e9muINV6mCrQwR2y1jh/XAEJES+WeNFzQIy5y4= gitlab.com/elixxir/client v1.5.1-0.20220712214129-83531d271630 h1:6lOS1ZC/WseqCXu74zbeblviDiaox/rKTE2wh4HwgH0=
gitlab.com/elixxir/client v1.5.1-0.20220707223957-5b095fc07bc2/go.mod h1:GCevkp2aa+vpIsSrlF/HsRlTjf107jgCglZ/0JKqW7E= gitlab.com/elixxir/client v1.5.1-0.20220712214129-83531d271630/go.mod h1:Za6N94xHIFFbtiKqHUe8VVVwV6M2NarUYhbRVrtrzAc=
gitlab.com/elixxir/comms v0.0.4-0.20220603231314-e47e4af13326 h1:Zid8oNHtbOqF6ebrcGIccvIMabFNGh9dzY1b7mgIcF0= gitlab.com/elixxir/comms v0.0.4-0.20220603231314-e47e4af13326 h1:Zid8oNHtbOqF6ebrcGIccvIMabFNGh9dzY1b7mgIcF0=
gitlab.com/elixxir/comms v0.0.4-0.20220603231314-e47e4af13326/go.mod h1:tlHSrtSliKWUxsck8z/Ql/VJkMdSONV2BeWaUAAXzgk= gitlab.com/elixxir/comms v0.0.4-0.20220603231314-e47e4af13326/go.mod h1:tlHSrtSliKWUxsck8z/Ql/VJkMdSONV2BeWaUAAXzgk=
gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c=
gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA= gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA=
gitlab.com/elixxir/crypto v0.0.7-0.20220606201132-c370d5039cea h1:+FjwbKl6X9TDT7qd7gG5N5PSbziPWP3NgjK5ci1b7/8= gitlab.com/elixxir/crypto v0.0.7-0.20220629210331-d568778d08c6 h1:au5l76f3UkqW3RFutaViKuqkNkPPvWjzVZaR7A2eUi0=
gitlab.com/elixxir/crypto v0.0.7-0.20220606201132-c370d5039cea/go.mod h1:Oy+VWQ2Sa0Ybata3oTV+Yc46hkaDwAsuIMW0wJ01z2M= gitlab.com/elixxir/crypto v0.0.7-0.20220629210331-d568778d08c6/go.mod h1:Oy+VWQ2Sa0Ybata3oTV+Yc46hkaDwAsuIMW0wJ01z2M=
gitlab.com/elixxir/ekv v0.1.7 h1:OW2z+N4QCqqMFzouAwFTWWMKz0Y/PDhyYReN7gQ5NiQ= gitlab.com/elixxir/ekv v0.1.7 h1:OW2z+N4QCqqMFzouAwFTWWMKz0Y/PDhyYReN7gQ5NiQ=
gitlab.com/elixxir/ekv v0.1.7/go.mod h1:e6WPUt97taFZe5PFLPb1Dupk7tqmDCTQu1kkstqJvw4= gitlab.com/elixxir/ekv v0.1.7/go.mod h1:e6WPUt97taFZe5PFLPb1Dupk7tqmDCTQu1kkstqJvw4=
gitlab.com/elixxir/primitives v0.0.0-20200731184040-494269b53b4d/go.mod h1:OQgUZq7SjnE0b+8+iIAT2eqQF+2IFHn73tOo+aV11mg= gitlab.com/elixxir/primitives v0.0.0-20200731184040-494269b53b4d/go.mod h1:OQgUZq7SjnE0b+8+iIAT2eqQF+2IFHn73tOo+aV11mg=
......
...@@ -101,23 +101,13 @@ func main() { ...@@ -101,23 +101,13 @@ func main() {
} }
} }
// Create an E2E client
// The 'restlike' package handles AuthCallbacks,
// xxdk.DefaultAuthCallbacks is fine here
jww.INFO.Printf("Using E2E parameters: %+v", e2eParams)
messenger, err := xxdk.Login(net, xxdk.DefaultAuthCallbacks{},
identity, e2eParams)
if err != nil {
jww.FATAL.Panicf("Unable to Login: %+v", err)
}
// Save contact file------------------------------------------------------- // Save contact file-------------------------------------------------------
// Save the contact file so that client can connect to this server // Save the contact file so that client can connect to this server
writeContact(contactFilePath, identity.GetContact()) writeContact(contactFilePath, identity.GetContact())
// Start rest-like connect server------------------------------------------ // Start rest-like connect server------------------------------------------
restlikeServer, err := restConnect.NewServer(identity, messenger.Cmix, restlikeServer, err := restConnect.NewServer(identity, net,
e2eParams, connParams) e2eParams, connParams)
if err != nil { if err != nil {
jww.FATAL.Panicf("Unable to start restlike connect server: %+v", err) jww.FATAL.Panicf("Unable to start restlike connect server: %+v", err)
...@@ -137,7 +127,8 @@ func main() { ...@@ -137,7 +127,8 @@ func main() {
// Set networkFollowerTimeout to a value of your choice (seconds) // Set networkFollowerTimeout to a value of your choice (seconds)
networkFollowerTimeout := 5 * time.Second networkFollowerTimeout := 5 * time.Second
err = messenger.StartNetworkFollower(networkFollowerTimeout) err = restlikeServer.ConnectServer.E2e.
StartNetworkFollower(networkFollowerTimeout)
if err != nil { if err != nil {
jww.FATAL.Panicf("Failed to start network follower: %+v", err) jww.FATAL.Panicf("Failed to start network follower: %+v", err)
} }
...@@ -163,7 +154,8 @@ func main() { ...@@ -163,7 +154,8 @@ func main() {
connected := make(chan bool, 10) connected := make(chan bool, 10)
// Provide a callback that will be signalled when network // Provide a callback that will be signalled when network
// health status changes // health status changes
messenger.GetCmix().AddHealthCallback( restlikeServer.ConnectServer.E2e.
GetCmix().AddHealthCallback(
func(isConnected bool) { func(isConnected bool) {
connected <- isConnected connected <- isConnected
}) })
...@@ -178,7 +170,8 @@ func main() { ...@@ -178,7 +170,8 @@ func main() {
jww.DEBUG.Printf("Waiting for SIGTERM signal to close process") jww.DEBUG.Printf("Waiting for SIGTERM signal to close process")
<-c <-c
err = messenger.StopNetworkFollower() err = restlikeServer.ConnectServer.E2e.
StopNetworkFollower()
if err != nil { if err != nil {
jww.ERROR.Printf("Failed to stop network follower: %+v", err) jww.ERROR.Printf("Failed to stop network follower: %+v", err)
} else { } else {
......
...@@ -6,7 +6,7 @@ help consumers better understand our API and how it may be used. ...@@ -6,7 +6,7 @@ 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 `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. avoiding the usage of CLI flags for basic variables you may change in the code.
This file initiates an xxdk E2E client. With that client established, a This file initiates an xxdk E2E object. With that client established, a
REST-like client is built on top. Using a precanned contact object created REST-like client is built on top. Using a precanned contact object created
in `restSingleUseServer` this REST-like client contacts the server with a simple in `restSingleUseServer` this REST-like client contacts the server with a simple
request. request.
......
...@@ -6,7 +6,7 @@ to help consumers better understand our API and how it may be used. ...@@ -6,7 +6,7 @@ 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 `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. avoiding the usage of CLI flags for basic variables you may change in the code.
This file initiates an xxdk E2E client. With that client established, a This file initiates an xxdk E2E object. With that client established, a
REST-like server is built on top. This program creates contact file REST-like server is built on top. This program creates contact file
`restSingleUseServer.xxc` which may be used by a client to contact the server. `restSingleUseServer.xxc` which may be used by a client to contact the server.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment