forked from SeattleTestbed/monitor_script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcentralizedadvertise.repy
51 lines (36 loc) · 1.37 KB
/
centralizedadvertise.repy
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
"""
Author: Justin Cappos
Start Date: July 8, 2008
Description:
Advertisements to a central server (similar to openDHT)
"""
include session.repy
# I'll use socket timeout to prevent hanging when it takes a long time...
include sockettimeout.repy
servername = "satya.cs.washington.edu"
serverport = 10101
def centralizedadvertise_announce(key, value, ttlval):
sockobj = timeout_openconn(servername,serverport, timeout=10)
try:
session_sendmessage(sockobj, "PUT|"+str(key)+"|"+str(value)+"|"+str(ttlval))
response = session_recvmessage(sockobj)
if response != 'OK':
raise Exception, "Centralized announce failed '"+response+"'"
finally:
# BUG: This raises an error right now if the call times out ( #260 )
# This isn't a big problem, but it is the "wrong" exception
sockobj.close()
return True
def centralizedadvertise_lookup(key, maxvals=100):
sockobj = timeout_openconn(servername,serverport, timeout=10)
try:
session_sendmessage(sockobj, "GET|"+str(key)+"|"+str(maxvals))
recvdata = session_recvmessage(sockobj)
# worked
if recvdata.endswith('OK'):
return recvdata[:-len('OK')].split(',')
raise Exception, "Centralized lookup failed"
finally:
# BUG: This raises an error right now if the call times out ( #260 )
# This isn't a big problem, but it is the "wrong" exception
sockobj.close()