Added USER_NEW trigger.
This commit is contained in:
parent
4db2ea97ed
commit
f6e2e95b5a
7 changed files with 64 additions and 4 deletions
|
@ -127,6 +127,14 @@ void Controller::SharedMemStats(void * config){
|
|||
|
||||
/// Updates the given active connection with new stats data.
|
||||
void Controller::statSession::update(unsigned long index, IPC::statExchange & data){
|
||||
//update the sync byte: 0 = requesting fill, 1 = needs checking, > 1 = state known
|
||||
if (!data.getSync()){
|
||||
data.setSync(sync);
|
||||
}else{
|
||||
if (sync < 2){
|
||||
sync = data.getSync();
|
||||
}
|
||||
}
|
||||
curConns[index].update(data);
|
||||
//store timestamp of last received data, if newer
|
||||
if (data.now() > lastSec){
|
||||
|
@ -171,6 +179,7 @@ void Controller::statSession::finish(unsigned long index){
|
|||
Controller::statSession::statSession(){
|
||||
firstSec = 0xFFFFFFFFFFFFFFFFull;
|
||||
lastSec = 0;
|
||||
sync = 1;
|
||||
}
|
||||
|
||||
/// Moves the given connection to the given session
|
||||
|
|
|
@ -58,6 +58,7 @@ namespace Controller {
|
|||
unsigned long long lastSec;
|
||||
std::deque<statStorage> oldConns;
|
||||
std::map<unsigned long, statStorage> curConns;
|
||||
char sync;
|
||||
public:
|
||||
statSession();
|
||||
void wipeOld(unsigned long long);
|
||||
|
|
|
@ -193,6 +193,14 @@ namespace Mist {
|
|||
/// output handler name
|
||||
/// request URL (if any)
|
||||
/// ~~~~~~~~~~~~~~~
|
||||
/// The `"USER_NEW"` trigger is stream-specific, and is ran when a new user first opens a stream. Segmented protcols are unduplicated over the duration of the statistics log (~10 minutes), true streaming protocols (RTMP, RTSP) are not deduplicated as no duplication ever takes place. Its payload is:
|
||||
/// ~~~~~~~~~~~~~~~
|
||||
/// streamname
|
||||
/// connected client host
|
||||
/// User agent checksum (CRC32 of User-agent string)
|
||||
/// output handler name
|
||||
/// request URL (if any)
|
||||
/// ~~~~~~~~~~~~~~~
|
||||
void Output::initialize(){
|
||||
if (isInitialized){
|
||||
return;
|
||||
|
@ -219,6 +227,33 @@ namespace Mist {
|
|||
myConn.close();
|
||||
}
|
||||
}
|
||||
if(Triggers::shouldTrigger("USER_NEW", streamName)){
|
||||
//sync byte 0 = no sync yet, wait for sync from controller...
|
||||
IPC::statExchange tmpEx(statsPage.getData());
|
||||
unsigned int i = 0;
|
||||
while (!tmpEx.getSync() && i < 30){
|
||||
Util::sleep(100);
|
||||
stats();
|
||||
}
|
||||
HIGH_MSG("USER_NEW sync achieved: %u", (unsigned int)tmpEx.getSync());
|
||||
//1 = check requested (connection is new)
|
||||
if (tmpEx.getSync() == 1){
|
||||
std::string payload = streamName+"\n" + myConn.getHost() +"\n" + JSON::Value((long long)crc).asString() + "\n"+capa["name"].asStringRef()+"\n"+reqUrl;
|
||||
if (!Triggers::doTrigger("USER_NEW", payload, streamName)){
|
||||
MEDIUM_MSG("Closing connection because denied by USER_NEW trigger");
|
||||
myConn.close();
|
||||
tmpEx.setSync(100);//100 = denied
|
||||
}else{
|
||||
tmpEx.setSync(10);//10 = accepted
|
||||
}
|
||||
}
|
||||
//100 = denied
|
||||
if (tmpEx.getSync() == 100){
|
||||
myConn.close();
|
||||
MEDIUM_MSG("Closing connection because denied by USER_NEW sync byte");
|
||||
}
|
||||
//anything else = accepted
|
||||
}
|
||||
/*LTS-END*/
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue