-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_server.py
49 lines (34 loc) · 996 Bytes
/
simple_server.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from gc import disable
from sys import argv
from time import sleep
from twisted.protocols.basic import LineOnlyReceiver
from twisted.internet.defer import Deferred
from twisted.internet.task import react
from twisted.internet.protocol import Factory
from twisted.internet.endpoints import serverFromString
disable()
def compare(a, b):
if len(a) != len(b):
print("length mismatch")
return False
for i in range(len(a)):
sleep(0.0)
if a[i] != b[i]:
return False
return True
class PasswordCompare(LineOnlyReceiver):
password = b"this is very secret you cannot guess"
responses = [
b"denied",
b"ok",
]
def lineReceived(self, line):
self.sendLine(self.responses[compare(line, self.password)])
def main(reactor, listen_address):
serverFromString(
reactor, listen_address
).listen(
Factory.forProtocol(PasswordCompare)
)
return Deferred()
react(main, argv[1:])