network.py 文件源码

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

项目:ossim 作者: isislovecruft 项目源码 文件源码
def do_churn(self):
        """Simulate churn: delete and add nodes from/to the network."""
        nAdd = int(random.expovariate(self._lamdbaAdd) + 0.5)
        nDel = int(random.expovariate(self._lamdbaDel) + 0.5)

        # kill nDel non-dead nodes at random.
        random.shuffle(self._wholenet)
        nkilled = 0
        for node in self._wholenet:
            if nkilled == nDel:
                break
            if not node._dead:
                node.kill()
                nkilled += 1

        # add nAdd new nodes.
        for n in xrange(self._total, self._total+nAdd):
            node = Node("node%d"%n,
                        port=_randport(),
                        evil=random.random() < self._pevil)
            self._total += 1
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号