File size: 1,147 Bytes
c0aca40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e7c9ed
c0aca40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Node executable of the math topology.

The orchestrator starts this program once per turn, writes the incoming envelope as JSON on
stdin and reads the outgoing envelope from stdout. The behaviour is selected by --role, which
the topology sets to the node id (formalizer_a, formalizer_b, solver_a, solver_b, verifier,
adversary or arbiter). Extra arguments added by the orchestrator are accepted and ignored.
"""

import argparse
import json
import os
import sys

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from lingologos_math import agents, faults  # noqa: E402


def main() -> int:
    parser = argparse.ArgumentParser(description="Math topology node")
    parser.add_argument("--role", required=True, choices=sorted(agents.STEPS))
    parser.add_argument("--node-id", default=None)
    args, _ignored = parser.parse_known_args()
    faults.from_env()
    incoming = json.loads(sys.stdin.read())
    outgoing = agents.run_step(args.role, incoming, args.node_id or args.role)
    sys.stdout.write(json.dumps(outgoing))
    return 0


if __name__ == "__main__":
    sys.exit(main())