@@ -358,7 +358,7 @@ not := msg.FailedNotification(&lime.Reason{Code: 1, Description: "Destination no
358358
359359### Command
360360
361- The command envelope is used to ** manipulate resources of a server ** .
361+ The command envelope is used to ** manipulate resources of a remote node ** .
362362It provides a REST capable interface, with a URI and methods (verbs), much like the HTTP protocol.
363363It also supports multiplexing, so the connection is not blocked when a request is sent.
364364
@@ -446,14 +446,96 @@ In case of `failure` response status, the command should have the `reason` prope
446446For creating a request command in Go, you can use the ` lime.RequestCommand ` type:
447447
448448``` go
449- cmd := &lime.RequestCommand {}
450- cmd .SetURIString (" /contacts" ).
449+ reqCmd := &lime.RequestCommand {}
450+ reqCmd .SetURIString (" /contacts" ).
451451 SetMethod (lime.CommandMethodGet ).
452452 SetID (lime.NewEnvelopeID ())
453453```
454454
455455Note that for the ` id ` value, we are using the value returned by the ` lime.NewEnvelopeID() ` function, which will return
456456a UUID v4 string (something like ` 3cdd2654-911d-497e-834a-3b7865510155 ` ).
457457
458- If you are building a server, you can add handlers for specific commands using the ` RequestCommandHandler* ` methods from
459- the ` lime.Client ` and ` lime.Server ` types.
458+ For sending a command request, you should use the ` ProcessCommand ` method from the ` lime.Client ` and ` lime.Server `
459+ types, instead of the ` SendCommand ` method. The ` ProcessCommand ` method take care of await for the correspondent
460+ response command.
461+
462+ ``` go
463+ respCmd , err := client.ProcessCommand (context.Background (), reqCmd)
464+ if err == nil {
465+ // TODO: Handle the response
466+ }
467+ ```
468+
469+ In the server side, you can add handlers for specific commands using the ` RequestCommandHandler* ` methods from
470+ the ` lime.Server ` type.
471+
472+ ``` go
473+ server := lime.NewServerBuilder ().
474+ RequestCommandHandlerFunc (
475+ // Set a predicate for filtering only the get contacts commands
476+ func (cmd *lime .RequestCommand ) bool {
477+ return cmd.Method == lime.CommandMethodGet && cmd.URI .Path () == " /contacts"
478+ },
479+ // The handler implementation
480+ func (ctx context .Context , cmd *lime .RequestCommand , s lime .Sender ) error {
481+ // Create a document collection of contacts
482+ contacts := &lime.DocumentCollection {
483+ Total: 2 ,
484+ ItemType: chat.MediaTypeContact (),
485+ Items: []lime.Document {
486+ &chat.Contact {Name: " John Doe" },
487+ &chat.Contact {Name: " Mary" },
488+ },
489+ }
490+ // Send the response to the sender
491+ respCmd := cmd.SuccessResponseWithResource (contacts)
492+ return s.SendResponseCommand (ctx, respCmd)
493+ }).
494+ // TODO: Setup other server options
495+ Build ()
496+ ```
497+
498+ This is also valid for the ` lime.Client ` type.
499+ In Lime, the ** client can receive and process commands requests** from other nodes, like the server.
500+
501+ ### Session
502+
503+ The session envelope is used for the negotiation, authentication and establishment of the communication channel between
504+ the client and a server.
505+ It helps select the transport options, like compression and encryption (TLS), authentication credentials, and session
506+ metadata, like its ` id ` and local/remote node addresses.
507+
508+ For instance, the first envelope sent in every like session is the ** new session** envelope, which the client sends to
509+ the server after the transport connection is established:
510+
511+ ``` json
512+ {
513+ "state" : " new"
514+ }
515+ ```
516+ The server should reply this with another session envelope, according to the session state that it wants to enforce.
517+
518+ For instance, the server may want to present the client the transport options for negotiation.
519+ This is useful for applying the TLS encryption to an unencrypted connection (the TCP connection starts without
520+ encryption by default).
521+
522+ ``` json
523+ {
524+ "id" : " 0676a702-a7d6-43e6-947f-bde3c3e25eb5" ,
525+ "from" : " server@localhost/s1" ,
526+ "state" : " negotiating" ,
527+ "compressionOptions" : [" none" ],
528+ "encryptionOptions" : [" none" , " tls" ]
529+ }
530+ ```
531+
532+ Note that this envelope haves a ` id ` defined, which is the ** session id** .
533+ The next session envelopes sent by the client should use this same id, until the end of the session.
534+
535+ The session state progression can occur in the following order:
536+ 1 . new (client started)
537+ 2 . negotiating (optional)
538+ 3 . authenticating (optional)
539+ 4 . established
540+ 5 . finishing (optional, client started)
541+ 6 . finished OR failed
0 commit comments