当前位置: 首页>>代码示例>>Python>>正文


Python RateLimit.called方法代码示例

本文整理汇总了Python中util.RateLimit.called方法的典型用法代码示例。如果您正苦于以下问题:Python RateLimit.called方法的具体用法?Python RateLimit.called怎么用?Python RateLimit.called使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在util.RateLimit的用法示例。


在下文中一共展示了RateLimit.called方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: cbMergerSiteAdd

# 需要导入模块: from util import RateLimit [as 别名]
# 或者: from util.RateLimit import called [as 别名]
 def cbMergerSiteAdd(self, to, addresses):
     added = 0
     for address in addresses:
         added += 1
         site_manager.need(address)
     if added:
         self.cmd("notification", ["done", "Added <b>%s</b> new site" % added, 5000])
     RateLimit.called(self.site.address + "-MergerSiteAdd")
     site_manager.updateMergerSites()
开发者ID:OliverCole,项目名称:ZeroNet,代码行数:11,代码来源:MergerSitePlugin.py

示例2: actionFindHashIds

# 需要导入模块: from util import RateLimit [as 别名]
# 或者: from util.RateLimit import called [as 别名]
    def actionFindHashIds(self, params):
        site = self.sites.get(params["site"])
        s = time.time()
        if not site or not site.settings["serving"]:  # Site unknown or not serving
            self.response({"error": "Unknown site"})
            self.connection.badAction(5)
            return False

        event_key = "%s_findHashIds_%s_%s" % (self.connection.ip, params["site"], len(params["hash_ids"]))
        if self.connection.cpu_time > 0.5 or not RateLimit.isAllowed(event_key, 60 * 5):
            time.sleep(0.1)
            back_ip4, back_onion = self.findHashIds(site, params["hash_ids"], limit=10)
        else:
            back_ip4, back_onion = self.findHashIds(site, params["hash_ids"])
        RateLimit.called(event_key)

        # Check my hashfield
        if self.server.tor_manager and self.server.tor_manager.site_onions.get(site.address):  # Running onion
            my_ip = helper.packOnionAddress(self.server.tor_manager.site_onions[site.address], self.server.port)
            my_back = back_onion
        elif config.ip_external:  # External ip defined
            my_ip = helper.packAddress(config.ip_external, self.server.port)
            my_back = back_ip4
        elif self.server.ip and self.server.ip != "*":  # No external ip defined
            my_ip = helper.packAddress(self.server.ip, self.server.port)
            my_back = back_ip4
        else:
            my_ip = None
            my_back = back_ip4

        my_hashfield_set = set(site.content_manager.hashfield)
        for hash_id in params["hash_ids"]:
            if hash_id in my_hashfield_set:
                if hash_id not in my_back:
                    my_back[hash_id] = []
                if my_ip:
                    my_back[hash_id].append(my_ip)  # Add myself

        if config.verbose:
            self.log.debug(
                "Found: IP4: %s, Onion: %s for %s hashids in %.3fs" %
                (len(back_ip4), len(back_onion), len(params["hash_ids"]), time.time() - s)
            )
        self.response({"peers": back_ip4, "peers_onion": back_onion})
开发者ID:binerf,项目名称:zeronet_tor,代码行数:46,代码来源:FileRequest.py


注:本文中的util.RateLimit.called方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。