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

add setting unicast bit #49

Closed
wants to merge 0 commits into from
Closed

Conversation

XiXiangFiles
Copy link

I have fixed issue for "Support unicast-response bit #21". In the classes.js file, increased 2 lines to support it. I used the string "UNI" to express the "unicast".

@pusateri
Copy link
Contributor

RFC 6762 Section 5.4 calls these "QU" questions for Query Unicast.

@XiXiangFiles
Copy link
Author

XiXiangFiles commented Feb 22, 2019

I have renamed the string "UNI" to "QU". thanks for your comments .

Copy link
Collaborator

@silverwind silverwind left a comment

Choose a reason for hiding this comment

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

I don't think this is the right approach. The high bit of the class is indicating something similar to a flag in this case, while I think the lower bits should still be parsed as a regular class. So I think we should parse it as unicast_response property on the returned object and still return the class from the lower bits.

@silverwind
Copy link
Collaborator

silverwind commented Feb 22, 2019

Read the RFC section again. I think it certainly is better to handle it like a flag, like question.QU = true, I'd say the property should be absent when decoding a response, given that the RFC states the bit is only valid for questions.

@XiXiangFiles
Copy link
Author

XiXiangFiles commented Feb 22, 2019

Many thanks for your comments, i learned a lot in your opinions. i will try to revise it, and i had got an idea for your comments.

@XiXiangFiles
Copy link
Author

XiXiangFiles commented Feb 25, 2019

I had revised the codes, the classes.js had recovered to the recent status and the index.js added the flag in question section. When the question.QU is "true ", the class value will set the bit.

@silverwind
Copy link
Collaborator

Could you also add a test?

index.js Outdated
@@ -1395,8 +1394,8 @@ question.encode = function (q, buf, offset) {

buf.writeUInt16BE(types.toType(q.type), offset)
offset += 2
if (q.QU === undefined || q.QU !== true) { buf.writeUInt16BE(classes.toClass(q.class === undefined ? 'IN' : q.class), offset) } else { buf.writeUInt16BE(classes.toClass(q.class === undefined ? 'IN' : q.class) + 32768, offset) }
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can reduce this to if (q.QU)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, for the value 32768, we have the variable QU_MASK which you can use.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, and please structure the if body on a separate line

if (cond) {
 // body
} else {
 // body
}

index.js Outdated
@@ -1417,7 +1416,11 @@ question.decode = function (buf, offset) {
q.type = types.toString(buf.readUInt16BE(offset))
offset += 2

q.class = classes.toString(buf.readUInt16BE(offset))
if (buf.readUInt16BE(offset) - 32768 > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

buf.readUInt16BE(offset) >= QU_MASK

Copy link
Collaborator

Choose a reason for hiding this comment

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

also cache the result, e.g. classValue = buf.readUInt16BE(offset).

index.js Outdated
@@ -1417,7 +1416,11 @@ question.decode = function (buf, offset) {
q.type = types.toString(buf.readUInt16BE(offset))
offset += 2

q.class = classes.toString(buf.readUInt16BE(offset))
if (buf.readUInt16BE(offset) - 32768 > 0) {
classes.toString(buf.readUInt16BE(offset) - 32768)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you want to assign to q.class here.

@XiXiangFiles
Copy link
Author

I had already added the test and followed your comments to revise the code. thank you very much for your advice.

@ke4nec
Copy link

ke4nec commented Aug 22, 2022

Is there any progress?

@silverwind
Copy link
Collaborator

Should probably raise a new PR with the feedback applied.

@MaximKalinin
Copy link

Should probably raise a new PR with the feedback applied.

What kind of feedback should be applied? I might be wrong, but seems like all the essential suggestions are already there.

@silverwind
Copy link
Collaborator

silverwind commented Nov 10, 2023

These, I would expect a comment on each at least:

#49 (review)
#49 (review)
#49 (review)

Thought it has been far too long, but if you bring the branch up to date, I will have another look.

@XiXiangFiles
Copy link
Author

@silverwind update at here

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.

None yet

5 participants