-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigure.py
executable file
·252 lines (234 loc) · 5.58 KB
/
configure.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/usr/bin/env python3
import argparse
import json
from pathlib import Path
def gen_env_consumer_api(
transport: str,
coord_host: str,
party_hosts: list[str],
party_ports: list[int],
):
output = f"""\
COORDINATION_SERVER_URL={transport}://{coord_host}:8005
CERTS_PATH=certs
PARTY_HOSTS={json.dumps(party_hosts)}
PARTY_PORTS={json.dumps(party_ports)}
PRIVKEY_PEM_PATH=ssl_certs/privkey.pem
FULLCHAIN_PEM_PATH=ssl_certs/fullchain.pem
PARTY_WEB_PROTOCOL={transport}
PORT=8004
"""
return output
def gen_env_coord(
transport: str,
party_hosts: list[str],
party_ports: list[int],
):
output = f"""\
PORT=8005
PARTY_HOSTS={json.dumps(party_hosts)}
PARTY_PORTS={json.dumps(party_ports)}
PARTY_API_KEY=81f47c24b9fbe22421ea3ae92a9cc8f6
PARTY_WEB_PROTOCOL={transport}
PROHIBIT_MULTIPLE_CONTRIBUTIONS=False
USER_QUEUE_HEAD_TIMEOUT=60
PRIVKEY_PEM_PATH=ssl_certs/privkey.pem
FULLCHAIN_PEM_PATH=ssl_certs/fullchain.pem
FREE_PORTS_START=8010
FREE_PORTS_END=8100
"""
return output
def gen_env_party(
transport: str,
coord_host: str,
party_hosts: list[str],
party_ports: list[int],
):
output = f"""\
PORT=8006
PARTY_ID=0
COORDINATION_SERVER_URL={transport}://{coord_host}:8005
PARTY_API_KEY=81f47c24b9fbe22421ea3ae92a9cc8f6
PARTY_HOSTS={json.dumps(party_hosts)}
PARTY_PORTS={json.dumps(party_ports)}
PARTY_WEB_PROTOCOL={transport}
MAX_DATA_PROVIDERS=1000
PERFORM_COMMITMENT_CHECK=False
PRIVKEY_PEM_PATH=ssl_certs/privkey.pem
FULLCHAIN_PEM_PATH=ssl_certs/fullchain.pem
"""
return output
def gen_docker_compose(notary_ip: str, add_data_consumer_api: bool):
s = f"""\
services:
coord:
build:
context: ./mpc_demo_infra/coordination_server/docker
ports:
- "8005:8005"
volumes:
- coord-data:/root/mpc-demo-infra/
stdin_open: true
tty: true
init: true
extra_hosts:
- "tlsnotaryserver.io:127.0.0.1"
depends_on:
- party_0
- party_1
- party_2
notary:
build:
context: ./mpc_demo_infra/notary_server/docker
args:
NORTARY_IP: {notary_ip}
ports:
- "8003:8003"
environment:
- NOTARY_IP={notary_ip}
stdin_open: true
tty: true
init: true
extra_hosts:
- "tlsnotaryserver.io:127.0.0.1"
"""
if add_data_consumer_api:
s += """\
data_consumer_api:
build:
context: ./mpc_demo_infra/data_consumer_api/docker
ports:
- "8004:8004"
stdin_open: true
tty: true
init: true
"""
s += """\
party_0:
build:
context: ./mpc_demo_infra/computation_party_server/docker
args:
PORT: 8006
PARTY_ID: 0
NUM_PARTIES: 3
ports:
- "8006:8006"
- "8013:8013"
environment:
- PARTY_ID=0
volumes:
- party0-data:/root/MP-SPDZ/
stdin_open: true
tty: true
init: true
extra_hosts:
- "tlsnotaryserver.io:127.0.0.1"
party_1:
build:
context: ./mpc_demo_infra/computation_party_server/docker
args:
PORT: 8007
PARTY_ID: 1
NUM_PARTIES: 3
ports:
- "8007:8007"
- "8014:8014"
environment:
- PARTY_ID=1
volumes:
- party1-data:/root/MP-SPDZ/
stdin_open: true
tty: true
init: true
extra_hosts:
- "tlsnotaryserver.io:127.0.0.1"
party_2:
build:
context: ./mpc_demo_infra/computation_party_server/docker
args:
PORT: 8008
PARTY_ID: 2
NUM_PARTIES: 3
ports:
- "8008:8008"
- "8015:8015"
environment:
- PARTY_ID=2
volumes:
- party2-data:/root/MP-SPDZ/
stdin_open: true
tty: true
init: true
extra_hosts:
- "tlsnotaryserver.io:127.0.0.1"
volumes:
coord-data:
party0-data:
party1-data:
party2-data:
"""
return s
def parse_args():
parser = argparse.ArgumentParser(description="config-file generation script")
parser.add_argument(
'--transport',
choices=['http', 'https'],
default='http',
help=f"Transport to use. http is used by default",
)
parser.add_argument(
'--notary-ip',
type=str,
default='127.0.0.1',
help="IP address of the server on which the notary server runs",
)
parser.add_argument(
'--dry-run',
action='store_true',
help='Print out the contents of config files',
)
parser.add_argument(
'--data-consumer-api',
action='store_true',
help='Add Data Consumer API server',
)
return parser.parse_args()
args = parse_args()
def write_file(file_path: Path, content: str, args):
if args.dry_run:
print(f"----> {file_path}")
print(content)
else:
with open(file_path, 'w') as f:
f.write(content)
print(f"Created {str(file_path)}")
party_hosts = ["party_0", "party_1", "party_2"]
party_ports =[8006, 8007, 8008]
mpc_demo_infra = Path('mpc_demo_infra')
# write .env.consumer_api if needed
if args.data_consumer_api:
dot_env_consumer_api = gen_env_consumer_api(
args.transport,
args.notary_ip,
party_hosts,
party_ports,
)
write_file(mpc_demo_infra / 'data_consumer_api' / 'docker' / '.env.consumer_api', dot_env_consumer_api, args)
# write .env.coord
dot_env_coord = gen_env_coord(
args.transport,
party_hosts,
party_ports,
)
write_file(mpc_demo_infra / 'coordination_server' / 'docker' / '.env.coord', dot_env_coord, args)
# write .env.party for partys
dot_env_party = gen_env_party(
args.transport,
args.notary_ip,
party_hosts,
party_ports,
)
write_file(mpc_demo_infra / 'computation_party_server' / 'docker' / '.env.party', dot_env_party, args)
# write docker-compose.yml
docker_compose_yml = gen_docker_compose(args.notary_ip, args.data_consumer_api)
write_file(Path('docker-compose.yml'), docker_compose_yml, args)