-
Notifications
You must be signed in to change notification settings - Fork 9
/
ns_petname.py
34 lines (27 loc) · 1.01 KB
/
ns_petname.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
# this is a Tor Proposition 279-compliant name resolution provider
# that resolves a predefined set of .pet.onion domains.
import sys
pet_names = {
'txtorcon.pet.onion': 'timaq4ygg2iegci7.onion',
'duckduckgo.pet.onion': '3g2upl4pq6kufc4m.onion',
'torist.pet.onion': 'toristinkirir4xj.onion',
'scihub.pet.onion': 'scihub22266oqcxt.onion',
}
print('INIT 1 0')
while True:
line = sys.stdin.readline()
args = line.split()
if args[0] == 'RESOLVE':
query_id, nm, _ = args[1:]
try:
new_name = pet_names[nm]
print('RESOLVED {} 0 {}'.format(query_id, new_name))
except KeyError:
# spec says "XXX Should <RESULT> be optional in the case
# of failure?" and I think the answer should be "yes", but
# I'm echoing the asked-for name back here ...
print('RESOLVED {} 3 {}'.format(query_id, nm))
elif args[0] == 'CANCEL':
query_id = args[1]
print('CANCELED {}'.format(query_id))
sys.stdout.flush()