示例#1
0
    def __init__(
        self,
        collection_name: str,
        dhf: DHTFacade,
        own_guid_hex,
        key_composer=None,
        logger=None,
    ):

        self.collection_name = collection_name
        self.collection_name_present = '.%s.present' % collection_name
        self.collection_name_deleted = '.%s.deleted' % collection_name
        self.model_class_name = '.%s.model' % collection_name
        self.own_guid_hex = own_guid_hex
        self.dhf = dhf
        self._key_compose = key_composer
        self.logger = default_value(logger, ErtLogger(logger=Print()))

        self.dl_deleted = instance_dl(
            dhf=dhf,
            hex=self.own_guid_hex,
            collection_name=self.collection_name_deleted)
        self.dl_present = instance_dl(
            dhf=dhf,
            hex=self.own_guid_hex,
            collection_name=self.collection_name_present)
示例#2
0
 def __init__(self, dhf: DHTFacade, collection_name: str):
     self.collection_name = '.' + collection_name + 's'  # '.gigs'
     self.dhf = dhf
     self.me = OwnerGuidHashIO(dhf.ert.rsa_guid_hex)
     self.delete_collection_name = '.deleted_' + collection_name  # '.deleted_gigs'
     self.my_items = instance_dl(self.dhf, self.me.hex(),
                                 self.collection_name)
     self.my_deleted_items = instance_dl(self.dhf, self.me.hex(),
                                         self.delete_collection_name)
     self.item_model = collection_name.title()
     self.value_protocol = DHTValueProtocol()
示例#3
0
 def GET(self, guid):
     # owner = OwnerGuidHashIO(guid)
     dl = instance_dl(self.dhf, guid, self.collection_name)
     # self.dl.dlitem_dict.dhf.owner = owner
     ll = list(dl.iter_values())
     d_js = json.dumps(ll, ensure_ascii=False)
     d_sj_bin = d_js.encode()
     return d_sj_bin
示例#4
0
文件: kad.py 项目: hardc0d3/Ethearnal
 def repush_direct_own_gigs(self, collection='.gigs'):
     from webdht.double_linked import instance_dl
     dl = instance_dl(self, cdx.guid_bin_to_hex(self.bin_guid), collection)
     for hk_hex in dl.iter_hk():
         # logger(hk_hex)
         # self.direct_push(hk_hex)
         for peer in self.peers:
             host = peer['host']
             port = peer['port']
             self.repush_remote_direct(hk_hex, host, port)
示例#5
0
    def __init__(self, cherry,
                 dhf: DHTFacade,
                 me_owner: HashIO,
                 mount_point: str='/api/v1/dht/gigs/',
                 mount_it=True):
        self.cherry = cherry
        self.dhf = dhf
        self.mount_point = mount_point
        self.collection_name = '.gigs'
        self.delete_collection_name = '.deleted_gigs'
        self.me = me_owner
        self.mygigs = instance_dl(self.dhf, self.me.hex(), self.collection_name)
        self.deleted_gigs = instance_dl(self.dhf, self.me.hex(), self.delete_collection_name)

        if mount_it:
            self.mount()
            print('MOUNT WEB:', self.mount_point)

        self.required_fields = ('general_domain_of_expertise', 'title', 'description', 'price', 'required_ert')
示例#6
0
    def DELETE(self, hkey):
        owner_guid = self.dhf.ert.rsa_guid_hex
        dl = instance_dl(self.dhf, owner_guid, self.collection_name)

        item = dl.delete(key='', hkey=hkey)
        if item:
            dl.dlitem_dict.__setitem__(item.key, item)
            d = item.to_dict()
            js = json.dumps(d, ensure_ascii=False)
            return js.encode()
        return b'null'
示例#7
0
    def __init__(self, cherry,
                 dhf: DHTFacade,
                 me_owner: HashIO,
                 mount_point: str='/api/v1/dht/portfolios/',
                 mount_it=True):
        self.cherry = cherry
        self.dhf = dhf
        self.mount_point = mount_point
        self.collection_name = '.portfolios'
        self.me = me_owner
        self.mygigs = instance_dl(self.dhf, self.me.hex(), self.collection_name)
        if mount_it:
            self.mount()
            print('MOUNT WEB:', self.mount_point)

        self.required_fields = ('title', 'description')
示例#8
0
    def __init__(self, cherry,
                 dhf: DHTFacade,
                 me_owner: HashIO,
                 mount_point: str='/api/v1/dht/events/',
                 mount_it=True):
        self.cherry = cherry
        self.dhf = dhf
        self.mount_point = mount_point
        self.collection_name = '.evt'
        self.me = me_owner
        self.myevts = instance_dl(self.dhf, self.me.hex(), self.collection_name)
        self.dhf.events = self

        if mount_it:
            self.mount()
            print('MOUNT WEB:', self.mount_point)
示例#9
0
 def __init__(self,
              cherry,
              dhf: DHTFacade,
              collection_name: str,
              me_owner: HashIO,
              mount_point: str = '/api/v1/guid/%s/',
              mount_it=True):
     self.cherry = cherry
     self.dhf = dhf
     self.collection_name = collection_name
     self.mount_point = mount_point % collection_name
     self.me = me_owner
     self.mygigs = instance_dl(self.dhf, self.me.hex(),
                               self.collection_name)
     if mount_it:
         self.mount()
         print('MOUNT WEB:', self.mount_point)
示例#10
0
    def GET(self, owner_guid=None, deleted=None):

        if deleted and owner_guid:
            dl = instance_dl(self.dhf, owner_guid, self.delete_collection_name)
            ll = list(dl.iter_hk(inverted=False))
            d_js = json.dumps(ll, ensure_ascii=False)
            d_sj_bin = d_js.encode()
            return d_sj_bin

        if owner_guid:
            ll = self.get_per_guid(owner_guid)
            d_js = json.dumps(ll, ensure_ascii=False)
            d_sj_bin = d_js.encode()
            return d_sj_bin
        else:
            c = self.dhf.dht.storage.pubkeys.cursor.execute('SELECT bkey from ertref;')
            guid_list = [guid_bin_to_hex(k[0]).decode() for k in c.fetchall()]
            ll = list()
            for guid in guid_list:
                ll.append({guid: self.get_per_guid(guid)})
            d_js = json.dumps(ll, ensure_ascii=False)
            d_sj_bin = d_js.encode()
            return d_sj_bin
示例#11
0
文件: kad.py 项目: hardc0d3/Ethearnal
 def repush_direct_own_gigs_to_clone(self,  host, port, collection='.gigs'):
     from webdht.double_linked import instance_dl
     dl = instance_dl(self, cdx.guid_bin_to_hex(self.bin_guid), collection)
     for hk_hex in dl.iter_hk():
         self.repush_remote_direct(hk_hex, host, port)
示例#12
0
文件: kad.py 项目: hardc0d3/Ethearnal
 def repush_own_deleted_gigs(self):
     from webdht.double_linked import instance_dl
     dl = instance_dl(self, cdx.guid_bin_to_hex(self.bin_guid), '.deleted_gigs')
     for hk_hex in dl.iter_hk():
         self.repush_remote(hk_hex)
示例#13
0
 def get_per_guid(self, owner_guid):
     dl = instance_dl(self.dhf, owner_guid, self.collection_name)
     ll = list(dl.iter_hk())
     return ll