Exemplo n.º 1
0
class ChiselSet(object):
    def __init__(self, pyfs, chisel_set_id, fingerprint):
        self.id = chisel_set_id
        self.pyfs = pyfs
        self.fingerprint = fingerprint

        self.peers = {}
        self._pending_item_requests = {}

        self.scroll = LocalScroll(pyfs, chisel_set_id, fingerprint)
        self.pool = Pool(pyfs)

    def add_peer(self, peer_id):
        self.peers[peer_id] = RemoteScroll(self.pyfs, self.id, peer_id)

    def __iter__(self):
        for item_hash in self.scroll:
            yield self.pool.get(item)

    def add(self, item):
        item_hash = settings.HASH(item)
        if not self.pool.has(item_hash):
            self.pool.put(item)
        if self.scroll.add(item_hash):
            return item_hash
        return self.scroll.add(item_hash)

    def has(self, item_hash):
        return self.scroll.has(item_hash)
Exemplo n.º 2
0
class ChiselSet(object):
    """
    A ChiselSet combines a Scroll and a Pool, and a list of Notaries.
    """
    def __init__(self, pyfs, chisel_set_id, fingerprint):
        self.id = chisel_set_id
        self.pyfs = pyfs
        self.fingerprint = fingerprint
        self._pending_item_requests = {}

        self.scroll = LocalScroll(pyfs, chisel_set_id, fingerprint)
        self.pool = Pool(pyfs)
    
    def __iter__(self):
        for item_hash in self.scroll:
            yield self.pool.get(item_hash)
    
    def add(self, item):
        item_hash = settings.HASH(item)
        if not self.pool.has(item_hash):
            self.pool.put(item)
        if self.scroll.add(item_hash):
            return item_hash

    def has(self, item_hash):
        return self.scroll.has(item_hash)
Exemplo n.º 3
0
    def __init__(self, pyfs, chisel_set_id, fingerprint):
        self.id = chisel_set_id
        self.pyfs = pyfs
        self.fingerprint = fingerprint

        self.peers = {}
        self._pending_item_requests = {}

        self.scroll = LocalScroll(pyfs, chisel_set_id, fingerprint)
        self.pool = Pool(pyfs)
Exemplo n.º 4
0
    def __init__(self, pyfs, chisel_set_id, fingerprint):
        self.id = chisel_set_id
        self.pyfs = pyfs
        self.fingerprint = fingerprint
        self._pending_item_requests = {}

        self.scroll = LocalScroll(pyfs, chisel_set_id, fingerprint)
        self.pool = Pool(pyfs)