[DEV] better management of he sha512 acquisition ==> faster and detect pb in release of remote object...

This commit is contained in:
Edouard DUPIN 2017-05-01 22:27:51 +00:00
parent f5a1f4b463
commit 6f2ec947ed
7 changed files with 56 additions and 9 deletions

View File

@ -53,6 +53,23 @@ lutin -cclang -mdebug zeus-package-base?build?run%zeus-launch:--srv=video
lutin -cclang -mdebug zeus-package-base?build?run%zeus-gateway:--user=userName~server.org:--srv=user:--srv=picture:--srv=video
```
Install and auto run:
=====================
copy systemd file ```tools/router/data/zeus-router.service``` in ```/usr/lib/systemd/system/zeus-router.service```
Jump in ```ROOT```
Force systemd toupdate his dataBase
systemctl daemon-reload
Start the service:
systemctl start zeus-router.service
License (MPL v2.0)
=====================

View File

@ -21,6 +21,7 @@
#include <zeus/ObjectRemote.hpp>
#include <echrono/Steady.hpp>
#include <zeus/FutureGroup.hpp>
#include <algue/sha512.hpp>
static std::string extractAndRemove(const std::string& _inputValue, const char _startMark, const char _stopMark, std::vector<std::string>& _values) {
_values.clear();
@ -46,12 +47,16 @@ static std::string extractAndRemove(const std::string& _inputValue, const char _
}
bool pushVideoFile(zeus::service::ProxyVideo& _srv, std::string _path, std::map<std::string,std::string> _basicKey = std::map<std::string,std::string>()) {
APPL_PRINT("Add media : '" << _path << "'");
std::string extention;
if ( _path.rfind('.') != std::string::npos
&& _path.rfind('.') != 0) {
extention = etk::tolower(std::string(_path.begin()+_path.rfind('.')+1, _path.end()));
}
// internal extention ....
if (extention == "sha512") {
return true;
}
APPL_PRINT("Add media : '" << _path << "'");
if ( extention != "avi"
&& extention != "mkv"
&& extention != "mov"
@ -60,8 +65,16 @@ bool pushVideoFile(zeus::service::ProxyVideo& _srv, std::string _path, std::map<
APPL_ERROR("Sot send file : " << _path << " Not manage extention...");
return false;
}
std::string storedSha512;
if (etk::FSNodeExist(_path + ".sha512") == true) {
//TODO ...
storedSha512 = etk::FSNodeReadAllData(_path + ".sha512");
} else {
storedSha512 = algue::stringConvert(algue::sha512::encodeFromFile(_path));
etk::FSNodeWriteAllData(_path + ".sha512", storedSha512);
}
// TODO: Do it better ==> add the calback to know the push progression ...
uint32_t mediaId = _srv.add(zeus::File::create(_path)).waitFor(echrono::seconds(20000)).get();
uint32_t mediaId = _srv.add(zeus::File::create(_path, storedSha512)).waitFor(echrono::seconds(20000)).get();
if (mediaId == 0) {
APPL_ERROR("Get media ID = 0 With no error");
return false;

View File

@ -236,6 +236,7 @@ ememory::SharedPtr<appl::GateWayInterface> appl::Router::get(const std::string&
APPL_INFO("New Child log in = " << logFile);
}
std::string delay = "--router-delay=" + etk::to_string(*propertyDelayToStop);
//std::string delay = "--router-delay=-1";
APPL_INFO("execute: " << binary << " " << userConf << " --srv=all " << delay << " " << basePath << " " << logFile);
int ret = execlp( binary.c_str(),
binary.c_str(), // must repeate the binary name to have the name as first argument ...

View File

@ -1,13 +1,14 @@
[Unit]
Description=zeus main router interface
Wants=network-online.target
After=network.target network-online.service
#After=network.target network-online.service
[Service]
User=Heero
User=heero
#EnvironmentFile=/etc/conf.d/ushare
ExecStart=/home/heero/.local/application/moebius-package-base.app/bin/zeus-router --elog-file= --elog-level=4
Type=simple
Nice=-10
[Install]
WantedBy=multi-user.target

View File

@ -16,6 +16,10 @@ ememory::SharedPtr<zeus::File> zeus::File::create(std::string _fileNameReal) {
return ememory::makeShared<zeus::FileImpl>(_fileNameReal);
}
ememory::SharedPtr<zeus::File> zeus::File::create(std::string _fileNameReal, std::string _sha512) {
return ememory::makeShared<zeus::FileImpl>(_fileNameReal, _sha512);
}
ememory::SharedPtr<zeus::File> zeus::File::create(std::string _fileNameReal, std::string _fileNameShow, std::string _mineType) {
return ememory::makeShared<zeus::FileImpl>(_fileNameReal, _fileNameShow, _mineType);
}
@ -29,7 +33,6 @@ zeus::FileImpl::FileImpl(std::string _fileNameReal, std::string _sha512) :
m_gettedData(0),
m_sha512(_sha512) {
m_size = m_node.fileSize();
m_node.fileOpenRead();
std::string extention;
if ( _fileNameReal.rfind('.') != std::string::npos
&& _fileNameReal.rfind('.') != 0) {
@ -52,7 +55,6 @@ zeus::FileImpl::FileImpl(std::string _fileNameReal, std::string _fileNameShow, s
m_mineType(_mineType),
m_sha512(_sha512) {
m_size = m_node.fileSize();
m_node.fileOpenRead();
if ( _sha512.size() > 0
&& _sha512.size() != 128) {
ZEUS_ERROR("Set a wrong sha512 file type");
@ -61,7 +63,9 @@ zeus::FileImpl::FileImpl(std::string _fileNameReal, std::string _fileNameShow, s
}
zeus::FileImpl::~FileImpl() {
m_node.fileClose();
if (m_node.fileIsOpen() == true) {
m_node.fileClose();
}
}
uint64_t zeus::FileImpl::getSize() {
@ -94,8 +98,12 @@ zeus::Raw zeus::FileImpl::getPart(uint64_t _start, uint64_t _stop) {
if (_start >= m_size) {
throw std::invalid_argument("REQUEST start position out of file size" + etk::to_string(_start) + " > " + etk::to_string(m_size));
}
if (m_node.fileIsOpen() == false) {
m_node.fileOpenRead();
}
m_gettedData += (_stop - _start);
ZEUS_PRINT("Reading file : " << m_gettedData << "/" << m_size << " ==> " << float(m_gettedData)/float(m_size)*100.0f << "%");
//ZEUS_PRINT("Reading file : " << m_gettedData << "/" << m_size << " ==> " << float(m_gettedData)/float(m_size)*100.0f << "%");
std::cout << "Reading file : " << m_gettedData << "/" << m_size << " ==> " << float(m_gettedData)/float(m_size)*100.0f << "% \r";
zeus::Raw tmp(_stop - _start);
if (m_node.fileSeek(_start, etk::seekNode_start) == false) {
ZEUS_ERROR("REQUEST seek error ...");
@ -103,6 +111,9 @@ zeus::Raw zeus::FileImpl::getPart(uint64_t _start, uint64_t _stop) {
return zeus::Raw();
}
int64_t sizeCopy = m_node.fileRead(tmp.writeData(), 1, _stop-_start);
if (m_size <= _stop) {
m_node.fileClose();
}
// TODO : Check if copy is correct ...
return std::move(tmp);
}

View File

@ -11,6 +11,10 @@
#param:fileName:Name of the local file to instanciate.
[factory] create(string)
#brief:Factory to create a local object.
#param:fileName:Name of the local file to instanciate.
#param:sha512: Sha-512 string if the file
[factory] create(string, string)
#brief:Factory to create a local object.
#param:fileNameReal:Name of the local file to instanciate.
#param:fileNameShow:Name of the file like the remote user will se it.
#param:mineType:Mine-type of the file.

View File

@ -115,7 +115,7 @@ std::string zeus::MediaImpl::getDecoratedName() {
ememory::SharedPtr<zeus::File> zeus::MediaImpl::getFile() {
auto it = m_metadata.find("mime-type");
if (it != m_metadata.end()) {
return zeus::File::create(m_basePath + m_fileName + "." + zeus::getExtention(it->second), "", it->second);
return zeus::File::create(m_basePath + m_fileName + "." + zeus::getExtention(it->second), "", it->second, getSha512());
}
// no mimetype specify ... ==> theoric impossible case ...
return zeus::File::create(m_basePath + m_fileName, "", "");