Skip to content

[MessageControl] Add an option to configure the interface used by UDPOutput #359

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MessageControl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ set(PLUGIN_MESSAGECONTROL_MAX_EXPORTCONNECTIONS 5 CACHE STRING "Maximum allowed
set(PLUGIN_MESSAGECONTROL_REMOTE "false" CACHE STRING "Remote binding details enabled")
set(PLUGIN_MESSAGECONTROL_PORT "0" CACHE STRING "PORT address")
set(PLUGIN_MESSAGECONTROL_BINDING "0.0.0.0" CACHE STRING "Binding IP Address")
set(PLUGIN_MESSAGECONTROL_INTERFACE "eth0" CACHE STRING "Interface to bind to")

add_subdirectory(BuffersFlush)

Expand Down
1 change: 1 addition & 0 deletions MessageControl/MessageControl.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ if boolean("@PLUGIN_MESSAGECONTROL_REMOTE@"):
remote = JSON()
remote.add("port", "@PLUGIN_MESSAGECONTROL_PORT@")
remote.add("binding", "@PLUGIN_MESSAGECONTROL_BINDING@")
remote.add("interface", "@PLUGIN_MESSAGECONTROL_INTERFACE@")
configuration.add("remote", remote)
8 changes: 6 additions & 2 deletions MessageControl/MessageControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,22 @@ namespace Thunder {
: Core::JSON::Container()
, Port(2200)
, Binding("0.0.0.0")
, Interface("eth0")
{
Add(_T("port"), &Port);
Add(_T("binding"), &Binding);
Add(_T("interface"), &Interface);
}

MessageControl::Config::NetworkNode::NetworkNode(const NetworkNode& copy)
: Core::JSON::Container()
, Port(copy.Port)
, Binding(copy.Binding)
, Interface(copy.Interface)
{
Add(_T("port"), &Port);
Add(_T("binding"), &Binding);
Add(_T("interface"), &Interface);
}

MessageControl::MessageControl()
Expand Down Expand Up @@ -115,8 +119,8 @@ namespace Thunder {
_config.FileName = service->VolatilePath() + _config.FileName.Value();
Announce(new Publishers::FileOutput(abbreviate, _config.FileName.Value()));
}
if ((_config.Remote.IsSet() == true) && (_config.Remote.Binding.Value().empty() == false) && (_config.Remote.Port.Value() != 0)) {
Announce(new Publishers::UDPOutput(abbreviate, Core::NodeId(_config.Remote.NodeId()), _service));
if ((_config.Remote.IsSet() == true) && (_config.Remote.Binding.Value().empty() == false) && (_config.Remote.Port.Value() != 0) && (_config.Remote.Interface.Value().empty() == false)) {
Announce(new Publishers::UDPOutput(abbreviate, Core::NodeId(_config.Remote.NodeId()), _service, _config.Remote.Interface.Value()));
}

_webSocketExporter.Initialize(service, _config.MaxExportConnections.Value());
Expand Down
1 change: 1 addition & 0 deletions MessageControl/MessageControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ namespace Plugin {
public:
Core::JSON::DecUInt16 Port;
Core::JSON::String Binding;
Core::JSON::String Interface;
};

public:
Expand Down
6 changes: 5 additions & 1 deletion MessageControl/MessageControlPlugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@
"bindig" : {
"type": "string",
"description": "Binding address"
},
"interface" : {
"type": "string",
"description": "Interface"
}
},
"required": [ "port", "binding" ]
"required": [ "port", "binding", "interface" ]
}
},
"required": [
Expand Down
10 changes: 8 additions & 2 deletions MessageControl/MessageOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,12 @@ namespace Publishers {
Trigger();
}

UDPOutput::UDPOutput(const Core::Messaging::MessageInfo::abbreviate abbreviate, const Core::NodeId& nodeId, PluginHost::IShell* service)
UDPOutput::UDPOutput(const Core::Messaging::MessageInfo::abbreviate abbreviate, const Core::NodeId& nodeId, PluginHost::IShell* service, const string& interface)
: _convertor(abbreviate)
, _output(nodeId)
, _notification(*this)
, _subSystem(service->SubSystems())
, _interface(interface)
{
ASSERT(_subSystem != nullptr);

Expand All @@ -198,7 +199,12 @@ namespace Publishers {
{
if (_subSystem->IsActive(PluginHost::ISubSystem::NETWORK)) {
if (_output.IsOpen() == false) {
_output.Open(0);
if (_interface.empty() == false) {
_output.Open(0, _interface);
}
else {
_output.Open(0);
}
}
ASSERT(_output.IsOpen() == true);
}
Expand Down
3 changes: 2 additions & 1 deletion MessageControl/MessageOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ namespace Publishers {
UDPOutput(const UDPOutput&) = delete;
UDPOutput& operator=(const UDPOutput&) = delete;

explicit UDPOutput(const Core::Messaging::MessageInfo::abbreviate abbreviate, const Core::NodeId& nodeId, PluginHost::IShell* service);
explicit UDPOutput(const Core::Messaging::MessageInfo::abbreviate abbreviate, const Core::NodeId& nodeId, PluginHost::IShell* service, const string& interface);

~UDPOutput() override
{
Expand All @@ -420,6 +420,7 @@ namespace Publishers {
Channel _output;
Core::SinkType<Notification> _notification;
PluginHost::ISubSystem* _subSystem;
string _interface;
};

class WebSocketOutput : public IPublish {
Expand Down
Loading