예제 #1
0
	def main(self):
		
		HOST = "192.168.0.98" #IP of Bristol VM
		SENSOR_HOST = '192.168.0.38'
		PORT = 5008

		conn = connection.Client(HOST, PORT)
		time_conn = connection.Client(SENSOR_HOST,PORT)


		try:
			self.log.info('Opening connection')

			conn.connect()
			self.log.info('connected!')
			time_conn.connect()
			self.log.info('connected to sensor!')

			count = 0
			while True:

				command = conn.receive_message()

				if command != None: 

					self.log.info('Received: ' + str(command))

					data = command.split('/')

					for d in data:
						if d:
							if d != 'invalid':
								start_command = timeit.default_timer()
								self.execute_command(d)
								end_command = timeit.default_timer()

							time_conn.send_message('Received-'+ str(count))
							self.log.info('Time from sensor to controller: '
								+ str(end_command-start_command))
							count += 1
				else:
					break

		except KeyboardInterrupt:
			self.log.debug('\nINTERRUPTED BY USER')	
		except Exception as e:
			self.log.debug("ERROR: " + str(e))
		finally:
			conn.destroy()
			time_conn.destroy()
			self.log.debug('Finishing program')
예제 #2
0
    def silence_analysys(self):
        self.log.info("* Listening mic. ")
        cur_data = ''  # current chunk  of audio data
        rel = self.RATE / self.CHUNK
        slid_win = deque(maxlen=self.SILENCE_LIMIT * rel)

        #Prepend audio from self.PREV_AUDIO secs before noise was detected
        prev_audio = deque(maxlen=self.PREV_AUDIO * rel)
        started = False
        audio2send = []

        while True:
            cur_data = self.audioQueue.get()

            #Checks for keyboard interruption on main thread
            if cur_data == None:
                break

            slid_win.append(math.sqrt(abs(audioop.avg(cur_data, 4))))

            #Mic is not silent
            if (sum([x > self.THRESHOLD for x in slid_win]) > 0):

                #New recording has started
                if (not started):
                    self.log.info("Starting record of phrase")
                    #VM's IP and port
                    self.s = connection.Client('192.168.0.98', 5007)
                    self.s.connect()

                    started = True
                    self.s.send_message(''.join(prev_audio))

                self.s.send_message(cur_data)

                if self.save:
                    audio2send.append(cur_data)

            #Recording was happening and mic became silent
            elif (started is True):
                #Save time of command issuing
                inittime = timeit.default_timer()
                self.timeQueue.put(inittime)

                self.log.info("Finished")
                self.s.destroy()

                if self.save:
                    self.save_speech(list(prev_audio) + audio2send)
                    audio2send = []

                # Reset all
                started = False
                slid_win = deque(maxlen=self.SILENCE_LIMIT * rel)
                prev_audio = deque(maxlen=0.5 * rel)

                self.log.info("Listening ...")
            #Mic is silent
            else:
                prev_audio.append(cur_data)
예제 #3
0
 def run(self):
     test = self.start_test
     self.info('started, test range {0:d}:{1:d}'
               .format(self.start_test, self.end_test))
     while (test <= self.end_test):
         self.info('test {0:d}: send'.format(test))
         client = connection.Client(self.host, self.port)
         try:
             client.send(self.next())
             data = client.receive()
             self.info('test {0:d}: received: {1}'.format(test, data.decode('ascii', 'ignore').split('\n', 1)[0]))
         finally:
             client.close()
         test += 1
예제 #4
0
파일: http2dumb.py 프로젝트: vehar/httpooh
    def run(self):
        self.client = connection.Client(self.host, self.port, self.is_tls)

        self.info('started, test range {0}:{1}'.format(self.start_test,
                                                       self.end_test))
        test = self.start_test
        successfully_sent = True
        while test <= self.end_test:
            if self.client.isconnected() is False:
                self.client.connect()
                self.info('send a client connection preface')
                self.client.send(http2core.getclientpreface())
                self.info('send a valid settings frame')

                # TODO: it can be created once
                settings = SettingsFrame()
                self.client.send(settings.encode())
                data = self.client.receive()

            try:
                self.info('test {0:d}: start'.format(test))
                if successfully_sent:
                    fuzzed_data = self.next()
                    successfully_sent = False
                self.client.send(fuzzed_data)
                successfully_sent = True
            except socket.error as msg:
                # move on to next test only if current one was successfully sent out
                # TODO: delay?
                self.info(
                    'test {0:d}: a error occured while sending data: {1}'.
                    format(test, msg))
                self.info('test {0:d}: re-connect'.format(test))
                continue

            try:
                data = self.client.receive()
                self.info('test {0:d}: received data:'.format(test),
                          helper.bytes2hex(data))
            except socket.error as msg:
                self.info(
                    'test {0:d}: a error occured while receiving data, ignore it: {1}'
                    .format(test, msg))

            test += 1
예제 #5
0
파일: http2smart.py 프로젝트: vehar/httpooh
 def run(self):
     self.info('start, state: {}'.format(self.fuzzer.get_state()))
     client = connection.Client(self.config.host, self.config.port, self.config.tls)
     while self.fuzzer.ready():
         self.info('state: {}'.format(self.fuzzer.get_state()))
         client.connect()
         try:
             fuzzed = self.fuzzer.fuzz(Http1Upgrade())
             self.info('send fuzzed request:', str(fuzzed))
             client.send(fuzzed.encode())
             data = client.receive()
             self.info('received from server:', helper.truncate(data.decode('ascii')))
         except socket.error as msg:
             self.achtung('the following error occurred while sending data: {}'.format(msg))
         finally:
             self.fuzzer.next()
             client.close()
     self.info('finished')
예제 #6
0
	def silence_analysys(self):
			self.log.info( "* Listening mic. ")
			cur_data = ''  # current chunk  of audio data
			rel = self.RATE / self.CHUNK
			slid_win = deque(maxlen = self.SILENCE_LIMIT * rel)
			#Prepend audio from self.PREV_AUDIO seconds before noise was detected
			prev_audio = deque(maxlen = self.PREV_AUDIO * rel) 
			started = False
			audio2send = []
			while True:
				cur_data = self.audioQueue.get()
				if cur_data == None:
					break

				slid_win.append(math.sqrt(abs(audioop.avg(cur_data, 4))))
				#print slid_win[-1]
				if(sum([x > self.THRESHOLD for x in slid_win]) > 0):
					if(not started):
						self.log.info("Starting record of phrase")
						#VM's IP and port
						self.s = connection.Client('192.168.0.84', 57000)
						self.s.connect()
						started = True
						self.s.send_message(''.join(prev_audio))
						audio2send = list(prev_audio)
					self.s.send_message(cur_data)
					audio2send.append(cur_data)
				elif (started is True):
					self.log.info("Finished")
					self.s.destroy()

					self.save_speech(audio2send)
					audio2send = []

					# Reset all
					started = False
					slid_win = deque(maxlen = self.SILENCE_LIMIT * rel)
					prev_audio = deque(maxlen=0.5 * rel) 

					self.log.info("Listening ...")
				else:
					prev_audio.append(cur_data)
예제 #7
0
    def main(self):

        HOST = "192.168.0.98"  #IP of Bristol VM
        PORT = 5008

        conn = connection.Client(HOST, PORT)

        try:
            print 'Opening connection'

            conn.connect()

            while True:

                command = conn.receive_message()

                if command != None:

                    self.log.info('Received: ' + str(command))

                    data = command.split('/')

                    for d in data:
                        if d:
                            lamp, command_dict = self.convert_command(d)
                            if command_dict:  #False if command_dict is empty
                                for l in lamp:
                                    self.log.info('lamp: ' + str(lamp) + '\n' +
                                                  str(command_dict))
                                    self.update_lamp(l, command_dict)

        except KeyboardInterrupt:
            print '\nINTERRUPTED BY USER'
        except Exception as e:
            self.log.debug("ERROR: " + str(e))
        finally:
            conn.destroy()
            self.log.debug('Finishing program')
예제 #8
0
t.start()

# Set and start control thread
controller = control.Control(proxydb=proxies, sharestats=shares)
controller.listen_ip = args.control
controller.listen_port = args.control_port
controller.poolmap['pool'] = args.pool
controller.poolmap['port'] = args.port
controller.poolmap['user'] = args.username
controller.poolmap['pass'] = args.password
t = threading.Thread(target=controller.start, args=[])
t.daemon = True
t.start()

# Start listening for incoming connections
server_listen = connection.Server(args.listen, args.listen_port)


while not shutdown:
    # Wait for client connection
    miner = server_listen.listen()
    pool_connection = connection.Client(controller.poolmap['pool'], controller.poolmap['port'])
    pool = pool_connection.connect()
    proxy = Proxy.Proxy(pool, sharestats=shares)
    proxy.set_auth(controller.poolmap['user'], controller.poolmap['pass'])
    proxy.add_miner(miner)
    t = threading.Thread(target=proxy.start, args=[])
    t.daemon = True
    t.start()
    proxies.add_proxy(proxy, t)
예제 #9
0
import socket
import controller, connection

client = connection.Client()
conn = client.connectServer()

app = controller.Controller(conn)
app.startPlayer()

conn.close()
print('quit')
예제 #10
0
# Set log stuff
Log.verbose = args.verbose
Log.filename = args.log
Log.stdout = not args.quiet
log = Log.Log('main')

# Share statistics module
shares = share_stats.Shares()

# Start proxy cleaner thread
proxies = Proxy.ProxyDB()
t = threading.Thread(target=proxies.cleaner, args=[])
t.daemon = True
t.start()

# Start listening for incoming connections
server_listen = connection.Server(args.listen, args.listen_port)

while not shutdown:
    # Wait for client connection
    miner = server_listen.listen()
    pool_connection = connection.Client(args.pool, args.port)
    pool = pool_connection.connect()
    proxy = Proxy.Proxy(pool, sharestats=shares)
    #proxy.set_auth(controller.poolmap['user'], controller.poolmap['pass'])
    proxy.add_miner(miner)
    t = threading.Thread(target=proxy.start, args=[])
    t.daemon = True
    t.start()
    proxies.add_proxy(proxy, t)
예제 #11
0
        config.read(configFile)

        return config[section][prop]

    except KeyError:
        print(
            'Configuration file does not exist, or is corrupted. Please create it using helpers/makeconfig.py'
        )
        return ''


import socket

savedir = getProperty('config.ini', 'files', 'savedir')
s = socket.socket()
host = ''  # Means all available interfaces
port = 13131
s.bind((host, port))

s.listen(1)

import connection
while True:
    con, addr = s.accept()

    current = connection.Client(con, addr, savedir)
    current.start()

con.close()