more than one check per connections.
This commit is contained in:
parent
bdb441f237
commit
fbda583fd2
|
@ -109,7 +109,6 @@ module NSCA
|
||||||
def self.parse entry, key = nil, password = nil, no_verification_checks = nil
|
def self.parse entry, key = nil, password = nil, no_verification_checks = nil
|
||||||
entry = NSCA::xor key, entry if key
|
entry = NSCA::xor key, entry if key
|
||||||
entry = NSCA::xor password, entry if password
|
entry = NSCA::xor password, entry if password
|
||||||
p entry: entry
|
|
||||||
ver, crc32sum, *x = entry.unpack( PACK_STRING)
|
ver, crc32sum, *x = entry.unpack( PACK_STRING)
|
||||||
raise VersionCheckFailed, "Packet version 3 expected. (recv: #{ver})" \
|
raise VersionCheckFailed, "Packet version 3 expected. (recv: #{ver})" \
|
||||||
unless no_verification_checks or 3 == ver
|
unless no_verification_checks or 3 == ver
|
||||||
|
|
|
@ -6,6 +6,8 @@ require 'securerandom'
|
||||||
|
|
||||||
module NSCA
|
module NSCA
|
||||||
class Server
|
class Server
|
||||||
|
include Enumerable
|
||||||
|
|
||||||
attr_reader :iv_key, :server, :packet_version, :password
|
attr_reader :iv_key, :server, :packet_version, :password
|
||||||
def initialize *args
|
def initialize *args
|
||||||
opts = {}
|
opts = {}
|
||||||
|
@ -38,7 +40,16 @@ module NSCA
|
||||||
def accept() Connection.new @server.accept, self end
|
def accept() Connection.new @server.accept, self end
|
||||||
def close() @server.close end
|
def close() @server.close end
|
||||||
|
|
||||||
|
def each &block
|
||||||
|
return Enumerator.new( self) unless block_given?
|
||||||
|
while conn = accept
|
||||||
|
yield conn
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class Connection
|
class Connection
|
||||||
|
include Enumerable
|
||||||
|
|
||||||
def initialize socket, server
|
def initialize socket, server
|
||||||
@socket, @server = socket, server
|
@socket, @server = socket, server
|
||||||
@iv_key, @password = server.iv_key, server.password
|
@iv_key, @password = server.iv_key, server.password
|
||||||
|
@ -52,6 +63,13 @@ module NSCA
|
||||||
@packet_version.parse data, @iv_key, @password if data
|
@packet_version.parse data, @iv_key, @password if data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def each &block
|
||||||
|
return Enumerator.new( self) unless block_given?
|
||||||
|
while data = fetch
|
||||||
|
yield data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def eof?() @socket.eof? end
|
def eof?() @socket.eof? end
|
||||||
def read() @socket.read @packet_length end
|
def read() @socket.read @packet_length end
|
||||||
def close() @socket.close end
|
def close() @socket.close end
|
||||||
|
|
|
@ -8,7 +8,7 @@ module NSCA
|
||||||
end
|
end
|
||||||
serv = NSCA::Server.new *args
|
serv = NSCA::Server.new *args
|
||||||
sock = serv.accept
|
sock = serv.accept
|
||||||
sock.fetch
|
sock.to_a
|
||||||
ensure
|
ensure
|
||||||
sock.close if sock
|
sock.close if sock
|
||||||
serv.close if serv
|
serv.close if serv
|
||||||
|
|
|
@ -19,14 +19,17 @@ class TestNSCA < Test::Unit::TestCase
|
||||||
T0 = TestChecks::T0
|
T0 = TestChecks::T0
|
||||||
T1 = TestChecks::T1
|
T1 = TestChecks::T1
|
||||||
T2 = TestChecks::T2
|
T2 = TestChecks::T2
|
||||||
NSCA.destinations << NSCA::Client.new( 'localhost', 5667, password: 'abcdefghijkl')
|
|
||||||
NSCA.send TestChecks::T0.new( 1, "0123456789"*51+"AB")
|
|
||||||
|
|
||||||
return
|
checks = []
|
||||||
|
checks << TestChecks::T0.new( 1, "0123456789"*51+"AB")
|
||||||
|
|
||||||
pd1 = PD1.new 3
|
pd1 = PD1.new 3
|
||||||
pd2 = PD2.new 0.9996
|
pd2 = PD2.new 0.9996
|
||||||
pd3 = PD3.new 2
|
pd3 = PD3.new 2
|
||||||
NSCA.send TestChecks::T1.new( nil, "Should be OK", [pd1, pd2, pd3])
|
checks << TestChecks::T1.new( nil, "Should be OK", [pd1, pd2, pd3])
|
||||||
|
|
||||||
|
NSCA::destinations << NSCA::Client.new( 'localhost', 5667, password: 'abcdefghijkl')
|
||||||
|
NSCA::send *checks
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue