forked from matrix-org/meshsim
-
Notifications
You must be signed in to change notification settings - Fork 3
/
meshsim.py
executable file
·104 lines (89 loc) · 2.87 KB
/
meshsim.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
#!/usr/bin/env python3
# Copyright 2019 New Vector Ltd
#
# This file is part of meshsim.
#
# meshsim is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# meshsim is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with coap-proxy. If not, see <https://www.gnu.org/licenses/>.
import os
import argparse
from meshsim import app
from meshsim.mesh import Mesh
def main():
parser = argparse.ArgumentParser(
description="Mesh network simulator.")
parser.add_argument(
"host", help="The IP address of this host in the docker network."
)
parser.add_argument(
"--port",
"-p",
help="The port for meshsim to listen on",
nargs=1,
default=3000,
type=int,
)
parser.add_argument(
"--jaeger",
"-j",
help="Enable Jaeger tracing in Node and CoAP proxy",
action="store_true",
)
parser.add_argument(
"--no-proxy",
"-n",
help="Have nodes talk directly to each other rather than via the CoAP proxy",
action="store_false",
dest="use_proxy",
)
parser.add_argument(
"--node-provider",
"-P",
help="The node provider",
choices=["synapse", "libp2p"],
action="store",
dest="provider",
)
parser.add_argument(
"--proxy-dump-payloads",
help="Debug option to make the CoAP proxy log the packets that are being sent/received",
action="store_true",
)
args = parser.parse_args()
app.config['ARGS'] = args
host = args.host
os.environ["POSTGRES_HOST"] = host
os.environ["SYNAPSE_LOG_HOST"] = host
if args.jaeger:
os.environ["SYNAPSE_JAEGER_HOST"] = host
if args.use_proxy:
os.environ["SYNAPSE_USE_PROXY"] = "1"
if args.proxy_dump_payloads:
os.environ["PROXY_DUMP_PAYLOADS"] = "1"
provider = None
if args.provider == "synapse":
from meshsim.ext.synapse import SynapseProvider
provider = SynapseProvider()
elif args.provider == "libp2p":
from meshsim.ext.libp2p import Libp2pProvider
provider = Libp2pProvider()
else:
raise ValueError(
"Provider not defined or missing ({})".format(args.provider))
# Not ideal but better than pure globals
app.node_provider = provider
app.mesh = Mesh(provider)
provider.init_client_health_host()
app.run(host="0.0.0.0", port=args.port, debug=True)
if __name__ == "__main__":
main()