Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using gwamp to connect to crossbar #6195

Closed
wants to merge 4 commits into from
Closed

Using gwamp to connect to crossbar #6195

wants to merge 4 commits into from

Conversation

DeepDiver1975
Copy link
Member

@DeepDiver1975 DeepDiver1975 commented Nov 28, 2017

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
@@ -28,6 +28,8 @@ if(NOT TOKEN_AUTH_ONLY)
endif()
endif()

find_package(Qt5WebSockets)
Copy link
Member 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
Member 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
Member 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

@@ -47,6 +49,13 @@ if(APPLE AND NOT TOKEN_AUTH_ONLY)
set (QT_LIBRARIES ${QT_LIBRARIES} ${Qt5MacExtras_LIBRARIES})
endif()

if(Qt5WebSockets_FOUND)
Copy link
Member Author

Choose a reason for hiding this comment

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

not needed

@@ -26,8 +26,11 @@ elseif(UNIX AND NOT APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now")
endif()

find_package(Qt5Qml REQUIRED)
Copy link
Member Author

Choose a reason for hiding this comment

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

not needed

@@ -292,7 +301,7 @@ endif()

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
Member Author

Choose a reason for hiding this comment

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

not needed

@@ -157,6 +157,13 @@ set(3rdparty_SRC
../3rdparty/qtsingleapplication/qtlocalpeer.cpp
../3rdparty/qtsingleapplication/qtsingleapplication.cpp
../3rdparty/qtsingleapplication/qtsinglecoreapplication.cpp
../3rdparty/qmsgpack/src/msgpack.cpp
Copy link
Member 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
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.

@@ -157,6 +157,13 @@ set(3rdparty_SRC
../3rdparty/qtsingleapplication/qtlocalpeer.cpp
../3rdparty/qtsingleapplication/qtsingleapplication.cpp
../3rdparty/qtsingleapplication/qtsinglecoreapplication.cpp
../3rdparty/qmsgpack/src/msgpack.cpp
Copy link
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.

session->start();
});

QObject::connect(_webSocket.data(), QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error), [&](QAbstractSocket::SocketError err){
Copy link
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
Member 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

@@ -218,6 +218,10 @@ add_definitions( -D_WIN32_WINNT=0x0600)
add_definitions( -DWINVER=0x0600)
endif( WIN32 )

set(CMAKE_CXX_STANDARD 14)
Copy link
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
Member 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
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
Copy link
Contributor

guruz commented Nov 28, 2017

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

.gitmodules Outdated
url = git@github.com:unitednetworks/qwamp.git
[submodule "src/3rdparty/qmsgpack"]
path = src/3rdparty/qmsgpack
url = git@github.com:romixlab/qmsgpack.git
Copy link
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.

Choose a reason for hiding this comment

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

https://github.com/unitednetworks/qwamp
says Apache 2.0 correct? Thats perfect and I'll add it to the list.
https://github.com/romixlab/qmsgpack/blob/master/LICENSE
is MIT right? Also perfect ... I do need to add both, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes both

@@ -218,6 +218,10 @@ add_definitions( -D_WIN32_WINNT=0x0600)
add_definitions( -DWINVER=0x0600)
endif( WIN32 )

set(CMAKE_CXX_STANDARD 14)
Copy link
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

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
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 :-)

@@ -353,6 +353,7 @@ private slots:
bool _csyncUnavail;
bool _proxyDirty;
QPointer<RequestEtagJob> _requestEtagJob;
QScopedPointer<QTcpSocket> _webSocket;
Copy link
Contributor

Choose a reason for hiding this comment

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

QSslSocket?

Copy link
Member 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
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
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
Member 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
Member 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
Copy link
Contributor

guruz commented Nov 28, 2017

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
Member 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
Member Author

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

@DeepDiver1975
Copy link
Member 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

Copy link
Contributor

@ogoffart ogoffart left a comment

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
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.

_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
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.

// 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
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.

}
//initialize wamp connection
_webSocket.reset(new QTcpSocket());
QUrl webSocketUrl(wsUrl);
Copy link
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.

});

QObject::connect(_webSocket.data(), static_cast<void (QAbstractSocket::*)(QAbstractSocket::SocketError err)>(&QAbstractSocket::error), [&](QAbstractSocket::SocketError err) {
qInfo() << "tcp error: " << err;
Copy link
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.

qInfo() << _webSocket->errorString();
});
qInfo() << "Connecting to websocket " << wsUrl;
_webSocket->abort();
Copy link
Contributor

Choose a reason for hiding this comment

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

abort?

if (webSocketUrl.scheme() == "ws") {
_webSocket->connectToHost(webSocketUrl.host(), webSocketUrl.port());
} else {
qCCritical(lcFolder) << "Invalid web socket scheme: " << webSocketUrl;
Copy link
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