Fix gettransports
This commit is contained in:
parent
039d791b90
commit
026901ce90
7 changed files with 91 additions and 59 deletions
|
@ -1,9 +1,18 @@
|
|||
'''
|
||||
Onionr - Private P2P Communication
|
||||
"""Onionr - Private P2P Communication.
|
||||
|
||||
Proof of work module
|
||||
'''
|
||||
'''
|
||||
Proof of work module
|
||||
"""
|
||||
import multiprocessing, time, math, threading, binascii, sys, json
|
||||
import nacl.encoding, nacl.hash, nacl.utils
|
||||
|
||||
import config
|
||||
import logger
|
||||
from onionrblocks import onionrblockapi, storagecounter
|
||||
from onionrutils import bytesconverter
|
||||
from onionrcrypto import hashers
|
||||
|
||||
from .blocknoncestart import BLOCK_NONCE_START_INT
|
||||
"""
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
|
@ -16,31 +25,22 @@
|
|||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import multiprocessing, time, math, threading, binascii, sys, json
|
||||
import nacl.encoding, nacl.hash, nacl.utils
|
||||
|
||||
import config, logger
|
||||
from onionrblocks import onionrblockapi, storagecounter
|
||||
from onionrutils import bytesconverter
|
||||
from onionrcrypto import hashers
|
||||
|
||||
from .blocknoncestart import BLOCK_NONCE_START_INT
|
||||
"""
|
||||
config.reload()
|
||||
|
||||
def getDifficultyModifier():
|
||||
'''returns the difficulty modifier for block storage based
|
||||
"""returns the difficulty modifier for block storage based
|
||||
on a variety of factors, currently only disk use.
|
||||
'''
|
||||
"""
|
||||
percentUse = storagecounter.StorageCounter().get_percent()
|
||||
difficultyIncrease = math.floor(4 * percentUse) # difficulty increase is a step function
|
||||
|
||||
return difficultyIncrease
|
||||
|
||||
def getDifficultyForNewBlock(data):
|
||||
'''
|
||||
"""
|
||||
Get difficulty for block. Accepts size in integer, Block instance, or str/bytes full block contents
|
||||
'''
|
||||
"""
|
||||
if isinstance(data, onionrblockapi.Block):
|
||||
dataSizeInBytes = len(bytesconverter.str_to_bytes(data.getRaw()))
|
||||
else:
|
||||
|
@ -54,15 +54,15 @@ def getDifficultyForNewBlock(data):
|
|||
return retData
|
||||
|
||||
def getHashDifficulty(h: str):
|
||||
'''
|
||||
"""
|
||||
Return the amount of leading zeroes in a hex hash string (hexHash)
|
||||
'''
|
||||
"""
|
||||
return len(h) - len(h.lstrip('0'))
|
||||
|
||||
def hashMeetsDifficulty(hexHash):
|
||||
'''
|
||||
"""
|
||||
Return bool for a hash string to see if it meets pow difficulty defined in config
|
||||
'''
|
||||
"""
|
||||
hashDifficulty = getHashDifficulty(hexHash)
|
||||
|
||||
try:
|
||||
|
@ -138,9 +138,9 @@ class POW:
|
|||
self.difficulty = newDiff
|
||||
|
||||
def getResult(self):
|
||||
'''
|
||||
"""
|
||||
Returns the result then sets to false, useful to automatically clear the result
|
||||
'''
|
||||
"""
|
||||
|
||||
try:
|
||||
retVal = self.result
|
||||
|
@ -151,9 +151,9 @@ class POW:
|
|||
return retVal
|
||||
|
||||
def waitForResult(self):
|
||||
'''
|
||||
"""
|
||||
Returns the result only when it has been found, False if not running and not found
|
||||
'''
|
||||
"""
|
||||
result = False
|
||||
try:
|
||||
while True:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue