Exemplo n.º 1
0
 def isHashPieceCorrect(self,data):
     if utils.sha1_hash(data) == self.pieceHash:
         return True
     else:
         logging.warning("Error Piece Hash")
         logging.debug("{} : {}".format(utils.sha1_hash(data),self.pieceHash))
         self.initBlocks()
         return False
Exemplo n.º 2
0
 def isHashPieceCorrect(self, data):
     if utils.sha1_hash(data) == self.pieceHash:
         return True
     else:
         logging.warning("Error Piece Hash")
         logging.debug("{} : {}".format(utils.sha1_hash(data),
                                        self.pieceHash))
         self.initBlocks()
         return False
Exemplo n.º 3
0
    def __init__(self, path):

        with open(path, 'r') as file:
            contents = file.read()

        self.torrentFile = bencode.bdecode(contents)
        self.totalLength = 0
        self.pieceLength = self.torrentFile['info']['piece length']
        self.pieces = self.torrentFile['info']['pieces']
        self.info_hash = sha1_hash(str(
            bencode.bencode(self.torrentFile['info'])
        ))
        self.peer_id = self.generatePeerId()
        self.announceList = self.getTrakers()
        self.fileNames = []

        self.getFiles()

        if self.totalLength % self.pieceLength == 0:
            self.numberOfPieces = self.totalLength / self.pieceLength
        else:
            self.numberOfPieces = (self.totalLength / self.pieceLength) + 1

        logging.debug(self.announceList)
        logging.debug(self.fileNames)

        assert(self.totalLength > 0)
        assert(len(self.fileNames) > 0)
Exemplo n.º 4
0
    def __init__(self, path):
        import bencode
        from libs.utils import sha1_hash
        with open(path, 'r') as file:
            contents = file.read()

        self.torrentFile = bencode.bdecode(contents)
        file1 = open("torrent_info.txt", "w")
        file1.write(str(self.torrentFile))
        self.totalLength = 0
        self.pieceLength = self.torrentFile['info']['piece length']
        self.pieces = self.torrentFile['info']['pieces']
        self.info_hash = sha1_hash(
            str(bencode.bencode(self.torrentFile['info'])))
        self.peer_id = self.generatePeerId()
        self.announceList = self.getTrackers()
        self.fileNames = []

        self.getFiles()

        if self.totalLength % self.pieceLength == 0:
            self.numberOfPieces = self.totalLength / self.pieceLength
        else:
            self.numberOfPieces = (self.totalLength / self.pieceLength) + 1

        logging.debug(self.announceList)
        logging.debug(self.fileNames)

        assert (self.totalLength > 0)
        assert (len(self.fileNames) > 0)
Exemplo n.º 5
0
 def generatePeerId(self):
     seed = str(time.time())
     return sha1_hash(seed)
Exemplo n.º 6
0
 def generatePeerId(self):
     import time
     from libs.utils import sha1_hash
     seed = str(time.time())
     return sha1_hash(seed)
Exemplo n.º 7
0
 def generatePeerId(self):
     seed = str(time.time())
     return sha1_hash(seed)