picloud next iteration

This commit is contained in:
2021-04-05 17:42:02 +03:00
parent 8eff5d24c9
commit f0d4801d3c
13 changed files with 237 additions and 90 deletions

View File

@@ -20,23 +20,70 @@
#include "picloudtcp.h"
#include "picrypt.h"
#include "pichunkstream.h"
#include "piethernet.h"
const char hash_def_key[] = "_picrypt_";
PIByteArray & operator <<(PIByteArray & s, const PICloud::Header & v) {
s << v.version << v.type << v.sname;
return s;
}
PIByteArray & operator >>(PIByteArray & s, PICloud::Header & v) {
s >> v.version >> v.type >> v.sname;
return s;
PICloud::TCP::Header::Header() {
version = Version_1;
}
PICloud::TCP::TCP() {
}
void PICloud::TCP::setRole(PICloud::TCP::Role r) {
header.role = r;
}
void PICloud::TCP::setServerName(const PIString & server_name) {
sname = server_name;
}
void PICloud::TCP::sendStart(PIEthernet * eth) {
header.type = PICloud::TCP::Connect;
PIByteArray ba;
ba << header << sname;
eth->send(ba);
}
PIPair<PICloud::TCP::Type, PICloud::TCP::Role> PICloud::TCP::parseHeader(PIByteArray & ba) {
PIPair<PICloud::TCP::Type, PICloud::TCP::Role> ret;
ret.first = Invalid;
if (ba.size() < sizeof(Header)) return ret;
PICloud::TCP::Header hdr;
ba >> hdr;
if (hdr.version != header.version) {
piCout << "[PICloud]" << "invalid TCP version!";
return ret;
}
ret.first = (Type)hdr.type;
ret.second = (Role)hdr.role;
return ret;
}
PIByteArray PICloud::TCP::parseData(PIByteArray & ba) {
if (header.role == Server) {
PIString client;
ba >> client;
return ba;
}
if (header.role == Client) {
return ba;
}
return PIByteArray();
}
PIString PICloud::TCP::parseConnect(PIByteArray & ba) {
PIString ret;
ba >> ret;
return ret;
}