Skip to content
Snippets Groups Projects
Commit 27bb5ddb authored by Jake Taylor's avatar Jake Taylor
Browse files

Added restlike/README.md

parent 2dc8d6ce
No related branches found
No related tags found
1 merge request!510Release
......@@ -86,13 +86,9 @@ func NewClient(ndfJSON, storageDir string, password []byte,
_, err = CheckVersionAndSetupStorage(def, storageDir, password,
protoUser, cmixGrp, e2eGrp, registrationCode)
if err != nil {
return err
}
return nil
}
// NewVanityClient creates a user with a receptionID that starts with
// the supplied prefix It creates client storage, generates keys,
// connects, and registers with the network. Note that this does not
......@@ -442,8 +438,8 @@ func (c *Client) registerFollower() error {
// ----- Client Functions -----
// GetErrorsChannel returns a channel which passess errors from the
// long running threads controlled by StartNetworkFollower and
// GetErrorsChannel returns a channel which passes errors from the
// long-running threads controlled by StartNetworkFollower and
// StopNetworkFollower
func (c *Client) GetErrorsChannel() <-chan interfaces.ClientError {
return c.clientErrorChannel
......
......@@ -35,7 +35,7 @@ func MakeIdentity(rng csprng.Source, grp *cyclic.Group) (Identity, error) {
grp, rng)
//make the ID
id, err := xx.NewID(rsaKey.GetPublic(),
newId, err := xx.NewID(rsaKey.GetPublic(),
salt, id.User)
if err != nil {
return Identity{}, err
......@@ -43,7 +43,7 @@ func MakeIdentity(rng csprng.Source, grp *cyclic.Group) (Identity, error) {
//create the identity object
I := Identity{
ID: id,
ID: newId,
RSAPrivatePem: rsaKey,
Salt: salt,
DHKeyPrivate: privkey,
......
......@@ -121,7 +121,6 @@ func GetParameters(params string) (Params, error) {
func Connect(recipient contact.Contact, myId *id.ID, privKey *cyclic.Int,
rng *fastRNG.StreamGenerator, grp *cyclic.Group, net cmix.Client,
p Params) (Connection, error) {
//add the identity
net.AddIdentity(myId, time.Time{}, false)
......
# Initialization
These steps must first be performed in order to begin creating server objects of any variety.
### Make an api.Client Object
The api.Client object created here will be used for all types of api.Identity and server initialization.
1. Obtain the NDF
```go
ndfJson, err := DownloadAndVerifySignedNdfWithUrl(url, cert)
```
2. If not done in previous runs, create a new api.Client object in storage using ndfJson.
`storageDir` and `password` may be customized.
Example:
```go
err := NewClient(ndfJson, "/clientStorage", []byte("testPassword"), "")
```
3. Login in order to obtain the api.Client object.
`storageDir` and `password` may be customized, but must match the values provided to `NewClient()`.
The result of `api.GetDefaultParams()` may also be freely modified according to your needs.
Example:
```go
client, err := Login("/clientStorage", []byte("testPassword"), api.GetDefaultParams())
```
4. Start the network follower. Timeout may be modified as needed.
Example:
```go
err := client.StartNetworkFollower(10*time.Second)
```
### Make an api.Identity Object
The api.Identity object created here will be used for all types of server initialization.
It requires an api.Client object.
Example:
```go
identity, err := MakeIdentity(client.GetRng(), client.GetStorage().GetE2EGroup())
```
# Creating Servers
### Creating Connect-backed Servers
`receptionId`: the client ID that will be used for all incoming requests.
Derived from api.Identity object
`privKey`: the private key belonging to the receptionId.
Derived from api.Identity object
`rng`: from api.Client object
`grp`: from api.Client storage object
`net`: from api.Client object
`p`: customizable parameters for the server
Obtained and mutable via `connect.GetDefaultParams()`
Example:
```go
server, err := connect.NewServer(myIdentity.ID, myIdentity.DHKeyPrivate, client.GetRng(),
client.GetStorage().GetE2EGroup(), client.GetCmix(), connect.GetDefaultParams())
```
### Creating Single-backed Servers
`receptionId`: the client ID that will be used for all incoming requests.
Derived from api.Identity object
`privKey`: the private key belonging to the receptionId.
Derived from api.Identity object
`grp`: from api.Client storage object
`net`: from api.Client object
Example:
```go
server, err := single.NewServer(myIdentity.ID, myIdentity.DHKeyPrivate,
client.GetStorage().GetE2EGroup(), client.GetCmix())
```
# Adding Server Endpoints.
Once you have a `server` object, you can begin adding Endpoints to process incoming client requests.
See documentation in restlike/types.go for more information.
Example:
```go
// Build a callback for the new endpoint
// The callback processes a restlike.Message and returns a restlike.Message response
cb := func(msg *Message) *Message {
// Read the incoming restlike.Message and print its contents
// NOTE: You may encode the msg.Contents in any way you like, as long as it matches on both sides.
// In this case, we're expecting a simple byte encoding.
fmt.Printf("Incoming message: %s", string(msg.Content))
// Return a friendly response to the incoming message
// NOTE: For responses, Content, Headers, and Error are the only meaningful fields
return &restlike.Message{
Content: []byte("Hello! Nice to meet you."),
Headers: &restlike.Headers{
Headers: nil,
Version: 0,
},
Error: nil,
}
}
// Add an endpoint that accepts 'restlike.Get' requests at the 'results' endpoint
server.GetEndpoints().Add("results", restlike.Get, cb)
```
......@@ -23,13 +23,13 @@ type Server struct {
// NewServer builds a RestServer with single-use and
// the provided arguments, then registers necessary external services
func NewServer(receptionId *id.ID, privKey *cyclic.Int, net single.ListenCmix, e2eGrp *cyclic.Group) *Server {
func NewServer(receptionId *id.ID, privKey *cyclic.Int, grp *cyclic.Group, net single.ListenCmix) *Server {
newServer := &Server{
receptionId: receptionId,
endpoints: restlike.NewEndpoints(),
}
newServer.listener = single.Listen(catalog.RestLike, receptionId, privKey,
net, e2eGrp, &receiver{newServer.endpoints})
net, grp, &receiver{newServer.endpoints})
return newServer
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment