6.1.6. Communication protocol between background service and app
gRPC is a modern open source high performance RPC framework that can run in any environment. It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking and authentication. It is also applicable in last mile of distributed computing to connect devices, mobile applications and browsers to backend services.
This RPC system offers support for .NET core and is recommended by Microsoft for Windows Communication Foundation developers. The following link details this more: https://docs.microsoft.com/es-es/dotnet/architecture/grpc-for-wcf-developers/why-grpc
Reference: https://grpc.io/
6.1.6.1. Advantages of gRPC
Performance: gRPC uses HTTP/2. This new version uses smaller and faster binary protocol for the messages. It also supports multiplexing requests over a single connection. Thanks to this, we do not have the “head-of-line” issue anymore, the responses will be sent as soon as they are ready (without wait in queue).
Interoperability: There are tools and libraries for the languages .NET, Java, Python, Go, C++, Node.js, Swift, Dart, Ruby, PHP and more. Also, it is compatible with all platforms, making performant apps thanks to the Protocol Buffers binary wire format and the efficient code generation.
Usability and productivity: It provides excellent tooling, with much of the necessary boilerplate code automatically generated. So, more developer time is freed up to focus on business logic.
Streaming: gRPC has full bidirectional streaming and can operate over regular internet connections, load balancers, and service meshes.
Deadline and cancellation: gRPC clients can specify a maximum time for a remote procedure call to finish and if it is exceeded, the server can cancel its execution independently of the client. In addition, the client can also end operations if the time has been exceeded or even earlier, in the case of an interaction by the user.
Security: gRPC is implicitly secure when it iss using HTTP/2 over a TLS end-to-end encrypted connection. It also supports client certificate authentication.
Reference: https://docs.microsoft.com/es-es/dotnet/architecture/grpc-for-wcf-developers/why-grpc
6.1.6.2. Conclusion about the communication protocol
We can use gRPC to create TCP connections with the client and communicate various necessary information between the client and the daemon. The background service will receive the following information:
Connection to VPN
Disconnection to VPN
Manual ingest to get the device information
Get VPN state
Register the Agent
As we just discussed in this section, gRPC uses the buffer protocol language. We can use the latest version which is proto3.
6.1.6.3. Workflows
The agent program configures the functions that will be executed when gRPC reads a message from the client. Then, it starts a parallel thread to take care of this internally. In addition, it spawns another parallel thread for user device scanning tasks. Each time data has to be obtained, a thread is generated for each entity (an entity could be networks for example), and it will wait until it is finished. When it has finished obtaining data, or it was not necessary to do this task, the waiting time (Cron time in the appsettings.json configuration) is calculated for the next data collection. The thread will go into sleep mode for the configured time.
