예제 #1
0
    def __init__(self, host, user, password, database):
        print("GatewayAuth: Starting gateway database..")
        self.gd = gateway_database.GatewayDatabase(host, user, password,
                                                   database)

        pnconfig = PNConfiguration()
        pnconfig.subscribe_key = self.gd.sub_key()
        pnconfig.publish_key = self.gd.pub_key()
        pnconfig.secret_key = self.gd.sec_key()
        pnconfig.subscribe_timeout = 9 ^ 99
        pnconfig.connect_timeout = 9 ^ 99
        pnconfig.non_subscribe_timeout = 9 ^ 99
        pnconfig.ssl = True
        pnconfig.reconnect_policy = PNReconnectionPolicy.LINEAR
        pnconfig.uuid = 'GA'
        pnconfig.auth_key = idgen.id_generator(size=42)

        self.pubnub = PubNub(pnconfig)
        self.pubnub.add_listener(self)
        self.pubnub.unsubscribe_all()

        self.admin_channel = idgen.id_generator(size=255)
        self.pubnub.grant().channels(self.admin_channel).auth_keys(
            [self.gd.receivers_key(),
             pnconfig.auth_key]).read(True).write(True).manage(True).sync()

        print("GatewayAuth: Starting the receiver..")
        self.gr = gateway_receiver.Receiver(self.gd, self.admin_channel)
        self.gateway_uuids = [pnconfig.uuid, self.gr.uuid]
        self.gateway_channels = ["gateway_auth", "gateway_global"]

        self.pubnub.grant().channels(
            self.gateway_channels).read(True).write(True).manage(True).sync()
        print(
            "GatewayAuth: Connecting to gateway channel and gateway global feed.."
        )
        self.pubnub.subscribe().channels(
            self.gateway_channels +
            [self.admin_channel]).with_presence().execute()

        self.receiver_auth_key = self.gd.receivers_key()