-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.py
More file actions
30 lines (25 loc) · 716 Bytes
/
server.py
File metadata and controls
30 lines (25 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
'''
server.py
Should act like a normal server
Should not know it is being accessed through onion routing
Should send back the hash of the received message
'''
import socket
import hashlib
TCP_IP = socket.gethostbyname(socket.gethostname())
#TCP_IP = '127.0.0.1'
TCP_PORT = 1601
BUFFER_SIZE = 512 # Normally 1024, but we want fast response
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((TCP_IP, TCP_PORT))
s.listen(1) #maximum 1 connection
while 1:
conn, addr = s.accept()
addr = addr[0]
print 'Connection address:', addr
data = conn.recv(BUFFER_SIZE)
hashed = hashlib.sha224(data).hexdigest()
if not data: break
print "received data:", data
conn.send(hashed) # return hash
conn.close()