mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
rename atp-get to atp-client. add ability to list atp file mappings and to upload new files
This commit is contained in:
parent
fad686571a
commit
e9a8c3f5e8
5 changed files with 179 additions and 63 deletions
|
@ -17,8 +17,8 @@ set_target_properties(ac-client PROPERTIES FOLDER "Tools")
|
|||
add_subdirectory(skeleton-dump)
|
||||
set_target_properties(skeleton-dump PROPERTIES FOLDER "Tools")
|
||||
|
||||
add_subdirectory(atp-get)
|
||||
set_target_properties(atp-get PROPERTIES FOLDER "Tools")
|
||||
add_subdirectory(atp-client)
|
||||
set_target_properties(atp-client PROPERTIES FOLDER "Tools")
|
||||
|
||||
add_subdirectory(oven)
|
||||
set_target_properties(oven PROPERTIES FOLDER "Tools")
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
set(TARGET_NAME atp-get)
|
||||
set(TARGET_NAME atp-client)
|
||||
setup_hifi_project(Core Widgets)
|
||||
setup_memory_debugger()
|
||||
link_hifi_libraries(shared networking)
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// ATPGetApp.cpp
|
||||
// tools/atp-get/src
|
||||
// ATPClientApp.cpp
|
||||
// tools/atp-client/src
|
||||
//
|
||||
// Created by Seth Alves on 2017-3-15
|
||||
// Copyright 2017 High Fidelity, Inc.
|
||||
|
@ -15,26 +15,36 @@
|
|||
#include <QFile>
|
||||
#include <QLoggingCategory>
|
||||
#include <QCommandLineParser>
|
||||
|
||||
#include <NetworkLogging.h>
|
||||
#include <SharedLogging.h>
|
||||
#include <AddressManager.h>
|
||||
#include <DependencyManager.h>
|
||||
#include <SettingHandle.h>
|
||||
#include <AssetUpload.h>
|
||||
|
||||
#include "ATPGetApp.h"
|
||||
#include "ATPClientApp.h"
|
||||
|
||||
ATPGetApp::ATPGetApp(int argc, char* argv[]) :
|
||||
#define HIGH_FIDELITY_ATP_CLIENT_USER_AGENT "Mozilla/5.0 (HighFidelityATPClient)"
|
||||
|
||||
ATPClientApp::ATPClientApp(int argc, char* argv[]) :
|
||||
QCoreApplication(argc, argv)
|
||||
{
|
||||
// parse command-line
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription("High Fidelity ATP-Get");
|
||||
parser.setApplicationDescription("High Fidelity ATP-Client");
|
||||
|
||||
const QCommandLineOption helpOption = parser.addHelpOption();
|
||||
|
||||
const QCommandLineOption verboseOutput("v", "verbose output");
|
||||
parser.addOption(verboseOutput);
|
||||
|
||||
const QCommandLineOption uploadOption("T", "upload local file", "local-file-to-send");
|
||||
parser.addOption(uploadOption);
|
||||
|
||||
const QCommandLineOption outputFilenameOption("o", "output filename", "output-file-name");
|
||||
parser.addOption(outputFilenameOption);
|
||||
|
||||
const QCommandLineOption domainAddressOption("d", "domain-server address", "127.0.0.1");
|
||||
parser.addOption(domainAddressOption);
|
||||
|
||||
|
@ -70,67 +80,94 @@ ATPGetApp::ATPGetApp(int argc, char* argv[]) :
|
|||
}
|
||||
|
||||
|
||||
QStringList filenames = parser.positionalArguments();
|
||||
if (filenames.empty() || filenames.size() > 2) {
|
||||
qDebug() << "give remote url and optional local filename as arguments";
|
||||
QStringList posArgs = parser.positionalArguments();
|
||||
if (posArgs.size() != 1) {
|
||||
qDebug() << "give remote url argument";
|
||||
parser.showHelp();
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
|
||||
_url = QUrl(filenames[0]);
|
||||
_url = QUrl(posArgs[0]);
|
||||
if (_url.scheme() != "atp") {
|
||||
qDebug() << "url should start with atp:";
|
||||
parser.showHelp();
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
|
||||
if (filenames.size() == 2) {
|
||||
_localOutputFile = filenames[1];
|
||||
int domainPort = 40103;
|
||||
if (_url.port() != -1) {
|
||||
domainPort = _url.port();
|
||||
}
|
||||
|
||||
QString domainServerAddress = "127.0.0.1:40103";
|
||||
if (parser.isSet(outputFilenameOption)) {
|
||||
_localOutputFile = parser.value(outputFilenameOption);
|
||||
}
|
||||
|
||||
if (parser.isSet(uploadOption)) {
|
||||
_localUploadFile = parser.value(uploadOption);
|
||||
}
|
||||
|
||||
|
||||
if (parser.isSet(listenPortOption)) {
|
||||
_listenPort = parser.value(listenPortOption).toInt();
|
||||
}
|
||||
|
||||
QString domainServerAddress = QString("127.0.0.1") + ":" + QString::number(domainPort);
|
||||
if (parser.isSet(domainAddressOption)) {
|
||||
domainServerAddress = parser.value(domainAddressOption);
|
||||
qDebug() << "domainServerAddress is " << domainServerAddress;
|
||||
connectToDomain(domainServerAddress);
|
||||
} else if (!_url.host().isEmpty()) {
|
||||
QUrl domainURL;
|
||||
domainURL.setScheme("hifi");
|
||||
domainURL.setHost(_url.host());
|
||||
connectToDomain(domainURL.toString());
|
||||
} else {
|
||||
qDebug() << "domainServerAddress is default " << domainServerAddress;
|
||||
connectToDomain(domainServerAddress);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ATPClientApp::connectToDomain(QString domainServerAddress) {
|
||||
|
||||
if (_verbose) {
|
||||
qDebug() << "domain-server address is" << domainServerAddress;
|
||||
}
|
||||
|
||||
int listenPort = INVALID_PORT;
|
||||
if (parser.isSet(listenPortOption)) {
|
||||
listenPort = parser.value(listenPortOption).toInt();
|
||||
}
|
||||
DependencyManager::set<AccountManager>();
|
||||
auto accountManager = DependencyManager::get<AccountManager>();
|
||||
QString username = accountManager->getAccountInfo().getUsername();
|
||||
qDebug() << "username is" << username;
|
||||
|
||||
Setting::init();
|
||||
DependencyManager::registerInheritance<LimitedNodeList, NodeList>();
|
||||
|
||||
DependencyManager::set<AccountManager>([&]{ return QString("Mozilla/5.0 (HighFidelityATPGet)"); });
|
||||
DependencyManager::set<AccountManager>([&]{ return QString(HIGH_FIDELITY_ATP_CLIENT_USER_AGENT); });
|
||||
DependencyManager::set<AddressManager>();
|
||||
DependencyManager::set<NodeList>(NodeType::Agent, listenPort);
|
||||
|
||||
DependencyManager::set<NodeList>(NodeType::Agent, _listenPort);
|
||||
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
nodeList->startThread();
|
||||
|
||||
// setup a timer for domain-server check ins
|
||||
QTimer* domainCheckInTimer = new QTimer(nodeList.data());
|
||||
connect(domainCheckInTimer, &QTimer::timeout, nodeList.data(), &NodeList::sendDomainServerCheckIn);
|
||||
domainCheckInTimer->start(DOMAIN_SERVER_CHECK_IN_MSECS);
|
||||
_domainCheckInTimer = new QTimer(nodeList.data());
|
||||
connect(_domainCheckInTimer, &QTimer::timeout, nodeList.data(), &NodeList::sendDomainServerCheckIn);
|
||||
_domainCheckInTimer->start(DOMAIN_SERVER_CHECK_IN_MSECS);
|
||||
|
||||
const DomainHandler& domainHandler = nodeList->getDomainHandler();
|
||||
|
||||
connect(&domainHandler, SIGNAL(hostnameChanged(const QString&)), SLOT(domainChanged(const QString&)));
|
||||
// connect(&domainHandler, SIGNAL(resetting()), SLOT(resettingDomain()));
|
||||
// connect(&domainHandler, SIGNAL(disconnectedFromDomain()), SLOT(clearDomainOctreeDetails()));
|
||||
connect(&domainHandler, &DomainHandler::domainConnectionRefused, this, &ATPGetApp::domainConnectionRefused);
|
||||
connect(&domainHandler, &DomainHandler::domainConnectionRefused, this, &ATPClientApp::domainConnectionRefused);
|
||||
|
||||
connect(nodeList.data(), &NodeList::nodeAdded, this, &ATPGetApp::nodeAdded);
|
||||
connect(nodeList.data(), &NodeList::nodeKilled, this, &ATPGetApp::nodeKilled);
|
||||
connect(nodeList.data(), &NodeList::nodeActivated, this, &ATPGetApp::nodeActivated);
|
||||
connect(nodeList.data(), &NodeList::nodeAdded, this, &ATPClientApp::nodeAdded);
|
||||
connect(nodeList.data(), &NodeList::nodeKilled, this, &ATPClientApp::nodeKilled);
|
||||
connect(nodeList.data(), &NodeList::nodeActivated, this, &ATPClientApp::nodeActivated);
|
||||
// connect(nodeList.data(), &NodeList::uuidChanged, getMyAvatar(), &MyAvatar::setSessionUUID);
|
||||
// connect(nodeList.data(), &NodeList::uuidChanged, this, &ATPGetApp::setSessionUUID);
|
||||
connect(nodeList.data(), &NodeList::packetVersionMismatch, this, &ATPGetApp::notifyPacketVersionMismatch);
|
||||
// connect(nodeList.data(), &NodeList::uuidChanged, this, &ATPClientApp::setSessionUUID);
|
||||
connect(nodeList.data(), &NodeList::packetVersionMismatch, this, &ATPClientApp::notifyPacketVersionMismatch);
|
||||
|
||||
nodeList->addSetOfNodeTypesToNodeInterestSet(NodeSet() << NodeType::AudioMixer << NodeType::AvatarMixer
|
||||
<< NodeType::EntityServer << NodeType::AssetServer << NodeType::MessagesMixer);
|
||||
|
@ -140,63 +177,131 @@ ATPGetApp::ATPGetApp(int argc, char* argv[]) :
|
|||
auto assetClient = DependencyManager::set<AssetClient>();
|
||||
assetClient->init();
|
||||
|
||||
QTimer* doTimer = new QTimer(this);
|
||||
doTimer->setSingleShot(true);
|
||||
connect(doTimer, &QTimer::timeout, this, &ATPGetApp::timedOut);
|
||||
doTimer->start(4000);
|
||||
QTimer* _timeoutTimer = new QTimer(this);
|
||||
_timeoutTimer->setSingleShot(true);
|
||||
connect(_timeoutTimer, &QTimer::timeout, this, &ATPClientApp::timedOut);
|
||||
_timeoutTimer->start(4000);
|
||||
}
|
||||
|
||||
ATPGetApp::~ATPGetApp() {
|
||||
ATPClientApp::~ATPClientApp() {
|
||||
delete _domainCheckInTimer;
|
||||
delete _timeoutTimer;
|
||||
}
|
||||
|
||||
|
||||
void ATPGetApp::domainConnectionRefused(const QString& reasonMessage, int reasonCodeInt, const QString& extraInfo) {
|
||||
void ATPClientApp::domainConnectionRefused(const QString& reasonMessage, int reasonCodeInt, const QString& extraInfo) {
|
||||
qDebug() << "domainConnectionRefused";
|
||||
}
|
||||
|
||||
void ATPGetApp::domainChanged(const QString& domainHostname) {
|
||||
void ATPClientApp::domainChanged(const QString& domainHostname) {
|
||||
if (_verbose) {
|
||||
qDebug() << "domainChanged";
|
||||
}
|
||||
}
|
||||
|
||||
void ATPGetApp::nodeAdded(SharedNodePointer node) {
|
||||
void ATPClientApp::nodeAdded(SharedNodePointer node) {
|
||||
if (_verbose) {
|
||||
qDebug() << "node added: " << node->getType();
|
||||
}
|
||||
}
|
||||
|
||||
void ATPGetApp::nodeActivated(SharedNodePointer node) {
|
||||
void ATPClientApp::nodeActivated(SharedNodePointer node) {
|
||||
if (node->getType() == NodeType::AssetServer) {
|
||||
lookup();
|
||||
auto path = _url.path();
|
||||
|
||||
if (_verbose) {
|
||||
qDebug() << "path is " << path;
|
||||
}
|
||||
|
||||
qDebug() << "_localUploadFile =" << _localUploadFile;
|
||||
|
||||
if (!_localUploadFile.isEmpty()) {
|
||||
uploadAsset();
|
||||
} else if (path == "/") {
|
||||
listAssets();
|
||||
} else {
|
||||
lookupAsset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ATPGetApp::nodeKilled(SharedNodePointer node) {
|
||||
void ATPClientApp::nodeKilled(SharedNodePointer node) {
|
||||
qDebug() << "nodeKilled";
|
||||
}
|
||||
|
||||
void ATPGetApp::timedOut() {
|
||||
void ATPClientApp::timedOut() {
|
||||
finish(1);
|
||||
}
|
||||
|
||||
void ATPGetApp::notifyPacketVersionMismatch() {
|
||||
void ATPClientApp::notifyPacketVersionMismatch() {
|
||||
if (_verbose) {
|
||||
qDebug() << "packet version mismatch";
|
||||
}
|
||||
finish(1);
|
||||
}
|
||||
|
||||
void ATPGetApp::lookup() {
|
||||
|
||||
void ATPClientApp::uploadAsset() {
|
||||
auto path = _url.path();
|
||||
qDebug() << "path is " << path;
|
||||
if (path == "/") {
|
||||
qDebug() << "cannot upload to path of /";
|
||||
QCoreApplication::exit(1);
|
||||
}
|
||||
|
||||
auto upload = DependencyManager::get<AssetClient>()->createUpload(_localUploadFile);
|
||||
QObject::connect(upload, &AssetUpload::finished, this, [=](AssetUpload* upload, const QString& hash) mutable {
|
||||
if (upload->getError() != AssetUpload::NoError) {
|
||||
qDebug() << "upload failed: " << upload->getErrorString();
|
||||
} else {
|
||||
setMapping(hash);
|
||||
}
|
||||
|
||||
upload->deleteLater();
|
||||
});
|
||||
|
||||
upload->start();
|
||||
}
|
||||
|
||||
void ATPClientApp::setMapping(QString hash) {
|
||||
auto path = _url.path();
|
||||
auto assetClient = DependencyManager::get<AssetClient>();
|
||||
auto request = assetClient->createSetMappingRequest(path, hash);
|
||||
|
||||
connect(request, &SetMappingRequest::finished, this, [=](SetMappingRequest* request) mutable {
|
||||
if (request->getError() != SetMappingRequest::NoError) {
|
||||
qDebug() << "upload succeeded, but couldn't set mapping: " << request->getErrorString();
|
||||
}
|
||||
request->deleteLater();
|
||||
});
|
||||
|
||||
request->start();
|
||||
}
|
||||
|
||||
void ATPClientApp::listAssets() {
|
||||
auto request = DependencyManager::get<AssetClient>()->createGetAllMappingsRequest();
|
||||
QObject::connect(request, &GetAllMappingsRequest::finished, this, [=](GetAllMappingsRequest* request) mutable {
|
||||
auto result = request->getError();
|
||||
if (result == GetAllMappingsRequest::NotFound) {
|
||||
qDebug() << "not found: " << request->getErrorString();
|
||||
} else if (result == GetAllMappingsRequest::NoError) {
|
||||
auto mappings = request->getMappings();
|
||||
for (auto& kv : mappings ) {
|
||||
qDebug() << kv.first << kv.second;
|
||||
}
|
||||
} else {
|
||||
qDebug() << "error -- " << request->getError() << " -- " << request->getErrorString();
|
||||
}
|
||||
request->deleteLater();
|
||||
});
|
||||
request->start();
|
||||
}
|
||||
|
||||
void ATPClientApp::lookupAsset() {
|
||||
auto path = _url.path();
|
||||
auto request = DependencyManager::get<AssetClient>()->createGetMappingRequest(path);
|
||||
QObject::connect(request, &GetMappingRequest::finished, this, [=](GetMappingRequest* request) mutable {
|
||||
auto result = request->getError();
|
||||
if (result == GetMappingRequest::NotFound) {
|
||||
qDebug() << "not found";
|
||||
qDebug() << "not found: " << request->getErrorString();
|
||||
} else if (result == GetMappingRequest::NoError) {
|
||||
qDebug() << "found, hash is " << request->getHash();
|
||||
download(request->getHash());
|
||||
|
@ -208,7 +313,7 @@ void ATPGetApp::lookup() {
|
|||
request->start();
|
||||
}
|
||||
|
||||
void ATPGetApp::download(AssetHash hash) {
|
||||
void ATPClientApp::download(AssetHash hash) {
|
||||
auto assetClient = DependencyManager::get<AssetClient>();
|
||||
auto assetRequest = new AssetRequest(hash);
|
||||
|
||||
|
@ -217,7 +322,7 @@ void ATPGetApp::download(AssetHash hash) {
|
|||
|
||||
if (request->getError() == AssetRequest::Error::NoError) {
|
||||
QString data = QString::fromUtf8(request->getData());
|
||||
if (_localOutputFile == "") {
|
||||
if (_localOutputFile == "" || _localOutputFile == "-") {
|
||||
QTextStream cout(stdout);
|
||||
cout << data;
|
||||
} else {
|
||||
|
@ -238,7 +343,7 @@ void ATPGetApp::download(AssetHash hash) {
|
|||
assetRequest->start();
|
||||
}
|
||||
|
||||
void ATPGetApp::finish(int exitCode) {
|
||||
void ATPClientApp::finish(int exitCode) {
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
|
||||
// send the domain a disconnect packet, force stoppage of domain-server check-ins
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// ATPGetApp.h
|
||||
// tools/atp-get/src
|
||||
// ATPClientApp.h
|
||||
// tools/atp-client/src
|
||||
//
|
||||
// Created by Seth Alves on 2017-3-15
|
||||
// Copyright 2017 High Fidelity, Inc.
|
||||
|
@ -10,8 +10,8 @@
|
|||
//
|
||||
|
||||
|
||||
#ifndef hifi_ATPGetApp_h
|
||||
#define hifi_ATPGetApp_h
|
||||
#ifndef hifi_ATPClientApp_h
|
||||
#define hifi_ATPClientApp_h
|
||||
|
||||
#include <QApplication>
|
||||
#include <udt/Constants.h>
|
||||
|
@ -23,11 +23,11 @@
|
|||
#include <MappingRequest.h>
|
||||
|
||||
|
||||
class ATPGetApp : public QCoreApplication {
|
||||
class ATPClientApp : public QCoreApplication {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ATPGetApp(int argc, char* argv[]);
|
||||
~ATPGetApp();
|
||||
ATPClientApp(int argc, char* argv[]);
|
||||
~ATPClientApp();
|
||||
|
||||
private slots:
|
||||
void domainConnectionRefused(const QString& reasonMessage, int reasonCodeInt, const QString& extraInfo);
|
||||
|
@ -38,15 +38,26 @@ private slots:
|
|||
void notifyPacketVersionMismatch();
|
||||
|
||||
private:
|
||||
void connectToDomain(QString domainServerAddress);
|
||||
|
||||
NodeList* _nodeList;
|
||||
void timedOut();
|
||||
void lookup();
|
||||
void uploadAsset();
|
||||
void setMapping(QString hash);
|
||||
void lookupAsset();
|
||||
void listAssets();
|
||||
void download(AssetHash hash);
|
||||
void finish(int exitCode);
|
||||
bool _verbose;
|
||||
|
||||
QUrl _url;
|
||||
QString _localOutputFile;
|
||||
QString _localUploadFile;
|
||||
|
||||
int _listenPort { INVALID_PORT };
|
||||
|
||||
QTimer* _domainCheckInTimer { nullptr };
|
||||
QTimer* _timeoutTimer { nullptr };
|
||||
};
|
||||
|
||||
#endif // hifi_ATPGetApp_h
|
||||
#endif // hifi_ATPClientApp_h
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// main.cpp
|
||||
// tools/atp-get/src
|
||||
// tools/atp-client/src
|
||||
//
|
||||
// Created by Seth Alves on 2017-3-15
|
||||
// Copyright 2017 High Fidelity, Inc.
|
||||
|
@ -15,7 +15,7 @@
|
|||
|
||||
#include <BuildInfo.h>
|
||||
|
||||
#include "ATPGetApp.h"
|
||||
#include "ATPClientApp.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -25,7 +25,7 @@ int main(int argc, char * argv[]) {
|
|||
QCoreApplication::setOrganizationDomain(BuildInfo::ORGANIZATION_DOMAIN);
|
||||
QCoreApplication::setApplicationVersion(BuildInfo::VERSION);
|
||||
|
||||
ATPGetApp app(argc, argv);
|
||||
ATPClientApp app(argc, argv);
|
||||
|
||||
return app.exec();
|
||||
}
|
Loading…
Reference in a new issue