-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomap_client.py
133 lines (91 loc) · 3.64 KB
/
omap_client.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
"""This file demonstrates how to set up client for each of the omap we include in this library.
Each function shows how the client should initialize the server and how to perform operations.
"""
from daoram.dependency import InteractRemoteServer
from daoram.omaps import AVLOdsOmap, BPlusOdsOmap, OramTreeOdsOmap
from daoram.orams import DAOram
def avl_ods_omap_client():
# Define number of data to store.
num_data = pow(2, 10)
# Create the omap instance.
omap = AVLOdsOmap(num_data=num_data, key_size=10, data_size=10, client=InteractRemoteServer())
# Initialize the client to make connection.
omap.client.init_connection()
# Set the storage to the server.
omap.init_server_storage()
# Issue some insert queries.
for i in range(num_data):
omap.insert(key=i, value=i)
# Issue some search queries.
for i in range(num_data):
print(f"Read key {i} have value {omap.search(key=i)}")
# Finally close the connection.
omap.client.close_connection()
def bplus_ods_omap_client():
# Define number of data to store.
num_data = pow(2, 10)
# Create the omap instance.
omap = BPlusOdsOmap(order=10, num_data=num_data, key_size=10, data_size=10, client=InteractRemoteServer())
# Initialize the client to make connection.
omap.client.init_connection()
# Set the storage to the server.
omap.init_server_storage()
# Issue some insert queries.
for i in range(num_data):
omap.insert(key=i, value=i)
# Issue some search queries.
for i in range(num_data):
print(f"Read key {i} have value {omap.search(key=i)}")
# Finally close the connection.
omap.client.close_connection()
def daoram_avl_omap_client():
# Define number of data to store.
num_data = pow(2, 10)
# Create a client object for shared usage.
client = InteractRemoteServer()
# Create the ods object.
ods = AVLOdsOmap(num_data=num_data, key_size=10, data_size=10, client=client)
# Create the oram object.
oram = DAOram(num_data=num_data, data_size=10, client=client)
# Create the omap object.
omap = OramTreeOdsOmap(num_data=num_data, ods=ods, oram=oram)
# Initialize the client to make connection.
client.init_connection()
# Set the storage to the server.
omap.init_server_storage()
# Issue some insert queries.
for i in range(num_data):
omap.insert(key=i, value=i)
# Issue some search queries.
for i in range(num_data):
print(f"Read key {i} have value {omap.search(key=i)}")
# Finally close the connection.
client.close_connection()
def daoram_bplus_omap_client():
# Define number of data to store.
num_data = pow(2, 10)
# Create a client object for shared usage.
client = InteractRemoteServer()
# Create the ods object.
ods = BPlusOdsOmap(order=10, num_data=num_data, key_size=10, data_size=10, client=client)
# Create the oram object.
oram = DAOram(num_data=num_data, data_size=10, client=client)
# Create the omap object.
omap = OramTreeOdsOmap(num_data=num_data, ods=ods, oram=oram)
# Initialize the client to make connection.
client.init_connection()
# Set the storage to the server.
omap.init_server_storage()
# Issue some insert queries.
for i in range(num_data):
omap.insert(key=i, value=i)
# Issue some search queries.
for i in range(num_data):
print(f"Read key {i} have value {omap.search(key=i)}")
# Finally close the connection.
client.close_connection()
if __name__ == '__main__':
# avl_ods_omap_client()
# bplus_ods_omap_client()
# daoram_avl_omap_client()
daoram_bplus_omap_client()