-
Notifications
You must be signed in to change notification settings - Fork 239
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
[web] fix rest-test issues #593
base: main
Are you sure you want to change the base?
Changes from 2 commits
a43127a
7a4769c
50baa34
0e7a66a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,11 +123,6 @@ Resource::Resource(ControllerOpenThread *aNcp) | |
mResourceCallbackMap.emplace(OT_REST_RESOURCE_PATH_DIAGNOETIC, &Resource::HandleDiagnosticCallback); | ||
} | ||
|
||
void Resource::Init(void) | ||
{ | ||
otThreadSetReceiveDiagnosticGetCallback(mInstance, &Resource::DiagnosticResponseHandler, this); | ||
} | ||
|
||
void Resource::Handle(Request &aRequest, Response &aResponse) const | ||
{ | ||
std::string url = aRequest.GetUrl(); | ||
|
@@ -518,31 +513,22 @@ void Resource::UpdateDiag(std::string aKey, std::vector<otNetworkDiagTlv> &aDiag | |
|
||
void Resource::Diagnostic(const Request &aRequest, Response &aResponse) const | ||
{ | ||
otbrError error = OTBR_ERROR_NONE; | ||
otThreadSetReceiveDiagnosticGetCallback(mInstance, &Resource::DiagnosticResponseHandler, | ||
const_cast<Resource *>(this)); | ||
OT_UNUSED_VARIABLE(aRequest); | ||
struct otIp6Address rloc16address = *otThreadGetRloc(mInstance); | ||
struct otIp6Address multicastAddress; | ||
|
||
VerifyOrExit(otThreadSendDiagnosticGet(mInstance, &rloc16address, kAllTlvTypes, sizeof(kAllTlvTypes)) == | ||
OT_ERROR_NONE, | ||
error = OTBR_ERROR_REST); | ||
VerifyOrExit(otIp6AddressFromString(kMulticastAddrAllRouters, &multicastAddress) == OT_ERROR_NONE, | ||
error = OTBR_ERROR_REST); | ||
OT_ERROR_NONE); | ||
VerifyOrExit(otIp6AddressFromString(kMulticastAddrAllRouters, &multicastAddress) == OT_ERROR_NONE); | ||
VerifyOrExit(otThreadSendDiagnosticGet(mInstance, &multicastAddress, kAllTlvTypes, sizeof(kAllTlvTypes)) == | ||
OT_ERROR_NONE, | ||
error = OTBR_ERROR_REST); | ||
OT_ERROR_NONE); | ||
|
||
exit: | ||
|
||
if (error == OTBR_ERROR_NONE) | ||
{ | ||
aResponse.SetStartTime(steady_clock::now()); | ||
aResponse.SetCallback(); | ||
} | ||
else | ||
{ | ||
ErrorHandler(aResponse, HttpStatusCode::kStatusInternalServerError); | ||
} | ||
aResponse.SetStartTime(steady_clock::now()); | ||
aResponse.SetCallback(); | ||
Comment on lines
-540
to
+532
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now, what happens if we fail in this function? Simply ignore the error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found that It may fail when node is detached or no buffer for message. So I think one solution is to define more HTTP status code according to these newly added error code, I think I could do it after #532 is merged. Another solution is like this, we ignore all errors(more simple, but still reasonable). For one thing, it could address the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@tttttangTH Is this true for your changes? I didn't see why we cannot handle the possible failures in this PR. It looks to me that keeping
should just work. Why did you remove this error handler? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because if we call But actually I prefer not viewing it as an error for HTTP response because the reason for calling I know the right way to deal with this problem is to make an exception for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is Maybe we can return But if the test is sending too much requests and is expecting Thoughts? @tttttangTH @wgtdkp There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tttttangTH You should not just remove the error handler. You can at least add a log for this error.
I don't see why we need to wait for #532. Are there any REST feature that depends on #532? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have't found any other feature depend on #532 , but it seems we won't catch I noticed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need to address it in this PR: the function name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, will do it in #537 |
||
} | ||
|
||
void Resource::DiagnosticResponseHandler(otMessage *aMessage, const otMessageInfo *aMessageInfo, void *aContext) | ||
|
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.
why setting callback for each
Diagnostic
is necessary?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.
For example, If
factoryreset
is called, the callback may be bind to another function. We should ensure that each timediagnostic
API inresource
is called, the response message can be collected by ourresource
handler.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.
After
factoryreset
,Resource::Init
will run again and sets up the callback ? Is the original code causing real issues?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.
Resource::Init
will only be run once when we start otbr-agent, thenfactoryreset
will set the callback to the default(seems a handler for CLI), I am not sure whether there is another approach that setotThreadSetReceiveDiagnosticGetCallback
to another function. do you think we do this each time beforediagnostics
API is called is acceptable? or is there an approach that we could detect whetherfactoryreset
is called?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 think
factoryreset
re-exec the whole process, so the process restarts as if it was just launched normally. We should not blamefactoryreset
for any issue. If multiple components of ot-br-posix is usingotThreadSetReceiveDiagnosticGetCallback
, maybe they should coordinate with each other.Should we use
EventEmitter
so that ot-br-posix callsotThreadSetReceiveDiagnosticGetCallback
just once and let other components subscribe to the corresponding event usingEventEmitter::On
? @gjc13 @tttttangTHThere 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.
Ok, will try to do like this.