diff --git a/connectClient/README.md b/connectClient/README.md index 1ed0a3fdd16550f696c03c0432596e76cab95b1d..b1e2fe9558f9fd2196306ab6ffd7fe672f54fa31 100644 --- a/connectClient/README.md +++ b/connectClient/README.md @@ -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 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 `connectServer` this connection client contacts the server with a simple message. diff --git a/connectServer/README.md b/connectServer/README.md index f7e8213b49275d37e4d349db01e3af137f1514d7..9cb3e446005aa0729519bf26a824a3f96f948ee5 100644 --- a/connectServer/README.md +++ b/connectServer/README.md @@ -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 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 `connectServer.xxc` which may be used by a client to contact the server. diff --git a/restConnectClient/README.md b/restConnectClient/README.md new file mode 100644 index 0000000000000000000000000000000000000000..5addbf4b3719a56b335d25e5330eb0b1189eeb0e --- /dev/null +++ b/restConnectClient/README.md @@ -0,0 +1,89 @@ +# 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. diff --git a/restConnectServer/README.md b/restConnectServer/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f2ad74053bca00b0a1beb37d103feae707c6d48f --- /dev/null +++ b/restConnectServer/README.md @@ -0,0 +1,41 @@ +# 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. diff --git a/restConnectServer/go.mod b/restConnectServer/go.mod index 5ade6a2f4a20da17ef4a600cc182d579e33ee899..ae8d752df66575f9d61364307f3b5d5289231954 100644 --- a/restConnectServer/go.mod +++ b/restConnectServer/go.mod @@ -3,9 +3,10 @@ module restConnectServer go 1.18 require ( + github.com/pkg/errors v0.9.1 github.com/spf13/jwalterweatherman v1.1.0 - gitlab.com/elixxir/client v1.5.1-0.20220707223957-5b095fc07bc2 - gitlab.com/elixxir/crypto v0.0.7-0.20220606201132-c370d5039cea + gitlab.com/elixxir/client v1.5.1-0.20220712214129-83531d271630 + gitlab.com/elixxir/crypto v0.0.7-0.20220629210331-d568778d08c6 gitlab.com/xx_network/primitives v0.0.4-0.20220630163313-7890038258c6 ) @@ -17,7 +18,6 @@ require ( github.com/golang/protobuf v1.5.2 // indirect github.com/mitchellh/go-homedir v1.1.0 // 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/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 // indirect github.com/ttacon/libphonenumber v1.2.1 // indirect diff --git a/restConnectServer/go.sum b/restConnectServer/go.sum index 13a24a21c3f7e1a88f36284ecada32aa7bde1e32..6654bc174d931e8cc8862a8872542126cd923c65 100644 --- a/restConnectServer/go.sum +++ b/restConnectServer/go.sum @@ -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= 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/client v1.5.1-0.20220707223957-5b095fc07bc2 h1:x3+i6e9muINV6mCrQwR2y1jh/XAEJES+WeNFzQIy5y4= -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 h1:6lOS1ZC/WseqCXu74zbeblviDiaox/rKTE2wh4HwgH0= +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/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.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.20220606201132-c370d5039cea/go.mod h1:Oy+VWQ2Sa0Ybata3oTV+Yc46hkaDwAsuIMW0wJ01z2M= +gitlab.com/elixxir/crypto v0.0.7-0.20220629210331-d568778d08c6 h1:au5l76f3UkqW3RFutaViKuqkNkPPvWjzVZaR7A2eUi0= +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/go.mod h1:e6WPUt97taFZe5PFLPb1Dupk7tqmDCTQu1kkstqJvw4= gitlab.com/elixxir/primitives v0.0.0-20200731184040-494269b53b4d/go.mod h1:OQgUZq7SjnE0b+8+iIAT2eqQF+2IFHn73tOo+aV11mg= diff --git a/restConnectServer/main.go b/restConnectServer/main.go index 893c1af1f6d04f744f3699dfa2bad619c6581fbb..48beb539f1634ac77a56977a37248b37c9991298 100644 --- a/restConnectServer/main.go +++ b/restConnectServer/main.go @@ -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 the contact file so that client can connect to this server writeContact(contactFilePath, identity.GetContact()) // Start rest-like connect server------------------------------------------ - restlikeServer, err := restConnect.NewServer(identity, messenger.Cmix, + restlikeServer, err := restConnect.NewServer(identity, net, e2eParams, connParams) if err != nil { jww.FATAL.Panicf("Unable to start restlike connect server: %+v", err) @@ -137,7 +127,8 @@ func main() { // Set networkFollowerTimeout to a value of your choice (seconds) networkFollowerTimeout := 5 * time.Second - err = messenger.StartNetworkFollower(networkFollowerTimeout) + err = restlikeServer.ConnectServer.E2e. + StartNetworkFollower(networkFollowerTimeout) if err != nil { jww.FATAL.Panicf("Failed to start network follower: %+v", err) } @@ -163,7 +154,8 @@ func main() { connected := make(chan bool, 10) // Provide a callback that will be signalled when network // health status changes - messenger.GetCmix().AddHealthCallback( + restlikeServer.ConnectServer.E2e. + GetCmix().AddHealthCallback( func(isConnected bool) { connected <- isConnected }) @@ -178,7 +170,8 @@ func main() { jww.DEBUG.Printf("Waiting for SIGTERM signal to close process") <-c - err = messenger.StopNetworkFollower() + err = restlikeServer.ConnectServer.E2e. + StopNetworkFollower() if err != nil { jww.ERROR.Printf("Failed to stop network follower: %+v", err) } else { diff --git a/restSingleUseClient/README.md b/restSingleUseClient/README.md index 2ce63caf457aa63471b7b08cebf8514bfb547c94..63bde890e7787caf2ec2323c4200f1da52436667 100644 --- a/restSingleUseClient/README.md +++ b/restSingleUseClient/README.md @@ -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 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 in `restSingleUseServer` this REST-like client contacts the server with a simple request. @@ -80,7 +80,7 @@ In order to verify the response, look at the client log for the string `Response: `: ```bash - grep "Response: " restSingleUseClient/client.log +grep "Response: " restSingleUseClient/client.log INFO 2022/07/07 11:43:42.923030 Response: content:"This is content" headers:{headers:"this is a response"} INFO 2022/07/07 11:43:50.376968 Response: content:"This is content" headers:{headers:"this is a response"} ``` diff --git a/restSingleUseServer/README.md b/restSingleUseServer/README.md index 2a48e21e9810abc453d1e4417afab5465b02ee0d..c0389ad0087450a13565930bcfb9d3b894bd21cc 100644 --- a/restSingleUseServer/README.md +++ b/restSingleUseServer/README.md @@ -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 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 `restSingleUseServer.xxc` which may be used by a client to contact the server.