Skip to content

Commit

Permalink
Merge pull request #39 from ebroder/random-but-non-unique-query-ids
Browse files Browse the repository at this point in the history
Drop duplicate query ID handling
  • Loading branch information
weppos committed Jul 12, 2012
2 parents b5cfb32 + 3a22dbe commit 4c6aa6e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
15 changes: 1 addition & 14 deletions lib/net/dns/header.rb
Expand Up @@ -63,10 +63,6 @@ class WrongOpcodeError < ArgumentError
class Error < StandardError
end

# The requested ID is already in use.
class DuplicateIDError < Error
end


#
# = Name
Expand Down Expand Up @@ -180,8 +176,6 @@ def to_s
# Array with given strings
OPARR = %w[QUERY IQUERY STATUS]

@@id_arr = []

# Reader for +id+ attribute
attr_reader :id
# Reader for the operational code
Expand Down Expand Up @@ -357,12 +351,8 @@ def data
# performing security tests.
#
def id=(val)
if @@id_arr.include? val
raise DuplicateIDError, "ID `#{val}' already used"
end
if (1..65535).include? val
@id = val
@@id_arr.push val
else
raise ArgumentError, "ID `#{val}' out of range"
end
Expand Down Expand Up @@ -729,10 +719,7 @@ def new_from_hash(hash)
end
def genID
while (@@id_arr.include?(q = rand(65535)))
end
@@id_arr.push(q)
q
rand(65535)
end
end
Expand Down
3 changes: 0 additions & 3 deletions test/header_test.rb
Expand Up @@ -119,9 +119,6 @@ def test_simple
assert_raises(ArgumentError) do
Header.parse("aa")
end
assert_raises(Header::DuplicateIDError) do
@default.id = 441
end
assert_raises(ArgumentError) do
@default.id = 1000000
end
Expand Down

0 comments on commit 4c6aa6e

Please sign in to comment.