MistServer
2.5.3-Pro-19-gf5e75b1 ( Generic_64)
|
Holds everything unique to the controller. More...
Data Structures | |
class | cpudata |
A class storing information about the cpu the server is running on. More... | |
struct | liveCheck |
class | sessIndex |
This is a comparison and storage class that keeps sessions apart from each other. More... | |
struct | statLog |
class | statSession |
A session class that keeps track of both current and archived connections. More... | |
class | statStorage |
Functions | |
void | AddStreams (JSON::Value &in, JSON::Value &out) |
bool | authorize (JSON::Value &Request, JSON::Value &Response, Socket::Connection &conn) |
Checks an authorization request for a given user. More... | |
static void | buildPipedArguments (JSON::Value &p, char *argarr[], const JSON::Value &capabilities) |
static void | builPipedPart (JSON::Value &p, char *argarr[], int &argnum, const JSON::Value &argset) |
bool | CheckAllStreams (JSON::Value &data) |
Checks all streams, restoring if needed. More... | |
void | checkAvailProtocols () |
Aquire list of available protocols, storing in global 'capabilities' JSON::Value. More... | |
void | checkCapable (JSON::Value &capa) |
Checks the capabilities of the system. More... | |
void | checkConfig (JSON::Value &in, JSON::Value &out) |
Check the submitted configuration and handle things accordingly. More... | |
bool | CheckProtocols (JSON::Value &p, const JSON::Value &capabilities) |
Checks current protocol configuration, updates state of enabled connectors if neccessary. More... | |
void | checkServerLimits () |
void | checkStream (std::string name, JSON::Value &data) |
Checks the validity of a stream, updates internal stream status. More... | |
void | checkStreamLimits (std::string streamName, long long currentKbps, long long connectedUsers) |
void | CheckStreams (JSON::Value &in, JSON::Value &out) |
Parse a given stream configuration. More... | |
JSON::Value | CheckUpdateInfo () |
void | CheckUpdates () |
Calls CheckUpdateInfo(), uses the resulting JSON::Value to download any needed updates. More... | |
void | deleteStream (const std::string &name, JSON::Value &out) |
void | fillActive (JSON::Value &req, JSON::Value &rep, bool onlyNow=false) |
This takes a "active_streams" request, and fills in the response data. More... | |
void | fillClients (JSON::Value &req, JSON::Value &rep) |
This takes a "clients" request, and fills in the response data. More... | |
void | fillTotals (JSON::Value &req, JSON::Value &rep) |
This takes a "totals" request, and fills in the response data. More... | |
std::string | getCountry (std::string ip) |
int | handleAPIConnection (Socket::Connection &conn) |
Handles a single incoming API connection. More... | |
void | handleMsg (void *err) |
Handles output of a Mist application, detecting and catching debug messages. More... | |
bool | hasViewers (std::string streamName) |
Returns true if this stream has at least one connected client. More... | |
std::string | hostLookup (std::string ip) |
bool | isBlacklisted (std::string host, std::string streamName, int timeConnected) |
void | killStatistics (char *data, size_t len, unsigned int id) |
Forces a disconnect to all users. More... | |
void | Log (std::string kind, std::string message) |
Store and print a log message. More... | |
bool | onList (std::string ip, std::string list) |
void | parseStatistics (char *data, size_t len, unsigned int id) |
This function is called by the shared memory page that holds statistics. More... | |
std::string | readFile (std::string filename) |
void | SharedMemStats (void *config) |
This function runs as a thread and roughly once per second retrieves statistics from all connected clients, as well as wipes old statistics that have disconnected over 10 minutes ago. More... | |
bool | streamsEqual (JSON::Value &one, JSON::Value &two) |
Checks whether two streams are equal. More... | |
void | updateComponent (const std::string &component, const std::string &md5sum, Socket::Connection &updrConn) |
Attempts to download an update for the listed component. More... | |
void | UpdateProtocol (std::string protocol) |
Checks if the binary mentioned in the protocol argument is currently active, if so, restarts it. More... | |
void | uplinkConnection (void *np) |
void | writeConfig () |
Writes the current config to shared memory to be used in other processes. More... | |
bool | WriteFile (std::string Filename, std::string contents) |
Write contents to Filename. More... | |
bool | writeFile (std::string filename, std::string &contents) |
Variables | |
JSON::Value | capabilities |
Global storage of capabilities. More... | |
Util::Config | conf |
Global storage of configuration. More... | |
tthread::mutex | configMutex |
Mutex for server config access. More... | |
std::map< unsigned long, sessIndex > | connToSession |
Map of socket IDs to session info. More... | |
static std::map< std::string, pid_t > | currentConnectors |
The currently running connectors. More... | |
std::map< std::string, pid_t > | inputProcesses |
bool | killOnExit = KILL_ON_EXIT |
tthread::mutex | logMutex |
Mutex for log thread. More... | |
bool | restarting = false |
Signals if the controller is shutting down (false) or restarting (true). More... | |
std::map< sessIndex, statSession > | sessions |
list of sessions that have statistics data available More... | |
tthread::mutex | statsMutex |
JSON::Value | Storage |
Global storage of data. More... | |
std::string | uniqId |
JSON::Value | updates |
Holds everything unique to the controller.
void Controller::AddStreams | ( | JSON::Value & | in, |
JSON::Value & | out | ||
) |
"STREAM_ADD"
trigger is stream-specific, and is ran whenever a new stream is added to the server configuration.If cancelled, the stream is not added. Its payload is:
The "STREAM_CONFIG"
trigger is stream-specific, and is ran whenever a stream's configuration is changed. If cancelled, the configuration is not changed. Its payload is:
bool Controller::authorize | ( | JSON::Value & | Request, |
JSON::Value & | Response, | ||
Socket::Connection & | conn | ||
) |
Checks an authorization request for a given user.
Request | The request to be parsed. |
Response | The location to store the generated response. |
conn | The user to be checked for authorization. |
"authorize"
request must be sent. Since HTTP does not use persistent connections, you are required to re-sent authentication with every API request made. To prevent plaintext sending of the password, a random challenge string is sent first, and then the password is hashed together with this challenge string to create a one-time-use string to login with. If the user is not authorized, this request is the only request the server will respond to until properly authorized. "authorize"
requests take the form of: "NOACC"
, where it is left out. A status of "OK"
means you are currently logged in and have access to all other API requests. A status of "CHALL"
means you are not logged in, and a challenge has been provided to login with. A status of "NOACC"
means there are no valid accounts to login with. In this case - and ONLY in this case - it is possible to create a initial login through the API itself. To do so, send a request as follows: "ACC_MADE"
indicates the account was created successfully and can now be used to login as normal.
|
inlinestatic |
|
inlinestatic |
bool Controller::CheckAllStreams | ( | JSON::Value & | data | ) |
Checks all streams, restoring if needed.
data | The stream configuration for the server. |
void Controller::checkAvailProtocols | ( | ) |
Aquire list of available protocols, storing in global 'capabilities' JSON::Value.
void Controller::checkCapable | ( | JSON::Value & | capa | ) |
Checks the capabilities of the system.
capa | The location to store the capabilities. |
"capabilities"
requests are always empty: void Controller::checkConfig | ( | JSON::Value & | in, |
JSON::Value & | out | ||
) |
Check the submitted configuration and handle things accordingly.
in | The new configuration. |
out | The location to store the resulting configuration. |
"config"
requests take the form of: bool Controller::CheckProtocols | ( | JSON::Value & | p, |
const JSON::Value & | capabilities | ||
) |
Checks current protocol configuration, updates state of enabled connectors if neccessary.
Checks current protocol configuration, updates state of enabled connectors if neccesary.
p | An object containing all protocols. |
capabilities | An object containing the detected capabilities. |
"OUTPUT_START"
trigger is global, and is ran whenever a new protocol listener is started. It cannot be cancelled. Its payload is: "OUTPUT_STOP"
trigger is global, and is ran whenever a protocol listener is terminated. It cannot be cancelled. Its payload is: void Controller::checkServerLimits | ( | ) |
void Controller::checkStream | ( | std::string | name, |
JSON::Value & | data | ||
) |
Checks the validity of a stream, updates internal stream status.
name | The name of the stream |
data | The corresponding configuration values. |
void Controller::checkStreamLimits | ( | std::string | streamName, |
long long | currentKbps, | ||
long long | connectedUsers | ||
) |
void Controller::CheckStreams | ( | JSON::Value & | in, |
JSON::Value & | out | ||
) |
Parse a given stream configuration.
in | The requested configuration. |
out | The new configuration after parsing. |
"streams"
requests take the form of: JSON::Value Controller::CheckUpdateInfo | ( | ) |
"update"
and "checkupdate"
requests (LTS-only) are responded to as: ~~~~~~~~~~~~~~~{.js} { "error": "Something went wrong", // 'Optional' "release": "LTS64_99", "version": "1.2 / 6.0.0", "date": "January 5th, 2014", "uptodate": 0, "needs_update": ["MistBuffer", "MistController"], //Controller is guaranteed to be last "MistController": "abcdef1234567890", //md5 sum of latest version //...all other MD5 sums follow } ~~~~~~~~~~~~~~~ Note that "update"
will only list known information, while "checkupdate"
triggers an information refresh from the update server.
void Controller::CheckUpdates | ( | ) |
Calls CheckUpdateInfo(), uses the resulting JSON::Value to download any needed updates.
Will shut down the server if the JSON::Value contained a "shutdown" member.
void Controller::deleteStream | ( | const std::string & | name, |
JSON::Value & | out | ||
) |
"STREAM_REMOVE"
trigger is stream-specific, and is ran whenever a stream is removed from the server configuration.If cancelled, the stream is not removed. Its payload is:
void Controller::fillActive | ( | JSON::Value & | req, |
JSON::Value & | rep, | ||
bool | onlyNow = false |
||
) |
This takes a "active_streams" request, and fills in the response data.
"active_streams"
and "stats_streams"
requests may either be empty, in which case the response looks like this: "stats_streams"
will list all streams that any statistics data is available for, and only those. "active_streams"
only lists streams that are currently active, and only those. If the request is an array, which may contain any of the following elements: void Controller::fillClients | ( | JSON::Value & | req, |
JSON::Value & | rep | ||
) |
This takes a "clients" request, and fills in the response data.
"clients"
requests take the form of: void Controller::fillTotals | ( | JSON::Value & | req, |
JSON::Value & | rep | ||
) |
This takes a "totals" request, and fills in the response data.
"totals"
requests take the form of: std::string Controller::getCountry | ( | std::string | ip | ) |
int Controller::handleAPIConnection | ( | Socket::Connection & | conn | ) |
Handles a single incoming API connection.
Assumes the connection is unauthorized and will allow for 4 requests without authorization before disconnecting.
"addstream"
requests (LTS-only) take the form of: "addstream"
or "deletestream"
as part of your request will alter the "streams"
response. As opposed to a full list of streams, this will now include a property "incomplete list"
set to 1 and only include successfully added streams. As deletions cannot fail, these are never mentioned. "deletestream"
requests (LTS-only) take the form of: "addstream"
or "deletestream"
as part of your request will alter the "streams"
response. As opposed to a full list of streams, this will now include a property "incomplete list"
set to 1 and only include successfully added streams. As deletions cannot fail, these are never mentioned. "addprotocol"
requests (LTS-only) take the form of: "deleteprotocol"
requests (LTS-only) take the form of: This takes a "browse" request, and fills in the response data.
"browse"
requests take the form of: "save"
requests are always empty: ./config.json
). "ui_settings"
requests can take two forms. The first is the "set" form: "LTS"
response, set to 1. "autoupdate"
requests (LTS-only) will cause MistServer to apply a rolling update to itself, and are not responded to. "log"
responses are always sent, and cannot be requested: "clearstatlogs"
request. void Controller::handleMsg | ( | void * | err | ) |
Handles output of a Mist application, detecting and catching debug messages.
Debug messages are automatically converted into Log messages. Closes the file descriptor on read error.
err | File descriptor of the stderr output of the process to monitor. |
bool Controller::hasViewers | ( | std::string | streamName | ) |
Returns true if this stream has at least one connected client.
std::string Controller::hostLookup | ( | std::string | ip | ) |
bool Controller::isBlacklisted | ( | std::string | host, |
std::string | streamName, | ||
int | timeConnected | ||
) |
void Controller::killStatistics | ( | char * | data, |
size_t | len, | ||
unsigned int | id | ||
) |
Forces a disconnect to all users.
void Controller::Log | ( | std::string | kind, |
std::string | message | ||
) |
Store and print a log message.
kind | The type of message. |
message | The message to be logged. |
bool Controller::onList | ( | std::string | ip, |
std::string | list | ||
) |
void Controller::parseStatistics | ( | char * | data, |
size_t | len, | ||
unsigned int | id | ||
) |
This function is called by the shared memory page that holds statistics.
It updates the internally saved statistics data, moving across sessions or archiving when neccessary.
std::string Controller::readFile | ( | std::string | filename | ) |
void Controller::SharedMemStats | ( | void * | config | ) |
This function runs as a thread and roughly once per second retrieves statistics from all connected clients, as well as wipes old statistics that have disconnected over 10 minutes ago.
bool Controller::streamsEqual | ( | JSON::Value & | one, |
JSON::Value & | two | ||
) |
Checks whether two streams are equal.
one | The first stream for the comparison. |
two | The second stream for the comparison. |
void Controller::updateComponent | ( | const std::string & | component, |
const std::string & | md5sum, | ||
Socket::Connection & | updrConn | ||
) |
Attempts to download an update for the listed component.
component | Filename of the component being checked. |
md5sum | The MD5 sum of the latest version of this file. |
updrConn | An connection to releases.mistserver.org to (re)use. Will be (re)opened if closed. |
void Controller::UpdateProtocol | ( | std::string | protocol | ) |
Checks if the binary mentioned in the protocol argument is currently active, if so, restarts it.
protocol | The protocol to check. |
void Controller::uplinkConnection | ( | void * | np | ) |
void Controller::writeConfig | ( | ) |
Writes the current config to shared memory to be used in other processes.
"SYSTEM_START"
trigger is global, and is ran as soon as the server configuration is first stable.It has no payload. If cancelled, the system immediately shuts down again.
The "SYSTEM_CONFIG"
trigger is global, and is ran every time the server configuration is updated. Its payload is the new configuration in JSON format. This trigger cannot be cancelled.
bool Controller::WriteFile | ( | std::string | Filename, |
std::string | contents | ||
) |
Write contents to Filename.
Filename | The full path of the file to write to. |
contents | The data to be written to the file. |
bool Controller::writeFile | ( | std::string | filename, |
std::string & | contents | ||
) |
JSON::Value Controller::capabilities |
Global storage of capabilities.
Util::Config Controller::conf |
Global storage of configuration.
tthread::mutex Controller::configMutex |
Mutex for server config access.
std::map< unsigned long, Controller::sessIndex > Controller::connToSession |
Map of socket IDs to session info.
|
static |
The currently running connectors.
std::map<std::string, pid_t> Controller::inputProcesses |
bool Controller::killOnExit = KILL_ON_EXIT |
tthread::mutex Controller::logMutex |
Mutex for log thread.
bool Controller::restarting = false |
Signals if the controller is shutting down (false) or restarting (true).
std::map< Controller::sessIndex, Controller::statSession > Controller::sessions |
list of sessions that have statistics data available
tthread::mutex Controller::statsMutex |
JSON::Value Controller::Storage |
Global storage of data.
std::string Controller::uniqId |
JSON::Value Controller::updates |