Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
deckard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
24
Issues
24
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Knot projects
deckard
Commits
2054fa11
Commit
2054fa11
authored
Feb 20, 2017
by
Petr Špaček
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
deckard: document basic functions in query/answer processing
parent
db7c1c32
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
9 deletions
+36
-9
pydnstest/scenario.py
pydnstest/scenario.py
+22
-7
pydnstest/testserver.py
pydnstest/testserver.py
+14
-2
No files found.
pydnstest/scenario.py
View file @
2054fa11
...
...
@@ -404,7 +404,12 @@ class Range:
return
False
def
reply
(
self
,
query
):
""" Find matching response to given query. """
"""
Get answer for given query (adjusted if needed).
Returns:
(DNS message object) or None if there is no candidate in this range
"""
self
.
received
+=
1
for
candidate
in
self
.
stored
:
try
:
...
...
@@ -539,7 +544,11 @@ class Step:
def
__query
(
self
,
ctx
,
tcp
=
False
,
choice
=
None
,
source
=
None
):
""" Resolve a query. """
"""
Send query and wait for an answer (if the query is not RAW).
The received answer is stored in self.answer and ctx.last_answer.
"""
if
len
(
self
.
data
)
==
0
:
raise
Exception
(
"query definition required"
)
if
self
.
data
[
0
]
.
is_raw_data_entry
is
True
:
...
...
@@ -637,10 +646,16 @@ class Scenario:
self
.
force_ipv6
=
False
def
reply
(
self
,
query
,
address
=
None
):
""" Attempt to find a range reply for a query. """
step_id
=
0
"""
Generate answer packet for given query.
The answer can be DNS message object or a binary blob.
Returns:
(answer, boolean "is the answer binary blob?")
"""
current_step_id
=
0
if
self
.
current_step
is
not
None
:
step_id
=
self
.
current_step
.
id
current_
step_id
=
self
.
current_step
.
id
# Unknown address, select any match
# TODO: workaround until the server supports stub zones
all_addresses
=
set
()
...
...
@@ -650,12 +665,12 @@ class Scenario:
address
=
None
# Find current valid query response range
for
rng
in
self
.
ranges
:
if
rng
.
eligible
(
step_id
,
address
):
if
rng
.
eligible
(
current_
step_id
,
address
):
self
.
current_range
=
rng
return
(
rng
.
reply
(
query
),
False
)
# Find any prescripted one-shot replies
for
step
in
self
.
steps
:
if
step
.
id
<
step_id
or
step
.
type
!=
'REPLY'
:
if
step
.
id
<
current_
step_id
or
step
.
type
!=
'REPLY'
:
continue
try
:
candidate
=
step
.
data
[
0
]
...
...
pydnstest/testserver.py
View file @
2054fa11
...
...
@@ -11,7 +11,13 @@ import binascii
from
dprint
import
dprint
def
recvfrom_msg
(
stream
,
raw
=
False
):
""" Receive DNS/UDP/TCP message. """
"""
Receive DNS message from TCP/UDP socket.
Returns:
if raw == False: (DNS message object, peer address)
if raw == True: (blob, peer address)
"""
if
stream
.
type
==
socket
.
SOCK_DGRAM
:
data
,
addr
=
stream
.
recvfrom
(
4096
)
elif
stream
.
type
==
socket
.
SOCK_STREAM
:
...
...
@@ -156,7 +162,13 @@ class TestServer:
return
addrlist
;
def
handle_query
(
self
,
client
):
""" Handle incoming queries. """
"""
Receive query from client socket and send an answer.
Returns:
True if client socket should be closed by caller
False if client socket should be kept open
"""
client_address
=
client
.
getsockname
()[
0
]
query
,
addr
=
recvfrom_msg
(
client
)
if
query
is
None
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment