diff --git a/api/client.go b/api/client.go index 3c39f1194060b4d3b18c280d7cd21766715132a8..002542157ea6a8e49924aa0d44e4419566d1d450 100644 --- a/api/client.go +++ b/api/client.go @@ -86,11 +86,7 @@ func NewClient(ndfJSON, storageDir string, password []byte, _, err = CheckVersionAndSetupStorage(def, storageDir, password, protoUser, cmixGrp, e2eGrp, registrationCode) - if err != nil { - return err - } - - return nil + return err } // NewVanityClient creates a user with a receptionID that starts with @@ -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 diff --git a/api/identity.go b/api/identity.go index f14b8020dd69a884200fe0144f1900ece9a79cba..2ef5c5bb4cb5bfc468b368ab8d5f1ff4cf25b740 100644 --- a/api/identity.go +++ b/api/identity.go @@ -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, diff --git a/connect/connect.go b/connect/connect.go index 0747184292194f581e6e51bf8cd711dcc44c556b..0de11c560d74c6e085fe5fc3276cedb69a81490c 100644 --- a/connect/connect.go +++ b/connect/connect.go @@ -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) diff --git a/restlike/README.md b/restlike/README.md new file mode 100644 index 0000000000000000000000000000000000000000..5b8878cc85947150e23db5543cbcc8b7e0e8e742 --- /dev/null +++ b/restlike/README.md @@ -0,0 +1,126 @@ +# 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) +``` diff --git a/restlike/single/server.go b/restlike/single/server.go index b5bbbd4ee8dc14f58e4dddbfdc356c6b33582d5c..99c2bc08b6327d372ade95711a2a0c945ce33795 100644 --- a/restlike/single/server.go +++ b/restlike/single/server.go @@ -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 }