-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblockstore.py
56 lines (44 loc) · 1.6 KB
/
blockstore.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
50
51
52
53
54
55
56
import rpyc
import sys
"""
The BlockStore service is an in-memory data store that stores blocks of data,
indexed by the hash value. Thus it is a key-value store. It supports basic
get() and put() operations. It does not need to support deleting blocks of
data–we just let unused blocks remain in the store. The BlockStore service only
knows about blocks–it doesn’t know anything about how blocks relate to files.
"""
class BlockStore(rpyc.Service):
"""
Initialize any datastructures you may need.
"""
def __init__(self):
self.hashlist = {}
"""
store_block(h, b) : Stores block b in the key-value store, indexed by
hash value h
As per rpyc syntax, adding the prefix 'exposed_' will expose this
method as an RPC call
"""
def exposed_store_block(self, h, block):
self.hashlist[h] = block
# print(self.hashlist)
"""
b = get_block(h) : Retrieves a block indexed by hash value h
As per rpyc syntax, adding the prefix 'exposed_' will expose this
method as an RPC call
"""
def exposed_get_block(self, h):
return self.hashlist[h]
"""
True/False = has_block(h) : Signals whether block indexed by h exists
in the BlockStore service
As per rpyc syntax, adding the prefix 'exposed_' will expose this
method as an RPC call
"""
def exposed_has_block(self, h):
return bool(self.hashlist.get(h))
if __name__ == '__main__':
from rpyc.utils.server import ThreadPoolServer
port = int(sys.argv[1])
server = ThreadPoolServer(BlockStore(), port=port)
server.start()