Sessions rework
This commit is contained in:
parent
3e85da2afd
commit
074e757028
27 changed files with 1222 additions and 1183 deletions
486
lib/comms.cpp
486
lib/comms.cpp
|
@ -7,6 +7,7 @@
|
|||
#include "timing.h"
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include "config.h"
|
||||
|
||||
namespace Comms{
|
||||
Comms::Comms(){
|
||||
|
@ -141,200 +142,45 @@ namespace Comms{
|
|||
}
|
||||
}
|
||||
|
||||
Statistics::Statistics() : Comms(){sem.open(SEM_STATISTICS, O_CREAT | O_RDWR, ACCESSPERMS, 1);}
|
||||
Sessions::Sessions() : Connections(){sem.open(SEM_STATISTICS, O_CREAT | O_RDWR, ACCESSPERMS, 1);}
|
||||
|
||||
void Statistics::unload(){
|
||||
if (index != INVALID_RECORD_INDEX){
|
||||
setStatus(COMM_STATUS_DISCONNECT | getStatus());
|
||||
}
|
||||
index = INVALID_RECORD_INDEX;
|
||||
}
|
||||
|
||||
void Statistics::reload(bool _master, bool reIssue){
|
||||
void Sessions::reload(bool _master, bool reIssue){
|
||||
Comms::reload(COMMS_STATISTICS, COMMS_STATISTICS_INITSIZE, _master, reIssue);
|
||||
}
|
||||
|
||||
void Statistics::addFields(){
|
||||
Comms::addFields();
|
||||
dataAccX.addField("sync", RAX_UINT);
|
||||
dataAccX.addField("now", RAX_64UINT);
|
||||
dataAccX.addField("time", RAX_64UINT);
|
||||
dataAccX.addField("lastsecond", RAX_64UINT);
|
||||
dataAccX.addField("down", RAX_64UINT);
|
||||
dataAccX.addField("up", RAX_64UINT);
|
||||
dataAccX.addField("host", RAX_RAW, 16);
|
||||
dataAccX.addField("stream", RAX_STRING, 100);
|
||||
dataAccX.addField("connector", RAX_STRING, 20);
|
||||
dataAccX.addField("crc", RAX_32UINT);
|
||||
dataAccX.addField("pktcount", RAX_64UINT);
|
||||
dataAccX.addField("pktloss", RAX_64UINT);
|
||||
dataAccX.addField("pktretrans", RAX_64UINT);
|
||||
}
|
||||
|
||||
void Statistics::nullFields(){
|
||||
Comms::nullFields();
|
||||
setCRC(0);
|
||||
setConnector("");
|
||||
setStream("");
|
||||
setHost("");
|
||||
setUp(0);
|
||||
setDown(0);
|
||||
setLastSecond(0);
|
||||
setTime(0);
|
||||
setNow(0);
|
||||
setSync(0);
|
||||
setPacketCount(0);
|
||||
setPacketLostCount(0);
|
||||
setPacketRetransmitCount(0);
|
||||
}
|
||||
|
||||
void Statistics::fieldAccess(){
|
||||
Comms::fieldAccess();
|
||||
sync = dataAccX.getFieldAccX("sync");
|
||||
now = dataAccX.getFieldAccX("now");
|
||||
time = dataAccX.getFieldAccX("time");
|
||||
lastSecond = dataAccX.getFieldAccX("lastsecond");
|
||||
down = dataAccX.getFieldAccX("down");
|
||||
up = dataAccX.getFieldAccX("up");
|
||||
host = dataAccX.getFieldAccX("host");
|
||||
stream = dataAccX.getFieldAccX("stream");
|
||||
connector = dataAccX.getFieldAccX("connector");
|
||||
crc = dataAccX.getFieldAccX("crc");
|
||||
pktcount = dataAccX.getFieldAccX("pktcount");
|
||||
pktloss = dataAccX.getFieldAccX("pktloss");
|
||||
pktretrans = dataAccX.getFieldAccX("pktretrans");
|
||||
}
|
||||
|
||||
uint8_t Statistics::getSync() const{return sync.uint(index);}
|
||||
uint8_t Statistics::getSync(size_t idx) const{return (master ? sync.uint(idx) : 0);}
|
||||
void Statistics::setSync(uint8_t _sync){sync.set(_sync, index);}
|
||||
void Statistics::setSync(uint8_t _sync, size_t idx){
|
||||
std::string Sessions::getSessId() const{return sessId.string(index);}
|
||||
std::string Sessions::getSessId(size_t idx) const{return (master ? sessId.string(idx) : 0);}
|
||||
void Sessions::setSessId(std::string _sid){sessId.set(_sid, index);}
|
||||
void Sessions::setSessId(std::string _sid, size_t idx){
|
||||
if (!master){return;}
|
||||
sync.set(_sync, idx);
|
||||
sessId.set(_sid, idx);
|
||||
}
|
||||
|
||||
uint64_t Statistics::getNow() const{return now.uint(index);}
|
||||
uint64_t Statistics::getNow(size_t idx) const{return (master ? now.uint(idx) : 0);}
|
||||
void Statistics::setNow(uint64_t _now){now.set(_now, index);}
|
||||
void Statistics::setNow(uint64_t _now, size_t idx){
|
||||
if (!master){return;}
|
||||
now.set(_now, idx);
|
||||
bool Sessions::sessIdExists(std::string _sid){
|
||||
for (size_t i = 0; i < recordCount(); i++){
|
||||
if (getStatus(i) == COMM_STATUS_INVALID || (getStatus(i) & COMM_STATUS_DISCONNECT)){continue;}
|
||||
if (getSessId(i) == _sid){
|
||||
if (Util::Procs::isRunning(getPid(i))){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t Statistics::getTime() const{return time.uint(index);}
|
||||
uint64_t Statistics::getTime(size_t idx) const{return (master ? time.uint(idx) : 0);}
|
||||
void Statistics::setTime(uint64_t _time){time.set(_time, index);}
|
||||
void Statistics::setTime(uint64_t _time, size_t idx){
|
||||
if (!master){return;}
|
||||
time.set(_time, idx);
|
||||
void Sessions::addFields(){
|
||||
Connections::addFields();
|
||||
dataAccX.addField("sessid", RAX_STRING, 80);
|
||||
}
|
||||
|
||||
uint64_t Statistics::getLastSecond() const{return lastSecond.uint(index);}
|
||||
uint64_t Statistics::getLastSecond(size_t idx) const{
|
||||
return (master ? lastSecond.uint(idx) : 0);
|
||||
}
|
||||
void Statistics::setLastSecond(uint64_t _lastSecond){lastSecond.set(_lastSecond, index);}
|
||||
void Statistics::setLastSecond(uint64_t _lastSecond, size_t idx){
|
||||
if (!master){return;}
|
||||
lastSecond.set(_lastSecond, idx);
|
||||
void Sessions::nullFields(){
|
||||
Connections::nullFields();
|
||||
setSessId("");
|
||||
}
|
||||
|
||||
uint64_t Statistics::getDown() const{return down.uint(index);}
|
||||
uint64_t Statistics::getDown(size_t idx) const{return (master ? down.uint(idx) : 0);}
|
||||
void Statistics::setDown(uint64_t _down){down.set(_down, index);}
|
||||
void Statistics::setDown(uint64_t _down, size_t idx){
|
||||
if (!master){return;}
|
||||
down.set(_down, idx);
|
||||
}
|
||||
|
||||
uint64_t Statistics::getUp() const{return up.uint(index);}
|
||||
uint64_t Statistics::getUp(size_t idx) const{return (master ? up.uint(idx) : 0);}
|
||||
void Statistics::setUp(uint64_t _up){up.set(_up, index);}
|
||||
void Statistics::setUp(uint64_t _up, size_t idx){
|
||||
if (!master){return;}
|
||||
up.set(_up, idx);
|
||||
}
|
||||
|
||||
std::string Statistics::getHost() const{return std::string(host.ptr(index), 16);}
|
||||
std::string Statistics::getHost(size_t idx) const{
|
||||
if (!master){return std::string((size_t)16, (char)'\000');}
|
||||
return std::string(host.ptr(idx), 16);
|
||||
}
|
||||
void Statistics::setHost(std::string _host){host.set(_host, index);}
|
||||
void Statistics::setHost(std::string _host, size_t idx){
|
||||
if (!master){return;}
|
||||
host.set(_host, idx);
|
||||
}
|
||||
|
||||
std::string Statistics::getStream() const{return stream.string(index);}
|
||||
std::string Statistics::getStream(size_t idx) const{return (master ? stream.string(idx) : "");}
|
||||
void Statistics::setStream(std::string _stream){stream.set(_stream, index);}
|
||||
void Statistics::setStream(std::string _stream, size_t idx){
|
||||
if (!master){return;}
|
||||
stream.set(_stream, idx);
|
||||
}
|
||||
|
||||
std::string Statistics::getConnector() const{return connector.string(index);}
|
||||
std::string Statistics::getConnector(size_t idx) const{
|
||||
return (master ? connector.string(idx) : "");
|
||||
}
|
||||
void Statistics::setConnector(std::string _connector){connector.set(_connector, index);}
|
||||
void Statistics::setConnector(std::string _connector, size_t idx){
|
||||
if (!master){return;}
|
||||
connector.set(_connector, idx);
|
||||
}
|
||||
|
||||
uint32_t Statistics::getCRC() const{return crc.uint(index);}
|
||||
uint32_t Statistics::getCRC(size_t idx) const{return (master ? crc.uint(idx) : 0);}
|
||||
void Statistics::setCRC(uint32_t _crc){crc.set(_crc, index);}
|
||||
void Statistics::setCRC(uint32_t _crc, size_t idx){
|
||||
if (!master){return;}
|
||||
crc.set(_crc, idx);
|
||||
}
|
||||
|
||||
uint64_t Statistics::getPacketCount() const{return pktcount.uint(index);}
|
||||
uint64_t Statistics::getPacketCount(size_t idx) const{
|
||||
return (master ? pktcount.uint(idx) : 0);
|
||||
}
|
||||
void Statistics::setPacketCount(uint64_t _count){pktcount.set(_count, index);}
|
||||
void Statistics::setPacketCount(uint64_t _count, size_t idx){
|
||||
if (!master){return;}
|
||||
pktcount.set(_count, idx);
|
||||
}
|
||||
|
||||
uint64_t Statistics::getPacketLostCount() const{return pktloss.uint(index);}
|
||||
uint64_t Statistics::getPacketLostCount(size_t idx) const{
|
||||
return (master ? pktloss.uint(idx) : 0);
|
||||
}
|
||||
void Statistics::setPacketLostCount(uint64_t _lost){pktloss.set(_lost, index);}
|
||||
void Statistics::setPacketLostCount(uint64_t _lost, size_t idx){
|
||||
if (!master){return;}
|
||||
pktloss.set(_lost, idx);
|
||||
}
|
||||
|
||||
uint64_t Statistics::getPacketRetransmitCount() const{return pktretrans.uint(index);}
|
||||
uint64_t Statistics::getPacketRetransmitCount(size_t idx) const{
|
||||
return (master ? pktretrans.uint(idx) : 0);
|
||||
}
|
||||
void Statistics::setPacketRetransmitCount(uint64_t _retrans){pktretrans.set(_retrans, index);}
|
||||
void Statistics::setPacketRetransmitCount(uint64_t _retrans, size_t idx){
|
||||
if (!master){return;}
|
||||
pktretrans.set(_retrans, idx);
|
||||
}
|
||||
|
||||
std::string Statistics::getSessId() const{return getSessId(index);}
|
||||
|
||||
std::string Statistics::getSessId(size_t idx) const{
|
||||
char res[140];
|
||||
memset(res, 0, 140);
|
||||
std::string tmp = host.string(idx);
|
||||
memcpy(res, tmp.c_str(), (tmp.size() > 16 ? 16 : tmp.size()));
|
||||
tmp = stream.string(idx);
|
||||
memcpy(res + 16, tmp.c_str(), (tmp.size() > 100 ? 100 : tmp.size()));
|
||||
tmp = connector.string(idx);
|
||||
memcpy(res + 116, tmp.c_str(), (tmp.size() > 20 ? 20 : tmp.size()));
|
||||
Bit::htobl(res + 136, crc.uint(idx));
|
||||
return Secure::md5(res, 140);
|
||||
void Sessions::fieldAccess(){
|
||||
Connections::fieldAccess();
|
||||
sessId = dataAccX.getFieldAccX("sessid");
|
||||
}
|
||||
|
||||
Users::Users() : Comms(){}
|
||||
|
@ -404,4 +250,282 @@ namespace Comms{
|
|||
if (!master){return;}
|
||||
keyNum.set(_keyNum, idx);
|
||||
}
|
||||
|
||||
/// \brief Claims a spot on the connections page for the input/output which calls this function
|
||||
/// Starts the MistSession binary for each session, which handles the statistics
|
||||
/// and the USER_NEW and USER_END triggers
|
||||
/// \param streamName: Name of the stream the input is providing or an output is making available to viewers
|
||||
/// \param ip: IP address of the viewer which wants to access streamName. For inputs this value can be set to any value
|
||||
/// \param sid: Session ID given by the player or randomly generated
|
||||
/// \param protocol: Protocol currently in use for this connection
|
||||
/// \param sessionMode: Determines how a viewer session is defined:
|
||||
// If set to 0, all connections with the same viewer IP and stream name are bundled.
|
||||
// If set to 1, all connections with the same viewer IP and player ID are bundled.
|
||||
// If set to 2, all connections with the same player ID and stream name are bundled.
|
||||
// If set to 3, all connections with the same viewer IP, player ID and stream name are bundled.
|
||||
/// \param _master: If True, we are reading from this page. If False, we are writing (to our entry) on this page
|
||||
/// \param reIssue: If True, claim a new entry on this page
|
||||
void Connections::reload(std::string streamName, std::string ip, std::string sid, std::string protocol, std::string reqUrl, uint64_t sessionMode, bool _master, bool reIssue){
|
||||
if (sessionMode == 0xFFFFFFFFFFFFFFFFull){
|
||||
FAIL_MSG("The session mode was not initialised properly. Assuming default behaviour of bundling by viewer IP, stream name and player id");
|
||||
sessionMode = SESS_BUNDLE_STREAMNAME_HOSTNAME_SESSIONID;
|
||||
}
|
||||
// Generate a unique session ID for each viewer, input or output
|
||||
sessionId = generateSession(streamName, ip, sid, protocol, sessionMode);
|
||||
if (protocol.size() >= 6 && protocol.substr(0, 6) == "INPUT:"){
|
||||
sessionId = "I" + sessionId;
|
||||
}else if (protocol.size() >= 7 && protocol.substr(0, 7) == "OUTPUT:"){
|
||||
sessionId = "O" + sessionId;
|
||||
}
|
||||
char userPageName[NAME_BUFFER_SIZE];
|
||||
snprintf(userPageName, NAME_BUFFER_SIZE, COMMS_SESSIONS, sessionId.c_str());
|
||||
// Check if the page exists, if not, spawn new session process
|
||||
if (!_master){
|
||||
dataPage.init(userPageName, 0, false, false);
|
||||
if (!dataPage){
|
||||
pid_t thisPid;
|
||||
std::deque<std::string> args;
|
||||
args.push_back(Util::getMyPath() + "MistSession");
|
||||
args.push_back(sessionId);
|
||||
args.push_back("--sessionmode");
|
||||
args.push_back(JSON::Value(sessionMode).asString());
|
||||
args.push_back("--streamname");
|
||||
args.push_back(streamName);
|
||||
args.push_back("--ip");
|
||||
args.push_back(ip);
|
||||
args.push_back("--sid");
|
||||
args.push_back(sid);
|
||||
args.push_back("--protocol");
|
||||
args.push_back(protocol);
|
||||
args.push_back("--requrl");
|
||||
args.push_back(reqUrl);
|
||||
int err = fileno(stderr);
|
||||
thisPid = Util::Procs::StartPiped(args, 0, 0, &err);
|
||||
Util::Procs::forget(thisPid);
|
||||
HIGH_MSG("Spawned new session executeable (pid %u) for sessionId '%s', corresponding to host %s and stream %s", thisPid, sessionId.c_str(), ip.c_str(), streamName.c_str());
|
||||
}
|
||||
}
|
||||
// Open SEM_SESSION
|
||||
if(!sem){
|
||||
char semName[NAME_BUFFER_SIZE];
|
||||
snprintf(semName, NAME_BUFFER_SIZE, SEM_SESSION, sessionId.c_str());
|
||||
sem.open(semName, O_RDWR, ACCESSPERMS, 1);
|
||||
}
|
||||
Comms::reload(userPageName, COMMS_SESSIONS_INITSIZE, _master, reIssue);
|
||||
VERYHIGH_MSG("Reloading connection. Claimed record %lu", index);
|
||||
}
|
||||
|
||||
/// \brief Marks the data page as closed, so that we longer write any new data to is
|
||||
void Connections::setExit(){
|
||||
if (!master){return;}
|
||||
dataAccX.setExit();
|
||||
}
|
||||
|
||||
bool Connections::getExit(){
|
||||
return dataAccX.isExit();
|
||||
}
|
||||
|
||||
void Connections::unload(){
|
||||
if (index != INVALID_RECORD_INDEX){
|
||||
setStatus(COMM_STATUS_DISCONNECT | getStatus());
|
||||
}
|
||||
index = INVALID_RECORD_INDEX;
|
||||
}
|
||||
void Connections::addFields(){
|
||||
Comms::addFields();
|
||||
dataAccX.addField("now", RAX_64UINT);
|
||||
dataAccX.addField("time", RAX_64UINT);
|
||||
dataAccX.addField("lastsecond", RAX_64UINT);
|
||||
dataAccX.addField("down", RAX_64UINT);
|
||||
dataAccX.addField("up", RAX_64UINT);
|
||||
dataAccX.addField("host", RAX_RAW, 16);
|
||||
dataAccX.addField("stream", RAX_STRING, 100);
|
||||
dataAccX.addField("connector", RAX_STRING, 20);
|
||||
dataAccX.addField("tags", RAX_STRING, 512);
|
||||
dataAccX.addField("pktcount", RAX_64UINT);
|
||||
dataAccX.addField("pktloss", RAX_64UINT);
|
||||
dataAccX.addField("pktretrans", RAX_64UINT);
|
||||
}
|
||||
|
||||
void Connections::nullFields(){
|
||||
Comms::nullFields();
|
||||
setTags("");
|
||||
setConnector("");
|
||||
setStream("");
|
||||
setHost("");
|
||||
setUp(0);
|
||||
setDown(0);
|
||||
setLastSecond(0);
|
||||
setTime(0);
|
||||
setNow(0);
|
||||
setPacketCount(0);
|
||||
setPacketLostCount(0);
|
||||
setPacketRetransmitCount(0);
|
||||
}
|
||||
|
||||
void Connections::fieldAccess(){
|
||||
Comms::fieldAccess();
|
||||
now = dataAccX.getFieldAccX("now");
|
||||
time = dataAccX.getFieldAccX("time");
|
||||
lastSecond = dataAccX.getFieldAccX("lastsecond");
|
||||
down = dataAccX.getFieldAccX("down");
|
||||
up = dataAccX.getFieldAccX("up");
|
||||
host = dataAccX.getFieldAccX("host");
|
||||
stream = dataAccX.getFieldAccX("stream");
|
||||
connector = dataAccX.getFieldAccX("connector");
|
||||
tags = dataAccX.getFieldAccX("tags");
|
||||
pktcount = dataAccX.getFieldAccX("pktcount");
|
||||
pktloss = dataAccX.getFieldAccX("pktloss");
|
||||
pktretrans = dataAccX.getFieldAccX("pktretrans");
|
||||
}
|
||||
|
||||
uint64_t Connections::getNow() const{return now.uint(index);}
|
||||
uint64_t Connections::getNow(size_t idx) const{return (master ? now.uint(idx) : 0);}
|
||||
void Connections::setNow(uint64_t _now){now.set(_now, index);}
|
||||
void Connections::setNow(uint64_t _now, size_t idx){
|
||||
if (!master){return;}
|
||||
now.set(_now, idx);
|
||||
}
|
||||
|
||||
uint64_t Connections::getTime() const{return time.uint(index);}
|
||||
uint64_t Connections::getTime(size_t idx) const{return (master ? time.uint(idx) : 0);}
|
||||
void Connections::setTime(uint64_t _time){time.set(_time, index);}
|
||||
void Connections::setTime(uint64_t _time, size_t idx){
|
||||
if (!master){return;}
|
||||
time.set(_time, idx);
|
||||
}
|
||||
|
||||
uint64_t Connections::getLastSecond() const{return lastSecond.uint(index);}
|
||||
uint64_t Connections::getLastSecond(size_t idx) const{
|
||||
return (master ? lastSecond.uint(idx) : 0);
|
||||
}
|
||||
void Connections::setLastSecond(uint64_t _lastSecond){lastSecond.set(_lastSecond, index);}
|
||||
void Connections::setLastSecond(uint64_t _lastSecond, size_t idx){
|
||||
if (!master){return;}
|
||||
lastSecond.set(_lastSecond, idx);
|
||||
}
|
||||
|
||||
uint64_t Connections::getDown() const{return down.uint(index);}
|
||||
uint64_t Connections::getDown(size_t idx) const{return (master ? down.uint(idx) : 0);}
|
||||
void Connections::setDown(uint64_t _down){down.set(_down, index);}
|
||||
void Connections::setDown(uint64_t _down, size_t idx){
|
||||
if (!master){return;}
|
||||
down.set(_down, idx);
|
||||
}
|
||||
|
||||
uint64_t Connections::getUp() const{return up.uint(index);}
|
||||
uint64_t Connections::getUp(size_t idx) const{return (master ? up.uint(idx) : 0);}
|
||||
void Connections::setUp(uint64_t _up){up.set(_up, index);}
|
||||
void Connections::setUp(uint64_t _up, size_t idx){
|
||||
if (!master){return;}
|
||||
up.set(_up, idx);
|
||||
}
|
||||
|
||||
std::string Connections::getHost() const{return std::string(host.ptr(index), 16);}
|
||||
std::string Connections::getHost(size_t idx) const{
|
||||
if (!master){return std::string((size_t)16, (char)'\000');}
|
||||
return std::string(host.ptr(idx), 16);
|
||||
}
|
||||
void Connections::setHost(std::string _host){host.set(_host, index);}
|
||||
void Connections::setHost(std::string _host, size_t idx){
|
||||
if (!master){return;}
|
||||
host.set(_host, idx);
|
||||
}
|
||||
|
||||
std::string Connections::getStream() const{return stream.string(index);}
|
||||
std::string Connections::getStream(size_t idx) const{return (master ? stream.string(idx) : "");}
|
||||
void Connections::setStream(std::string _stream){stream.set(_stream, index);}
|
||||
void Connections::setStream(std::string _stream, size_t idx){
|
||||
if (!master){return;}
|
||||
stream.set(_stream, idx);
|
||||
}
|
||||
|
||||
std::string Connections::getConnector() const{return connector.string(index);}
|
||||
std::string Connections::getConnector(size_t idx) const{
|
||||
return (master ? connector.string(idx) : "");
|
||||
}
|
||||
void Connections::setConnector(std::string _connector){connector.set(_connector, index);}
|
||||
void Connections::setConnector(std::string _connector, size_t idx){
|
||||
if (!master){return;}
|
||||
connector.set(_connector, idx);
|
||||
}
|
||||
|
||||
bool Connections::hasConnector(size_t idx, std::string protocol){
|
||||
std::stringstream sstream(connector.string(idx));
|
||||
std::string _conn;
|
||||
while (std::getline(sstream, _conn, ',')){
|
||||
if (_conn == protocol){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string Connections::getTags() const{return tags.string(index);}
|
||||
std::string Connections::getTags(size_t idx) const{return (master ? tags.string(idx) : 0);}
|
||||
void Connections::setTags(std::string _sid){tags.set(_sid, index);}
|
||||
void Connections::setTags(std::string _sid, size_t idx){
|
||||
if (!master){return;}
|
||||
tags.set(_sid, idx);
|
||||
}
|
||||
|
||||
uint64_t Connections::getPacketCount() const{return pktcount.uint(index);}
|
||||
uint64_t Connections::getPacketCount(size_t idx) const{
|
||||
return (master ? pktcount.uint(idx) : 0);
|
||||
}
|
||||
void Connections::setPacketCount(uint64_t _count){pktcount.set(_count, index);}
|
||||
void Connections::setPacketCount(uint64_t _count, size_t idx){
|
||||
if (!master){return;}
|
||||
pktcount.set(_count, idx);
|
||||
}
|
||||
|
||||
uint64_t Connections::getPacketLostCount() const{return pktloss.uint(index);}
|
||||
uint64_t Connections::getPacketLostCount(size_t idx) const{
|
||||
return (master ? pktloss.uint(idx) : 0);
|
||||
}
|
||||
void Connections::setPacketLostCount(uint64_t _lost){pktloss.set(_lost, index);}
|
||||
void Connections::setPacketLostCount(uint64_t _lost, size_t idx){
|
||||
if (!master){return;}
|
||||
pktloss.set(_lost, idx);
|
||||
}
|
||||
|
||||
uint64_t Connections::getPacketRetransmitCount() const{return pktretrans.uint(index);}
|
||||
uint64_t Connections::getPacketRetransmitCount(size_t idx) const{
|
||||
return (master ? pktretrans.uint(idx) : 0);
|
||||
}
|
||||
void Connections::setPacketRetransmitCount(uint64_t _retrans){pktretrans.set(_retrans, index);}
|
||||
void Connections::setPacketRetransmitCount(uint64_t _retrans, size_t idx){
|
||||
if (!master){return;}
|
||||
pktretrans.set(_retrans, idx);
|
||||
}
|
||||
|
||||
/// \brief Generates a session ID which is unique per viewer
|
||||
/// \return generated session ID as string
|
||||
std::string Connections::generateSession(std::string streamName, std::string ip, std::string sid, std::string connector, uint64_t sessionMode){
|
||||
std::string concat;
|
||||
// First bit defines whether to include stream name
|
||||
if (sessionMode > 7){
|
||||
concat += streamName;
|
||||
sessionMode -= 8;
|
||||
}
|
||||
// Second bit defines whether to include viewer ip
|
||||
if (sessionMode > 3){
|
||||
concat += ip;
|
||||
sessionMode -= 4;
|
||||
}
|
||||
// Third bit defines whether to include player ip
|
||||
if (sessionMode > 1){
|
||||
concat += sid;
|
||||
sessionMode -= 2;
|
||||
}
|
||||
// Fourth bit defines whether to include protocol
|
||||
if (sessionMode == 1){
|
||||
concat += connector;
|
||||
sessionMode = 0;
|
||||
}
|
||||
if (sessionMode > 0){
|
||||
WARN_MSG("Could not resolve session mode of value %lu", sessionMode);
|
||||
}
|
||||
return Secure::sha256(concat.c_str(), concat.length());
|
||||
}
|
||||
}// namespace Comms
|
||||
|
|
50
lib/comms.h
50
lib/comms.h
|
@ -64,21 +64,21 @@ namespace Comms{
|
|||
Util::FieldAccX pid;
|
||||
};
|
||||
|
||||
class Statistics : public Comms{
|
||||
class Connections : public Comms{
|
||||
public:
|
||||
Statistics();
|
||||
operator bool() const{return dataPage.mapped && (master || index != INVALID_RECORD_INDEX);}
|
||||
void reload(std::string streamName, std::string ip, std::string sid, std::string protocol, std::string reqUrl, uint64_t sessionMode, bool _master = false, bool reIssue = false);
|
||||
void unload();
|
||||
void reload(bool _master = false, bool reIssue = false);
|
||||
operator bool() const{return dataPage.mapped && (master || index != INVALID_RECORD_INDEX);}
|
||||
std::string generateSession(std::string streamName, std::string ip, std::string sid, std::string connector, uint64_t sessionMode);
|
||||
std::string sessionId;
|
||||
|
||||
void setExit();
|
||||
bool getExit();
|
||||
|
||||
virtual void addFields();
|
||||
virtual void nullFields();
|
||||
virtual void fieldAccess();
|
||||
|
||||
uint8_t getSync() const;
|
||||
uint8_t getSync(size_t idx) const;
|
||||
void setSync(uint8_t _sync);
|
||||
void setSync(uint8_t _sync, size_t idx);
|
||||
|
||||
uint64_t getNow() const;
|
||||
uint64_t getNow(size_t idx) const;
|
||||
void setNow(uint64_t _now);
|
||||
|
@ -118,11 +118,12 @@ namespace Comms{
|
|||
std::string getConnector(size_t idx) const;
|
||||
void setConnector(std::string _connector);
|
||||
void setConnector(std::string _connector, size_t idx);
|
||||
bool hasConnector(size_t idx, std::string protocol);
|
||||
|
||||
uint32_t getCRC() const;
|
||||
uint32_t getCRC(size_t idx) const;
|
||||
void setCRC(uint32_t _crc);
|
||||
void setCRC(uint32_t _crc, size_t idx);
|
||||
std::string getTags() const;
|
||||
std::string getTags(size_t idx) const;
|
||||
void setTags(std::string _sid);
|
||||
void setTags(std::string _sid, size_t idx);
|
||||
|
||||
uint64_t getPacketCount() const;
|
||||
uint64_t getPacketCount(size_t idx) const;
|
||||
|
@ -139,11 +140,7 @@ namespace Comms{
|
|||
void setPacketRetransmitCount(uint64_t _retransmit);
|
||||
void setPacketRetransmitCount(uint64_t _retransmit, size_t idx);
|
||||
|
||||
std::string getSessId() const;
|
||||
std::string getSessId(size_t index) const;
|
||||
|
||||
private:
|
||||
Util::FieldAccX sync;
|
||||
protected:
|
||||
Util::FieldAccX now;
|
||||
Util::FieldAccX time;
|
||||
Util::FieldAccX lastSecond;
|
||||
|
@ -152,7 +149,8 @@ namespace Comms{
|
|||
Util::FieldAccX host;
|
||||
Util::FieldAccX stream;
|
||||
Util::FieldAccX connector;
|
||||
Util::FieldAccX crc;
|
||||
Util::FieldAccX sessId;
|
||||
Util::FieldAccX tags;
|
||||
Util::FieldAccX pktcount;
|
||||
Util::FieldAccX pktloss;
|
||||
Util::FieldAccX pktretrans;
|
||||
|
@ -186,4 +184,18 @@ namespace Comms{
|
|||
Util::FieldAccX track;
|
||||
Util::FieldAccX keyNum;
|
||||
};
|
||||
|
||||
class Sessions : public Connections{
|
||||
public:
|
||||
Sessions();
|
||||
void reload(bool _master = false, bool reIssue = false);
|
||||
std::string getSessId() const;
|
||||
std::string getSessId(size_t idx) const;
|
||||
void setSessId(std::string _sid);
|
||||
void setSessId(std::string _sid, size_t idx);
|
||||
bool sessIdExists(std::string _sid);
|
||||
virtual void addFields();
|
||||
virtual void nullFields();
|
||||
virtual void fieldAccess();
|
||||
};
|
||||
}// namespace Comms
|
||||
|
|
|
@ -196,11 +196,14 @@ static inline void show_stackframe(){}
|
|||
#define TRACK_PAGE_RECORDSIZE 36
|
||||
|
||||
#define COMMS_STATISTICS "MstStat"
|
||||
#define COMMS_STATISTICS_INITSIZE 8 * 1024 * 1024
|
||||
#define COMMS_STATISTICS_INITSIZE 16 * 1024 * 1024
|
||||
|
||||
#define COMMS_USERS "MstUser%s" //%s stream name
|
||||
#define COMMS_USERS_INITSIZE 512 * 1024
|
||||
|
||||
#define COMMS_SESSIONS "MstSession%s"
|
||||
#define COMMS_SESSIONS_INITSIZE 8 * 1024 * 1024
|
||||
|
||||
#define SEM_STATISTICS "/MstStat"
|
||||
#define SEM_USERS "/MstUser%s" //%s stream name
|
||||
|
||||
|
@ -226,7 +229,9 @@ static inline void show_stackframe(){}
|
|||
#define SEM_LIVE "/MstLIVE%s" //%s stream name
|
||||
#define SEM_INPUT "/MstInpt%s" //%s stream name
|
||||
#define SEM_TRACKLIST "/MstTRKS%s" //%s stream name
|
||||
#define SEM_SESSION "MstSess%s"
|
||||
#define SEM_SESSCACHE "/MstSessCacheLock"
|
||||
#define SESS_BUNDLE_STREAMNAME_HOSTNAME_SESSIONID 14
|
||||
#define SHM_CAPA "MstCapa"
|
||||
#define SHM_PROTO "MstProt"
|
||||
#define SHM_PROXY "MstProx"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue