-
Notifications
You must be signed in to change notification settings - Fork 232
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
integrate the mDNS client into the publisher. Start mDNS client, if there is a existing server running on the system. #16
Conversation
2bae93b
to
f62583d
Compare
|
||
#include "common/code_utils.hpp" | ||
#include "mdns_publisher.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"mdns_publisher.hpp" should be kept as the first included file.
Preprocessor #include directives should be grouped, ordered, or sorted as follows:
This compilation unit's corresponding header, if any.
C++ Standard Library headers
C Standard Library headers
Third-party library headers
First-party library headers
Private or local headers
Alphanumeric order within each subgroup
@@ -222,20 +376,58 @@ void Publisher::SetServiceName(const char *aServiceName) | |||
mServiceName = avahi_strdup(aServiceName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to leak memory here? It seems the previous memory of mServiceNames
is not freed.
src/web/web-service/web_service.cpp
Outdated
sNetworkName = "nn=" + sNetworkName; | ||
sExtPanId = "xp=" + sExtPanId; | ||
ot::Mdns::Publisher::SetNetworkNameTxT(sNetworkName.c_str()); | ||
ot::Mdns::Publisher::SetEPANIDTxT(sExtPanId.c_str()); | ||
ot::Mdns::Publisher::Instance().SetNetworkNameTxT(sNetworkName.c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it safe to let Publisher
save the pointer returned by std::string::c_str()
? Below is the doc of std::string::c_str()
The pointer returned may be invalidated by further calls to other member functions that modify the object.
avahi_simple_poll_quit(mSimplePoll); | ||
if (mServer) | ||
avahi_server_free(mServer); | ||
StartClient(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing break;
below?
d6822be
to
9113a9a
Compare
void PeriodicallyPublish(AVAHI_GCC_UNUSED AvahiTimeout *aTimeout); | ||
void Free(void); | ||
|
||
static Publisher &Instance(void) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Methods should have a verb (e.g. GetInstance()
).
@@ -31,6 +31,9 @@ | |||
* This file implements starting an mDNS server, and publish border router service. | |||
*/ | |||
|
|||
#include <avahi-client/publish.h> | |||
#include <avahi-core/publish.h> | |||
|
|||
#include "common/code_utils.hpp" | |||
|
|||
#include "mdns_publisher.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compilation unit's corresponding header should appear first.
break; | ||
|
||
case AVAHI_CLIENT_CONNECTING: | ||
; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know break
is not needed, but it is cleaner to include it.
break; | ||
|
||
case AVAHI_SERVER_FAILURE: | ||
|
||
syslog(LOG_ERR, "Server failure: %s\n", | ||
avahi_strerror(avahi_server_errno(aServer))); | ||
avahi_simple_poll_quit(mSimplePoll); | ||
isStart = false; | ||
break; | ||
|
||
case AVAHI_SERVER_INVALID: | ||
; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include break
here.
|
||
if ((mClient != NULL) && (avahi_client_get_state(mClient) == AVAHI_CLIENT_S_RUNNING)) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary newline.
|
||
Free(); | ||
return ret; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary newline.
|
||
case AVAHI_ENTRY_GROUP_UNCOMMITED: | ||
case AVAHI_ENTRY_GROUP_REGISTERING: | ||
; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include break
.
static uint16_t mPort; | ||
static char *mServiceName; | ||
static bool isStart; | ||
void ServerCallback(AvahiServer *aServer, AvahiServerState aState); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Methods should include verbs. For example HandleServerCallback()
, or something more appropriate.
AVAHI_GCC_UNUSED void *aUserData); | ||
void ClientCallback(AvahiClient *aClient, AvahiClientState aState); | ||
|
||
static void PeriodicallyPublish(AVAHI_GCC_UNUSED AvahiTimeout *aTimeout, AVAHI_GCC_UNUSED void *aUserData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Methods should include verbs. PeriodicallyPublish
does not tell me what this method actually does.
75237de
to
333ad64
Compare
|
||
if (avahi_entry_group_is_empty(mClientGroup)) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing this issue. I think we should consider if core api of avahi should be avoided later, as suggested in avahi's doc.
@@ -70,6 +101,11 @@ void Publisher::Free(void) | |||
avahi_server_free(mServer); | |||
} | |||
|
|||
if (mClient) | |||
{ | |||
avahi_client_free(mClient); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add mClient = NULL
?
@@ -70,6 +101,11 @@ void Publisher::Free(void) | |||
avahi_server_free(mServer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add mServer = NULL
?
@@ -78,21 +114,80 @@ void Publisher::Free(void) | |||
avahi_free(mServiceName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize mServiceName
and check if it's NULL here?
mNetworkNameTxt, mExtPanIdTxt, NULL) == 0, | ||
ret = kMdnsPublisher_FailedAddSevice); | ||
|
||
syslog(LOG_INFO, " Service Name: %s \n Port: %d \n Network Name: %s \n Extended Pan ID: %s \n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syslog should not include \n
serviceName = avahi_alternative_service_name(mServiceName); | ||
avahi_free(mServiceName); | ||
mServiceName = serviceName; | ||
syslog(LOG_INFO, "Service name collision, renaming service to '%s'\n", mServiceName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\n
as suggested above.
avahi_simple_poll_quit(mSimplePoll); | ||
if (mServer) | ||
{ | ||
avahi_server_free(mServer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it safer to add mServer = NULL
here?
{ | ||
mNetworkNameTxt = aTxtData; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary new line.
{ | ||
mNetworkNameTxt = aTxtData; | ||
|
||
avahi_free(mNetworkNameTxt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mNetworkNameTxt
is not initialized?
{ | ||
mExtPanIdTxt = aTxtData; | ||
avahi_free(mExtPanIdTxt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not initialized?
} | ||
|
||
void Publisher::SetType(const char *aType) | ||
{ | ||
|
||
mType = aType; | ||
avahi_free(mType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not initialized?
32e569b
to
22e23ad
Compare
script/bootstrap
Outdated
@@ -44,7 +44,7 @@ install_packages_apt() | |||
sudo apt-get install -y autoconf-archive | |||
|
|||
# mDNS | |||
sudo apt-get install -y libavahi-core-dev | |||
sudo apt-get install -y libavahi-common-dev libavahi-client-dev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is avahi-daemon
required?
} | ||
|
||
avahi_free(mServiceName); | ||
if (mServiceName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep same style of checking pointer is NULL or not? I found
if (xxx)
if (!xxx)
if (xxx != NULL)
(xxx == NULL)
|
||
if (mClientGroup != NULL) | ||
{ | ||
avahi_entry_group_free(mClientGroup); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set it to NULL?
mNetworkNameTxt, mExtPanIdTxt, NULL) == 0, | ||
ret = kMdnsPublisher_FailedAddSevice); | ||
VerifyOrExit(avahi_entry_group_add_service(mClientGroup, AVAHI_IF_UNSPEC, | ||
AVAHI_PROTO_UNSPEC, (AvahiPublishFlags) 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use static_cast<AvahiPublishFlags>
?
|
||
syslog(LOG_INFO, " Service Name: %s Port: %d Network Name: %s Extended Pan ID: %s ", | ||
mServiceName, mPort, mNetworkNameTxt, mExtPanIdTxt); | ||
syslog(LOG_INFO, " Service Name: %s Port: %d Network Name: %s Extended Pan ID: %s ", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary space at end of syslog format string. And is the preceding space in intended?
|
||
exit: | ||
if (ret != kMdnsPublisher_OK) | ||
|
||
if (ret == kMdnsPublisher_FailedAddSevice) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use switch?
mServiceName = serviceName; | ||
syslog(LOG_INFO, "Service name collision, renaming service to '%s'", mServiceName); | ||
avahi_entry_group_reset(mClientGroup); | ||
CreateService(aClient); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it intended to ignore error from CreateService()
?
{ | ||
avahi_simple_poll_quit(mSimplePoll); | ||
case AVAHI_CLIENT_CONNECTING: | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing default
case?
…here is a server running on the system.
@bukepo, Thanks a lot for your comments and suggestions, I have updated this RP according to your comments. |
No description provided.