-
Notifications
You must be signed in to change notification settings - Fork 1
/
centralizedadvertise.repy
78 lines (51 loc) · 2.03 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
Author: Justin Cappos
Start Date: July 8, 2008
Description:
Advertisements to a central server (similar to openDHT)
"""
include centralizedadvertise_base.repy
# Hmm, perhaps I should make an initialization call instead of hardcoding this?
# I suppose it doesn't matter since one can always override these values
servername = "advertiseserver.poly.edu"
# This port is updated to use the new port (legacy port is 10101)
serverport = 10102
def centralizedadvertise_announce(key, value, ttlval):
"""
<Purpose>
Announce a key / value pair into the CHT.
<Arguments>
key: the key to put the value under. This will be converted to a string.
value: the value to store at the key. This is also converted to a string.
ttlval: the amount of time until the value expires. Must be an integer
<Exceptions>
TypeError if ttlval is of the wrong type.
ValueError if ttlval is not positive
CentralAdvertiseError is raised the server response is corrupted
Various network and timeout exceptions are raised by timeout_openconn
and session_sendmessage / session_recvmessage
<Side Effects>
The CHT will store the key / value pair.
<Returns>
None
"""
return centralizedadvertisebase_announce(servername, serverport, key, value, ttlval)
def centralizedadvertise_lookup(key, maxvals=100):
"""
<Purpose>
Returns a list of valid values stored under a key
<Arguments>
key: the key to put the value under. This will be converted to a string.
maxvals: the maximum number of values to return. Must be an integer
<Exceptions>
TypeError if maxvals is of the wrong type.
ValueError if maxvals is not a positive number
CentralAdvertiseError is raised the server response is corrupted
Various network and timeout exceptions are raised by timeout_openconn
and session_sendmessage / session_recvmessage
<Side Effects>
None
<Returns>
The list of values
"""
return centralizedadvertisebase_lookup(servername, serverport, key, maxvals)