예제 #1
0
 def _create_minimal_record(self):
     data = {
         "uaid": str(uuid.uuid4()),
         "router_type": "webupsh",
         "last_connect": generate_last_connect(),
         "connected_at": ms_time(),
     }
     return data
예제 #2
0
 def _create_minimal_record(self):
     data = {
         "uaid": str(uuid.uuid4()),
         "router_type": "webpush",
         "last_connect": generate_last_connect(),
         "connected_at": ms_time(),
         "current_month": datetime.today().month,
     }
     return data
예제 #3
0
 def _save_router_data(self, router_data, router_type):
     """Called when new data needs to be saved to a user-record"""
     user_item = dict(
         uaid=self.uaid,
         router_type=router_type,
         router_data=router_data,
         connected_at=int(time.time() * 1000),
         last_connect=generate_last_connect(),
     )
     return deferToThread(self.ap_settings.router.register_user, user_item)
예제 #4
0
파일: endpoint.py 프로젝트: oremj/autopush
 def _save_router_data(self, router_data, router_type):
     """Called when new data needs to be saved to a user-record"""
     user_item = dict(
         uaid=self.uaid,
         router_type=router_type,
         router_data=router_data,
         connected_at=int(time.time() * 1000),
         last_connect=generate_last_connect(),
     )
     return deferToThread(self.ap_settings.router.register_user, user_item)
예제 #5
0
 def _register_user(self, uaid, router_type, router_data):
     # type: (uuid.UUID, str, JSONDict) -> None
     """Save a new user record"""
     self.db.router.register_user(dict(
         uaid=uaid.hex,
         router_type=router_type,
         router_data=router_data,
         connected_at=ms_time(),
         last_connect=generate_last_connect(),
     ))
예제 #6
0
 def create_user(self, hello):
     # type: (Hello) -> JSONDict
     return dict(
         uaid=uuid4().hex,
         node_id=self.conf.router_url,
         connected_at=hello.connected_at,
         router_type="webpush",
         last_connect=generate_last_connect(),
         record_version=USER_RECORD_VERSION,
         current_month=self.db.current_msg_month,
     )
예제 #7
0
    def lookup_user(self, hello):
        # type: (Hello) -> (Optional[JSONDict], JSONDict)
        flags = dict(
            message_month=None,
            check_storage=False,
            reset_uaid=False,
            rotate_message_table=False,
        )
        uaid = hello.uaid.hex
        try:
            record = self.db.router.get_uaid(uaid)
        except ItemNotFound:
            return None, flags

        # All records must have a router_type and connected_at, in some odd
        # cases a record exists for some users without it
        if "router_type" not in record or "connected_at" not in record:
            self.drop_user(uaid, record, 104)
            return None, flags

        # Current month must exist and be a valid prior month
        if ("current_month" not in record) or record["current_month"] \
                not in self.db.message_tables:
            self.drop_user(uaid, record, 105)
            return None, flags

        # If we got here, its a valid user that needs storage checked
        flags["check_storage"] = True

        # Determine if message table rotation is needed
        flags["message_month"] = record["current_month"]
        if record["current_month"] != self.db.current_msg_month:
            flags["rotate_message_table"] = True

        # Include and update last_connect if needed, otherwise exclude
        if has_connected_this_month(record):
            del record["last_connect"]
        else:
            record["last_connect"] = generate_last_connect()

        # Determine if this is missing a record version
        if ("record_version" not in record or
                int(record["record_version"]) < USER_RECORD_VERSION):
            flags["reset_uaid"] = True

        # Update the node_id, connected_at for this node/connected_at
        record["node_id"] = self.conf.router_url
        record["connected_at"] = hello.connected_at
        return record, flags
예제 #8
0
    def _register_user(self, uaid, router_type, router_data):
        # type: (uuid.UUID, str, JSONDict) -> None
        """Save a new user record

        We set the expiry to 0 here because mobile users never check back,
        so the record may be incorrectly expired. (Expiry records older than
        5 years are not automatically deleted.)
        """
        self.db.router.register_user(
            dict(uaid=uaid.hex,
                 router_type=router_type,
                 router_data=router_data,
                 connected_at=ms_time(),
                 last_connect=generate_last_connect(),
                 expiry=0))
예제 #9
0
    def _register_user(self, existing_user=True):
        user_item = dict(
            uaid=self.ps.uaid,
            node_id=self.ap_settings.router_url,
            connected_at=self.ps.connected_at,
            router_type=self.ps.router_type,
        )

        # Write out the last_connect and current_month as applicable for new
        # users
        if not existing_user:
            user_item["last_connect"] = generate_last_connect()
            if self.ps.use_webpush:
                user_item["current_month"] = self.ps.message_month

        # If this connection uses the wakeup mechanism, add it.
        if self.ps.wake_data:
            user_item["wake_data"] = self.ps.wake_data

        return self.deferToThread(self.ap_settings.router.register_user,
                                  user_item)
예제 #10
0
    def _register_user(self, existing_user=True):
        user_item = dict(
            uaid=self.ps.uaid,
            node_id=self.ap_settings.router_url,
            connected_at=self.ps.connected_at,
            router_type=self.ps.router_type,
        )

        # Write out the last_connect and current_month as applicable for new
        # users
        if not existing_user:
            user_item["last_connect"] = generate_last_connect()
            if self.ps.use_webpush:
                user_item["current_month"] = self.ps.message_month

        # If this connection uses the wakeup mechanism, add it.
        if self.ps.wake_data:
            user_item["wake_data"] = self.ps.wake_data

        return self.deferToThread(self.ap_settings.router.register_user,
                                  user_item)