2 # This example measures the performance of Path ORAM when
3 # storage is accessed through an SSH client using the Secure
4 # File Transfer Protocol (SFTP).
6 # In order to run this example, you must provide a host
7 # (server) address along with valid login credentials
16 from pyoram.util.misc import MemorySize
17 from pyoram.oblivious_storage.tree.path_oram import \
20 from pyoram.storage.AliTimer import *
25 pyoram.config.SHOW_PROGRESS_BAR = True
27 # Set SSH login credentials here
28 # (by default, we pull these from the environment
29 # for testing purposes)
30 ssh_host = os.environ.get('PYORAM_SSH_TEST_HOST')
31 ssh_username = os.environ.get('PYORAM_SSH_TEST_USERNAME')
32 ssh_password = os.environ.get('PYORAM_SSH_TEST_PASSWORD')
34 # Set the storage location and size
35 storage_name = "heap.bin"
38 # one block per bucket in the
39 # storage heap of height 8
40 # block_count = 2**(8+1)-1
41 # block_count = 2**(12+1)-1
42 # block_count = 2**(15+1)-1
43 block_count = 2**(8+1)-1
46 timer = Foo.Instance()
48 print("Storage Name: %s" % (storage_name))
49 print("Block Count: %s" % (block_count))
50 print("Block Size: %s" % (MemorySize(block_size)))
51 print("Total Memory: %s"
52 % (MemorySize(block_size*block_count)))
53 print("Actual Storage Required: %s"
55 PathORAM.compute_storage_size(
58 storage_type='sftp'))))
61 # Start an SSH client using paramiko
62 print("Starting SSH Client")
63 with paramiko.SSHClient() as ssh:
64 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
65 ssh.load_system_host_keys()
67 username=ssh_username,
68 password=ssh_password)
70 print("Setting Up Path ORAM Storage")
71 start_time = time.time()
72 with PathORAM.setup(storage_name,
78 concurrency_level = 0,
79 ignore_existing=True) as f:
80 print("Total Data Transmission: %s" % (MemorySize(f.bytes_sent + f.bytes_received)))
81 print("Done Initializing")
84 stop_time = time.time()
85 print("Initial Setup Processing Time: " + str(stop_time - start_time))
86 print("Initial Setup Network Time: " + str(timer.getTime()))
89 # print("Total Setup Time: %.2f s"
90 # % (time.time()-setup_start))
91 # print("Current Stash Size: %s"
96 start_time = time.time()
98 # We close the device and reopen it after
99 # setup to reset the bytes sent and bytes
102 print("Starting test Run...")
105 with PathORAM(storage_name,
110 concurrency_level = 0,
114 stop_time = time.time()
115 print("Total Data Transmission: %s" % (MemorySize(f.bytes_sent + f.bytes_received)))
116 print("Test Setup Processing Time: " + str(stop_time - start_time))
117 print("Test Setup Network Time: " + str(timer.getTime()))
125 keys.extend(range(0, block_count))
129 print("Starting Ali Test 2")
131 test_count = block_count
132 start_time = time.time()
134 for t in tqdm.tqdm(list(range(test_count)), desc="Running I/O Performance Test"):
138 f.write_block(ind, bytearray(s.ljust(block_size, '\0')))
139 print("Total Data Transmission: %s" % (MemorySize(f.bytes_sent + f.bytes_received)))
141 # for t in tqdm.tqdm(list(range(test_count)), desc="Running I/O Performance Test"):
143 # # print(f.read_block(ind))
148 stop_time = time.time()
149 print("Test Processing Time: " + str(stop_time - start_time))
150 print("Test Network Time: " + str(timer.getTime()))
157 # print("Current Stash Size: %s"
159 # print("Access Block Avg. Data Transmitted: %s (%.3fx)"
160 # % (MemorySize((f.bytes_sent + f.bytes_received)/float(test_count)),
161 # (f.bytes_sent + f.bytes_received)/float(test_count)/float(block_size)))
162 # print("Fetch Block Avg. Latency: %.2f ms"
163 # % ((stop_time-start_time)/float(test_count)*1000))
175 if __name__ == "__main__":
176 main() # pragma: no cover