Example #1
0
	def setup_timeout(self, ID=0):
		Time = time.time()
		Times = struct.pack('d',Time)
		if ID == 0: ID = random.getrandbits(32) # ID size in bits

		ping.data_ping(self.socket,self.server[1],ID,Times)
		msg = ping.read_ping(self.socket,self.timeout())
		if not msg:                   raise Exception('PingServer::setup_timeout: no valid response from '+self.server[0])
		addr,rID,data = msg['address'],msg['ID'],msg['payload']
		log.debug("Addr=%s rID=%d Data=%d bytes"%(addr[0],rID,len(data)))
		if len(data) == 0:            raise Exception('PingServer::setup_timeout: null response from '+self.server[0])
		if rID != ID:                 raise Exception('PingServer::setup_timeout: invalid response id from '+self.server[0])
		if data != Times:             raise Exception('PingServer::setup_timeout: invalid response data from '+self.server[0])
		if addr[0] != self.server[1]: raise Exception('PingServer::setup_timeout: invalid response server from '+self.server[0])
		delay = time.time() - Time
		log.notice('echo delay: %.02fms'%(1000*delay))
Example #2
0
	def setup_block(self, ID = 0):
		if ID == 0: ID = random.getrandbits(32) # ID size in bits
		Fill = chr(random.getrandbits(8)) # repeated data
		Filler = self.block_size * Fill

		ping.data_ping(self.socket,self.server[1],ID,Filler)
		msg = ping.read_ping(self.socket,self.timeout())
		if not msg:                   raise Exception('PingServer::setup_block: no valid response from '+self.server[0])
		addr,rID,data = msg['address'],msg['ID'],msg['payload']
		log.debug("Addr=%s rID=%d Data=%d bytes"%(addr[0],rID,len(data)))
		if len(data) == 0:            raise Exception('PingServer::setup_block: null response from '+self.server[0])
		if rID != ID:                 raise Exception('PingServer::setup_block: invalid response id from '+self.server[0])
		if data != len(data)*Fill:    raise Exception('PingServer::setup_block: invalid response data from '+self.server[0])
		if addr[0] != self.server[1]: raise Exception('PingServer::setup_block: invalid response server from '+self.server[0])
		self.block_size = len(data)
		self.empty_block = self.null_block()
		log.notice('echo length: %d bytes'%self.block_size)