-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmanager.py
155 lines (134 loc) · 5.03 KB
/
manager.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
from manager.engine.joinmarket_engine import JoinmarketEngine
from manager.engine.wasabi_engine import WasabiEngine
import manager.commands.genscen
import sys
import argparse
args = None
engine = None
versions = set()
def run():
try:
engine.run()
except KeyboardInterrupt:
print()
print("KeyboardInterrupt received")
except Exception as e:
print(f"Terminating exception: {e}", file=sys.stderr)
finally:
engine.stop_coinjoins()
if not args.no_logs:
engine.store_logs()
driver.cleanup(args.image_prefix)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run coinjoin simulation setup")
subparsers = parser.add_subparsers(dest="command", title="command")
parser.add_argument(
"--engine",
type=str,
choices=["wasabi", "joinmarket"],
default="wasabi",
)
parser.add_argument(
"--driver",
type=str,
choices=["docker", "podman", "kubernetes"],
default="docker",
)
parser.add_argument("--no-logs", action="store_true", default=False)
console_subparser = subparsers.add_parser("console", help="run console")
console_subparser.add_argument(
"--force-rebuild", action="store_true", help="force rebuild of images"
)
console_subparser.add_argument("--namespace", type=str, default="coinjoin")
console_subparser.add_argument(
"--image-prefix", type=str, default="", help="image prefix"
)
console_subparser.add_argument("--proxy", type=str, default="")
console_subparser.add_argument(
"--btc-node-ip", type=str, help="override btc-node ip", default=""
)
console_subparser.add_argument(
"--control-ip", type=str, help="control ip", default="localhost"
)
console_subparser.add_argument("--reuse-namespace", action="store_true", default=False)
build_subparser = subparsers.add_parser("build", help="build images")
build_subparser.add_argument(
"--force-rebuild", action="store_true", help="force rebuild of images"
)
build_subparser.add_argument("--namespace", type=str, default="coinjoin")
build_subparser.add_argument(
"--image-prefix", type=str, default="", help="image prefix"
)
run_subparser = subparsers.add_parser("run", help="run simulation")
run_subparser.add_argument(
"--force-rebuild", action="store_true", help="force rebuild of images"
)
run_subparser.add_argument(
"--image-prefix", type=str, default="", help="image prefix"
)
run_subparser.add_argument(
"--scenario", type=str, help="scenario specification file"
)
run_subparser.add_argument(
"--btc-node-ip", type=str, help="override btc-node ip", default=""
)
run_subparser.add_argument(
"--wasabi-backend-ip",
type=str,
help="override wasabi-backend ip",
default="",
)
run_subparser.add_argument(
"--control-ip", type=str, help="control ip", default="localhost"
)
run_subparser.add_argument("--proxy", type=str, default="")
run_subparser.add_argument("--namespace", type=str, default="coinjoin")
run_subparser.add_argument("--reuse-namespace", action="store_true", default=False)
clean_subparser = subparsers.add_parser("clean", help="clean up")
clean_subparser.add_argument("--namespace", type=str, default="coinjoin")
clean_subparser.add_argument(
"--reuse-namespace", action="store_true", default=False
)
clean_subparser.add_argument("--proxy", type=str, default="")
clean_subparser.add_argument(
"--image-prefix", type=str, default="", help="image prefix"
)
genscen_subparser = subparsers.add_parser("genscen", help="generate scenario file")
manager.commands.genscen.setup_parser(genscen_subparser)
args = parser.parse_args()
if args.command == "genscen":
manager.commands.genscen.handler(args)
exit(0)
match args.driver:
case "docker":
from manager.driver.docker import DockerDriver
driver = DockerDriver("coinjoin")
driver = DockerDriver(args.namespace)
case "podman":
from manager.driver.podman import PodmanDriver
driver = PodmanDriver()
case "kubernetes":
from manager.driver.kubernetes import KubernetesDriver
driver = KubernetesDriver(args.namespace, args.reuse_namespace)
case _:
print(f"Unknown driver '{args.driver}'")
exit(1)
match args.engine:
case "joinmarket":
engine = JoinmarketEngine(args, driver)
case "wasabi":
engine = WasabiEngine(args, driver)
case _:
print(f"Unknown engine '{args.engine}'")
exit(1)
engine.load_scenario()
match args.command:
case "build":
engine.prepare_images()
case "clean":
driver.cleanup(args.image_prefix)
case "run":
run()
case _:
print(f"Unknown command '{args.command}'")
exit(1)