Exemplo n.º 1
0
def main():
    logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s', level=logging.INFO)

    parser = argparse.ArgumentParser(description='Run bridge frontend')
    parser.add_argument(
        'endpoint',
        help='''Base endpoint of the bridge backend. Follows ZeroMQ transmit
             protocol syntax. For example: tcp://bridge.example.com:5555''')
    args = parser.parse_args()

    logging.info("Initializing sockets")
    zmqctx = zmq.Context.instance()
    endpoint_generator = messaging.endpoints(args.endpoint)
    control_socket = zmqctx.socket(zmq.DEALER)
    control_socket.connect(next(endpoint_generator))
    event_socket = zmqctx.socket(zmq.SUB)
    event_socket.setsockopt(zmq.SUBSCRIBE, DEAL_COMMAND)
    event_socket.setsockopt(zmq.SUBSCRIBE, CALL_COMMAND)
    event_socket.setsockopt(zmq.SUBSCRIBE, BIDDING_COMMAND)
    event_socket.setsockopt(zmq.SUBSCRIBE, PLAY_COMMAND)
    event_socket.setsockopt(zmq.SUBSCRIBE, DUMMY_COMMAND)
    event_socket.setsockopt(zmq.SUBSCRIBE, TRICK_COMMAND)
    event_socket.setsockopt(zmq.SUBSCRIBE, DEALEND_COMMAND)
    event_socket.connect(next(endpoint_generator))

    logging.info("Starting main window")
    app = QApplication(sys.argv)
    window = BridgeWindow(control_socket, event_socket)
    code = app.exec_()

    logging.info("Main window closed. Closing sockets.")
    zmqctx.destroy()
    sys.exit(code)
Exemplo n.º 2
0
 def testEndpoints(self):
     gen = endpoints("tcp://127.0.0.1:5555")
     self.assertEqual(next(gen), "tcp://127.0.0.1:5555")
     self.assertEqual(next(gen), "tcp://127.0.0.1:5556")
Exemplo n.º 3
0
def main():
    parser = argparse.ArgumentParser(
        description="A lightweight bridge application")
    parser.add_argument(
        "endpoint",
        help="""Base endpoint of the bridge backend. Follows ZeroMQ transmit
             protocol syntax. For example: tcp://bridge.example.com:5555""")
    parser.add_argument(
        "--server-key-file",
        help="""File to read CURVE server key from. If provided, the sockets are
             setup to use CURVE security mechanism with the given server
             key.""",
        type=argparse.FileType("r")
    )
    parser.add_argument(
        "--secret-key-file",
        help="""File to read CURVE secret key from. If the server key is given, and the
             secret key is not, a new keypair is autogenerated.""",
        type=argparse.FileType("r")
    )
    parser.add_argument(
        "--public-key-file",
        help="""File to read CURVE public key from. If the public key is given, and the
             public key is not, a new keypair is autogenerated.""",
        type=argparse.FileType("r")
    )
    parser.add_argument(
        '--position',
        help="""If provided, the application requests the server to assign the
             given position. If the position is not available (or if the option
             is not given), any position is requested.""")
    parser.add_argument(
        '--game',
        help="""UUID of the game to be joined. The game is not created unless
             --create-game option is also provided.""")
    parser.add_argument(
        '--create-game', action="store_true",
        help="""If given, the application requests the backend to create new
             game. UUID can be optionally given by providing --game option.""")
    parser.add_argument(
        '--player',
        help="""UUID of the player. If omitted, an UUID is generated.""")
    parser.add_argument(
        "--verbose", "-v", action="count", default=0,
        help="""Increase logging levels. Repeat for even more logging.""")
    args = parser.parse_args()

    logging_level = logging.WARNING
    if args.verbose == 1:
        logging_level = logging.INFO
    elif args.verbose >= 2:
        logging_level = logging.DEBUG
    logging.basicConfig(
        format='%(asctime)s %(levelname)-8s %(message)s', level=logging_level)

    logging.info("Initializing sockets")
    zmqctx = zmq.Context.instance()
    endpoint_generator = messaging.endpoints(args.endpoint)
    control_socket = zmqctx.socket(zmq.DEALER)
    curve_server_key = _get_key_from_file(args.server_key_file)
    curve_secret_key = _get_key_from_file(args.secret_key_file)
    curve_public_key = _get_key_from_file(args.public_key_file)
    messaging.setupCurve(control_socket, curve_server_key, curve_secret_key, curve_public_key)
    control_socket.connect(next(endpoint_generator))
    event_socket = zmqctx.socket(zmq.SUB)
    messaging.setupCurve(event_socket, curve_server_key)
    event_socket.connect(next(endpoint_generator))

    logging.info("Starting main window")
    app = QApplication(sys.argv)
    window = BridgeWindow(
        control_socket, event_socket, args.position, args.game,
        args.create_game, args.player)
    code = app.exec_()

    logging.info("Main window closed. Closing sockets.")
    zmqctx.destroy(linger=0)
    return code
Exemplo n.º 4
0
 def testEndpoints(self):
     gen = endpoints("tcp://127.0.0.1:5555")
     self.assertEqual(next(gen), "tcp://127.0.0.1:5555")
     self.assertEqual(next(gen), "tcp://127.0.0.1:5556")