-
Notifications
You must be signed in to change notification settings - Fork 11
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
make sure the command length header data be 4 bytes #153
Conversation
Codecov Report
@@ Coverage Diff @@
## master #153 +/- ##
==========================================
- Coverage 86.36% 86.23% -0.13%
==========================================
Files 14 14
Lines 1305 1308 +3
==========================================
+ Hits 1127 1128 +1
- Misses 178 180 +2
Continue to review full report at Codecov.
|
hi @jwenjian thanks, for this. I'll try and do a proper review later on. |
@@ -1852,6 +1852,12 @@ def _msg_to_log(self, msg: bytes) -> str: | |||
# `client.reader` and `client.writer` should not have timeouts since they are non-blocking | |||
# https://github.com/komuw/naz/issues/116 | |||
command_length_header_data = await self.reader.read(4) | |||
|
|||
# make sure the header data be 4 bytes |
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.
@jwenjian I wonder if using await self.reader.readexactly(4)
[1] would be better?
although that raises IncompleteReadError
[2] which we would have to handle somehow.
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.
Also relevant[3].
I do not know which is better. Let me know your thoughts
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 readexactly
method is better if we have a proper way to handle the IncompleteReadError
log an error and ignore it or raise it?
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.
It seems there is no timeout
in the read*()
functions?
So if the readexactly(4)
raises an error, it means that there is no more data and the read partial bytes(length must be less than 4) is not part of an valid SMPP PDU, so I suggest to abandon it then continue the while loop.
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.
In my opinion, like the way you handle the message body in Line 1900, it should works fine to the headers.
also don't know which is better, so maybe we can use the way I do in this pr util we find out a more efficient way.
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 your input. I think we can start with this and improve if/when it becomes neccessary
I'll think about it some more.
|
What: - make sire that `naz` reads exacly the first 16bytes of the smpp header this builds on the earlier work; #153 but now `naz` takes it a step further and will unbind & close connection if it is unable to read the entire SMPP header Why: - this is done to prevent inconsistency and also to try and be faithful to the smpp spec. - updates; #135 - Other[1] smpp clients also do something similar References: 1. https://github.com/fiorix/go-smpp/blob/6dbf72b9bcea72cea4a035e3a2fc434c4dabaae7/smpp/pdu/header.go#L67-L73
Thank you for contributing to naz.
Every contribution to naz is important.
Contributor offers to license certain software (a “Contribution” or multiple
“Contributions”) to naz, and naz agrees to accept said Contributions,
under the terms of the MIT License.
Contributor understands and agrees that naz shall have the irrevocable and perpetual right to make
and distribute copies of any Contribution, as well as to create and distribute collective works and
derivative works of any Contribution, under the MIT License.
Now,
What(What have you changed?)
command_length_header_data
be 4 bytesGit diff:
Why(Why did you change it?)
self.reader.read(4)
will not ensure the bytes length be 4, if so, thestruct.unpack(">I", command_length_header_data)
will throw an exception with message: unpack requires a buffer of 4 bytesReferences: