1
0
Fork 0
mirror of https://github.com/fastogt/fastocloud.git synced 2025-02-12 12:11:51 +00:00

New protocol

This commit is contained in:
Topilski 2024-12-26 09:06:54 +03:00
parent 1156584283
commit 9bbf38717a
33 changed files with 846 additions and 1321 deletions

View file

@ -1,7 +1,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.16 FATAL_ERROR) CMAKE_MINIMUM_REQUIRED(VERSION 3.16 FATAL_ERROR)
SET(BRANDING_PROJECT_NAME "fastocloud" CACHE STRING "Branding for ${BRANDING_PROJECT_NAME}") #default SET(BRANDING_PROJECT_NAME "fastocloud" CACHE STRING "Branding for ${BRANDING_PROJECT_NAME}") #default
SET(BRANDING_PROJECT_VERSION "1.4.4.17" CACHE STRING "Branding version for ${BRANDING_PROJECT_NAME}") #default SET(BRANDING_PROJECT_VERSION "1.5.0.18" CACHE STRING "Branding version for ${BRANDING_PROJECT_NAME}") #default
SET(BRANDING_PROJECT_BUILD_TYPE_VERSION "release" CACHE STRING "Build version type for ${BRANDING_PROJECT_NAME}") #default alfa,beta,rc,release SET(BRANDING_PROJECT_BUILD_TYPE_VERSION "release" CACHE STRING "Build version type for ${BRANDING_PROJECT_NAME}") #default alfa,beta,rc,release
SET(BRANDING_PROJECT_DOMAIN "www.fastogt.com" CACHE STRING "Branding domain url for ${BRANDING_PROJECT_NAME}") #default SET(BRANDING_PROJECT_DOMAIN "www.fastogt.com" CACHE STRING "Branding domain url for ${BRANDING_PROJECT_NAME}") #default
SET(BRANDING_PROJECT_COMPANYNAME "FastoGT" CACHE STRING "Company name for ${BRANDING_PROJECT_NAME}") #default SET(BRANDING_PROJECT_COMPANYNAME "FastoGT" CACHE STRING "Company name for ${BRANDING_PROJECT_NAME}") #default

View file

@ -109,7 +109,6 @@ SET(SERVER_DAEMON_HEADERS
${CMAKE_SOURCE_DIR}/src/server/daemon/client.h ${CMAKE_SOURCE_DIR}/src/server/daemon/client.h
${CMAKE_SOURCE_DIR}/src/server/daemon/server.h ${CMAKE_SOURCE_DIR}/src/server/daemon/server.h
${CMAKE_SOURCE_DIR}/src/server/daemon/commands.h ${CMAKE_SOURCE_DIR}/src/server/daemon/commands.h
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_factory.h
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/details/shots.h ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/details/shots.h
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/server_info.h ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/server_info.h
@ -126,7 +125,6 @@ SET(SERVER_DAEMON_SOURCES
${CMAKE_SOURCE_DIR}/src/server/daemon/client.cpp ${CMAKE_SOURCE_DIR}/src/server/daemon/client.cpp
${CMAKE_SOURCE_DIR}/src/server/daemon/server.cpp ${CMAKE_SOURCE_DIR}/src/server/daemon/server.cpp
${CMAKE_SOURCE_DIR}/src/server/daemon/commands.cpp ${CMAKE_SOURCE_DIR}/src/server/daemon/commands.cpp
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_factory.cpp
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/details/shots.cpp ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/details/shots.cpp
${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/server_info.cpp ${CMAKE_SOURCE_DIR}/src/server/daemon/commands_info/service/server_info.cpp

View file

@ -12,259 +12,326 @@
along with fastocloud. If not, see <http://www.gnu.org/licenses/>. along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <memory>
#include "server/daemon/client.h" #include "server/daemon/client.h"
#include "server/daemon/commands_factory.h" #include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <common/json/json.h>
#include <common/daemon/commands/restart_info.h>
#include <common/daemon/commands/stop_info.h>
namespace {
const std::string kErrorInvalid = "{\"error\":{\"code\":-1, \"message\":\"NOTREACHED\"}}";
const auto kDataOK = common::json::MakeSuccessDataJson();
} // namespace
namespace fastocloud { namespace fastocloud {
namespace server { namespace server {
ProtocoledDaemonClient::ProtocoledDaemonClient(common::libev::IoLoop* server, const common::net::socket_info& info) ProtocoledDaemonClient::ProtocoledDaemonClient(common::libev::IoLoop* server, const common::net::socket_info& info)
: base_class(std::make_shared<fastotv::protocol::FastoTVCompressor>(), server, info) {} : base_class(server, info), is_verified_(false), exp_time_(0) {}
common::ErrnoError ProtocoledDaemonClient::StopMe() { bool ProtocoledDaemonClient::IsVerified() const {
const common::daemon::commands::StopInfo stop_req; return is_verified_;
fastotv::protocol::request_t req; }
common::Error err_ser = StopServiceRequest(NextRequestID(), stop_req, &req);
common::time64_t ProtocoledDaemonClient::GetExpTime() const {
return exp_time_;
}
void ProtocoledDaemonClient::SetVerified(bool verified, common::time64_t exp_time) {
is_verified_ = verified;
exp_time_ = exp_time;
}
bool ProtocoledDaemonClient::IsExpired() const {
return exp_time_ < common::time::current_utc_mstime();
}
bool ProtocoledDaemonClient::HaveFullAccess() const {
return IsVerified() && !IsExpired();
}
common::http::http_protocol ProtocoledDaemonClient::GetProtocol() const {
return common::http::HP_1_0;
}
common::libev::http::HttpServerInfo ProtocoledDaemonClient::GetServerInfo() const {
return common::libev::http::HttpServerInfo();
}
common::ErrnoError ProtocoledDaemonClient::StopMe(const common::uri::GURL& url) {
const common::daemon::commands::StopInfo params;
std::string result;
common::Error err_ser = params.SerializeToString(&result);
if (err_ser) { if (err_ser) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN); return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
} }
return WriteRequest(req); return PostJson(url, result.c_str(), result.size(), false);
} }
common::ErrnoError ProtocoledDaemonClient::RestartMe() { common::ErrnoError ProtocoledDaemonClient::Broadcast(const common::json::WsDataJson& request) {
const common::daemon::commands::RestartInfo stop_req; std::string result;
fastotv::protocol::request_t req; ignore_result(request.SerializeToString(&result));
common::Error err_ser = RestartServiceRequest(NextRequestID(), stop_req, &req); return SendFrame(result.c_str(), result.size());
}
common::ErrnoError ProtocoledDaemonClient::RestartMe(const common::uri::GURL& url) {
const common::daemon::commands::RestartInfo params;
std::string result;
common::Error err_ser = params.SerializeToString(&result);
if (err_ser) { if (err_ser) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN); return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
} }
return PostJson(url, result.c_str(), result.size(), false);
return WriteRequest(req);
} }
common::ErrnoError ProtocoledDaemonClient::StopFail(fastotv::protocol::sequance_id_t id, common::Error err) { common::ErrnoError ProtocoledDaemonClient::StopFail(common::http::http_status code, common::Error err) {
const std::string error_str = err->GetDescription(); return SendErrorJson(code, err);
fastotv::protocol::response_t resp; }
common::Error err_ser = StopServiceResponseFail(id, error_str, &resp);
common::ErrnoError ProtocoledDaemonClient::StopSuccess() {
return SendDataJson(common::http::HS_OK, kDataOK);
}
common::ErrnoError ProtocoledDaemonClient::RestartFail(common::http::http_status code, common::Error err) {
return SendErrorJson(code, err);
}
common::ErrnoError ProtocoledDaemonClient::RestartSuccess() {
return SendDataJson(common::http::HS_OK, kDataOK);
}
common::ErrnoError ProtocoledDaemonClient::GetHardwareHashFail(common::http::http_status code, common::Error err) {
return SendErrorJson(code, err);
}
common::ErrnoError ProtocoledDaemonClient::GetHardwareHashSuccess(
const common::daemon::commands::HardwareHashInfo& params) {
json_object* jrequest_init = nullptr;
common::Error err_ser = params.Serialize(&jrequest_init);
if (err_ser) { if (err_ser) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN); return GetHardwareHashFail(common::http::HS_INTERNAL_ERROR, err_ser);
} }
return WriteResponse(resp); std::string result;
} common::json::DataJson js = common::json::MakeSuccessDataJson(jrequest_init); // take ownerships
err_ser = js.SerializeToString(&result);
common::ErrnoError ProtocoledDaemonClient::StopSuccess(fastotv::protocol::sequance_id_t id) {
fastotv::protocol::response_t resp;
common::Error err_ser = StopServiceResponseSuccess(id, &resp);
if (err_ser) { if (err_ser) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN); return GetHardwareHashFail(common::http::HS_INTERNAL_ERROR, err_ser);
} }
return WriteResponse(resp); return SendDataJson(common::http::HS_OK, js);
} }
common::ErrnoError ProtocoledDaemonClient::Ping() { common::ErrnoError ProtocoledDaemonClient::GetStatsFail(common::http::http_status code, common::Error err) {
common::daemon::commands::ClientPingInfo server_ping_info; return SendErrorJson(code, err);
return Ping(server_ping_info);
} }
common::ErrnoError ProtocoledDaemonClient::Ping(const common::daemon::commands::ClientPingInfo& server_ping_info) { common::ErrnoError ProtocoledDaemonClient::GetStatsSuccess(const service::FullServiceInfo& stats) {
fastotv::protocol::request_t ping_request; json_object* jrequest_init = nullptr;
common::Error err_ser = PingRequest(NextRequestID(), server_ping_info, &ping_request); common::Error err_ser = stats.Serialize(&jrequest_init);
if (err_ser) { if (err_ser) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN); return GetHardwareHashFail(common::http::HS_INTERNAL_ERROR, err_ser);
} }
return WriteRequest(ping_request); std::string result;
} common::json::DataJson js = common::json::MakeSuccessDataJson(jrequest_init); // take ownerships
err_ser = js.SerializeToString(&result);
common::ErrnoError ProtocoledDaemonClient::PongFail(fastotv::protocol::sequance_id_t id, common::Error err) {
const std::string error_str = err->GetDescription();
fastotv::protocol::response_t resp;
common::Error err_ser = PingServiceResponseFail(id, error_str, &resp);
if (err_ser) { if (err_ser) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN); return GetStatsFail(common::http::HS_INTERNAL_ERROR, err_ser);
} }
return WriteResponse(resp); return SendDataJson(common::http::HS_OK, js);
} }
common::ErrnoError ProtocoledDaemonClient::Pong(fastotv::protocol::sequance_id_t id) { common::ErrnoError ProtocoledDaemonClient::GetLogServiceFail(common::http::http_status code, common::Error err) {
common::daemon::commands::ServerPingInfo server_ping_info; return SendErrorJson(code, err);
return Pong(id, server_ping_info);
} }
common::ErrnoError ProtocoledDaemonClient::Pong(fastotv::protocol::sequance_id_t id, common::ErrnoError ProtocoledDaemonClient::GetLogServiceSuccess(const std::string& path) {
const common::daemon::commands::ServerPingInfo& pong) { const char* file_path_str_ptr = path.c_str();
fastotv::protocol::response_t resp; struct stat sb;
common::Error err_ser = PingServiceResponseSuccess(id, pong, &resp); if (stat(file_path_str_ptr, &sb) < 0) {
if (err_ser) { return GetLogServiceFail(common::http::HS_FORBIDDEN, common::make_error("File not found."));
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
}
return WriteResponse(resp);
}
common::ErrnoError ProtocoledDaemonClient::ActivateFail(fastotv::protocol::sequance_id_t id, common::Error err) {
const std::string error_str = err->GetDescription();
fastotv::protocol::response_t resp;
common::Error err_ser = ActivateResponseFail(id, error_str, &resp);
if (err_ser) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
} }
return WriteResponse(resp); if (S_ISDIR(sb.st_mode)) {
} return GetLogServiceFail(common::http::HS_FORBIDDEN, common::make_error("Bad filename."));
common::ErrnoError ProtocoledDaemonClient::ActivateSuccess(fastotv::protocol::sequance_id_t id,
const std::string& result) {
fastotv::protocol::response_t resp;
common::Error err_ser = ActivateResponseSuccess(id, result, &resp);
if (err_ser) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
} }
return WriteResponse(resp); int file = open(file_path_str_ptr, O_RDONLY);
} if (file == INVALID_DESCRIPTOR) { /* open the file for reading */
return GetLogServiceFail(common::http::HS_FORBIDDEN, common::make_error("File is protected."));
common::ErrnoError ProtocoledDaemonClient::GetLogServiceFail(fastotv::protocol::sequance_id_t id, common::Error err) {
const std::string error_str = err->GetDescription();
fastotv::protocol::response_t resp;
common::Error err_ser = GetLogServiceResponseFail(id, error_str, &resp);
if (err_ser) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
} }
return WriteResponse(resp); size_t cast = sb.st_size;
} common::ErrnoError err = SendHeadersInternal(common::http::HS_OK, "text/plain", &cast, &sb.st_mtime);
if (err) {
common::ErrnoError ProtocoledDaemonClient::GetLogServiceSuccess(fastotv::protocol::sequance_id_t id) { ::close(file);
fastotv::protocol::response_t resp; return GetLogServiceFail(common::http::HS_INTERNAL_ERROR, common::make_error(err->GetDescription()));
common::Error err_ser = GetLogServiceResponseSuccess(id, &resp);
if (err_ser) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
} }
return WriteResponse(resp); err = SendFileByFd(file, sb.st_size);
::close(file);
return err;
} }
common::ErrnoError ProtocoledDaemonClient::GetLogStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) { common::ErrnoError ProtocoledDaemonClient::GetLogStreamFail(common::http::http_status code, common::Error err) {
const std::string error_str = err->GetDescription(); return SendErrorJson(code, err);
fastotv::protocol::response_t resp;
common::Error err_ser = GetLogStreamResponseFail(id, error_str, &resp);
if (err_ser) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
}
return WriteResponse(resp);
} }
common::ErrnoError ProtocoledDaemonClient::GetLogStreamSuccess(fastotv::protocol::sequance_id_t id) { common::ErrnoError ProtocoledDaemonClient::GetLogStreamSuccess(const std::string& path) {
fastotv::protocol::response_t resp; const char* file_path_str_ptr = path.c_str();
common::Error err_ser = GetLogStreamResponseSuccess(id, &resp); struct stat sb;
if (err_ser) { if (stat(file_path_str_ptr, &sb) < 0) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN); return GetLogStreamFail(common::http::HS_FORBIDDEN, common::make_error("File not found."));
} }
return WriteResponse(resp); if (S_ISDIR(sb.st_mode)) {
return GetLogStreamFail(common::http::HS_FORBIDDEN, common::make_error("Bad filename."));
}
int file = open(file_path_str_ptr, O_RDONLY);
if (file == INVALID_DESCRIPTOR) { /* open the file for reading */
return GetLogStreamFail(common::http::HS_FORBIDDEN, common::make_error("File is protected."));
}
size_t cast = sb.st_size;
common::ErrnoError err = SendHeadersInternal(common::http::HS_OK, "text/plain", &cast, &sb.st_mtime);
if (err) {
::close(file);
return GetLogStreamFail(common::http::HS_INTERNAL_ERROR, common::make_error(err->GetDescription()));
}
err = SendFileByFd(file, sb.st_size);
::close(file);
return err;
} }
common::ErrnoError ProtocoledDaemonClient::GetPipeStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) { common::ErrnoError ProtocoledDaemonClient::GetPipeStreamFail(common::http::http_status code, common::Error err) {
const std::string error_str = err->GetDescription(); return SendErrorJson(code, err);
fastotv::protocol::response_t resp;
common::Error err_ser = GetPipeStreamResponseFail(id, error_str, &resp);
if (err_ser) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
}
return WriteResponse(resp);
} }
common::ErrnoError ProtocoledDaemonClient::GetPipeStreamSuccess(fastotv::protocol::sequance_id_t id) { common::ErrnoError ProtocoledDaemonClient::GetPipeStreamSuccess(const std::string& path) {
fastotv::protocol::response_t resp; const char* file_path_str_ptr = path.c_str();
common::Error err_ser = GetPipeStreamResponseSuccess(id, &resp); struct stat sb;
if (err_ser) { if (stat(file_path_str_ptr, &sb) < 0) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN); return GetLogStreamFail(common::http::HS_FORBIDDEN, common::make_error("File not found."));
} }
return WriteResponse(resp); if (S_ISDIR(sb.st_mode)) {
return GetLogStreamFail(common::http::HS_FORBIDDEN, common::make_error("Bad filename."));
}
int file = open(file_path_str_ptr, O_RDONLY);
if (file == INVALID_DESCRIPTOR) { /* open the file for reading */
return GetLogStreamFail(common::http::HS_FORBIDDEN, common::make_error("File is protected."));
}
size_t cast = sb.st_size;
common::ErrnoError err = SendHeadersInternal(common::http::HS_OK, "text/plain", &cast, &sb.st_mtime);
if (err) {
::close(file);
return GetLogStreamFail(common::http::HS_INTERNAL_ERROR, common::make_error(err->GetDescription()));
}
err = SendFileByFd(file, sb.st_size);
::close(file);
return err;
} }
common::ErrnoError ProtocoledDaemonClient::StartStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) { common::ErrnoError ProtocoledDaemonClient::GetConfigStreamFail(common::http::http_status code, common::Error err) {
const std::string error_str = err->GetDescription(); return SendErrorJson(code, err);
fastotv::protocol::response_t resp;
common::Error err_ser = StartStreamResponseFail(id, error_str, &resp);
if (err_ser) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
}
return WriteResponse(resp);
} }
common::ErrnoError ProtocoledDaemonClient::StartStreamSuccess(fastotv::protocol::sequance_id_t id) { common::ErrnoError ProtocoledDaemonClient::GetConfigStreamSuccess(const std::string& path) {
fastotv::protocol::response_t resp; const char* file_path_str_ptr = path.c_str();
common::Error err_ser = StartStreamResponseSuccess(id, &resp); struct stat sb;
if (err_ser) { if (stat(file_path_str_ptr, &sb) < 0) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN); return GetLogStreamFail(common::http::HS_FORBIDDEN, common::make_error("File not found."));
} }
return WriteResponse(resp); if (S_ISDIR(sb.st_mode)) {
return GetLogStreamFail(common::http::HS_FORBIDDEN, common::make_error("Bad filename."));
}
int file = open(file_path_str_ptr, O_RDONLY);
if (file == INVALID_DESCRIPTOR) { /* open the file for reading */
return GetLogStreamFail(common::http::HS_FORBIDDEN, common::make_error("File is protected."));
}
size_t cast = sb.st_size;
common::ErrnoError err =
SendHeadersInternal(common::http::HS_OK, "text/plain", &cast, &sb.st_mtime); // "application/json"
if (err) {
::close(file);
return GetLogStreamFail(common::http::HS_INTERNAL_ERROR, common::make_error(err->GetDescription()));
}
err = SendFileByFd(file, sb.st_size);
::close(file);
return err;
} }
common::ErrnoError ProtocoledDaemonClient::ReStartStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) { common::ErrnoError ProtocoledDaemonClient::StartStreamFail(common::http::http_status code, common::Error err) {
const std::string error_str = err->GetDescription(); return SendErrorJson(code, err);
fastotv::protocol::response_t resp;
common::Error err_ser = RestartStreamResponseFail(id, error_str, &resp);
if (err_ser) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
}
return WriteResponse(resp);
} }
common::ErrnoError ProtocoledDaemonClient::ReStartStreamSuccess(fastotv::protocol::sequance_id_t id) { common::ErrnoError ProtocoledDaemonClient::StartStreamSuccess() {
fastotv::protocol::response_t resp; return SendDataJson(common::http::HS_OK, kDataOK);
common::Error err_ser = RestartStreamResponseSuccess(id, &resp);
if (err_ser) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
}
return WriteResponse(resp);
} }
common::ErrnoError ProtocoledDaemonClient::StopStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) { common::ErrnoError ProtocoledDaemonClient::ReStartStreamFail(common::http::http_status code, common::Error err) {
const std::string error_str = err->GetDescription(); return SendErrorJson(code, err);
fastotv::protocol::response_t resp;
common::Error err_ser = StopStreamResponseFail(id, error_str, &resp);
if (err_ser) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
}
return WriteResponse(resp);
} }
common::ErrnoError ProtocoledDaemonClient::StopStreamSuccess(fastotv::protocol::sequance_id_t id) { common::ErrnoError ProtocoledDaemonClient::ReStartStreamSuccess() {
fastotv::protocol::response_t resp; return SendDataJson(common::http::HS_OK, kDataOK);
common::Error err_ser = StopStreamResponseSuccess(id, &resp);
if (err_ser) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN);
}
return WriteResponse(resp);
} }
common::ErrnoError ProtocoledDaemonClient::UnknownMethodError(fastotv::protocol::sequance_id_t id, common::ErrnoError ProtocoledDaemonClient::StopStreamFail(common::http::http_status code, common::Error err) {
const std::string& method) { return SendErrorJson(code, err);
fastotv::protocol::response_t resp; }
common::Error err_ser = UnknownMethodResponse(id, method, &resp);
common::ErrnoError ProtocoledDaemonClient::StopStreamSuccess() {
return SendDataJson(common::http::HS_OK, kDataOK);
}
common::ErrnoError ProtocoledDaemonClient::UnknownMethodError(common::http::http_method method,
const std::string& route) {
common::Error err =
common::make_error(common::MemSPrintf("not handled %s for route: %s", common::ConvertToString(method), route));
return SendErrorJson(common::http::HS_NOT_FOUND, err);
}
common::ErrnoError ProtocoledDaemonClient::SendHeadersInternal(common::http::http_status code,
const char* mime_type,
size_t* length,
time_t* mod) {
return SendHeaders(GetProtocol(), code, {}, mime_type, length, mod, false, GetServerInfo());
}
common::ErrnoError ProtocoledDaemonClient::SendErrorJson(common::http::http_status code, common::Error err) {
auto errj = common::json::ErrorJson(common::json::MakeErrorJsonMessage(code, err));
std::string result = kErrorInvalid;
ignore_result(errj.SerializeToString(&result));
return SendJson(GetProtocol(), code, {}, result.c_str(), result.size(), false, GetServerInfo());
}
common::ErrnoError ProtocoledDaemonClient::SendDataJson(common::http::http_status code,
const common::json::DataJson& data) {
std::string result;
common::Error err_ser = data.SerializeToString(&result);
if (err_ser) { if (err_ser) {
return common::make_errno_error(err_ser->GetDescription(), EAGAIN); return SendErrorJson(common::http::HS_INTERNAL_ERROR, err_ser);
} }
return WriteResponse(resp); return SendJson(GetProtocol(), code, {}, result.c_str(), result.size(), false, GetServerInfo());
} }
} // namespace server } // namespace server

View file

@ -14,61 +14,86 @@
#pragma once #pragma once
#include <string> #include <common/daemon/commands/hhash_info.h>
#include <common/json/json.h>
#include <common/daemon/client.h> #include <common/libev/websocket/websocket_client.h>
#include <common/daemon/commands/license_info.h>
#include <common/daemon/commands/ping_info.h>
#include <common/license/types.h> #include <common/license/types.h>
#include <fastotv/protocol/protocol.h> #include <fastotv/protocol/protocol.h>
#include <fastotv/protocol/types.h> #include <fastotv/protocol/types.h>
#include <string>
#include "server/daemon/commands_info/service/server_info.h"
namespace fastocloud { namespace fastocloud {
namespace server { namespace server {
class ProtocoledDaemonClient : public fastotv::protocol::ProtocolClient<common::daemon::DaemonClient> { class ProtocoledDaemonClient : public common::libev::websocket::WebSocketServerClient {
public: public:
typedef fastotv::protocol::ProtocolClient<common::daemon::DaemonClient> base_class; typedef common::libev::websocket::WebSocketServerClient base_class;
ProtocoledDaemonClient(common::libev::IoLoop* server, const common::net::socket_info& info); ProtocoledDaemonClient(common::libev::IoLoop* server, const common::net::socket_info& info);
common::ErrnoError StopMe() WARN_UNUSED_RESULT; bool IsVerified() const;
common::ErrnoError RestartMe() WARN_UNUSED_RESULT; void SetVerified(bool verified, common::time64_t exp_time);
common::ErrnoError StopFail(fastotv::protocol::sequance_id_t id, common::Error err) WARN_UNUSED_RESULT; common::time64_t GetExpTime() const;
common::ErrnoError StopSuccess(fastotv::protocol::sequance_id_t id) WARN_UNUSED_RESULT; bool IsExpired() const;
bool HaveFullAccess() const;
common::ErrnoError Ping() WARN_UNUSED_RESULT; common::http::http_protocol GetProtocol() const;
common::ErrnoError Ping(const common::daemon::commands::ClientPingInfo& server_ping_info) WARN_UNUSED_RESULT; common::libev::http::HttpServerInfo GetServerInfo() const;
common::ErrnoError PongFail(fastotv::protocol::sequance_id_t id, common::Error err) WARN_UNUSED_RESULT; common::ErrnoError StopMe(const common::uri::GURL& url) WARN_UNUSED_RESULT;
common::ErrnoError Pong(fastotv::protocol::sequance_id_t id) WARN_UNUSED_RESULT; common::ErrnoError RestartMe(const common::uri::GURL& url) WARN_UNUSED_RESULT;
common::ErrnoError Pong(fastotv::protocol::sequance_id_t id,
const common::daemon::commands::ServerPingInfo& pong) WARN_UNUSED_RESULT;
common::ErrnoError ActivateFail(fastotv::protocol::sequance_id_t id, common::Error err) WARN_UNUSED_RESULT; common::ErrnoError StopFail(common::http::http_status code, common::Error err) WARN_UNUSED_RESULT;
common::ErrnoError ActivateSuccess(fastotv::protocol::sequance_id_t id, const std::string& result) WARN_UNUSED_RESULT; common::ErrnoError StopSuccess() WARN_UNUSED_RESULT;
common::ErrnoError GetLogServiceFail(fastotv::protocol::sequance_id_t id, common::Error err) WARN_UNUSED_RESULT; common::ErrnoError RestartFail(common::http::http_status code, common::Error err) WARN_UNUSED_RESULT;
common::ErrnoError GetLogServiceSuccess(fastotv::protocol::sequance_id_t id) WARN_UNUSED_RESULT; common::ErrnoError RestartSuccess() WARN_UNUSED_RESULT;
common::ErrnoError GetLogStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) WARN_UNUSED_RESULT; common::ErrnoError GetHardwareHashFail(common::http::http_status code, common::Error err) WARN_UNUSED_RESULT;
common::ErrnoError GetLogStreamSuccess(fastotv::protocol::sequance_id_t id) WARN_UNUSED_RESULT; common::ErrnoError GetHardwareHashSuccess(const common::daemon::commands::HardwareHashInfo& params)
WARN_UNUSED_RESULT;
common::ErrnoError GetPipeStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) WARN_UNUSED_RESULT; common::ErrnoError GetStatsFail(common::http::http_status code, common::Error err) WARN_UNUSED_RESULT;
common::ErrnoError GetPipeStreamSuccess(fastotv::protocol::sequance_id_t id) WARN_UNUSED_RESULT; common::ErrnoError GetStatsSuccess(const service::FullServiceInfo& stats) WARN_UNUSED_RESULT;
common::ErrnoError StartStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) WARN_UNUSED_RESULT; common::ErrnoError GetLogServiceFail(common::http::http_status code, common::Error err) WARN_UNUSED_RESULT;
common::ErrnoError StartStreamSuccess(fastotv::protocol::sequance_id_t id) WARN_UNUSED_RESULT; common::ErrnoError GetLogServiceSuccess(const std::string& path) WARN_UNUSED_RESULT;
common::ErrnoError ReStartStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) WARN_UNUSED_RESULT; common::ErrnoError GetLogStreamFail(common::http::http_status code, common::Error err) WARN_UNUSED_RESULT;
common::ErrnoError ReStartStreamSuccess(fastotv::protocol::sequance_id_t id) WARN_UNUSED_RESULT; common::ErrnoError GetLogStreamSuccess(const std::string& path) WARN_UNUSED_RESULT;
common::ErrnoError StopStreamFail(fastotv::protocol::sequance_id_t id, common::Error err) WARN_UNUSED_RESULT; common::ErrnoError GetPipeStreamFail(common::http::http_status code, common::Error err) WARN_UNUSED_RESULT;
common::ErrnoError StopStreamSuccess(fastotv::protocol::sequance_id_t id) WARN_UNUSED_RESULT; common::ErrnoError GetPipeStreamSuccess(const std::string& path) WARN_UNUSED_RESULT;
common::ErrnoError UnknownMethodError(fastotv::protocol::sequance_id_t id, common::ErrnoError StartStreamFail(common::http::http_status code, common::Error err) WARN_UNUSED_RESULT;
const std::string& method) WARN_UNUSED_RESULT; common::ErrnoError StartStreamSuccess() WARN_UNUSED_RESULT;
common::ErrnoError ReStartStreamFail(common::http::http_status code, common::Error err) WARN_UNUSED_RESULT;
common::ErrnoError ReStartStreamSuccess() WARN_UNUSED_RESULT;
common::ErrnoError StopStreamFail(common::http::http_status code, common::Error err) WARN_UNUSED_RESULT;
common::ErrnoError StopStreamSuccess() WARN_UNUSED_RESULT;
common::ErrnoError GetConfigStreamFail(common::http::http_status code, common::Error err) WARN_UNUSED_RESULT;
common::ErrnoError GetConfigStreamSuccess(const std::string& path) WARN_UNUSED_RESULT;
common::ErrnoError UnknownMethodError(common::http::http_method method, const std::string& route) WARN_UNUSED_RESULT;
common::ErrnoError Broadcast(const common::json::WsDataJson& request) WARN_UNUSED_RESULT;
private:
common::ErrnoError SendDataJson(common::http::http_status code, const common::json::DataJson& data);
common::ErrnoError SendErrorJson(common::http::http_status code, common::Error err);
common::ErrnoError SendHeadersInternal(common::http::http_status code,
const char* mime_type,
size_t* length,
time_t* mod);
bool is_verified_;
common::time64_t exp_time_;
}; };
} // namespace server } // namespace server

View file

@ -14,36 +14,39 @@
#include "server/daemon/commands.h" #include "server/daemon/commands.h"
// broadcast
#define SERVICE_STATISTIC_SERVICE "statistic_service"
namespace fastocloud { namespace fastocloud {
namespace server { namespace server {
common::Error ChangedSourcesStreamBroadcast(const ChangedSouresInfo& params, fastotv::protocol::request_t* req) { common::Error ChangedSourcesStreamBroadcast(const ChangedSouresInfo& params, common::json::WsDataJson* req) {
if (!req) { if (!req) {
return common::make_error_inval(); return common::make_error_inval();
} }
std::string changed_json; json_object* result_json = nullptr;
common::Error err_ser = params.SerializeToString(&changed_json); common::Error err_ser = params.Serialize(&result_json);
if (err_ser) { if (err_ser) {
return err_ser; return err_ser;
} }
*req = fastotv::protocol::request_t::MakeNotification(STREAM_CHANGED_SOURCES_STREAM, changed_json); *req = common::json::WsDataJson(BROADCAST_CHANGED_SOURCES_STREAM, result_json);
return common::Error(); return common::Error();
} }
common::Error StatisitcStreamBroadcast(const StatisticInfo& params, fastotv::protocol::request_t* req) { common::Error StatisitcStreamBroadcast(const StatisticInfo& params, common::json::WsDataJson* req) {
if (!req) { if (!req) {
return common::make_error_inval(); return common::make_error_inval();
} }
std::string stat_json; json_object* result_json = nullptr;
common::Error err_ser = params.SerializeToString(&stat_json); common::Error err_ser = params.Serialize(&result_json);
if (err_ser) { if (err_ser) {
return err_ser; return err_ser;
} }
*req = fastotv::protocol::request_t::MakeNotification(STREAM_STATISTIC_STREAM, stat_json); *req = common::json::WsDataJson(BROADCAST_STATISTIC_STREAM, result_json);
return common::Error(); return common::Error();
} }
@ -65,28 +68,33 @@ common::Error MlNotificationStreamBroadcast(const fastotv::commands_info::ml::No
} }
#endif #endif
common::Error StatisitcServiceBroadcast(fastotv::protocol::serializet_params_t params, common::Error StatisitcServiceBroadcast(const service::ServerInfo& params, common::json::WsDataJson* req) {
fastotv::protocol::request_t* req) {
if (!req) { if (!req) {
return common::make_error_inval(); return common::make_error_inval();
} }
*req = fastotv::protocol::request_t::MakeNotification(STREAM_STATISTIC_SERVICE, params); json_object* stat_json = nullptr;
return common::Error(); common::Error err_ser = params.Serialize(&stat_json);
}
common::Error QuitStatusStreamBroadcast(const stream::QuitStatusInfo& params, fastotv::protocol::request_t* req) {
if (!req) {
return common::make_error_inval();
}
std::string quit_json;
common::Error err_ser = params.SerializeToString(&quit_json);
if (err_ser) { if (err_ser) {
return err_ser; return err_ser;
} }
*req = fastotv::protocol::request_t::MakeNotification(STREAM_QUIT_STATUS_STREAM, quit_json); *req = common::json::WsDataJson(SERVICE_STATISTIC_SERVICE, stat_json);
return common::Error();
}
common::Error QuitStatusStreamBroadcast(const stream::QuitStatusInfo& params, common::json::WsDataJson* req) {
if (!req) {
return common::make_error_inval();
}
json_object* quit_json = nullptr;
common::Error err_ser = params.Serialize(&quit_json);
if (err_ser) {
return err_ser;
}
*req = common::json::WsDataJson(STREAM_QUIT_STATUS_STREAM, quit_json);
return common::Error(); return common::Error();
} }

View file

@ -14,15 +14,19 @@
#pragma once #pragma once
#include <fastotv/protocol/types.h>
#include <string> #include <string>
#include <fastotv/protocol/types.h> #include <common/json/json.h>
#if defined(MACHINE_LEARNING) #if defined(MACHINE_LEARNING)
#include <fastotv/commands_info/ml/notification_info.h> #include <fastotv/commands_info/ml/notification_info.h>
#endif #endif
#include "server/daemon/commands_info/service/server_info.h"
#include "server/daemon/commands_info/stream/quit_status_info.h" #include "server/daemon/commands_info/stream/quit_status_info.h"
#include "stream_commands/commands_info/changed_sources_info.h" #include "stream_commands/commands_info/changed_sources_info.h"
#include "stream_commands/commands_info/statistic_info.h" #include "stream_commands/commands_info/statistic_info.h"
@ -34,20 +38,17 @@
#define DAEMON_RESTART_STREAM "restart_stream" #define DAEMON_RESTART_STREAM "restart_stream"
#define DAEMON_GET_LOG_STREAM "get_log_stream" #define DAEMON_GET_LOG_STREAM "get_log_stream"
#define DAEMON_GET_PIPELINE_STREAM "get_pipeline_stream" #define DAEMON_GET_PIPELINE_STREAM "get_pipeline_stream"
#define DAEMON_GET_CONFIG_JSON_STREAM "get_config_json_stream"
#define DAEMON_ACTIVATE "activate_request" // {"key": "XXXXXXXXXXXXXXXXXX"}
#define DAEMON_STOP_SERVICE "stop_service" // {"delay": 0 } #define DAEMON_STOP_SERVICE "stop_service" // {"delay": 0 }
#define DAEMON_RESTART_SERVICE "restart_service" // {"delay": 0 } #define DAEMON_RESTART_SERVICE "restart_service" // {"delay": 0 }
#define DAEMON_STATS_SERVICE "stats"
#define DAEMON_GET_CONFIG_JSON_STREAM "get_config_json_stream"
#define DAEMON_PING_SERVICE "ping_service"
#define DAEMON_GET_LOG_SERVICE "get_log_service" // {"path":"http://localhost/service/id"} #define DAEMON_GET_LOG_SERVICE "get_log_service" // {"path":"http://localhost/service/id"}
#define DAEMON_SERVER_PING "ping_client"
// Broadcast // Broadcast
#define STREAM_CHANGED_SOURCES_STREAM "changed_source_stream" #define BROADCAST_CHANGED_SOURCES_STREAM "changed_source_stream"
#define STREAM_STATISTIC_STREAM "statistic_stream" #define BROADCAST_STATISTIC_STREAM "statistic_stream"
#define STREAM_QUIT_STATUS_STREAM "quit_status_stream" #define STREAM_QUIT_STATUS_STREAM "quit_status_stream"
#if defined(MACHINE_LEARNING) #if defined(MACHINE_LEARNING)
#define STREAM_ML_NOTIFICATION_STREAM "ml_notification_stream" #define STREAM_ML_NOTIFICATION_STREAM "ml_notification_stream"
@ -58,15 +59,17 @@ namespace fastocloud {
namespace server { namespace server {
// Broadcast // Broadcast
common::Error ChangedSourcesStreamBroadcast(const ChangedSouresInfo& params, fastotv::protocol::request_t* req); common::Error ChangedSourcesStreamBroadcast(const ChangedSouresInfo& params,
common::Error StatisitcStreamBroadcast(const StatisticInfo& params, fastotv::protocol::request_t* req); common::json::WsDataJson* req) WARN_UNUSED_RESULT;
common::Error StatisitcStreamBroadcast(const StatisticInfo& params, common::json::WsDataJson* req) WARN_UNUSED_RESULT;
#if defined(MACHINE_LEARNING) #if defined(MACHINE_LEARNING)
common::Error MlNotificationStreamBroadcast(const fastotv::commands_info::ml::NotificationInfo& params, common::Error MlNotificationStreamBroadcast(const fastotv::commands_info::ml::NotificationInfo& params,
fastotv::protocol::request_t* req); fastotv::protocol::request_t* req);
#endif #endif
common::Error StatisitcServiceBroadcast(fastotv::protocol::serializet_params_t params, common::Error StatisitcServiceBroadcast(const service::ServerInfo& params,
fastotv::protocol::request_t* req); common::json::WsDataJson* req) WARN_UNUSED_RESULT;
common::Error QuitStatusStreamBroadcast(const stream::QuitStatusInfo& params, fastotv::protocol::request_t* req);
common::Error QuitStatusStreamBroadcast(const stream::QuitStatusInfo& params, common::json::WsDataJson* req) WARN_UNUSED_RESULT;
} // namespace server } // namespace server
} // namespace fastocloud } // namespace fastocloud

View file

@ -1,311 +0,0 @@
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
This file is part of fastocloud.
fastocloud is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
fastocloud is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
*/
#include "server/daemon/commands_factory.h"
#include <common/sprintf.h>
#include "server/daemon/commands.h"
namespace fastocloud {
namespace server {
common::Error StopServiceRequest(fastotv::protocol::sequance_id_t id,
const common::daemon::commands::StopInfo& params,
fastotv::protocol::request_t* req) {
if (!req) {
return common::make_error_inval();
}
std::string req_str;
common::Error err_ser = params.SerializeToString(&req_str);
if (err_ser) {
return err_ser;
}
fastotv::protocol::request_t lreq;
lreq.id = id;
lreq.method = DAEMON_STOP_SERVICE;
lreq.params = req_str;
*req = lreq;
return common::Error();
}
common::Error RestartServiceRequest(fastotv::protocol::sequance_id_t id,
const common::daemon::commands::RestartInfo& params,
fastotv::protocol::request_t* req) {
if (!req) {
return common::make_error_inval();
}
std::string req_str;
common::Error err_ser = params.SerializeToString(&req_str);
if (err_ser) {
return err_ser;
}
fastotv::protocol::request_t lreq;
lreq.id = id;
lreq.method = DAEMON_RESTART_SERVICE;
lreq.params = req_str;
*req = lreq;
return common::Error();
}
common::Error PingRequest(fastotv::protocol::sequance_id_t id,
const common::daemon::commands::ClientPingInfo& params,
fastotv::protocol::request_t* req) {
if (!req) {
return common::make_error_inval();
}
std::string req_str;
common::Error err_ser = params.SerializeToString(&req_str);
if (err_ser) {
return err_ser;
}
fastotv::protocol::request_t lreq;
lreq.id = id;
lreq.method = DAEMON_SERVER_PING;
lreq.params = req_str;
*req = lreq;
return common::Error();
}
common::Error StopServiceResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp) {
if (!resp) {
return common::make_error_inval();
}
*resp =
fastotv::protocol::response_t::MakeMessage(id, common::protocols::json_rpc::JsonRPCMessage::MakeSuccessMessage());
return common::Error();
}
common::Error StopServiceResponseFail(fastotv::protocol::sequance_id_t id,
const std::string& error_text,
fastotv::protocol::response_t* resp) {
if (!resp) {
return common::make_error_inval();
}
*resp = fastotv::protocol::response_t::MakeError(
id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(error_text));
return common::Error();
}
common::Error GetLogServiceResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp) {
if (!resp) {
return common::make_error_inval();
}
*resp =
fastotv::protocol::response_t::MakeMessage(id, common::protocols::json_rpc::JsonRPCMessage::MakeSuccessMessage());
return common::Error();
}
common::Error GetLogServiceResponseFail(fastotv::protocol::sequance_id_t id,
const std::string& error_text,
fastotv::protocol::response_t* resp) {
if (!resp) {
return common::make_error_inval();
}
*resp = fastotv::protocol::response_t::MakeError(
id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(error_text));
return common::Error();
}
common::Error ActivateResponseSuccess(fastotv::protocol::sequance_id_t id,
const std::string& result,
fastotv::protocol::response_t* resp) {
if (!resp) {
return common::make_error_inval();
}
*resp = fastotv::protocol::response_t::MakeMessage(
id, common::protocols::json_rpc::JsonRPCMessage::MakeSuccessMessage(result));
return common::Error();
}
common::Error ActivateResponseFail(fastotv::protocol::sequance_id_t id,
const std::string& error_text,
fastotv::protocol::response_t* resp) {
if (!resp) {
return common::make_error_inval();
}
*resp = fastotv::protocol::response_t::MakeError(
id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(error_text));
return common::Error();
}
common::Error StartStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp) {
if (!resp) {
return common::make_error_inval();
}
*resp =
fastotv::protocol::response_t::MakeMessage(id, common::protocols::json_rpc::JsonRPCMessage::MakeSuccessMessage());
return common::Error();
}
common::Error StartStreamResponseFail(fastotv::protocol::sequance_id_t id,
const std::string& error_text,
fastotv::protocol::response_t* resp) {
if (!resp) {
return common::make_error_inval();
}
*resp = fastotv::protocol::response_t::MakeError(
id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(error_text));
return common::Error();
}
common::Error StopStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp) {
if (!resp) {
return common::make_error_inval();
}
*resp =
fastotv::protocol::response_t::MakeMessage(id, common::protocols::json_rpc::JsonRPCMessage::MakeSuccessMessage());
return common::Error();
}
common::Error StopStreamResponseFail(fastotv::protocol::sequance_id_t id,
const std::string& error_text,
fastotv::protocol::response_t* resp) {
if (!resp) {
return common::make_error_inval();
}
*resp = fastotv::protocol::response_t::MakeError(
id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(error_text));
return common::Error();
}
common::Error RestartStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp) {
if (!resp) {
return common::make_error_inval();
}
*resp =
fastotv::protocol::response_t::MakeMessage(id, common::protocols::json_rpc::JsonRPCMessage::MakeSuccessMessage());
return common::Error();
}
common::Error RestartStreamResponseFail(fastotv::protocol::sequance_id_t id,
const std::string& error_text,
fastotv::protocol::response_t* resp) {
if (!resp) {
return common::make_error_inval();
}
*resp = fastotv::protocol::response_t::MakeError(
id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(error_text));
return common::Error();
}
common::Error GetLogStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp) {
if (!resp) {
return common::make_error_inval();
}
*resp =
fastotv::protocol::response_t::MakeMessage(id, common::protocols::json_rpc::JsonRPCMessage::MakeSuccessMessage());
return common::Error();
}
common::Error GetLogStreamResponseFail(fastotv::protocol::sequance_id_t id,
const std::string& error_text,
fastotv::protocol::response_t* resp) {
if (!resp) {
return common::make_error_inval();
}
*resp = fastotv::protocol::response_t::MakeError(
id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(error_text));
return common::Error();
}
common::Error GetPipeStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp) {
if (!resp) {
return common::make_error_inval();
}
*resp =
fastotv::protocol::response_t::MakeMessage(id, common::protocols::json_rpc::JsonRPCMessage::MakeSuccessMessage());
return common::Error();
}
common::Error GetPipeStreamResponseFail(fastotv::protocol::sequance_id_t id,
const std::string& error_text,
fastotv::protocol::response_t* resp) {
if (!resp) {
return common::make_error_inval();
}
*resp = fastotv::protocol::response_t::MakeError(
id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(error_text));
return common::Error();
}
common::Error PingServiceResponseSuccess(fastotv::protocol::sequance_id_t id,
const common::daemon::commands::ServerPingInfo& ping,
fastotv::protocol::response_t* resp) {
if (!resp) {
return common::make_error_inval();
}
std::string ping_server_json;
common::Error err_ser = ping.SerializeToString(&ping_server_json);
if (err_ser) {
return err_ser;
}
*resp = fastotv::protocol::response_t::MakeMessage(
id, common::protocols::json_rpc::JsonRPCMessage::MakeSuccessMessage(ping_server_json));
return common::Error();
}
common::Error PingServiceResponseFail(fastotv::protocol::sequance_id_t id,
const std::string& error_text,
fastotv::protocol::response_t* resp) {
if (!resp) {
return common::make_error_inval();
}
*resp = fastotv::protocol::response_t::MakeError(
id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(error_text));
return common::Error();
}
common::Error UnknownMethodResponse(fastotv::protocol::sequance_id_t id,
const std::string& method,
fastotv::protocol::response_t* resp) {
if (!resp) {
return common::make_error_inval();
}
*resp =
fastotv::protocol::response_t::MakeError(id, common::protocols::json_rpc::JsonRPCError::MakeServerErrorFromText(
common::MemSPrintf("Unknown method: %s", method)));
return common::Error();
}
} // namespace server
} // namespace fastocloud

View file

@ -1,96 +0,0 @@
/* Copyright (C) 2014-2022 FastoGT. All right reserved.
This file is part of fastocloud.
fastocloud is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
fastocloud is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with fastocloud. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
#include <common/daemon/commands/activate_info.h>
#include <common/daemon/commands/ping_info.h>
#include <common/daemon/commands/restart_info.h>
#include <common/daemon/commands/stop_info.h>
#include <fastotv/protocol/types.h>
namespace fastocloud {
namespace server {
// requests
common::Error StopServiceRequest(fastotv::protocol::sequance_id_t id,
const common::daemon::commands::StopInfo& params,
fastotv::protocol::request_t* req);
common::Error RestartServiceRequest(fastotv::protocol::sequance_id_t id,
const common::daemon::commands::RestartInfo& params,
fastotv::protocol::request_t* req);
common::Error PingRequest(fastotv::protocol::sequance_id_t id,
const common::daemon::commands::ClientPingInfo& params,
fastotv::protocol::request_t* req);
// responses service
common::Error StopServiceResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp);
common::Error StopServiceResponseFail(fastotv::protocol::sequance_id_t id,
const std::string& error_text,
fastotv::protocol::response_t* resp);
common::Error GetLogServiceResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp);
common::Error GetLogServiceResponseFail(fastotv::protocol::sequance_id_t id,
const std::string& error_text,
fastotv::protocol::response_t* resp);
common::Error ActivateResponseSuccess(fastotv::protocol::sequance_id_t id,
const std::string& result,
fastotv::protocol::response_t* resp);
common::Error ActivateResponseFail(fastotv::protocol::sequance_id_t id,
const std::string& error_text,
fastotv::protocol::response_t* resp);
common::Error PingServiceResponseSuccess(fastotv::protocol::sequance_id_t id,
const common::daemon::commands::ServerPingInfo& ping,
fastotv::protocol::response_t* resp);
common::Error PingServiceResponseFail(fastotv::protocol::sequance_id_t id,
const std::string& error_text,
fastotv::protocol::response_t* resp);
common::Error UnknownMethodResponse(fastotv::protocol::sequance_id_t id,
const std::string& method,
fastotv::protocol::response_t* resp) WARN_UNUSED_RESULT;
// responces streams
common::Error StartStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp);
common::Error StartStreamResponseFail(fastotv::protocol::sequance_id_t id,
const std::string& error_text,
fastotv::protocol::response_t* resp);
common::Error StopStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp);
common::Error StopStreamResponseFail(fastotv::protocol::sequance_id_t id,
const std::string& error_text,
fastotv::protocol::response_t* resp);
common::Error RestartStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp);
common::Error RestartStreamResponseFail(fastotv::protocol::sequance_id_t id,
const std::string& error_text,
fastotv::protocol::response_t* resp);
common::Error GetLogStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp);
common::Error GetLogStreamResponseFail(fastotv::protocol::sequance_id_t id,
const std::string& error_text,
fastotv::protocol::response_t* resp);
common::Error GetPipeStreamResponseSuccess(fastotv::protocol::sequance_id_t id, fastotv::protocol::response_t* resp);
common::Error GetPipeStreamResponseFail(fastotv::protocol::sequance_id_t id,
const std::string& error_text,
fastotv::protocol::response_t* resp);
} // namespace server
} // namespace fastocloud

View file

@ -16,21 +16,16 @@
#include <string> #include <string>
#define PATH_FIELD "path"
#define FEEDBACK_DIR_FIELD "feedback_directory" #define FEEDBACK_DIR_FIELD "feedback_directory"
namespace fastocloud { namespace fastocloud {
namespace server { namespace server {
namespace stream { namespace stream {
GetLogInfo::GetLogInfo() : base_class(), feedback_dir_(), path_() {} GetLogInfo::GetLogInfo() : base_class(), feedback_dir_() {}
GetLogInfo::GetLogInfo(const fastotv::stream_id_t& stream_id, const std::string& feedback_dir, const url_t& path) GetLogInfo::GetLogInfo(const fastotv::stream_id_t& stream_id, const std::string& feedback_dir)
: base_class(stream_id), feedback_dir_(feedback_dir), path_(path) {} : base_class(stream_id), feedback_dir_(feedback_dir) {}
GetLogInfo::url_t GetLogInfo::GetLogPath() const {
return path_;
}
std::string GetLogInfo::GetFeedbackDir() const { std::string GetLogInfo::GetFeedbackDir() const {
return feedback_dir_; return feedback_dir_;
@ -50,20 +45,11 @@ common::Error GetLogInfo::DoDeSerialize(json_object* serialized) {
} }
inf.feedback_dir_ = feedback_dir; inf.feedback_dir_ = feedback_dir;
std::string path;
err = GetStringField(serialized, PATH_FIELD, &path);
if (err) {
return err;
}
inf.path_ = url_t(path);
*this = inf; *this = inf;
return common::Error(); return common::Error();
} }
common::Error GetLogInfo::SerializeFields(json_object* out) const { common::Error GetLogInfo::SerializeFields(json_object* out) const {
const std::string path_str = path_.spec();
ignore_result(SetStringField(out, PATH_FIELD, path_str));
ignore_result(SetStringField(out, FEEDBACK_DIR_FIELD, feedback_dir_)); ignore_result(SetStringField(out, FEEDBACK_DIR_FIELD, feedback_dir_));
return base_class::SerializeFields(out); return base_class::SerializeFields(out);
} }

View file

@ -14,10 +14,10 @@
#pragma once #pragma once
#include <string>
#include <common/uri/gurl.h> #include <common/uri/gurl.h>
#include <string>
#include "server/daemon/commands_info/stream/stream_info.h" #include "server/daemon/commands_info/stream/stream_info.h"
namespace fastocloud { namespace fastocloud {
@ -27,12 +27,10 @@ namespace stream {
class GetLogInfo : public StreamInfo { class GetLogInfo : public StreamInfo {
public: public:
typedef StreamInfo base_class; typedef StreamInfo base_class;
typedef common::uri::GURL url_t;
GetLogInfo(); GetLogInfo();
explicit GetLogInfo(const fastotv::stream_id_t& stream_id, const std::string& feedback_dir, const url_t& log_path); explicit GetLogInfo(const fastotv::stream_id_t& stream_id, const std::string& feedback_dir);
url_t GetLogPath() const;
std::string GetFeedbackDir() const; std::string GetFeedbackDir() const;
protected: protected:
@ -41,7 +39,6 @@ class GetLogInfo : public StreamInfo {
private: private:
std::string feedback_dir_; std::string feedback_dir_;
url_t path_;
}; };
typedef GetLogInfo GetPipelineInfo; typedef GetLogInfo GetPipelineInfo;

View file

@ -16,12 +16,6 @@
namespace fastocloud { namespace fastocloud {
namespace server { namespace server {
namespace stream { namespace stream {} // namespace stream
RestartInfo::RestartInfo() : base_class() {}
RestartInfo::RestartInfo(const fastotv::stream_id_t& stream_id) : base_class(stream_id) {}
} // namespace stream
} // namespace server } // namespace server
} // namespace fastocloud } // namespace fastocloud

View file

@ -20,13 +20,7 @@ namespace fastocloud {
namespace server { namespace server {
namespace stream { namespace stream {
class RestartInfo : public StreamInfo { typedef StreamInfo RestartInfo;
public:
typedef StreamInfo base_class;
RestartInfo();
explicit RestartInfo(const fastotv::stream_id_t& stream_id);
};
} // namespace stream } // namespace stream
} // namespace server } // namespace server

View file

@ -14,12 +14,11 @@
#pragma once #pragma once
#include <string>
#include <common/serializer/json_serializer.h> #include <common/serializer/json_serializer.h>
#include <fastotv/types.h> #include <fastotv/types.h>
#include <string>
namespace fastocloud { namespace fastocloud {
namespace server { namespace server {
namespace stream { namespace stream {

View file

@ -14,14 +14,14 @@
#pragma once #pragma once
#include <common/daemon/server.h> #include <common/libev/tcp/tcp_server.h>
namespace fastocloud { namespace fastocloud {
namespace server { namespace server {
class DaemonServer : public common::daemon::DaemonServer { class DaemonServer : public common::libev::tcp::TcpServer {
public: public:
typedef common::daemon::DaemonServer base_class; typedef common::libev::tcp::TcpServer base_class;
explicit DaemonServer(const common::net::HostAndPort& host, common::libev::IoLoopObserver* observer = nullptr); explicit DaemonServer(const common::net::HostAndPort& host, common::libev::IoLoopObserver* observer = nullptr);
private: private:

View file

@ -76,7 +76,7 @@ int main(int argc, char** argv, char** envp) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
err = fastocloud::server::ProcessSlaveWrapper::SendStopDaemonRequest(config); err = fastocloud::server::ProcessSlaveWrapper::SendStopDaemonRequest(config.host);
sleep(fastocloud::server::ProcessSlaveWrapper::cleanup_seconds + 1); sleep(fastocloud::server::ProcessSlaveWrapper::cleanup_seconds + 1);
if (err) { if (err) {
std::cerr << "Stop command failed error: " << err->GetDescription() << std::endl; std::cerr << "Stop command failed error: " << err->GetDescription() << std::endl;
@ -92,7 +92,7 @@ int main(int argc, char** argv, char** envp) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
err = fastocloud::server::ProcessSlaveWrapper::SendRestartDaemonRequest(config); err = fastocloud::server::ProcessSlaveWrapper::SendRestartDaemonRequest(config.host);
sleep(fastocloud::server::ProcessSlaveWrapper::cleanup_seconds + 1); sleep(fastocloud::server::ProcessSlaveWrapper::cleanup_seconds + 1);
if (err) { if (err) {
std::cerr << "Reload command failed error: " << err->GetDescription() << std::endl; std::cerr << "Reload command failed error: " << err->GetDescription() << std::endl;

View file

@ -21,18 +21,18 @@ typedef struct ssl_st SSL;
namespace fastocloud { namespace fastocloud {
namespace server { namespace server {
class HttpClient : public common::libev::http::HttpClient { class HttpClient : public common::libev::http::HttpServerClient {
public: public:
typedef common::libev::http::HttpClient base_class; typedef common::libev::http::HttpServerClient base_class;
HttpClient(common::libev::IoLoop* server, const common::net::socket_info& info); HttpClient(common::libev::IoLoop* server, const common::net::socket_info& info);
const char* ClassName() const override; const char* ClassName() const override;
}; };
class HttpsClient : public common::libev::http::HttpClient { class HttpsClient : public common::libev::http::HttpServerClient {
public: public:
typedef common::libev::http::HttpClient base_class; typedef common::libev::http::HttpServerClient base_class;
HttpsClient(common::libev::IoLoop* server, const common::net::socket_info& info, SSL* ssl); HttpsClient(common::libev::IoLoop* server, const common::net::socket_info& info, SSL* ssl);

View file

@ -112,8 +112,9 @@ void HttpHandler::ProcessReceived(HttpClient* hclient, const char* request, size
// keep alive // keep alive
common::http::header_t connection_field; common::http::header_t connection_field;
bool is_find_connection = hrequest.FindHeaderByKey("Connection", false, &connection_field); // bool is_find_connection = hrequest.FindHeaderByKey("Connection", false, &connection_field);
bool IsKeepAlive = is_find_connection ? common::EqualsASCII(connection_field.value, "Keep-Alive", false) : false; bool IsKeepAlive =
false; // is_find_connection ? common::EqualsASCII(connection_field.value, "Keep-Alive", false) : false;
const common::http::http_protocol protocol = hrequest.GetProtocol(); const common::http::http_protocol protocol = hrequest.GetProtocol();
const common::http::http_method method = hrequest.GetMethod(); const common::http::http_method method = hrequest.GetMethod();
if (method == common::http::http_method::HM_GET || method == common::http::http_method::HM_HEAD) { if (method == common::http::http_method::HM_GET || method == common::http::http_method::HM_HEAD) {
@ -181,7 +182,7 @@ void HttpHandler::ProcessReceived(HttpClient* hclient, const char* request, size
} }
if (hrequest.GetMethod() == common::http::http_method::HM_GET) { if (hrequest.GetMethod() == common::http::http_method::HM_GET) {
common::ErrnoError err = hclient->SendFileByFd(protocol, file, sb.st_size); common::ErrnoError err = hclient->SendFileByFd(protocol, file);
if (err) { if (err) {
DEBUG_MSG_ERROR(err, common::logging::LOG_LEVEL_ERR); DEBUG_MSG_ERROR(err, common::logging::LOG_LEVEL_ERR);
} else { } else {

View file

@ -14,10 +14,15 @@
#pragma once #pragma once
#include <common/libev/pipe_client.h>
#include <fastotv/protocol/protocol.h> #include <fastotv/protocol/protocol.h>
namespace common {
namespace libev {
class PipeReadClient;
class PipeWriteClient;
} // namespace libev
} // namespace common
namespace fastocloud { namespace fastocloud {
namespace server { namespace server {
namespace pipe { namespace pipe {

File diff suppressed because it is too large Load diff

View file

@ -14,10 +14,8 @@
#pragma once #pragma once
#include <map> #include <common/http/http.h>
#include <string> #include <common/json/json.h>
#include <vector>
#include <common/libev/io_loop_observer.h> #include <common/libev/io_loop_observer.h>
#include <common/net/types.h> #include <common/net/types.h>
#include <common/threads/ts_queue.h> #include <common/threads/ts_queue.h>
@ -29,6 +27,7 @@
#include "base/stream_info.h" #include "base/stream_info.h"
#include "server/config.h" #include "server/config.h"
#include "server/daemon/commands_info/service/server_info.h"
namespace fastocloud { namespace fastocloud {
namespace server { namespace server {
@ -38,6 +37,7 @@ class ProtocoledDaemonClient;
class ProcessSlaveWrapper : public common::libev::IoLoopObserver { class ProcessSlaveWrapper : public common::libev::IoLoopObserver {
public: public:
enum { BUF_SIZE = 4096 };
enum { enum {
node_stats_send_seconds = 10, node_stats_send_seconds = 10,
ping_timeout_clients_seconds = 60, ping_timeout_clients_seconds = 60,
@ -51,9 +51,8 @@ class ProcessSlaveWrapper : public common::libev::IoLoopObserver {
explicit ProcessSlaveWrapper(const Config& config); explicit ProcessSlaveWrapper(const Config& config);
~ProcessSlaveWrapper() override; ~ProcessSlaveWrapper() override;
static common::ErrnoError SendStopDaemonRequest(const Config& config); static common::ErrnoError SendStopDaemonRequest(const common::net::HostAndPort& host);
static common::ErrnoError SendRestartDaemonRequest(const Config& config); static common::ErrnoError SendRestartDaemonRequest(const common::net::HostAndPort& host);
common::net::HostAndPort GetServerHostAndPort();
int Exec(int argc, char** argv) WARN_UNUSED_RESULT; int Exec(int argc, char** argv) WARN_UNUSED_RESULT;
@ -75,11 +74,6 @@ class ProcessSlaveWrapper : public common::libev::IoLoopObserver {
void DataReadyToWrite(common::libev::IoClient* client) override; void DataReadyToWrite(common::libev::IoClient* client) override;
void PostLooped(common::libev::IoLoop* server) override; void PostLooped(common::libev::IoLoop* server) override;
virtual common::ErrnoError HandleRequestServiceCommand(ProtocoledDaemonClient* dclient,
const fastotv::protocol::request_t* req) WARN_UNUSED_RESULT;
virtual common::ErrnoError HandleResponceServiceCommand(ProtocoledDaemonClient* dclient,
const fastotv::protocol::response_t* resp) WARN_UNUSED_RESULT;
virtual common::ErrnoError HandleRequestStreamsCommand(stream_client_t* pclient, virtual common::ErrnoError HandleRequestStreamsCommand(stream_client_t* pclient,
const fastotv::protocol::request_t* req) WARN_UNUSED_RESULT; const fastotv::protocol::request_t* req) WARN_UNUSED_RESULT;
virtual common::ErrnoError HandleResponceStreamsCommand(stream_client_t* pclient, virtual common::ErrnoError HandleResponceStreamsCommand(stream_client_t* pclient,
@ -91,15 +85,18 @@ class ProcessSlaveWrapper : public common::libev::IoLoopObserver {
void StopImpl(); void StopImpl();
ChildStream* FindChildByID(fastotv::stream_id_t cid) const; ChildStream* FindChildByID(fastotv::stream_id_t cid) const;
void BroadcastClients(const fastotv::protocol::request_t& req); void BroadcastClients(const common::json::WsDataJson& req);
common::ErrnoError DaemonDataReceived(ProtocoledDaemonClient* dclient) WARN_UNUSED_RESULT; common::ErrnoError DaemonDataReceived(ProtocoledDaemonClient* dclient) WARN_UNUSED_RESULT;
common::ErrnoError ProcessReceived(ProtocoledDaemonClient* hclient, const char* request, size_t req_len);
common::ErrnoError StreamDataReceived(stream_client_t* pclient) WARN_UNUSED_RESULT; common::ErrnoError StreamDataReceived(stream_client_t* pclient) WARN_UNUSED_RESULT;
common::ErrnoError CreateChildStream(const serialized_stream_t& config_args) WARN_UNUSED_RESULT; common::ErrnoError CreateChildStream(const serialized_stream_t& config_args) WARN_UNUSED_RESULT;
common::ErrnoError CreateChildStreamImpl(const serialized_stream_t& config_args, common::ErrnoError CreateChildStreamImpl(const serialized_stream_t& config_args,
const StreamInfo& sha) WARN_UNUSED_RESULT; const StreamInfo& sha) WARN_UNUSED_RESULT;
common::ErrnoError StopChildStreamImpl(fastotv::stream_id_t sid, bool force) WARN_UNUSED_RESULT; common::ErrnoError StopChildStreamImpl(fastotv::stream_id_t sid, bool force) WARN_UNUSED_RESULT;
common::ErrnoError RestartChildStreamImpl(fastotv::stream_id_t sid) WARN_UNUSED_RESULT;
// stream // stream
common::ErrnoError HandleRequestChangedSourcesStream(stream_client_t* pclient, common::ErrnoError HandleRequestChangedSourcesStream(stream_client_t* pclient,
@ -113,35 +110,30 @@ class ProcessSlaveWrapper : public common::libev::IoLoopObserver {
#endif #endif
common::ErrnoError HandleRequestClientStartStream(ProtocoledDaemonClient* dclient, common::ErrnoError HandleRequestClientStartStream(ProtocoledDaemonClient* dclient,
const fastotv::protocol::request_t* req) WARN_UNUSED_RESULT; const common::http::HttpRequest& req) WARN_UNUSED_RESULT;
common::ErrnoError HandleRequestClientStopStream(ProtocoledDaemonClient* dclient, common::ErrnoError HandleRequestClientStopStream(ProtocoledDaemonClient* dclient,
const fastotv::protocol::request_t* req) WARN_UNUSED_RESULT; const common::http::HttpRequest& req) WARN_UNUSED_RESULT;
common::ErrnoError HandleRequestClientRestartStream(ProtocoledDaemonClient* dclient, common::ErrnoError HandleRequestClientRestartStream(ProtocoledDaemonClient* dclient,
const fastotv::protocol::request_t* req) WARN_UNUSED_RESULT; const common::http::HttpRequest& req) WARN_UNUSED_RESULT;
common::ErrnoError HandleRequestClientGetLogStream(ProtocoledDaemonClient* dclient, common::ErrnoError HandleRequestClientGetLogStream(ProtocoledDaemonClient* dclient,
const fastotv::protocol::request_t* req) WARN_UNUSED_RESULT; const common::http::HttpRequest& req) WARN_UNUSED_RESULT;
common::ErrnoError HandleRequestClientGetPipelineStream(ProtocoledDaemonClient* dclient, common::ErrnoError HandleRequestClientGetPipelineStream(ProtocoledDaemonClient* dclient,
const fastotv::protocol::request_t* req) WARN_UNUSED_RESULT; const common::http::HttpRequest& req) WARN_UNUSED_RESULT;
common::ErrnoError HandleRequestClientGetConfigJsonStream(ProtocoledDaemonClient* dclient, common::ErrnoError HandleRequestClientGetConfigJsonStream(ProtocoledDaemonClient* dclient,
const fastotv::protocol::request_t* req) WARN_UNUSED_RESULT; const common::http::HttpRequest& req) WARN_UNUSED_RESULT;
common::ErrnoError HandleRequestClientActivate(ProtocoledDaemonClient* dclient,
const fastotv::protocol::request_t* req) WARN_UNUSED_RESULT;
common::ErrnoError HandleRequestClientPingService(ProtocoledDaemonClient* dclient,
const fastotv::protocol::request_t* req) WARN_UNUSED_RESULT;
common::ErrnoError HandleRequestClientGetLogService(ProtocoledDaemonClient* dclient, common::ErrnoError HandleRequestClientGetLogService(ProtocoledDaemonClient* dclient,
const fastotv::protocol::request_t* req) WARN_UNUSED_RESULT; const common::http::HttpRequest& req) WARN_UNUSED_RESULT;
common::ErrnoError HandleRequestClientRestartService(ProtocoledDaemonClient* dclient,
const fastotv::protocol::request_t* req) WARN_UNUSED_RESULT;
common::ErrnoError HandleRequestClientStopService(ProtocoledDaemonClient* dclient, common::ErrnoError HandleRequestClientStopService(ProtocoledDaemonClient* dclient,
const fastotv::protocol::request_t* req) WARN_UNUSED_RESULT; const common::http::HttpRequest& req) WARN_UNUSED_RESULT;
common::ErrnoError HandleRequestClientRestartService(ProtocoledDaemonClient* dclient,
common::ErrnoError HandleResponcePingService(ProtocoledDaemonClient* dclient, const common::http::HttpRequest& req) WARN_UNUSED_RESULT;
const fastotv::protocol::response_t* resp) WARN_UNUSED_RESULT; common::ErrnoError HandleRequestClientGetStats(ProtocoledDaemonClient* dclient,
const common::http::HttpRequest& req) WARN_UNUSED_RESULT;
void CheckLicenseExpired(common::libev::IoLoop* server); void CheckLicenseExpired(common::libev::IoLoop* server);
std::string MakeServiceStats(common::Optional<common::time64_t> expiration_time) const; service::FullServiceInfo MakeServiceStats(common::time64_t expiration_time) const;
service::ServerInfo MakeServiceInfoStats() const;
struct NodeStats; struct NodeStats;
const Config config_; const Config config_;

View file

@ -18,17 +18,15 @@
#include <sys/prctl.h> #include <sys/prctl.h>
#endif #endif
#include <common/file_system/file_system.h>
#include <common/file_system/string_path_utils.h>
#include <common/libev/tcp/tcp_server.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#include <common/file_system/file_system.h>
#include <common/file_system/string_path_utils.h>
#include "base/stream_info.h" #include "base/stream_info.h"
#include "server/child_stream.h" #include "server/child_stream.h"
#include "server/daemon/server.h"
#include "server/utils/utils.h" #include "server/utils/utils.h"
#define PIPE #define PIPE

View file

@ -14,6 +14,8 @@
#include "server/tcp/client.h" #include "server/tcp/client.h"
#include <common/libev/tcp/tcp_client.h>
#include <memory> #include <memory>
namespace fastocloud { namespace fastocloud {

View file

@ -14,10 +14,17 @@
#pragma once #pragma once
#include <common/libev/tcp/tcp_client.h> #include <common/net/socket_info.h>
#include <fastotv/protocol/protocol.h> #include <fastotv/protocol/protocol.h>
namespace common {
namespace libev {
namespace tcp {
class TcpClient;
}
} // namespace libev
} // namespace common
namespace fastocloud { namespace fastocloud {
namespace server { namespace server {
namespace tcp { namespace tcp {

View file

@ -22,9 +22,10 @@ namespace server {
#if defined(OS_POSIX) #if defined(OS_POSIX)
common::ErrnoError CreatePipe(common::net::socket_descr_t* read_client_fd, common::ErrnoError CreatePipe(common::net::socket_descr_t* read_client_fd,
common::net::socket_descr_t* write_client_fd); common::net::socket_descr_t* write_client_fd) WARN_UNUSED_RESULT;
#endif #endif
common::ErrnoError CreateSocketPair(common::net::socket_descr_t* parent_sock, common::net::socket_descr_t* child_sock); common::ErrnoError CreateSocketPair(common::net::socket_descr_t* parent_sock,
common::net::socket_descr_t* child_sock) WARN_UNUSED_RESULT;
} // namespace server } // namespace server
} // namespace fastocloud } // namespace fastocloud

View file

@ -42,29 +42,20 @@ bool HtmlDump::Dump(GstBin* pipeline, const common::file_system::ascii_file_stri
return false; return false;
} }
#if GST_CHECK_VERSION(1, 11, 1)
char* dot_description = gst_debug_bin_to_dot_data(pipeline, GST_DEBUG_GRAPH_SHOW_ALL); char* dot_description = gst_debug_bin_to_dot_data(pipeline, GST_DEBUG_GRAPH_SHOW_ALL);
if (!dot_description) { if (!dot_description) {
return false; return false;
} }
std::string pipeline_description(dot_description); std::string pipeline_description(dot_description);
dumpfile << "<html><head></head>" dumpfile << "<html><head></head>" << "<body>" << " <script type=\"text/javascript\" src=\"" JS_LIB "\"></script>"
<< "<body>" << " <script>" << " document.body.innerHTML += Viz(String.raw`" << pipeline_description << "`);"
<< " <script type=\"text/javascript\" src=\"" JS_LIB "\"></script>" << " </script>" << "</body>" << "</html>";
<< " <script>"
<< " document.body.innerHTML += Viz(String.raw`" << pipeline_description << "`);"
<< " </script>"
<< "</body>"
<< "</html>";
g_free(dot_description); g_free(dot_description);
return true; return true;
#else #else
return false; return false;
#endif #endif
#else
return false;
#endif
} }
} // namespace dumper } // namespace dumper

View file

@ -22,7 +22,7 @@ namespace dumper {
class HtmlDump : public IDumper { class HtmlDump : public IDumper {
public: public:
bool Dump(GstBin* pipeline, const common::file_system::ascii_file_string_path& path) override; bool Dump(GstBin* pipeline, const common::file_system::ascii_file_string_path& path) override WARN_UNUSED_RESULT;
}; };
} // namespace dumper } // namespace dumper

View file

@ -24,7 +24,7 @@ namespace dumper {
class IDumper { class IDumper {
public: public:
virtual bool Dump(GstBin* pipeline, const common::file_system::ascii_file_string_path& path) = 0; virtual bool Dump(GstBin* pipeline, const common::file_system::ascii_file_string_path& path) WARN_UNUSED_RESULT = 0;
virtual ~IDumper(); virtual ~IDumper();
}; };

View file

@ -14,14 +14,13 @@
#pragma once #pragma once
#include <string>
#include <common/sprintf.h> #include <common/sprintf.h>
#include "stream/stypes.h" #include <string>
#include "stream/elements/depay/depay.h" // for ElementRtpPay #include "stream/elements/depay/depay.h" // for ElementRtpPay
#include "stream/elements/element.h" // for Element (ptr only), SupportedElements:... #include "stream/elements/element.h" // for Element (ptr only), SupportedElements:...
#include "stream/stypes.h"
namespace fastocloud { namespace fastocloud {
namespace stream { namespace stream {

View file

@ -400,9 +400,9 @@ void StreamController::ChildStatusChanged(common::libev::IoChild* child, int sta
common::ErrnoError StreamController::HandleRequestCommand(common::libev::IoClient* client, common::ErrnoError StreamController::HandleRequestCommand(common::libev::IoClient* client,
const fastotv::protocol::request_t* req) { const fastotv::protocol::request_t* req) {
if (req->method == STOP_STREAM) { if (req->method == REQUEST_STOP_STREAM) {
return HandleRequestStopStream(client, req); return HandleRequestStopStream(client, req);
} else if (req->method == RESTART_STREAM) { } else if (req->method == REQUEST_RESTART_STREAM) {
return HandleRequestRestartStream(client, req); return HandleRequestRestartStream(client, req);
} }

View file

@ -14,8 +14,8 @@
#pragma once #pragma once
#define STOP_STREAM "stop" #define REQUEST_STOP_STREAM "stop"
#define RESTART_STREAM "restart" #define REQUEST_RESTART_STREAM "restart"
#define CHANGED_SOURCES_STREAM "changed_source_stream" #define CHANGED_SOURCES_STREAM "changed_source_stream"
#define STATISTIC_STREAM "statistic_stream" #define STATISTIC_STREAM "statistic_stream"

View file

@ -45,7 +45,7 @@ common::Error RestartStreamRequest(fastotv::protocol::sequance_id_t id, fastotv:
fastotv::protocol::request_t lreq; fastotv::protocol::request_t lreq;
lreq.id = id; lreq.id = id;
lreq.method = RESTART_STREAM; lreq.method = REQUEST_RESTART_STREAM;
*req = lreq; *req = lreq;
return common::Error(); return common::Error();
} }
@ -57,7 +57,7 @@ common::Error StopStreamRequest(fastotv::protocol::sequance_id_t id, fastotv::pr
fastotv::protocol::request_t lreq; fastotv::protocol::request_t lreq;
lreq.id = id; lreq.id = id;
lreq.method = STOP_STREAM; lreq.method = REQUEST_STOP_STREAM;
*req = lreq; *req = lreq;
return common::Error(); return common::Error();
} }

View file

@ -14,11 +14,11 @@
#include "utils/m3u8_reader.h" #include "utils/m3u8_reader.h"
#include <common/convert2string.h>
#include <regex> #include <regex>
#include <string> #include <string>
#include <common/convert2string.h>
#define CHUNK_EXT ".ts" #define CHUNK_EXT ".ts"
#define CHUNK_EXT_RE "\\" CHUNK_EXT #define CHUNK_EXT_RE "\\" CHUNK_EXT

View file

@ -14,11 +14,11 @@
#pragma once #pragma once
#include <common/file_system/path.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include <common/file_system/path.h>
#include "utils/chunk_info.h" #include "utils/chunk_info.h"
namespace fastocloud { namespace fastocloud {