Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No encrypt #86

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 93 additions & 95 deletions cmd/qpub.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#include <cassert>
#include <chrono>
#include <iostream>
Expand All @@ -16,96 +14,96 @@ using namespace MediaNet;
int
main(int argc, char* argv[])
{
std::string relayName("localhost");

if (argc < 3) {
std::cerr << "Usage: " << argv[0] << " <hostname> <shortname>" << std::endl;
std::cerr << "\t<shortname>: qr://<resourceId>/<senderId>/<sourceId>/"
<< std::endl;
std::cerr << "\t Example: qr://1234/12/1/" << std::endl;
std::cerr << "resourceId, senderId, sourceId are MANDATORY & integers."
<< std::endl;
return -1;
}

QuicRClient qClient;
qClient.setCryptoKey(1, sframe::bytes(8, uint8_t(1)));
qClient.open(1, relayName, 5004, 1);

while (!qClient.ready()) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
std::cout << "Transport is ready" << std::endl;

// setup up sending rate and size

const int packetsPerSecond = 600;
const int transportHeaderBytes = 65;

int numToSend = 20 * packetsPerSecond;
int packetCount = 0;
auto startTimePoint = std::chrono::steady_clock::now();

auto name = ShortName::fromString(argv[2]);
name.fragmentID = 0;
name.mediaTime = packetCount;

do {
const int packetGapUs = 1000000 / packetsPerSecond;
auto sendTime =
startTimePoint + std::chrono::microseconds(packetGapUs * packetCount++);
std::this_thread::sleep_until(sendTime);

uint64_t bitRate = qClient.getTargetUpstreamBitrate(); // in bps

const int maxBitRate = 100 * 1000 * 1000;
if (bitRate > maxBitRate) {
// limit bitRate
bitRate = maxBitRate;
}

uint64_t bytesPerPacket = (bitRate / packetsPerSecond) / 8;

bytesPerPacket = 500; // TODO - remove

if (bytesPerPacket < transportHeaderBytes + 2) {
bytesPerPacket = transportHeaderBytes + 2;
std::clog << "Warning bitrate too low for packet rate" << std::endl;
}
if (bytesPerPacket > 1200) {
bytesPerPacket = 1200;
std::clog << "Warning bitrate too high for packet rate (need "
<< bitRate / (8 * 1200) << " pps)" << std::endl;
}

// std::clog << "bytesPerPackt=" << bytesPerPacket << std::endl;

name.mediaTime = packetCount;
auto packet = qClient.createPacket(name, 1200);

assert(bytesPerPacket - transportHeaderBytes >= 1);
packet->resize(bytesPerPacket - transportHeaderBytes);

uint8_t* buffer = &(packet->data());
*buffer++ = 1;

packet->setFEC(false);
packet->setReliable(false);
packet->setPriority(3);

qClient.publish(move(packet));

// empty the receive queue
do {
auto ack = qClient.recv();
if (ack) {
// std::clog << "got an ack" << std::endl;
} else {
break;
}
} while (true);

} while (--numToSend > 0);

return 0;
}
std::string relayName("localhost");

if (argc < 3) {
std::cerr << "Usage: " << argv[0] << " <hostname> <shortname>" << std::endl;
std::cerr << "\t<shortname>: qr://<resourceId>/<senderId>/<sourceId>/"
<< std::endl;
std::cerr << "\t Example: qr://1234/12/1/" << std::endl;
std::cerr << "resourceId, senderId, sourceId are MANDATORY & integers."
<< std::endl;
return -1;
}

QuicRClient qClient;
qClient.setCryptoKey(1, sframe::bytes(8, uint8_t(1)));
qClient.open(1, relayName, 5004, 1);

while (!qClient.ready()) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
std::cout << "Transport is ready" << std::endl;

// setup up sending rate and size

const int packetsPerSecond = 600;
const int transportHeaderBytes = 65;

int numToSend = 20 * packetsPerSecond;
int packetCount = 0;
auto startTimePoint = std::chrono::steady_clock::now();

auto name = ShortName::fromString(argv[2]);
name.fragmentID = 0;
name.mediaTime = packetCount;

do {
const int packetGapUs = 1000000 / packetsPerSecond;
auto sendTime =
startTimePoint + std::chrono::microseconds(packetGapUs * packetCount++);
std::this_thread::sleep_until(sendTime);

uint64_t bitRate = qClient.getTargetUpstreamBitrate(); // in bps

const int maxBitRate = 100 * 1000 * 1000;
if (bitRate > maxBitRate) {
// limit bitRate
bitRate = maxBitRate;
}

uint64_t bytesPerPacket = (bitRate / packetsPerSecond) / 8;

bytesPerPacket = 500; // TODO - remove

if (bytesPerPacket < transportHeaderBytes + 2) {
bytesPerPacket = transportHeaderBytes + 2;
std::clog << "Warning bitrate too low for packet rate" << std::endl;
}
if (bytesPerPacket > 1200) {
bytesPerPacket = 1200;
std::clog << "Warning bitrate too high for packet rate (need "
<< bitRate / (8 * 1200) << " pps)" << std::endl;
}

// std::clog << "bytesPerPackt=" << bytesPerPacket << std::endl;

name.mediaTime = packetCount;
auto packet = qClient.createPacket(name, 1200);

assert(bytesPerPacket - transportHeaderBytes >= 1);
packet->resize(bytesPerPacket - transportHeaderBytes);

uint8_t* buffer = &(packet->data());
*buffer++ = 1;

packet->setFEC(false);
packet->setReliable(false);
packet->setPriority(3);

qClient.publish(move(packet));

// empty the receive queue
do {
auto ack = qClient.recv();
if (ack) {
// std::clog << "got an ack" << std::endl;
} else {
break;
}
} while (true);

} while (--numToSend > 0);

return 0;
}
7 changes: 5 additions & 2 deletions cmd/qsub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ main(int argc, char* argv[])
if (argc == 2) {
relayName = std::string(argv[1]);
}
bool encrypt = false;

auto shortName = ShortName::fromString(argv[2]);

std::cout << "Subscribing to ->" << shortName << std::endl;
QuicRClient qClient;
qClient.setCryptoKey(1, sframe::bytes(8, uint8_t(1)));
if (encrypt) {
qClient.setCryptoKey(1, sframe::bytes(8, uint8_t(1)));
}
qClient.open(1, relayName, 5004, 1);

while (!qClient.ready()) {
Expand All @@ -50,7 +53,7 @@ main(int argc, char* argv[])
std::this_thread::sleep_for(std::chrono::milliseconds(1));
continue;
}
// std::clog << "QuicR received buff size=" << packet->size() << std::endl;
std::clog << "QuicR received buff size=" << packet->size() << std::endl;
numRecv++;
} while (numRecv < 100 * 1000);

Expand Down
1 change: 0 additions & 1 deletion cmd/relay/src/multimap_fib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ MultimapFib::addSubscription(const MediaNet::ShortName& name,
if (fibStore.count((name))) {
fibStore.erase(name);
}

fibStore.insert(std::make_pair(name, subscriberInfo));
std::clog << name << " has " << fibStore.count(name) << " subscription \n";
}
Expand Down
4 changes: 1 addition & 3 deletions cmd/relay/src/relay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Relay::processPub(std::unique_ptr<MediaNet::Packet>& packet,
ClientData clientData;
NamedDataChunk namedDataChunk;
EncryptedDataBlock encryptedDataBlock;
DataBlock dataBlock;
DataBlock dataBlock;
bool ok = true;
bool encrypted = true;
ok &= packet >> clientData;
Expand All @@ -121,8 +121,6 @@ Relay::processPub(std::unique_ptr<MediaNet::Packet>& packet,
encrypted = false;
}

assert(fromVarInt(dataBlock.metaDataLen) == 0); // TODO

uint16_t payloadSize = (encrypted)
? fromVarInt(encryptedDataBlock.cipherDataLen)
: fromVarInt(dataBlock.dataLen);
Expand Down
2 changes: 1 addition & 1 deletion include/quicr/quicRClient.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PacerPipe;
class QuicRClient
{
public:
QuicRClient();
QuicRClient(bool encrypted=true);
virtual ~QuicRClient();
virtual bool open(uint32_t clientID,
std::string relayName,
Expand Down
1 change: 0 additions & 1 deletion src/encode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ MediaNet::operator<<(std::unique_ptr<Packet>& p, const Subscribe& msg)
{
p << msg.name;
p << PacketTag::subscribe;

return p;
}

Expand Down
18 changes: 17 additions & 1 deletion src/encryptPipe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "quicr/packet.hh"
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>

using namespace MediaNet;

Expand All @@ -18,6 +20,18 @@ sframe::bytes static to_bytes(const T& range)
return sframe::bytes(range.begin(), range.end());
}

std::string
stringify(const sframe::input_bytes data)
{
std::stringstream hex(std::ios_base::out);
hex.flags(std::ios::hex);
for (const auto &byte : data)
{
hex << std::setw(2) << std::setfill('0') << int(byte);
}
return hex.str();
}

EncryptPipe::EncryptPipe(PipeInterface* t)
: PipeInterface(t)
, mls_context(FIXED_CIPHER_SUITE, SFRAME_EPOCH_BITS)
Expand Down Expand Up @@ -156,7 +170,9 @@ EncryptPipe::unprotect(const std::unique_ptr<Packet>& packet,
// start decryption from data (excluding header)
auto ciphertext = buffer_ref.subspan(packet->headerSize, payloadSize);
auto pt_out = sframe::bytes(ciphertext.size());
auto pt = mls_context.unprotect(pt_out, ciphertext);
auto res = stringify(ciphertext);
std::clog << "unprotect(" << ciphertext.size() << "):" << res << std::endl;
auto pt = mls_context.unprotect(pt_out, ciphertext);
// TODO see if we can reuse pt_out
return to_bytes(pt);
}
2 changes: 1 addition & 1 deletion src/fecPipe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ FecPipe::send(std::unique_ptr<Packet> packet)
}

if (!sendList.empty()) {
while (sendList.front().first <= nowMs) {
while (!sendList.empty() && sendList.front().first <= nowMs) {
std::unique_ptr<Packet> fecPacket = std::move(sendList.front().second);
sendList.pop_front();
nextPipe->send(move(fecPacket));
Expand Down
Loading