Skip to content

Commit d31aa69

Browse files
committed
fixes in initMessage(); code hygiene; comments
1 parent c3a68e6 commit d31aa69

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

src/dnsprotocol.nim

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ proc initResourceRecord*(name: string, `type`: Type, class: Class, ttl: int32,
178178
## `RDatas<dnsprotocol/types.html#RDatas>`_.
179179
##
180180
## **Note**
181-
## * `rdata` can be initialized as `nil`, but it is not recommended.
181+
## - `rdata` can be initialized as `nil`, but it is not recommended.
182182
result.name = name
183183

184184
if 0 == len(result.name) or '.' != result.name[^1]:
@@ -221,17 +221,17 @@ proc initMessage*(header: Header, questions: Questions = @[],
221221

222222
result.header.qdcount = len(result.questions).uint16
223223

224-
if len(result.questions) > 65535:
224+
if len(result.answers) > 65535:
225225
raise newException(ValueError, "The number of answers exceeds 65535")
226226

227227
result.header.ancount = len(result.answers).uint16
228228

229-
if len(result.questions) > 65535:
229+
if len(result.authorities) > 65535:
230230
raise newException(ValueError, "The number of authorities exceeds 65535")
231231

232232
result.header.nscount = len(result.authorities).uint16
233233

234-
if len(result.questions) > 65535:
234+
if len(result.additionals) > 65535:
235235
raise newException(ValueError, "The number of additionals exceeds 65535")
236236

237237
result.header.arcount = len(result.additionals).uint16
@@ -296,11 +296,9 @@ proc toBinMsg*(rr: ResourceRecord, ss: StringStream,
296296

297297
rdataToBinMsg(rr.rdata, rr, ss, dictionary)
298298

299-
let aOffset = getPosition(ss)
300-
301-
#rr.rdlength = uint16(aOffset - (rdlengthOffset + 2))
302-
303-
let rdlength = uint16(aOffset - (rdlengthOffset + 2))
299+
let
300+
aOffset = getPosition(ss)
301+
rdlength = uint16(aOffset - (rdlengthOffset + 2))
304302

305303
setPosition(ss, rdlengthOffset)
306304

src/dnsprotocol/rdatatypes.nim

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,19 @@ type
7676

7777
# END - RDatas specified in RFC-1886
7878

79+
# RDatas specified in RFC-2782 (https://www.rfc-editor.org/rfc/rfc2782)
80+
81+
RDataSRV* = ref object of RData
82+
priority*: uint16 ## The priority of this target host. A client MUST attempt to contact the target host with the lowest-numbered priority it can reach; target hosts with the same priority SHOULD be tried in an order defined by the weight field. The range is 0-65535. This is a 16 bit unsigned integer in network byte order.
83+
weight*: uint16 ## A server selection mechanism. The weight field specifies a relative weight for entries with the same priority. Larger weights SHOULD be given a proportionately higher probability of being selected. The range of this number is 0-65535. This is a 16 bit unsigned integer in network byte order.
84+
port*: uint16 ## The port on this target host of this service. The range is 0- 65535. This is a 16 bit unsigned integer in network byte order.
85+
target*: string ## A <domain-name> which specifies a host willing to act as a mail exchange for the owner name.
86+
87+
# END - RDatas specified in RFC-2782
88+
7989
# RDatas specified in RFC-8659 (https://tools.ietf.org/html/rfc8659)
8090

81-
CAAFlags* {.size: 1.} = object
91+
CAAFlags* {.size: 1.} = object # /!\ I need to review! /!\ bitsize is buggy with mm refc and async
8292
when system.cpuEndian == bigEndian:
8393
issuerCritical* {.bitsize:1.}: bool ## Issuer Critical Flag: If the value is set to "1", the Property is critical. A CA MUST NOT issue certificates for any FQDN if the Relevant RRset for that FQDN contains a CAA critical Property for an unknown or unsupported Property Tag.
8494
reserved* {.bitsize:7.}: uint8 ## Reserved for future use.
@@ -94,12 +104,6 @@ type
94104

95105
# END - RDatas specified in RFC-8659
96106

97-
RDataSRV* = ref object of RData
98-
priority*: uint16 ## The priority of this target host. A client MUST attempt to contact the target host with the lowest-numbered priority it can reach; target hosts with the same priority SHOULD be tried in an order defined by the weight field. The range is 0-65535. This is a 16 bit unsigned integer in network byte order.
99-
weight*: uint16 ## A server selection mechanism. The weight field specifies a relative weight for entries with the same priority. Larger weights SHOULD be given a proportionately higher probability of being selected. The range of this number is 0-65535. This is a 16 bit unsigned integer in network byte order.
100-
port*: uint16 ## The port on this target host of this service. The range is 0- 65535. This is a 16 bit unsigned integer in network byte order.
101-
target*: string ## A <domain-name> which specifies a host willing to act as a mail exchange for the owner name.
102-
103107
# All RDatas
104108
RDatas* = RDataA|RDataNS|RDataMD|RDataMF|RDataCNAME|RDataSOA|RDataMB|RDataMG|
105109
RDataMR|RDataNULL|RDataWKS|RDataPTR|RDataHINFO|RDataMINFO|RDataMX|

src/dnsprotocol/types.nim

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type
8585
#Notify = 4 ## Notify - RFC-1996
8686
#Update = 5 ## Update - RFC-2136
8787

88-
RCode* {.pure.} = enum ## Response code - this 4 bit field is set as part of responses. The values have the following interpretation:
88+
RCode* {.pure.} = enum ## Response code - this 4 bit field is set as part of responses.
8989
NoError = 0 ## No error condition
9090
FormatError = 1 ## The name server was unable to interpret the query.
9191
ServerFailure = 2 ## The name server was unable to process this query due to a problem with the name server.
@@ -99,14 +99,14 @@ type
9999
#NOTZONE = 10 ## RFC-2136
100100

101101
Flags* = object
102-
qr*: QR ## A one bit field that specifies whether this message is a query (0), or a response (1).
103-
opcode*: OpCode ## A four bit field that specifies kind of query in this message. This value is set by the originator of a query and copied into the response.
104-
aa*: bool ## Authoritative Answer - this bit is valid in responses, and specifies that the responding name server is an authority for the domain name in question section. Note that the contents of the answer section may have multiple owner names because of aliases. The AA bit corresponds to the name which matches the query name, or the first owner name in the answer section.
105-
tc*: bool ## TrunCation - specifies that this message was truncated due to length greater than that permitted on the transmission channel.
106-
rd*: bool ## Recursion Desired - this bit may be set in a query and is copied into the response. If RD is set, it directs the name server to pursue the query recursively. Recursive query support is optional.
107-
ra*: bool ## Recursion Available - this be is set or cleared in a response, and denotes whether recursive query support is available in the name server.
108-
z*: uint8 ## Reserved for future use. Must be zero in all queries and responses.
109-
rcode*: RCode ## Response code - this 4 bit field is set as part of responses.
102+
qr*: QR ## A one bit field that specifies whether this message is a query (0), or a response (1).
103+
opcode*: OpCode ## A four bit field that specifies kind of query in this message. This value is set by the originator of a query and copied into the response.
104+
aa*: bool ## Authoritative Answer - this bit is valid in responses, and specifies that the responding name server is an authority for the domain name in question section. Note that the contents of the answer section may have multiple owner names because of aliases. The AA bit corresponds to the name which matches the query name, or the first owner name in the answer section.
105+
tc*: bool ## TrunCation - specifies that this message was truncated due to length greater than that permitted on the transmission channel.
106+
rd*: bool ## Recursion Desired - this bit may be set in a query and is copied into the response. If RD is set, it directs the name server to pursue the query recursively. Recursive query support is optional.
107+
ra*: bool ## Recursion Available - this be is set or cleared in a response, and denotes whether recursive query support is available in the name server.
108+
z*: uint8 ## Reserved for future use. Must be zero in all queries and responses.
109+
rcode*: RCode ## Response code - this 4 bit field is set as part of responses.
110110

111111
#[ https://github.com/nim-lang/Nim/issues/16313
112112
Flags* {.size: 2.} = object

0 commit comments

Comments
 (0)