source: test/services/querier.py @ 4

Last change on this file since 4 was 3, checked in by tim, 9 years ago

.

  • Property svn:executable set to *
File size: 1.5 KB
RevLine 
[3]1#!/usr/bin/env python3
2#
3# Copyright (C) 2015 Blindspot Security LLC
4# by Timothy D. Morgan
5# twits: @ecbftw
6
7import sys
8import time
9import hashlib
10import socketserver
11import http.server
12import sqlite3
13
14mem = sqlite3.connect(':memory:')
15disk = sqlite3.connect('/var/tmp/x.db')
16memc = mem.cursor()
17diskc = disk.cursor()
18
19q='''CREATE TABLE user
20     (username text, pwdhash text, other text, data real, stuff real)'''
21memc.execute(q)
22diskc.execute(q)
23q="INSERT INTO user VALUES ('jack','010203040506070809000A0B0C0D0E0F','hello',42,3.1415926535)"
24memc.execute(q)
25diskc.execute(q)
26mem.commit()
27disk.commit()
28
29
30
31class HashHandler(http.server.BaseHTTPRequestHandler):
32    """
33    """
34
35    def do_GET(self):
36        resolution = time.clock_getres(time.CLOCK_MONOTONIC)
37
38        conn = None
39        if 't=' in self.path:
40            t = self.path.split('t=', 1)[1]
41            if t == '1':
42                conn = memc
43            elif t == '2':
44                conn = diskc
45
46        received = int(time.monotonic()/resolution)
47        if conn != None:
48            x = conn.execute("SELECT * FROM user WHERE username='jack'")
49        now = int(time.monotonic()/resolution)
50       
51        self.send_response(200)
52        self.send_header('Content-Type','text/plain; charset=UTF-8')
53        self.end_headers()
54
55        content = "waited: %d\n" % (now - received)
56        self.wfile.write(content.encode('utf-8'))
57        self.wfile.flush()
58
59
60if __name__ == "__main__":
61    HOST, PORT = "0.0.0.0", 3240
62    server = socketserver.TCPServer((HOST, PORT), HashHandler)
63    server.serve_forever()
Note: See TracBrowser for help on using the repository browser.