예제 #1
0
    def processBlockMetadata(self, blockHash):
        '''
            Read metadata from a block and cache it to the block database
        '''
        curTime = self.getRoundedEpoch(roundS=60)
        myBlock = Block(blockHash, self._core)
        if myBlock.isEncrypted:
            myBlock.decrypt()
        if (myBlock.isEncrypted
                and myBlock.decrypted) or (not myBlock.isEncrypted):
            blockType = myBlock.getMetadata(
                'type'
            )  # we would use myBlock.getType() here, but it is bugged with encrypted blocks
            signer = self.bytesToStr(myBlock.signer)
            valid = myBlock.verifySig()
            if myBlock.getMetadata('newFSKey') is not None:
                onionrusers.OnionrUser(self._core, signer).addForwardKey(
                    myBlock.getMetadata('newFSKey'))

            try:
                if len(blockType) <= 10:
                    self._core.updateBlockInfo(blockHash, 'dataType',
                                               blockType)
            except TypeError:
                logger.warn("Missing block information")
                pass
            # Set block expire time if specified
            try:
                expireTime = myBlock.getHeader('expire')
                assert len(
                    str(int(expireTime))
                ) < 20  # test that expire time is an integer of sane length (for epoch)
            except (AssertionError, ValueError, TypeError) as e:
                expireTime = onionrvalues.OnionrValues(
                ).default_expire + curTime
            finally:
                self._core.updateBlockInfo(blockHash, 'expire', expireTime)
            if not blockType is None:
                self._core.updateBlockInfo(blockHash, 'dataType', blockType)
            onionrevents.event('processblocks',
                               data={
                                   'block': myBlock,
                                   'type': blockType,
                                   'signer': signer,
                                   'validSig': valid
                               },
                               onionr=self._core.onionrInst)
        else:
            pass
예제 #2
0
파일: main.py 프로젝트: InvisaMage/onionr
 def showOutput(self):
     while type(self.channel) is type(None) and self.flowRunning:
         time.sleep(1)
     try:
         while self.flowRunning:
             for block in self.myCore.getBlocksByType('txt'):
                 block = Block(block)
                 if block.getMetadata('ch') != self.channel:
                     #print('not chan', block.getMetadata('ch'))
                     continue
                 if block.getHash() in self.alreadyOutputed:
                     #print('already')
                     continue
                 if not self.flowRunning:
                     break
                 logger.info('\n------------------------', prompt=False)
                 content = block.getContent()
                 # Escape new lines, remove trailing whitespace, and escape ansi sequences
                 content = self.myCore._utils.escapeAnsi(
                     content.replace('\n', '\\n').replace('\r',
                                                          '\\r').strip())
                 logger.info(block.getDate().strftime("%m/%d %H:%M") +
                             ' - ' + logger.colors.reset + content,
                             prompt=False)
                 self.alreadyOutputed.append(block.getHash())
             time.sleep(5)
     except KeyboardInterrupt:
         self.flowRunning = False