message_store.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:aDTN-python 作者: megfault 项目源码 文件源码
def add_object(self, data):
        """
        Attempt to insert a data object into the store. If it does not exist, it gets initialized. Otherwise the
        statistics are updated by increasing the receive count and the time of the last reception if the message has
        not been flagged as deleted.
        :param data: data object to store
        """
        idx = hash_string(data)
        now = int(time.time())
        with self.lock:
            Stats = Query()
            res = self.stats.search(Stats.idx == idx)
            if len(res) == 0:
                self.data.insert({'idx': idx, 'content': data})
                self.stats.insert({'idx': idx,
                                   'first_seen': now,
                                   'receive_count': 0,
                                   'send_count': 0,
                                   'last_received': None,
                                   'last_sent': None,
                                   'deleted': False})
                log_debug("Data object created: {}".format(data))
            else:
                deleted = res[0]['deleted']
                if deleted:
                    log_debug("Received deleted data object: {}".format(data))
                self.stats.update({'last_received': now}, Stats.idx == idx)
                self.stats.update(increment('receive_count'), Stats.idx == idx)
                log_debug("Data object updated: {}".format(data))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号