Start of channel_bitrates, start combining server and client common code.
This commit is contained in:
58
crypto.h
58
crypto.h
@@ -6,10 +6,8 @@
|
||||
|
||||
#include "tlv.h"
|
||||
|
||||
class CryptoBase {
|
||||
class CryptoUtil {
|
||||
public:
|
||||
virtual ~CryptoBase() {};
|
||||
|
||||
static std::string BinToHex(const std::string& bin);
|
||||
|
||||
static void GenKey(std::string* key);
|
||||
@@ -19,12 +17,30 @@ class CryptoBase {
|
||||
static void WriteKeyToFile(const std::string& filename, const std::string& key);
|
||||
|
||||
static void EncodeEncryptAppend(const std::string& secret_key, const std::string& public_key, const TLVNode& input, TLVNode* container);
|
||||
TLVNode *DecryptDecode(const std::string& secret_key, const std::string& public_key, const TLVNode& input);
|
||||
static TLVNode *DecryptDecode(const std::string& secret_key, const std::string& public_key, const TLVNode& input);
|
||||
};
|
||||
|
||||
class CryptoBase {
|
||||
public:
|
||||
std::ostream& Log(void *obj=nullptr);
|
||||
std::ostream& LogFatal(void *obj=nullptr);
|
||||
};
|
||||
|
||||
class CryptoConnBase : public CryptoBase {
|
||||
protected:
|
||||
CryptoConnBase(const std::string& secret_key);
|
||||
|
||||
enum {
|
||||
AWAITING_HANDSHAKE,
|
||||
READY,
|
||||
} state_;
|
||||
|
||||
const std::string secret_key_;
|
||||
std::string peer_public_key_;
|
||||
std::string ephemeral_secret_key_;
|
||||
std::string peer_ephemeral_public_key_;
|
||||
};
|
||||
|
||||
class CryptoPubServerConnection;
|
||||
|
||||
class CryptoPubServer : public CryptoBase {
|
||||
@@ -43,7 +59,7 @@ class CryptoPubServer : public CryptoBase {
|
||||
const std::string secret_key_;
|
||||
};
|
||||
|
||||
class CryptoPubServerConnection : public CryptoBase {
|
||||
class CryptoPubServerConnection : public CryptoConnBase {
|
||||
public:
|
||||
CryptoPubServerConnection(struct bufferevent* bev, const std::string& secret_key);
|
||||
~CryptoPubServerConnection();
|
||||
@@ -55,27 +71,19 @@ class CryptoPubServerConnection : public CryptoBase {
|
||||
static void OnError_(struct bufferevent* bev, const short what, void* this__);
|
||||
void OnError(const short what);
|
||||
|
||||
void SendHandshake();
|
||||
|
||||
struct bufferevent* bev_;
|
||||
|
||||
const std::string secret_key_;
|
||||
std::string ephemeral_secret_key_;
|
||||
std::string client_public_key_;
|
||||
std::string client_ephemeral_public_key_;
|
||||
|
||||
enum {
|
||||
AWAITING_HANDSHAKE,
|
||||
READY,
|
||||
} state_;
|
||||
|
||||
friend CryptoPubServer;
|
||||
};
|
||||
|
||||
class CryptoPubClient : public CryptoBase {
|
||||
class CryptoPubClient : public CryptoConnBase {
|
||||
public:
|
||||
CryptoPubClient(struct sockaddr* addr, socklen_t addrlen, const std::string& secret_key, const std::string& server_public_key);
|
||||
CryptoPubClient(struct sockaddr* addr, socklen_t addrlen, const std::string& secret_key, const std::string& server_public_key, const std::list<uint64_t>& channel_bitrates);
|
||||
~CryptoPubClient();
|
||||
|
||||
static CryptoPubClient* FromHostname(const std::string& server_address, const std::string& server_port, const std::string& secret_key, const std::string& server_public_key);
|
||||
static CryptoPubClient* FromHostname(const std::string& server_address, const std::string& server_port, const std::string& secret_key, const std::string& server_public_key, const std::list<uint64_t>& channel_bitrates);
|
||||
|
||||
void Loop();
|
||||
|
||||
@@ -87,17 +95,11 @@ class CryptoPubClient : public CryptoBase {
|
||||
void OnConnect();
|
||||
void OnError();
|
||||
|
||||
void SendHandshake();
|
||||
void SendTunnelRequest();
|
||||
|
||||
struct event_base* event_base_;
|
||||
struct bufferevent* bev_;
|
||||
|
||||
const std::string secret_key_;
|
||||
const std::string server_public_key_;
|
||||
std::string public_key_;
|
||||
std::string ephemeral_secret_key_;
|
||||
std::string server_ephemeral_public_key_;
|
||||
|
||||
enum {
|
||||
AWAITING_HANDSHAKE,
|
||||
READY,
|
||||
} state_;
|
||||
const std::list<uint64_t> channel_bitrates_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user