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

Broker command line options and build executable #772

Merged
merged 1 commit into from
Dec 30, 2020

Conversation

kleunen
Copy link
Contributor

@kleunen kleunen commented Dec 21, 2020

I added command line options (and config file) to configure the broker.

General options:
  --help                                produce help message
  --cfg arg                             Load configuration file
  --verbose arg (=1)                    set verbose level, possible values:
                                         0 - Fatal
                                         1 - Error
                                         2 - Warning
                                         3 - Info
                                         4 - Debug
                                         5 - Trace

TCP Server options:
  --tcp.port arg (=1883)                default port (TCP)
  --tcp.enable arg (=1)                 0/1

TCP Websocket Server options:
  --ws.port arg (=10080)                default port (TCP)
  --ws.enable arg (=0)                  0/1

TLS Server options:
  --tls.port arg (=8883)                default port (TLS)
  --tls.enable arg (=0)                 0/1
  --tls.certificate arg (=server.crt.pem)
                                        Certificate file
  --tls.private_key arg (=server.key.pem)
                                        Private key file

TLS Websocket Server options:
  --tlsws.port arg (=10443)             default port (TLS)
  --tlsws.enable arg (=0)               0/1

@codecov
Copy link

codecov bot commented Dec 21, 2020

Codecov Report

Merging #772 (827ffea) into master (89003fa) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #772   +/-   ##
=======================================
  Coverage   85.05%   85.05%           
=======================================
  Files          61       61           
  Lines        8684     8684           
=======================================
  Hits         7386     7386           
  Misses       1298     1298           

@redboltz
Copy link
Owner

I'm not sure why it happened but your PR seems to contain already merged change.
See
aaa61d1

For example

https://github.com/redboltz/mqtt_cpp/pull/772/files#diff-8438e6574a9cbca06fc27190e2dab4239f23e5e53b736428ad7b1d37dec831e7R329

is

aaa61d1#diff-8438e6574a9cbca06fc27190e2dab4239f23e5e53b736428ad7b1d37dec831e7R329

Rebase might solve the problem....?

@redboltz
Copy link
Owner

Basically, I agree to add commandline options to the example broker.
Using boost program_options is good.
Providing full options only is good. I mean shortcut option like -P shouldn't be provided at least this timing.

  --tcp.port arg (=1883)                default port (TCP)
  --tcp.enable arg (=1)                 0/1

But I don't think enabler and port pattern is good.
tcp.port depends on tcp.enable. It is confusing.
example/broker is just an example. So you don't need to care about backward compatibility.

I think that the better approach is only if ---tcp.port=1883 is provided then enable tcp.port, otherwise, disable tcp.port.
I know the well known MQTT (TCP) port is 1883. It is a good value for default.
So, how about this approach ?

Set the default --cfg parameter as broker.conf.
And mqtt_cpp provides the default broker.conf. In the broker.conf, set tcp.port as 1883.

By the way, if both broker.conf and commandline options are provided, then the commandline options should override the broker.conf one. Off course, the override should happen the individual option.

@kleunen
Copy link
Contributor Author

kleunen commented Dec 22, 2020

Rebase might solve the problem....?

Yes. Made small mistake there with rebase

@kleunen
Copy link
Contributor Author

kleunen commented Dec 22, 2020

What do you think about the executable build by CI now? I think it is useful to add to downloads on release, but maybe only build on tagged commit?

@kleunen
Copy link
Contributor Author

kleunen commented Dec 22, 2020

But I don't think enabler and port pattern is good.

But then what if you want to enable tcp and use default port

--tcp.port
Uses default port 1883
--tcp.port=12345
Use specified port?

Or maybe:
--tcp and --tcp.port as option ?

But that would be the same as I have now:

Start with default: (1883)
./broker --tcp

Start with non-default port
./broker --tcp --tcp.port=12345

@kleunen
Copy link
Contributor Author

kleunen commented Dec 22, 2020

And what about naming tls and tlsws or mqqts and wss?

@kleunen
Copy link
Contributor Author

kleunen commented Dec 22, 2020

The branch is now properly based

@kleunen
Copy link
Contributor Author

kleunen commented Dec 22, 2020

Static linking does give a warning, so I am not sure if it is really possible to completely static link the executable:

/usr/bin/clang++ -DBOOST_ASIO_NO_DEPRECATED -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -O3 -DNDEBUG -static -static-libgcc -static-libstdc++ CMakeFiles/broker.dir/broker.cpp.o -o broker  /opt/hostedtoolcache/boost/1.72.0/x64/lib/libboost_log-mt-x64.a /opt/hostedtoolcache/boost/1.72.0/x64/lib/libboost_program_options-mt-x64.a /opt/hostedtoolcache/boost/1.72.0/x64/lib/libboost_system-mt-x64.a /usr/lib/x86_64-linux-gnu/libz.a /usr/lib/x86_64-linux-gnu/libssl.a /usr/lib/x86_64-linux-gnu/libcrypto.a -ldl /opt/hostedtoolcache/boost/1.72.0/x64/lib/libboost_date_time-mt-x64.a /opt/hostedtoolcache/boost/1.72.0/x64/lib/libboost_chrono-mt-x64.a /opt/hostedtoolcache/boost/1.72.0/x64/lib/libboost_filesystem-mt-x64.a /opt/hostedtoolcache/boost/1.72.0/x64/lib/libboost_regex-mt-x64.a /opt/hostedtoolcache/boost/1.72.0/x64/lib/libboost_thread-mt-x64.a -lpthread /opt/hostedtoolcache/boost/1.72.0/x64/lib/libboost_atomic-mt-x64.a 
/usr/lib/x86_64-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
(.text+0x11): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/x86_64-linux-gnu/libcrypto.a(b_addr.o): In function `BIO_lookup_ex':
(.text+0xcfc): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/x86_64-linux-gnu/libcrypto.a(b_sock.o): In function `BIO_gethostbyname':
(.text+0x71): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

@kleunen
Copy link
Contributor Author

kleunen commented Dec 22, 2020

I removed the changes to CI from this PR, I will make a separate PR for this

CMakeLists.txt Outdated
ENDIF ()

IF (MQTT_USE_TLS)
FIND_PACKAGE (OpenSSL REQUIRED)
IF (MQTT_USE_STATIC_OPENSSL)
FIND_PACKAGE (ZLIB REQUIRED)
IF (UNIX AND NOT APPLE)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is also related to making a static build with CI, so I should move this to separate PR

Copy link
Owner

Choose a reason for hiding this comment

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

Do you move this to other PR ? Or is it required to pass CI ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is moved to other PR

@redboltz
Copy link
Owner

But I don't think enabler and port pattern is good.

But then what if you want to enable tcp and use default port

--tcp.port
Uses default port 1883
--tcp.port=12345
Use specified port?

Or maybe:
--tcp and --tcp.port as option ?

I mean if --tcp.port is not passed, then disable tcp port.
See https://wandbox.org/permlink/WVoBGEGkaHOWv4xd

If user writes broker.conf as follows:

[tcp]
port=5678

Use 5678 as TCP port,
See https://wandbox.org/permlink/rpFpFb7jsg36vAL8
Be careful, there is broker.conf tab on wandbox.

If user set command line option, then it is used:
See https://wandbox.org/permlink/NIC74audyQE2ImMl
Be careful, there is Runtime options: text box on the left of the code.

And we can provide the default broker.conf in example directory.
It can be copied to build directory using cmake COPY operation.

@kleunen
Copy link
Contributor Author

kleunen commented Dec 22, 2020

If user set command line option, then it is used:
See https://wandbox.org/permlink/NIC74audyQE2ImMl
Be careful, there is Runtime options: text box on the left of the code.

But this means you always have to specify the port, to enable TCP protocol

@redboltz
Copy link
Owner

If user set command line option, then it is used:
See https://wandbox.org/permlink/NIC74audyQE2ImMl
Be careful, there is Runtime options: text box on the left of the code.

But this means you always have to specify the port, to enable TCP protocol

Yes. It is no problem.
User should provide TCP port every time. It is better than unexpected port opens silently.
If user don't want to provide command line options, user can use broker.conf.
And broker.conf is provided by default.
So user can simple run ./broker then port 1883 is opened as TCP port.

@redboltz
Copy link
Owner

redboltz commented Dec 22, 2020

And what about naming tls and tlsws or mqqts and wss?

You mean this ?

TCP WS
NON TLS mqtt ws
TLS mqtts wss

I know this is widely used but I don't think it is good name for options.
Because it is not well structured.
ws and wss are used for generic websocket, not only mqtt.
I think that it is similar level as tcp.
I mean it is unbalance that only tcp and tls port options has mqtt information.

Here is the straight forward notation that reflects protocol layer:

TCP WS
NON TLS tcp.port tcp.ws.port
TLS tcp.tls.port tcp.tls.ws.port

I think that it is too complicated.

How about this?

TCP WS
NON TLS tcp.port ws.port
TLS tls.port wss.port

There is no mqtt information. It is redundant because the broker is for mqtt.
tcp, tls, ws, and wss are similar level.

@redboltz
Copy link
Owner

If user set command line option, then it is used:
See https://wandbox.org/permlink/NIC74audyQE2ImMl
Be careful, there is Runtime options: text box on the left of the code.

But this means you always have to specify the port, to enable TCP protocol

Yes. It is no problem.
User should provide TCP port every time. It is better than unexpected port opens silently.
If user don't want to provide command line options, user can use broker.conf.
And broker.conf is provided by default.
So user can simple run ./broker then port 1883 is opened as TCP port.

May be we need config file not found case process:
https://wandbox.org/permlink/THnT9s38bivxN63P

@kleunen
Copy link
Contributor Author

kleunen commented Dec 22, 2020

TCP WS
NON TLS tcp.port ws.port
TLS tls.port wss.port
There is no mqtt information. It is redundant because the broker is for mqtt.
tcp, tls, ws, and wss are similar level.

Yes I think this is best option

),
std::move(ctx),
std::forward<boost::asio::ssl::context>(ctx),
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
std::forward<boost::asio::ssl::context>(ctx),
MQTT_NS::force_move(ctx),

ctx is rvalue-reference not forwarding reference in your code.

),
std::move(ctx),
std::forward<boost::asio::ssl::context>(ctx),
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
std::forward<boost::asio::ssl::context>(ctx),
MQTT_NS::force_move(ctx),

ctx is rvalue-reference not forwarding reference in your code.

@kleunen
Copy link
Contributor Author

kleunen commented Dec 22, 2020

I think I changed spaces to tabs now, the coding rules does not says tabs vs spaces ?

@redboltz
Copy link
Owner

I think I changed spaces to tabs now, the coding rules does not says tabs vs spaces ?

I will add this. Please use spaces.

@kleunen
Copy link
Contributor Author

kleunen commented Dec 22, 2020

Error copying file "/Users/runner/work/mqtt_cpp/mqtt_cpp/example/server.key.pem" to "/Users/runner/work/_temp/example/broker.key.pem".

on macos.

Strange ...

@kleunen kleunen force-pushed the build_artifact branch 3 times, most recently from d2d7f64 to b048759 Compare December 22, 2020 12:08
@kleunen kleunen force-pushed the build_artifact branch 2 times, most recently from a2a21d0 to 827ffea Compare December 22, 2020 13:27
@kleunen
Copy link
Contributor Author

kleunen commented Dec 22, 2020

Maybe include a systemd init script for running the broker as well ?

@redboltz
Copy link
Owner

Sorry for my late merge. I'm under winter holidays :)

@redboltz redboltz merged commit b5e5f57 into redboltz:master Dec 30, 2020
@redboltz redboltz mentioned this pull request Dec 30, 2020
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.

2 participants