Send tunnel request.
This commit is contained in:
@@ -17,7 +17,7 @@ int main(int argc, char *argv[]) {
|
|||||||
std::string server_public_key_filename;
|
std::string server_public_key_filename;
|
||||||
std::string server_address;
|
std::string server_address;
|
||||||
std::string server_port;
|
std::string server_port;
|
||||||
std::list<uint64_t> channel_bitrates;
|
std::list<uint32_t> channel_bitrates;
|
||||||
{
|
{
|
||||||
int option, option_index;
|
int option, option_index;
|
||||||
while ((option = getopt_long(argc, argv, "s:", long_options, &option_index)) != -1) {
|
while ((option = getopt_long(argc, argv, "s:", long_options, &option_index)) != -1) {
|
||||||
@@ -38,7 +38,7 @@ int main(int argc, char *argv[]) {
|
|||||||
server_port = optarg;
|
server_port = optarg;
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
channel_bitrates.push_back(strtoull(optarg, NULL, 10));
|
channel_bitrates.push_back(strtoul(optarg, NULL, 10));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
crypto.cc
19
crypto.cc
@@ -165,6 +165,13 @@ bool CryptoPubConnBase::HandleSecureHandshake(const TLVNode& node) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CryptoPubConnBase::EncryptSend(const TLVNode& node) {
|
||||||
|
auto encrypted = CryptoUtil::EncodeEncrypt(ephemeral_secret_key_, peer_ephemeral_public_key_, node);
|
||||||
|
std::string out;
|
||||||
|
encrypted->Encode(&out);
|
||||||
|
bufferevent_write(bev_, out.data(), out.length());
|
||||||
|
}
|
||||||
|
|
||||||
void CryptoPubConnBase::OnReadable_(struct bufferevent* bev, void* this__) {
|
void CryptoPubConnBase::OnReadable_(struct bufferevent* bev, void* this__) {
|
||||||
auto this_ = (CryptoPubConnBase*)this__;
|
auto this_ = (CryptoPubConnBase*)this__;
|
||||||
this_->OnReadable();
|
this_->OnReadable();
|
||||||
@@ -314,7 +321,7 @@ void CryptoPubServerConnection::OnError(const short what) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CryptoPubClient::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::CryptoPubClient(struct sockaddr* addr, socklen_t addrlen, const std::string& secret_key, const std::string& server_public_key, const std::list<uint32_t>& channel_bitrates)
|
||||||
: CryptoPubConnBase(secret_key),
|
: CryptoPubConnBase(secret_key),
|
||||||
event_base_(event_base_new()),
|
event_base_(event_base_new()),
|
||||||
channel_bitrates_(channel_bitrates) {
|
channel_bitrates_(channel_bitrates) {
|
||||||
@@ -334,7 +341,7 @@ CryptoPubClient::~CryptoPubClient() {
|
|||||||
event_base_free(event_base_);
|
event_base_free(event_base_);
|
||||||
}
|
}
|
||||||
|
|
||||||
CryptoPubClient* 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) {
|
CryptoPubClient* 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<uint32_t>& channel_bitrates) {
|
||||||
struct addrinfo* res;
|
struct addrinfo* res;
|
||||||
int gai_ret = getaddrinfo(server_address.c_str(), server_port.c_str(), NULL, &res);
|
int gai_ret = getaddrinfo(server_address.c_str(), server_port.c_str(), NULL, &res);
|
||||||
if (gai_ret) {
|
if (gai_ret) {
|
||||||
@@ -393,6 +400,14 @@ void CryptoPubClient::SendHandshake() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CryptoPubClient::SendTunnelRequest() {
|
void CryptoPubClient::SendTunnelRequest() {
|
||||||
|
TLVNode tunnel_request(TLV_TYPE_TUNNEL_REQUEST);
|
||||||
|
for (auto channel_bitrate : channel_bitrates_) {
|
||||||
|
auto channel = new TLVNode(TLV_TYPE_CHANNEL);
|
||||||
|
channel_bitrate = htonl(channel_bitrate);
|
||||||
|
channel->AppendChild(new TLVNode(TLV_TYPE_DOWNSTREAM_BITRATE, std::string((char*)&channel_bitrate, sizeof(channel_bitrate))));
|
||||||
|
tunnel_request.AppendChild(channel);
|
||||||
|
}
|
||||||
|
EncryptSend(tunnel_request);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CryptoPubClient::OnError() {
|
void CryptoPubClient::OnError() {
|
||||||
|
|||||||
7
crypto.h
7
crypto.h
@@ -32,6 +32,7 @@ class CryptoPubConnBase : public CryptoBase {
|
|||||||
|
|
||||||
std::unique_ptr<TLVNode> BuildSecureHandshake();
|
std::unique_ptr<TLVNode> BuildSecureHandshake();
|
||||||
bool HandleSecureHandshake(const TLVNode& node);
|
bool HandleSecureHandshake(const TLVNode& node);
|
||||||
|
void EncryptSend(const TLVNode& node);
|
||||||
|
|
||||||
static void OnReadable_(struct bufferevent* bev, void* this__);
|
static void OnReadable_(struct bufferevent* bev, void* this__);
|
||||||
void OnReadable();
|
void OnReadable();
|
||||||
@@ -88,10 +89,10 @@ class CryptoPubServerConnection : public CryptoPubConnBase {
|
|||||||
|
|
||||||
class CryptoPubClient : public CryptoPubConnBase {
|
class CryptoPubClient : public CryptoPubConnBase {
|
||||||
public:
|
public:
|
||||||
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(struct sockaddr* addr, socklen_t addrlen, const std::string& secret_key, const std::string& server_public_key, const std::list<uint32_t>& channel_bitrates);
|
||||||
~CryptoPubClient();
|
~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, const std::list<uint64_t>& channel_bitrates);
|
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<uint32_t>& channel_bitrates);
|
||||||
|
|
||||||
void Loop();
|
void Loop();
|
||||||
|
|
||||||
@@ -108,5 +109,5 @@ class CryptoPubClient : public CryptoPubConnBase {
|
|||||||
|
|
||||||
struct event_base* event_base_;
|
struct event_base* event_base_;
|
||||||
|
|
||||||
const std::list<uint64_t> channel_bitrates_;
|
const std::list<uint32_t> channel_bitrates_;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user