Added automatic User-Agent stream tagging

This commit is contained in:
Thulinma 2017-04-15 13:30:14 +02:00
parent d0912c9d00
commit 9ddfa97148
8 changed files with 33 additions and 4 deletions

View file

@ -67,6 +67,7 @@ namespace Mist{
lastStats = 0; lastStats = 0;
maxSkipAhead = 7500; maxSkipAhead = 7500;
minSkipAhead = 5000; minSkipAhead = 5000;
uaDelay = 10;
realTime = 1000; realTime = 1000;
lastRecv = Util::epoch(); lastRecv = Util::epoch();
if (myConn){ if (myConn){
@ -1207,6 +1208,17 @@ namespace Mist{
}else{ }else{
tmpEx.lastSecond(0); tmpEx.lastSecond(0);
} }
/*LTS-START*/
//Tag the session with the user agent
static bool newUA = true;//we only do this once per connection
if (newUA && ((now - myConn.connTime()) >= uaDelay || !myConn) && UA.size()){
std::string APIcall = "{\"tag_sessid\":{\"" + tmpEx.getSessId() + "\":" + JSON::string_escape("UA:"+UA) + "}}";
Socket::UDPConnection uSock;
uSock.SetDestination("localhost", 4242);
uSock.SendNow(APIcall);
newUA = false;
}
/*LTS-END*/
statsPage.keepAlive(); statsPage.keepAlive();
} }
doSync(); doSync();

View file

@ -100,6 +100,8 @@ namespace Mist {
bool sought;///<If a seek has been done, this is set to true. Used for seeking on prepareNext(). bool sought;///<If a seek has been done, this is set to true. Used for seeking on prepareNext().
protected://these are to be messed with by child classes protected://these are to be messed with by child classes
bool pushing; bool pushing;
std::string UA; ///< User Agent string, if known.
uint16_t uaDelay;///<Seconds to wait before setting the UA.
uint64_t lastRecv; uint64_t lastRecv;
long long unsigned int firstTime;///< Time of first packet after last seek. Used for real-time sending. long long unsigned int firstTime;///< Time of first packet after last seek. Used for real-time sending.
virtual std::string getConnectedHost(); virtual std::string getConnectedHost();

View file

@ -8,7 +8,10 @@
#include <iomanip> #include <iomanip>
namespace Mist { namespace Mist {
OutDashMP4::OutDashMP4(Socket::Connection & conn) : HTTPOutput(conn){realTime = 0;} OutDashMP4::OutDashMP4(Socket::Connection & conn) : HTTPOutput(conn){
uaDelay = 0;
realTime = 0;
}
OutDashMP4::~OutDashMP4(){} OutDashMP4::~OutDashMP4(){}
std::string OutDashMP4::makeTime(uint64_t time){ std::string OutDashMP4::makeTime(uint64_t time){

View file

@ -131,6 +131,8 @@ namespace Mist {
} //BuildManifest } //BuildManifest
OutHDS::OutHDS(Socket::Connection & conn) : HTTPOutput(conn) { OutHDS::OutHDS(Socket::Connection & conn) : HTTPOutput(conn) {
uaDelay = 0;
realTime = 0;
audioTrack = 0; audioTrack = 0;
playUntil = 0; playUntil = 0;
} }

View file

@ -258,6 +258,7 @@ namespace Mist {
OutHLS::OutHLS(Socket::Connection & conn) : TSOutput(conn) { OutHLS::OutHLS(Socket::Connection & conn) : TSOutput(conn) {
uaDelay = 0;
realTime = 0; realTime = 0;
until=0xFFFFFFFFFFFFFFFFull; until=0xFFFFFFFFFFFFFFFFull;
} }

View file

@ -46,7 +46,10 @@ std::string toUTF16(std::string original) {
namespace Mist { namespace Mist {
OutHSS::OutHSS(Socket::Connection & conn) : HTTPOutput(conn){realTime = 0;} OutHSS::OutHSS(Socket::Connection & conn) : HTTPOutput(conn){
uaDelay = 0;
realTime = 0;
}
OutHSS::~OutHSS(){} OutHSS::~OutHSS(){}
void OutHSS::init(Util::Config * cfg) { void OutHSS::init(Util::Config * cfg) {

View file

@ -213,6 +213,9 @@ namespace Mist {
void HTTPOutput::onRequest(){ void HTTPOutput::onRequest(){
while (H.Read(myConn)){ while (H.Read(myConn)){
if (H.hasHeader("User-Agent")){
UA = H.GetHeader("User-Agent");
}
if (hasSessionIDs()){ if (hasSessionIDs()){
if (H.GetVar("sessId").size()){ if (H.GetVar("sessId").size()){
std::string ua = H.GetVar("sessId"); std::string ua = H.GetVar("sessId");
@ -222,8 +225,8 @@ namespace Mist {
crc = checksum::crc32(0, ua.data(), ua.size()); crc = checksum::crc32(0, ua.data(), ua.size());
} }
}else{ }else{
std::string ua = H.GetHeader("User-Agent") + H.GetHeader("X-Playback-Session-Id"); std::string mixed_ua = UA + H.GetHeader("X-Playback-Session-Id");
crc = checksum::crc32(0, ua.data(), ua.size()); crc = checksum::crc32(0, mixed_ua.data(), mixed_ua.size());
} }
INFO_MSG("Received request %s", H.getUrl().c_str()); INFO_MSG("Received request %s", H.getUrl().c_str());

View file

@ -597,6 +597,9 @@ namespace Mist {
if (amfData.getContentP(2)->getContentP("objectEncoding")) { if (amfData.getContentP(2)->getContentP("objectEncoding")) {
objencoding = amfData.getContentP(2)->getContentP("objectEncoding")->NumValue(); objencoding = amfData.getContentP(2)->getContentP("objectEncoding")->NumValue();
} }
if (amfData.getContentP(2)->getContentP("flashVer")) {
UA = amfData.getContentP(2)->getContentP("flashVer")->StrValue();
}
app_name = amfData.getContentP(2)->getContentP("tcUrl")->StrValue(); app_name = amfData.getContentP(2)->getContentP("tcUrl")->StrValue();
reqUrl = app_name;//LTS reqUrl = app_name;//LTS
app_name = app_name.substr(app_name.find('/', 7) + 1); app_name = app_name.substr(app_name.find('/', 7) + 1);