Skip to content

Using gwamp to connect to crossbar - #6195

Closed
DeepDiver1975 wants to merge 4 commits into
masterfrom
qwamp
Closed

DeepDiver1975 wants to merge 4 commits into
masterfrom
qwamp

Conversation

@DeepDiver1975

@DeepDiver1975 DeepDiver1975 commented Nov 28, 2017 •

Copy link
Copy Markdown
Contributor

ToDo

  • query capabilities for the wamp router endpoint
  • define proper session name - no idea what this should be
  • define a common realm which is to be used (involves server & router setup)
  • define topic names (involves server)
  • test with multiple accounts being connected to the same router - I had some issues ...
  • clarify authentication and topic access @DeepDiver1975

💟 I really love lambdas in C++ - nice to see the language evolving 💟

@DeepDiver1975 DeepDiver1975 self-assigned this Nov 28, 2017
endif()
endif()

find_package(Qt5WebSockets)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qwamp needs it - hmmm

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we patch qwamp to work without the qwebsocket dependency

set (QT_LIBRARIES ${QT_LIBRARIES} ${Qt5MacExtras_LIBRARIES})
endif()

if(Qt5WebSockets_FOUND)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

Comment thread src/CMakeLists.txt Outdated
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now")
endif()

find_package(Qt5Qml REQUIRED)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

Comment thread src/gui/CMakeLists.txt Outdated
add_library(updater STATIC ${updater_SRCS} ${updaterMoc})
target_link_libraries(updater ${synclib_NAME})
qt5_use_modules(updater Widgets Network Xml)
qt5_use_modules(updater Widgets Network Xml Qml)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

Comment thread src/gui/CMakeLists.txt
../3rdparty/qtsingleapplication/qtlocalpeer.cpp
../3rdparty/qtsingleapplication/qtsingleapplication.cpp
../3rdparty/qtsingleapplication/qtsinglecoreapplication.cpp
../3rdparty/qmsgpack/src/msgpack.cpp

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure there is a nicer way ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's fine.

The ideal way would be to have that in a separate .cmake file included in the qmsgpack repository, but since it's not the case, then so be it.

Comment thread src/gui/CMakeLists.txt
../3rdparty/qtsingleapplication/qtlocalpeer.cpp
../3rdparty/qtsingleapplication/qtsingleapplication.cpp
../3rdparty/qtsingleapplication/qtsinglecoreapplication.cpp
../3rdparty/qmsgpack/src/msgpack.cpp

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's fine.

The ideal way would be to have that in a separate .cmake file included in the qmsgpack repository, but since it's not the case, then so be it.

Comment thread src/gui/folder.cpp Outdated
session->start();
});

QObject::connect(_webSocket.data(), QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error), [&](QAbstractSocket::SocketError err){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QOverload requires Qt 5.7 (before that, we'd have to use static_cast)

(Actually, i've been thinking about copying QOverload within some header so we can use it while still being compatible with Qt 5.6)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well - what ever works - tell me whyt to do

Comment thread CMakeLists.txt
add_definitions( -DWINVER=0x0600)
endif( WIN32 )

set(CMAKE_CXX_STANDARD 14)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay, \o/ finally i'd be able to use auto in lamda :-)

I guess we can do that because we stopped supporting these old debian and centOS that did not even have GCC 4.8
although this is not strictly required for your patch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no - not required - but much more fun coding ;-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @jnweiger @dschmidt compilers

@guruz

guruz commented Nov 28, 2017

Copy link
Copy Markdown
Contributor

CI fails

[ 62%] Building CXX object test/CMakeFiles/FolderManTest.dir/__/src/gui/socketapi.cpp.o
/var/lib/jenkins/workspace/cloud-client_client_PR-6195-BV7HAL2B65CGYGSIKPS4QYBZTIWUU3BEFWV3AREJE2WQUV77E2EA/src/gui/folder.cpp:37:19: fatal error: qwamp.h: No such file or directory
 #include "qwamp.h"
                   ^
compilation terminated.
test/CMakeFiles/FolderManTest.dir/build.make:100: recipe for target 'test/CMakeFiles/FolderManTest.dir/__/src/gui/folder.cpp.o' failed

@DeepDiver1975 you can build with tests to reproduce

Comment thread .gitmodules Outdated
url = [email protected]:unitednetworks/qwamp.git
[submodule "src/3rdparty/qmsgpack"]
path = src/3rdparty/qmsgpack
url = [email protected]:romixlab/qmsgpack.git

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads-up to @hodyroff regarding licenses.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes both

Comment thread CMakeLists.txt
add_definitions( -DWINVER=0x0600)
endif( WIN32 )

set(CMAKE_CXX_STANDARD 14)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @jnweiger @dschmidt compilers

Comment thread src/gui/folder.cpp Outdated
qDebug() << "Session joined to realm1 with session ID " << s;

session->subscribe("etag-changed-channel", [&](const QVariantList& args, const QVariantMap& options){
qDebug() << "Event received";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While in general I think the lambdas are cool, we should not become a nodejs with 3x nested callbacks :-)

Comment thread src/gui/folder.h
bool _csyncUnavail;
bool _proxyDirty;
QPointer<RequestEtagJob> _requestEtagJob;
QScopedPointer<QTcpSocket> _webSocket;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QSslSocket?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guide me - can QSslSocket also establish a non-ssl connection?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use one of those depending on the account URL http vs https or how would this work? I wonder if the websocket URL should come from capabilities though so the server admin can scale it differently..

Things to keep in mind is the sslErrors signal. We have a AbstractSslErrorHandler that you can use.

The question is if websockets could return different ssl errors or not. Maybe as first implementation you assume they return the same error as the normal account WebDAV calls ..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server would expose the websocket url via a capability. The Url will either be ws:// or wss://.

So depending on using ssl or not I either call connectToHost or connectToHostEncrypted ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll postpone the ssl topic - websockets with self signed certificates are not working.
Hard to test at the moment.

@guruz

guruz commented Nov 28, 2017

Copy link
Copy Markdown
Contributor

https://github.com/romixlab/qmsgpack

By default these Qt types are supported: Int, UInt, LongLong, ULongLong, Double, QByteArray, Bool, QString, QStringList, QVariantList, QVariantMap.

Is QString serialized to the same kind of string as you will emit from the server side? So it's interoperable with non-Qt code using WAMP?

Crossbar.io supports all the favors of WAMP-over-WebSocket, including different serialization formats (JSON and MsgPack) as well as listening transports.

@DeepDiver1975

Copy link
Copy Markdown
Contributor Author

Is QString serialized to the same kind of string as you will emit from the server side? So it's interoperable with non-Qt code using WAMP?

In my non-representative local test the string as sent by the server popped up in the client the same way.
But it only contained ascii ...... need to have a second look.

@DeepDiver1975
DeepDiver1975 force-pushed the qwamp branch 2 times, most recently from 3896aa1 to 5ba6e6f Compare November 29, 2017 13:04
@DeepDiver1975

Copy link
Copy Markdown
Contributor Author

the windows build hates me - qt version? compiler used?

@DeepDiver1975

Copy link
Copy Markdown
Contributor Author

the windows build hates me - qt version? compiler used?

location of error: https://github.com/DeepDiver1975/qwamp/blob/782e65859617e52fa0d92d56551fc05da62c1f8f/qwamp.h#L415

compiler error:

[ 69%] Building CXX object src/gui/CMakeFiles/owncloud.dir/folderstatusdelegate.cpp.obj
In file included from /usr/i686-w64-mingw32/sys-root/mingw/include/windows.h:71:0,
                 from /var/lib/jenkins/workspace/cloud-client_client_PR-6195-BV7HAL2B65CGYGSIKPS4QYBZTIWUU3BEFWV3AREJE2WQUV77E2EA/src/common/utility.h:35,
                 from /var/lib/jenkins/workspace/cloud-client_client_PR-6195-BV7HAL2B65CGYGSIKPS4QYBZTIWUU3BEFWV3AREJE2WQUV77E2EA/src/gui/../libsync/account.h:31,
                 from /var/lib/jenkins/workspace/cloud-client_client_PR-6195-BV7HAL2B65CGYGSIKPS4QYBZTIWUU3BEFWV3AREJE2WQUV77E2EA/src/gui/folder.cpp:18:
/var/lib/jenkins/workspace/cloud-client_client_PR-6195-BV7HAL2B65CGYGSIKPS4QYBZTIWUU3BEFWV3AREJE2WQUV77E2EA/src/3rdparty/qwamp/qwamp.h:415:9: error: expected identifier before numeric constant
         ERROR = 8,
         ^
/var/lib/jenkins/workspace/cloud-client_client_PR-6195-BV7HAL2B65CGYGSIKPS4QYBZTIWUU3BEFWV3AREJE2WQUV77E2EA/src/3rdparty/qwamp/qwamp.h:415:9: error: expected '}' before numeric constant
/var/lib/jenkins/workspace/cloud-client_client_PR-6195-BV7HAL2B65CGYGSIKPS4QYBZTIWUU3BEFWV3AREJE2WQUV77E2EA/src/3rdparty/qwamp/qwamp.h:415:9: error: expected unqualified-id before numeric constant
In file included from /var/lib/jenkins/workspace/cloud-client_client_PR-6195-BV7HAL2B65CGYGSIKPS4QYBZTIWUU3BEFWV3AREJE2WQUV77E2EA/src/gui/folder.cpp:37:0:
/var/lib/jenkins/workspace/cloud-client_client_PR-6195-BV7HAL2B65CGYGSIKPS4QYBZTIWUU3BEFWV3AREJE2WQUV77E2EA/src/3rdparty/qwamp/qwamp.h:434:2: warning: extra ';' [-Wpedantic]
 };
  ^
/var/lib/jenkins/workspace/cloud-client_client_PR-6195-BV7HAL2B65CGYGSIKPS4QYBZTIWUU3BEFWV3AREJE2WQUV77E2EA/src/3rdparty/qwamp/qwamp.h:450:1: error: expected declaration before '}' token
 }
 ^
cc1plus: warning: unrecognized command line option '-Wno-gnu-zero-variadic-macro-arguments'
src/gui/CMakeFiles/owncloud.dir/build.make:573: recipe for target 'src/gui/CMakeFiles/owncloud.dir/folder.cpp.obj' failed
make[2]: *** [src/gui/CMakeFiles/owncloud.dir/folder.cpp.obj] Error 1

@ogoffart ogoffart left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are lots of unrelated whitespace changes.

QString Capabilities::getWebSocketUrl() const
{
if (!_capabilities.contains("websocket")) {
return "";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return QString()

(Otherwise you make a useless conversion from char*)

Also later.

Comment thread src/gui/folder.cpp
_session.reset(new QWamp::Session(sessionName, *_webSocket.data(), QWamp::Session::MessageFormat::Msgpack, true));

QObject::connect(_session.data(), &QWamp::Session::joined, [&](qint64 s) {
qDebug() << "Session joined to realm1 with session ID " << s;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is only temporary and you are going to clean up. In the final PR there should be no qDebug without categories.

Comment thread src/gui/folder.cpp
// TODO: add current userid
_session->subscribe("files.root-etag-changed.admin", [&](const QVariantList& args, const QVariantMap& options) {
qDebug() << "Event received";
QString notificationEtag = args.at(0).toString();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QList::at crashes if the list don't have enough argument, which can happen, i guess, if the server is sending garbage.
So you can use value() which will return an empty variant if out of bounds. or you should check if there is enough element in the list before.

Comment thread src/gui/folder.cpp
}
//initialize wamp connection
_webSocket.reset(new QTcpSocket());
QUrl webSocketUrl(wsUrl);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also probably need to handle the disconnect case, and re try to connect. Also handle error such as timeout and other kind.
So you will need to move this connection code somewhere else so you can call it when you want to re-connect.

Comment thread src/gui/folder.cpp
});

QObject::connect(_webSocket.data(), static_cast<void (QAbstractSocket::*)(QAbstractSocket::SocketError err)>(&QAbstractSocket::error), [&](QAbstractSocket::SocketError err) {
qInfo() << "tcp error: " << err;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably deserve to be a qCWarning. Don't forget to add a category. Also keep it in one line.

Comment thread src/gui/folder.cpp
qInfo() << _webSocket->errorString();
});
qInfo() << "Connecting to websocket " << wsUrl;
_webSocket->abort();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abort?

Comment thread src/gui/folder.cpp
if (webSocketUrl.scheme() == "ws") {
_webSocket->connectToHost(webSocketUrl.host(), webSocketUrl.port());
} else {
qCCritical(lcFolder) << "Invalid web socket scheme: " << webSocketUrl;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qCWarning... critical is a bit too high.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants