示例#1
0
    def run(self):
        time_redis = redis.time()
        # Send statistics to the test container : START

        link = "http://stats:80/api/receive.php?request=" + self.body[
            'path'] + "///" + str(time_redis[0]) + "." + str(
                time_redis[1]) + "///Start"
        requests.get(link)
        print("Thread started for metadoc ", self.body['path'],
              "currently time in redis: ", time_redis)

        tx_hash = store_var_contract.functions.addMetadocMap(
            self.body['path'], self.body['creation_date'], self.body['blocks'],
            self.body['original_size'],
            self.body['entangling_blocks']).transact()
        receipt = wait_for_receipt(w3, tx_hash, 1)
        redis.hset("files:{:s}".format(self.body['path']), "flag", 1)
        time_redis = redis.time()
        print("Thread finished for metadoc ", self.body['path'],
              "currently time in redis: ", time_redis)

        # Send statistics to the test container : FINISH
        link = "http://stats:80/api/receive.php?request=" + self.body[
            'path'] + "///" + str(time_redis[0]) + "." + str(
                time_redis[1]) + "///Finish"
        requests.get(link)
示例#2
0
 def run(self):
     time_redis = redis.time()
     print("Thread started for metablock ", self.body['key'],
           "currently time in redis: ", time_redis)
     tx_hash = store_var_contract.functions.addMetablock(
         self.body['key'], self.body['creation_date'],
         self.body['block_type'], self.body['checksum'],
         self.body['providers'], self.body['size']).transact()
     receipt = wait_for_receipt(w3, tx_hash, 1)
     time_redis = redis.time()
     print("Thread finished for metablock ", self.body['key'],
           "currently time in redis: ", time_redis)
示例#3
0
    def run(self):
        time_redis = redis.time()

        print("Thread started for metablock ", self.body['key'],
              "currently time in redis: ", time_redis, "type: ",
              self.body['block_type'])
        tx_hash = store_var_contract.functions.addMetablockMap(
            self.body['key'], self.body['creation_date'],
            self.body['providers'], self.body['block_type'],
            self.body['checksum'], self.body['size'],
            self.body['entangled_with']).transact()
        receipt = wait_for_receipt(w3, tx_hash, 1)
        redis.hset("blocks:{:s}".format(self.body['key']), "flag", 1)
        time_redis = redis.time()
        print("Thread finished for metablock ", self.body['key'],
              "currently time in redis: ", time_redis)
示例#4
0
    def run(self):

        if (self.body[0] == "f"):
            #Rebuild a metadoc
            key = store_var_contract.functions.getMetadocMap(
                self.body[6:]).call()
            #[0] = date of the creation
            #[1] = list of blocks
            #[2] = original size
            #[3] = entangling_blocks
            print(
                "Searching metadata in blockchain for path_given (metadoc) : "
                + self.body[6:])
            if (key[2] == 0):
                #Error, metadata of this file not in BC
                print(
                    "-- Metadoc have an original size of 0, means he's not in blockchain.\n"
                )
                return
            print("-- A metadoc key was found in blockchain")
            #Request Redis part :
            #Delete metadata of metadoc in Redis database, then push it again with blockchain metadata
            redis.delete("files:" + self.body[6:])
            print("---- Metadoc key deleted in Redis if it exists")
            key[1] = key[1].replace('"', '')
            # Parse data from blockchain, same thing that in metadata.py in Recast
            metadoc_to_redis = {
                "path": self.body[6:],
                "creation_date": key[0],
                "original_size": key[2],
                "blocks": key[1],
                "entangling_blocks": key[3],
                "flag": 1
            }
            #Add metadoc in Redis database
            redis.hmset("files:{:s}".format(self.body[6:]), metadoc_to_redis)
            print("---- Metadoc key added in Redis")
        else:
            #Rebuild a metablock
            metablock = store_var_contract.functions.getMetablockMap(
                self.body[7:]).call()
            #metablock[0] = creation_date
            #metablock[1] = providers
            #metablock[2] = block_type
            #metablock[3] = checksum
            #metablock[4] = size
            #metablock[5] = entangled_with

            #Convert uint type from blockchain to string for block type
            if (metablock[2] == 1):
                metablock[2] = "DATA"
            else:
                metablock[2] = "PARITY"
            #Delete double quote added by transaction return
            metablock[1] = metablock[1].replace('"', '')
            #Delete metablock entry in Redis
            redis.delete(self.body)
            print("---- Metablock key deleted in Redis")
            metablock_to_redis = {
                "key": self.body[7:],
                "creation_date": metablock[0],
                "providers": metablock[1],
                "block_type": metablock[2],
                "checksum": metablock[3],
                "entangled_with": metablock[5],
                "size": metablock[4],
                "flag": 1
            }
            #Add metadoc in Redis database
            redis.hmset("blocks:{:s}".format(self.body[7:]),
                        metablock_to_redis)
            print(metablock_to_redis)

        time_redis = redis.time()

        link = "http://cluster_stats:80/api/receive_rebuild.php?request=" + self.body + "///" + str(
            time_redis[0]) + "." + str(time_redis[1]) + "///All"
        requests.get(link)
        print("\nThread finished for: " + self.body + " at " +
              str(time_redis[0]) + "." + str(time_redis[1]))

        #Write stats in file
        fichier = open("save_check_corruption.txt", "a")
        fichier.write(self.body + " " + str(time_redis[0]) + "." +
                      str(time_redis[1]) + "\n")
        fichier.close()
示例#5
0
    return decoded_list


# +--------------------------------------------------------------+
# |        					SCRIPT        					                     |
# +--------------------------------------------------------------+

audit_number = 50
missing_entries = 0
bad_entries = 0
corrupted_entries = 0

# +--------------------------------------------------------------+
# Snapshot                                                       |
# +--------------------------------------------------------------+
time_begin = redis.time()
# Get metablock from Redis
all_metadata_metablock_entries = redis.zrange("block_index", 0, -1)
all_decoded_metablock_metadata = convert_redis_index(
    all_metadata_metablock_entries)
# Get metablock from Redis
all_metadata_metadoc_entries = redis.zrange("file_index", 0, -1)
all_decoded_metadoc_metadata = convert_redis_index(
    all_metadata_metadoc_entries)
# Get number metablock in blockchain
nb_metablock = store_var_contract.functions.getNumberMetablock().call()
# Get number metadoc in blockchain
nb_metadoc = store_var_contract.functions.getNumberMetadoc().call()

print("\n")
print("*********************************************************************")
示例#6
0
    def run(self):
        key = store_var_contract.functions.getMetadocMap(self.body).call()
        #[0] = date of the creation
        #[1] = list of blocks
        #[2] = original size
        #[3] = entangling_blocks
        print("Searching metadata in blockchain for path_given (metadoc) : "+self.body)
        if(key[2] == 0):
          #Error, metadata of this file not in BC
          print("-- Metadoc have an original size of 0, means he's not in blockchain.\n")
          return
        print("-- A metadoc key was found in blockchain")
        #Request Redis part :
        #Delete metadata of metadoc in Redis database, then push it again with blockchain metadata
        redis.delete("files:"+self.body)
        print("---- Metadoc key deleted in Redis")
        key[1] = key[1].replace('"','')
        # Parse data from blockchain, same thing that in metadata.py in Recast
        metadoc_to_redis = {
            "path": self.body,
            "creation_date": key[0],
            "original_size": key[2],
            "blocks": key[1],
            "entangling_blocks": key[3]
        }
        #Add metadoc in Redis database
        redis.hmset("files:{:s}".format(self.body), metadoc_to_redis)
        print("---- Metadoc key added in Redis")
        #Get each metablock
        list_blocks = key[1].split(",")
        print("-- List of all blocks of "+self.body)
        print(key[1])
        for block in list_blocks:
            print("-- Metablock: "+block)
            #Get metablock from blockchain
            metablock = store_var_contract.functions.getMetablockMap(block).call()
            #metablock[0] = creation_date
            #metablock[1] = providers
            #metablock[2] = block_type
            #metablock[3] = checksum
            #metablock[4] = size
            #metablock[5] = entangled_with

            #Convert uint type from blockchain to string for block type
            if(metablock[2] == 1):
              metablock[2] = "DATA"
            else:
              metablock[2] = "PARITY"
            #Delete double quote added by transaction return
            metablock[1] = metablock[1].replace('"','')
            #Delete metablock entry in Redis
            redis.delete("blocks:"+block)
            print("---- Metablock key deleted in Redis")
            metablock_to_redis = {
                "key": block,
                "creation_date": metablock[0],
                "providers": metablock[1],
                "block_type": metablock[2],
                "checksum": metablock[3],
                "entangled_with": metablock[5],
                "size": metablock[4]
                }
            #Add metadoc in Redis database
            redis.hmset("blocks:{:s}".format(block), metablock_to_redis)
        time_redis = redis.time()
        
        link="http://stats:80/api/receive_rebuild.php?request="+self.body+"///"+str(time_redis[0])+"."+str(time_redis[1])+"///All"
        requests.get(link)