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

[REVIEW] Integrate libwebsockets library #5683

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NoelGraf
Copy link
Member

This PR integrates libwebsockets library into the open62541 stack. The integration is done via the adapter in arch/lws. This adapter acts as a custom "event library" interface layer between the lws event lib support and the open62541 event loop. By integrating in this way, the libwebsockets library makes use of the open62541 event loop, which allows for a perfect integration into the stack.

Copy link
Member

@jpfr jpfr left a comment

Choose a reason for hiding this comment

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

Very nice!
Comments inline.

.gitmodules Outdated
@@ -13,3 +13,6 @@
path = deps/nodesetLoader
url = https://github.com/open62541/nodesetLoader
branch = master
[submodule "deps/libwebsockets"]
Copy link
Member

Choose a reason for hiding this comment

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

Don't use a git submodule.
99% of users should install libwebsockets via a package manager.
And the remaining 1% know how to do it themselves.

Copy link
Member

Choose a reason for hiding this comment

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

Remove the submodule. The users should manually install or use a distorted package.

CMakeLists.txt Outdated
set(LIBWEBSOCKETS_FOUND 0)
endif()
endif()
if(NOT LIBWEBSOCKETS_FOUND)
Copy link
Member

Choose a reason for hiding this comment

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

Throw an exception when not found.
The find_package thing allows users to manually define the folders.
That should be the only way of doing things.
Like for OpenSSL/mbedTLS.

Copy link
Member

Choose a reason for hiding this comment

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

Do not modify settings.
Abort with a warning when you cannot build.

CMakeLists.txt Outdated
#Libwebsockets
if(UA_ENABLE_LWS)
if(NOT LIBWEBSOCKETS_FOUND)
add_dependencies(open62541-object websockets_shared)
Copy link
Member

Choose a reason for hiding this comment

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

Not needed. LIBWEBSOCKETS_FOUND has to be true.

arch/eventloop_lws_http.c Outdated Show resolved Hide resolved
const UA_DataType *type;
UA_Boolean required;
} HTTPSendParameters[HTTP_PARAMETERSSIZE] = {
{{0, UA_STRING_STATIC("url")}, &UA_TYPES[UA_TYPES_STRING], true},
Copy link
Member

Choose a reason for hiding this comment

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

You mean address instead of url.
The url would include the port and path as well.
How would this be extended for https?
You can already add this as a comment.

}

static UA_StatusCode
HTTP_sendWithConnection(UA_ConnectionManager *cm, uintptr_t connectionId,
Copy link
Member

Choose a reason for hiding this comment

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

HTTP is synchronous.
So you have to wait for the previous request to receive a response before sending the next request.
Ensure there can be no misuse.

So either

  • block sending requests while still waiting for a response
  • Add the next requests to a list and send them out automatically later on.

}

static const struct lws_event_loop_ops event_loop_ops_custom = {
.name = "custom",
Copy link
Member

Choose a reason for hiding this comment

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

don't use tabs


UA_KeyValueMap map = {paramsSize, params};

cm->openConnection(cm, NULL, NULL, NULL, NULL);
Copy link
Member

Choose a reason for hiding this comment

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

Add a callback to log the received result.
Also add the handling of failure cases where the remote side does not exist.

How are HTTP status codes lik 404 handled?
Given to the callback as part of the parameter map?

include/open62541/util.h Show resolved Hide resolved
/usr/local/include
/usr/include
)
pkg_search_module(LIBWEBSOCKETS REQUIRED libwebsockets)
Copy link
Member

Choose a reason for hiding this comment

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

This requires pkg-config and is only available for Linux.
The previous cmake file was multi-platform.
And it should stay that way.

@jpfr
Copy link
Member

jpfr commented Mar 14, 2023

On more point.
The current Debian and Ubuntu releases are at lws version 4.0 and 4.1.
We should be compatible out-of-the-box with these.

Try to get as low as possible in the version requirements.
But stop before the #ifdef jungle gets too messy.

@NoelGraf NoelGraf force-pushed the feat_integrate_libwebsockets branch from edee065 to a7bf9bc Compare April 13, 2023 08:06
@NoelGraf NoelGraf force-pushed the feat_integrate_libwebsockets branch from ea334fc to 1401b4d Compare June 2, 2023 12:57
@NoelGraf NoelGraf force-pushed the feat_integrate_libwebsockets branch 2 times, most recently from 2687aeb to e4e5741 Compare June 29, 2023 09:23
@NoelGraf NoelGraf force-pushed the feat_integrate_libwebsockets branch from 37c498e to 2272aa2 Compare July 11, 2023 08:53
@NoelGraf NoelGraf changed the title [WIP] Integrate libwebsockets library [REVIEW] Integrate libwebsockets library Jul 11, 2023
Copy link
Member

@jpfr jpfr left a comment

Choose a reason for hiding this comment

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

Looks good. A few comments were unresolved from last time.
Let’s merge this for 1.4!

.gitmodules Outdated
@@ -13,3 +13,6 @@
path = deps/nodesetLoader
url = https://github.com/open62541/nodesetLoader
branch = master
[submodule "deps/libwebsockets"]
Copy link
Member

Choose a reason for hiding this comment

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

Remove the submodule. The users should manually install or use a distorted package.

CMakeLists.txt Outdated
set(LIBWEBSOCKETS_FOUND 0)
endif()
endif()
if(NOT LIBWEBSOCKETS_FOUND)
Copy link
Member

Choose a reason for hiding this comment

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

Do not modify settings.
Abort with a warning when you cannot build.


static UA_StatusCode
HTTP_eventSourceDelete(UA_ConnectionManager *cm) {
UA_String_clear(&cm->eventSource.name);
Copy link
Member

Choose a reason for hiding this comment

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

Still unresolved

* Open Connection Parameters:
* - 0:hostname [string]: Hostname (or IPv4/v6 address) of the connection (required).
* - 0:port [uint16]: Port of the target host (default: 443).
* - 0:path [string]: Path is the string of information that comes after the top level domain name (default: /).
Copy link
Member

Choose a reason for hiding this comment

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

The way I understand it, the connection will stay open for multiple requests.
The path, method and data should be parameters for sendWithConnection, not here.

@jpfr jpfr force-pushed the feat_integrate_libwebsockets branch from fae739c to b4fd3d5 Compare September 25, 2023 12:41
@jpfr jpfr force-pushed the feat_integrate_libwebsockets branch from b4fd3d5 to 6bf5e32 Compare February 12, 2024 10:20
@jpfr
Copy link
Member

jpfr commented Feb 12, 2024

Rebased on master.
The examples segfault...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants