Cadabra
Computer algebra system for field theory problems
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
snoop::SnoopImpl Class Reference

#include <SnoopPrivate.hh>

Public Member Functions

 SnoopImpl (Snoop *)
 
 ~SnoopImpl ()
 
Snoopoperator<< (const Flush &)
 
void init (const std::string &app_name, const std::string &app_version, std::string server="", std::string local_database_name="")
 Initialise the logging stream. More...
 
std::string get_user_uuid (const std::string &app_name)
 Get a string which uniquely identifies the current user. More...
 
Snooppayload (const std::vector< char > &)
 Log payload data. More...
 
Snoopoperator() (const std::string &type, std::string fl="", int loc=-1, std::string method="")
 Operator to initialise a logging entry with the type of. More...
 
void set_local_type (const std::string &type)
 
void sync_with_server (bool from_wsthread=false)
 Ensure that the local database is synchronised with the. More...
 
void sync_runs_with_server (bool from_wsthread=false)
 As above, but only for run entries. More...
 
void sync_logs_with_server (bool from_wsthread=false)
 As above, but only for log entries. More...
 
void sync_payloads_with_server (bool from_wsthread=false)
 As above, but only for payload data. More...
 
bool is_connected () const
 Are we connected to the log server? More...
 
std::string last_seen_version (std::string machine_id)
 Return version of last run seen on given device. More...
 
bool authenticate (std::function< void(std::string, bool)>, std::string user="", std::string pass="")
 Authentication logic; passes ticket or credentials to server, and registers callback function for when the response comes back. More...
 
bool is_ticket_valid (std::string ticket_uuid)
 Get status of a given authentication ticket. More...
 
std::string ticket_for_login (std::string user, std::string password)
 Get status of given user/pass combo. More...
 
bool add_user (std::string user, std::string password)
 Add a user/password combo to the user database. More...
 
void start_websocket_client ()
 Start the websocket client. More...
 
void create_tables ()
 Ensure that the required tables are present in the database file. More...
 
void create_authentication_tables ()
 Ensure that the required authentication tables are present in the authentication database. More...
 
void obtain_uuid ()
 Obtain a uuid by finding the last AppEntry stored in the local database. More...
 
bool store_app_entry (Snoop::AppEntry &)
 Store an app entry in the database. More...
 
bool store_app_entry_without_lock (Snoop::AppEntry &)
 
bool store_log_entry (Snoop::LogEntry &, bool avoid_server_duplicates)
 Store a log entry in the local database. More...
 
bool store_payload_entry (Snoop::PayLoad &)
 Store payload data in the local database. More...
 
std::vector< Snoop::AppEntryget_app_registrations (std::string uuid_filter="")
 Return a vector of all aps registered in the database. More...
 
void on_client_open (websocketpp::connection_hdl hdl)
 
void on_client_fail (websocketpp::connection_hdl hdl)
 
void on_client_close (websocketpp::connection_hdl hdl)
 
void on_client_message (websocketpp::connection_hdl hdl, message_ptr msg)
 

Public Attributes

Snoopsnoop_
 
sqlite3 * db
 
sqlite3 * payload_db
 
sqlite3 * auth_db
 
Snoop::AppEntry this_app_
 
Snoop::LogEntry this_log_
 
std::string server_
 
sqlite3_stmt * insert_statement
 Prepared statements (only need to prepare these once). More...
 
sqlite3_stmt * id_for_uuid_statement
 
sqlite3_stmt * payload_insert_statement
 
std::mutex sqlite_mutex
 
WebsocketClient wsclient
 Websocket client to talk to a remote logging server. More...
 
std::thread wsclient_thread
 
std::mutex connection_mutex
 
std::condition_variable connection_cv
 
bool connection_is_open
 
bool connection_attempt_failed
 
WebsocketClient::connection_ptr connection
 
websocketpp::connection_hdl our_connection_hdl
 

Private Member Functions

void store_ticket (std::string ticket_uuid, int user_id, bool valid)
 

Private Attributes

std::mutex call_mutex
 
bool secure
 
std::set< std::string > local_types
 
std::function< void(std::string, bool)> authentication_callback
 

Constructor & Destructor Documentation

◆ SnoopImpl()

snoop::SnoopImpl::SnoopImpl ( Snoop )

◆ ~SnoopImpl()

snoop::SnoopImpl::~SnoopImpl ( )

Member Function Documentation

◆ add_user()

bool snoop::SnoopImpl::add_user ( std::string  user,
std::string  password 
)

Add a user/password combo to the user database.

◆ authenticate()

bool snoop::SnoopImpl::authenticate ( std::function< void(std::string, bool)>  ,
std::string  user = "",
std::string  pass = "" 
)

Authentication logic; passes ticket or credentials to server, and registers callback function for when the response comes back.

◆ create_authentication_tables()

void snoop::SnoopImpl::create_authentication_tables ( )

Ensure that the required authentication tables are present in the authentication database.

Only used on the server.

◆ create_tables()

void snoop::SnoopImpl::create_tables ( )

Ensure that the required tables are present in the database file.

◆ get_app_registrations()

std::vector<Snoop::AppEntry> snoop::SnoopImpl::get_app_registrations ( std::string  uuid_filter = "")

Return a vector of all aps registered in the database.

If the uuid filter is non-empty, will filter on the given uuid.

◆ get_user_uuid()

std::string snoop::SnoopImpl::get_user_uuid ( const std::string &  app_name)

Get a string which uniquely identifies the current user.

This is stored in ~/.config/snoop/appname.conf.

◆ init()

void snoop::SnoopImpl::init ( const std::string &  app_name,
const std::string &  app_version,
std::string  server = "",
std::string  local_database_name = "" 
)

Initialise the logging stream.

Should be called once at program startup, but can be called multiple times without causing problems. The 'local_database_name' should be a full path but without extension; the main database name will be this path with '.sql' added, while the payload database will have '_payload.sql' at the end.

◆ is_connected()

bool snoop::SnoopImpl::is_connected ( ) const

Are we connected to the log server?

◆ is_ticket_valid()

bool snoop::SnoopImpl::is_ticket_valid ( std::string  ticket_uuid)

Get status of a given authentication ticket.

◆ last_seen_version()

std::string snoop::SnoopImpl::last_seen_version ( std::string  machine_id)

Return version of last run seen on given device.

◆ obtain_uuid()

void snoop::SnoopImpl::obtain_uuid ( )

Obtain a uuid by finding the last AppEntry stored in the local database.

Will attempt to re-turn a previously generated uuid but will do so only if one is stored for the current pid; if no entry with the current pid is stored then a new one will always be generated.

◆ on_client_close()

void snoop::SnoopImpl::on_client_close ( websocketpp::connection_hdl  hdl)

◆ on_client_fail()

void snoop::SnoopImpl::on_client_fail ( websocketpp::connection_hdl  hdl)

◆ on_client_message()

void snoop::SnoopImpl::on_client_message ( websocketpp::connection_hdl  hdl,
message_ptr  msg 
)

◆ on_client_open()

void snoop::SnoopImpl::on_client_open ( websocketpp::connection_hdl  hdl)

◆ operator()()

Snoop& snoop::SnoopImpl::operator() ( const std::string &  type,
std::string  fl = "",
int  loc = -1,
std::string  method = "" 
)

Operator to initialise a logging entry with the type of.

the log message as well as (optionally) the file, line number and method. Thread-safe: can be called from different threads at the same time.

◆ operator<<()

Snoop& snoop::SnoopImpl::operator<< ( const Flush )

◆ payload()

Snoop& snoop::SnoopImpl::payload ( const std::vector< char > &  )

Log payload data.

◆ set_local_type()

void snoop::SnoopImpl::set_local_type ( const std::string &  type)

◆ start_websocket_client()

void snoop::SnoopImpl::start_websocket_client ( )

Start the websocket client.

This tries to connect to the server and then waits in a separate thread until the server sends us something (typically in response to something the main thread makes by calling wsclient.send).

◆ store_app_entry()

bool snoop::SnoopImpl::store_app_entry ( Snoop::AppEntry )

Store an app entry in the database.

Will update the 'id' field in the AppEntry.

◆ store_app_entry_without_lock()

bool snoop::SnoopImpl::store_app_entry_without_lock ( Snoop::AppEntry )

◆ store_log_entry()

bool snoop::SnoopImpl::store_log_entry ( Snoop::LogEntry ,
bool  avoid_server_duplicates 
)

Store a log entry in the local database.

Generates its own receive_millis field (the one given gets overwritten). Will update the 'id' field in the LogEntry. Returns 'true' if the entry was stored, or 'false' if an entry with this client_log_id was already present (except when it is 0).

◆ store_payload_entry()

bool snoop::SnoopImpl::store_payload_entry ( Snoop::PayLoad )

Store payload data in the local database.

◆ store_ticket()

void snoop::SnoopImpl::store_ticket ( std::string  ticket_uuid,
int  user_id,
bool  valid 
)
private

◆ sync_logs_with_server()

void snoop::SnoopImpl::sync_logs_with_server ( bool  from_wsthread = false)

As above, but only for log entries.

◆ sync_payloads_with_server()

void snoop::SnoopImpl::sync_payloads_with_server ( bool  from_wsthread = false)

As above, but only for payload data.

◆ sync_runs_with_server()

void snoop::SnoopImpl::sync_runs_with_server ( bool  from_wsthread = false)

As above, but only for run entries.

◆ sync_with_server()

void snoop::SnoopImpl::sync_with_server ( bool  from_wsthread = false)

Ensure that the local database is synchronised with the.

server (this sends multiple app or log entries in one websocket message). Leave the bool argument at its default argument under all normal circumstances.

◆ ticket_for_login()

std::string snoop::SnoopImpl::ticket_for_login ( std::string  user,
std::string  password 
)

Get status of given user/pass combo.

This queries the underlying authentication database table. If the login is valid, a ticket will be inserted in the database and returned. An empty string is returned if login is invalid.

Member Data Documentation

◆ auth_db

sqlite3 * snoop::SnoopImpl::auth_db

◆ authentication_callback

std::function<void (std::string, bool)> snoop::SnoopImpl::authentication_callback
private

◆ call_mutex

std::mutex snoop::SnoopImpl::call_mutex
private

◆ connection

WebsocketClient::connection_ptr snoop::SnoopImpl::connection

◆ connection_attempt_failed

bool snoop::SnoopImpl::connection_attempt_failed

◆ connection_cv

std::condition_variable snoop::SnoopImpl::connection_cv

◆ connection_is_open

bool snoop::SnoopImpl::connection_is_open

◆ connection_mutex

std::mutex snoop::SnoopImpl::connection_mutex

◆ db

sqlite3* snoop::SnoopImpl::db

◆ id_for_uuid_statement

sqlite3_stmt * snoop::SnoopImpl::id_for_uuid_statement

◆ insert_statement

sqlite3_stmt* snoop::SnoopImpl::insert_statement

Prepared statements (only need to prepare these once).

◆ local_types

std::set<std::string> snoop::SnoopImpl::local_types
private

◆ our_connection_hdl

websocketpp::connection_hdl snoop::SnoopImpl::our_connection_hdl

◆ payload_db

sqlite3 * snoop::SnoopImpl::payload_db

◆ payload_insert_statement

sqlite3_stmt * snoop::SnoopImpl::payload_insert_statement

◆ secure

bool snoop::SnoopImpl::secure
private

◆ server_

std::string snoop::SnoopImpl::server_

◆ snoop_

Snoop* snoop::SnoopImpl::snoop_

◆ sqlite_mutex

std::mutex snoop::SnoopImpl::sqlite_mutex

◆ this_app_

Snoop::AppEntry snoop::SnoopImpl::this_app_

◆ this_log_

Snoop::LogEntry snoop::SnoopImpl::this_log_

◆ wsclient

WebsocketClient snoop::SnoopImpl::wsclient

Websocket client to talk to a remote logging server.

◆ wsclient_thread

std::thread snoop::SnoopImpl::wsclient_thread

The documentation for this class was generated from the following file: