Code Monkey home page Code Monkey logo

enclave's Introduction

Enclave: C++ network library

Enclave is a small C++ network library which is based on Qt framework. This library has next advantages:

  • multithreading server
  • optional encryption mode
  • network streams with request/response model
  • simple and intuitive API

Requirements

Qt 5+ (core and network modules) and any modern C++ compiler with support C++11.

Introduction

Project structure:

Directory Description
benchmark/ Benchmark for testing library perfomance
enclave/ Library
example-chat/ Simple chat based on this library

Architecture

This library internally use QTcpServer for server and QSslSocket (in both encryption and unecryption modes) for server and client connections. Network sockets are lived in separate threads - one thread on client and one or more threads on server (threads count depends on server thread policy). Interaction with user code occurs via Qt signal/slot mechanism and special classes which make safe using of internal structures. For transfer and receive data library provides abstraction of network socket with convenient interface - network streams.

How to use

The main two classes are Enclave::Server and Enclave::Client. Aggregation is prefer but you can also use inheritance. For interaction with its classes you have to connect to following signals. Notice that even if you set ignored SSL errors the signal errorSignal will be emitted (with flag ignored = true).

Server
Signal Description
connectionEstablishedSignal Emit when client connection was established
connectionClosedSignal Emit when client connection was closed
dataReceivedSignal Emit when network client data was received
errorSignal Emit when error happened
Client
Signal Description
connectedSignal Emit when client was connected
disconnectedSignal Emit when client connection was closed
dataReceivedSignal Emit when network server data was received
errorSignal Emit when error happened

Before starting client or server you can set encryption options and set appropriate thread policy (for server only).

Essential classes

Working with this library is provided by next essential classes.

NetworkConnection

It's wrapper of server or client connection. You can safely use methods of this class even if connection has already disappeared. The main method for network interaction is createStream. It create new network stream for specified command which you can use for send network data. Overloaded function have callback as parameter which will be executed when request of another network node will be received:

  • node one create stream with callback
  • node one put data to stream and send request
  • node two receive data as stream and create response stream
  • node two put data to stream and send response
  • node one callback is executed
NetworkStream

This class give abstraction for sending and receiving network data.

Benchmark

With console benchmark you can comparsion performance of different server thread policies.

Chat example

This simple chat example illustrate usage of Enclave library. If you want to run it you should set working directory enclave/example-chat/workdir.

Commands for create necessary certificates of this example:

# private key for root CA certificate
openssl genrsa -out ca.key 4096

# self-signed root CA certificate
openssl req -new -x509 -days 730 -key ca.key -out ca.crt

# private key for server certificate
openssl genrsa -out server.key 4096

# request a server certificate
openssl req -new -key server.key -out server.csr

# server certificate by request
openssl x509 -req -days 730 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt

# private key for client certificate
openssl genrsa -out client.key 4096

# request a client certificate
openssl req -new -key client.key -out client.csr

# client certificate by request
openssl x509 -req -days 365 -in client.csr -CA ca.crt -CAkey ca.key -set_serial 02 -out client.crt

enclave's People

Contributors

cpp11nullptr avatar

Watchers

James Cloos avatar shuyuan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.