Update logging
This commit is contained in:
parent
77f811c455
commit
7369b63614
@ -215,7 +215,7 @@ class API:
|
||||
|
||||
return resp
|
||||
if not os.environ.get("WERKZEUG_RUN_MAIN") == "true":
|
||||
logger.info('Starting client on ' + self.host + ':' + str(bindPort) + '...')
|
||||
logger.info('Starting client on ' + self.host + ':' + str(bindPort) + '...', timestamp=True)
|
||||
|
||||
try:
|
||||
app.run(host=self.host, port=bindPort, debug=True, threaded=True)
|
||||
|
@ -41,4 +41,4 @@ if __name__ == "__main__":
|
||||
bitcoin = OnionrBTC(torPort)
|
||||
while True:
|
||||
print(bitcoin.node.getBlockHash(bitcoin.node.getLastBlockHeight())) # Using print on purpose, do not change to logger
|
||||
time.sleep(5)
|
||||
time.sleep(5)
|
||||
|
@ -36,12 +36,12 @@ class OnionrCommunicate:
|
||||
|
||||
self.highFailureAmount = 7
|
||||
'''
|
||||
logger.info('Starting Bitcoin Node... with Tor socks port:' + str(sys.argv[2]))
|
||||
logger.info('Starting Bitcoin Node... with Tor socks port:' + str(sys.argv[2]), timestamp=True)
|
||||
try:
|
||||
self.bitcoin = btc.OnionrBTC(torP=int(sys.argv[2]))
|
||||
except _gdbm.error:
|
||||
pass
|
||||
logger.info('Bitcoin Node started, on block: ' + self.bitcoin.node.getBlockHash(self.bitcoin.node.getLastBlockHeight()))
|
||||
logger.info('Bitcoin Node started, on block: ' + self.bitcoin.node.getBlockHash(self.bitcoin.node.getLastBlockHeight()), timestamp=True)
|
||||
'''
|
||||
#except:
|
||||
#logger.fatal('Failed to start Bitcoin Node, exiting...')
|
||||
@ -89,16 +89,16 @@ class OnionrCommunicate:
|
||||
blockProcessTimer = 0
|
||||
if command != False:
|
||||
if command[0] == 'shutdown':
|
||||
logger.info('Daemon recieved exit command.')
|
||||
logger.info('Daemon recieved exit command.', timestamp=True)
|
||||
break
|
||||
elif command[0] == 'anounceNode':
|
||||
announceAmount = 1
|
||||
announceVal = False
|
||||
for i in command[1]:
|
||||
logger.info('Announcing our node to ' + command[1][i])
|
||||
logger.info('Announcing our node to ' + command[1][i], timestamp=True)
|
||||
while not announceVal:
|
||||
announceVal = self.performGet('announce', command[1][i], data=self._core.hsAdder, skipHighFailureAddress=True)
|
||||
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
return
|
||||
@ -123,14 +123,14 @@ class OnionrCommunicate:
|
||||
|
||||
while peersCheck > peersChecked:
|
||||
i = random.randint(0, maxN)
|
||||
logger.info('Using ' + peerList[i] + ' to find new peers')
|
||||
logger.info('Using ' + peerList[i] + ' to find new peers', timestamp=True)
|
||||
try:
|
||||
newAdders = self.performGet('pex', peerList[i], skipHighFailureAddress=True)
|
||||
logger.debug('Attempting to merge address: ')
|
||||
logger.debug(newAdders)
|
||||
self._utils.mergeAdders(newAdders)
|
||||
except requests.exceptions.ConnectionError:
|
||||
logger.info(peerList[i] + ' connection failed')
|
||||
logger.info(peerList[i] + ' connection failed', timestamp=True)
|
||||
continue
|
||||
else:
|
||||
try:
|
||||
@ -141,7 +141,7 @@ class OnionrCommunicate:
|
||||
# TODO: Require keys to come with POW token (very large amount of POW)
|
||||
self._utils.mergeKeys(newKeys)
|
||||
except requests.exceptions.ConnectionError:
|
||||
logger.info(peerList[i] + ' connection failed')
|
||||
logger.info(peerList[i] + ' connection failed', timestamp=True)
|
||||
continue
|
||||
else:
|
||||
peersChecked += 1
|
||||
@ -223,7 +223,7 @@ class OnionrCommunicate:
|
||||
self._core.setData(data)
|
||||
if data.startswith('-txt-'):
|
||||
self._core.setBlockType(hash, 'txt')
|
||||
logger.info('Successfully obtained data for ' + hash)
|
||||
logger.info('Successfully obtained data for ' + hash, timestamp=True)
|
||||
if len(data) < 120:
|
||||
logger.debug('Block text:\n' + data)
|
||||
else:
|
||||
|
@ -24,12 +24,12 @@ class OnionrCryptoTests(unittest.TestCase):
|
||||
crypto = onionrcrypto.OnionrCrypto(myCore)
|
||||
key = key = b"tttttttttttttttttttttttttttttttt"
|
||||
|
||||
logger.info("Encrypting: " + dataString)
|
||||
logger.info("Encrypting: " + dataString, timestamp=True)
|
||||
encrypted = crypto.symmetricEncrypt(dataString, key, returnEncoded=True)
|
||||
logger.info(encrypted)
|
||||
logger.info('Decrypting encrypted string:')
|
||||
logger.info(encrypted, timestamp=True)
|
||||
logger.info('Decrypting encrypted string:', timestamp=True)
|
||||
decrypted = crypto.symmetricDecrypt(encrypted, key, encodedMessage=True)
|
||||
logger.info(decrypted)
|
||||
logger.info(decrypted, timestamp=True)
|
||||
self.assertTrue(True)
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
unittest.main()
|
||||
|
@ -141,10 +141,10 @@ def log(prefix, data, color = '', timestamp=True):
|
||||
data : The actual data to output
|
||||
color : The color to output before the data
|
||||
'''
|
||||
curTime = ''
|
||||
if timestamp:
|
||||
curTime = time.strftime("%m-%d %H:%M:%S")
|
||||
else:
|
||||
curTime = ''
|
||||
|
||||
output = colors.reset + str(color) + '[' + colors.bold + str(prefix) + colors.reset + str(color) + '] ' + curTime + ' ' + str(data) + colors.reset
|
||||
if not get_settings() & USE_ANSI:
|
||||
output = colors.filter(output)
|
||||
@ -201,26 +201,26 @@ def confirm(default = 'y', message = 'Are you sure %s? '):
|
||||
return default == 'y'
|
||||
|
||||
# debug: when there is info that could be useful for debugging purposes only
|
||||
def debug(data):
|
||||
def debug(data, timestamp=True):
|
||||
if get_level() <= LEVEL_DEBUG:
|
||||
log('/', data)
|
||||
log('/', data, timestamp=timestamp)
|
||||
|
||||
# info: when there is something to notify the user of, such as the success of a process
|
||||
def info(data):
|
||||
def info(data, timestamp=False):
|
||||
if get_level() <= LEVEL_INFO:
|
||||
log('+', data, colors.fg.green)
|
||||
log('+', data, colors.fg.green, timestamp=timestamp)
|
||||
|
||||
# warn: when there is a potential for something bad to happen
|
||||
def warn(data):
|
||||
def warn(data, timestamp=True):
|
||||
if get_level() <= LEVEL_WARN:
|
||||
log('!', data, colors.fg.orange)
|
||||
log('!', data, colors.fg.orange, timestamp=timestamp)
|
||||
|
||||
# error: when only one function, module, or process of the program encountered a problem and must stop
|
||||
def error(data):
|
||||
def error(data, timestamp=True):
|
||||
if get_level() <= LEVEL_ERROR:
|
||||
log('-', data, colors.fg.red)
|
||||
log('-', data, colors.fg.red, timestamp=timestamp)
|
||||
|
||||
# fatal: when the something so bad has happened that the prorgam must stop
|
||||
def fatal(data):
|
||||
def fatal(data, timestamp=True):
|
||||
if get_level() <= LEVEL_FATAL:
|
||||
log('#', data, colors.bg.red + colors.fg.green + colors.bold)
|
||||
log('#', data, colors.bg.red + colors.fg.green + colors.bold, timestamp=timestamp)
|
||||
|
@ -97,7 +97,7 @@ HiddenServicePort 80 127.0.0.1:''' + str(self.hsPort) + '''
|
||||
logger.fatal('Failed to start Tor. Try killing any other Tor processes owned by this user.')
|
||||
return False
|
||||
|
||||
logger.info('Finished starting Tor')
|
||||
logger.info('Finished starting Tor', timestamp=True)
|
||||
self.readyState = True
|
||||
|
||||
myID = open('data/hs/hostname', 'r')
|
||||
|
@ -158,6 +158,8 @@ class Onionr:
|
||||
'addpeer': self.addPeer,
|
||||
'add-peer': self.addPeer,
|
||||
'add-address': self.addAddress,
|
||||
'add-addr': self.addAddress,
|
||||
'addaddr': self.addAddress,
|
||||
'addaddress': self.addAddress,
|
||||
|
||||
'connect': self.addAddress
|
||||
@ -173,12 +175,12 @@ class Onionr:
|
||||
'enable-plugin': 'Enables and starts a plugin',
|
||||
'disable-plugin': 'Disables and stops a plugin',
|
||||
'reload-plugin': 'Reloads a plugin',
|
||||
'list-peers': 'Displays a list of peers',
|
||||
'add-peer': 'Adds a peer (?)',
|
||||
'list-peers': 'Displays a list of peers',
|
||||
'add-msg': 'Broadcasts a message to the Onionr network',
|
||||
'pm': 'Adds a private message to block',
|
||||
'gui': 'Opens a graphical interface for Onionr',
|
||||
'getpms': 'Shows private messages sent to you'
|
||||
'get-pms': 'Shows private messages sent to you',
|
||||
'gui': 'Opens a graphical interface for Onionr'
|
||||
}
|
||||
|
||||
command = ''
|
||||
@ -300,7 +302,7 @@ class Onionr:
|
||||
'''
|
||||
Adds a peer (?)
|
||||
'''
|
||||
|
||||
|
||||
try:
|
||||
newPeer = sys.argv[2]
|
||||
except:
|
||||
@ -312,7 +314,9 @@ class Onionr:
|
||||
return
|
||||
|
||||
def addAddress(self):
|
||||
'''Adds a Onionr node address'''
|
||||
'''
|
||||
Adds a Onionr node address
|
||||
'''
|
||||
try:
|
||||
newAddress = sys.argv[2]
|
||||
except:
|
||||
@ -320,9 +324,9 @@ class Onionr:
|
||||
else:
|
||||
logger.info("Adding address: " + logger.colors.underline + newAddress)
|
||||
if self.onionrCore.addAddress(newAddress):
|
||||
logger.info("Successfully added address")
|
||||
logger.info("Successfully added address.")
|
||||
else:
|
||||
logger.warn("Unable to add address")
|
||||
logger.warn("Unable to add address.")
|
||||
|
||||
return
|
||||
|
||||
@ -342,7 +346,7 @@ class Onionr:
|
||||
self.onionrCore.setBlockType(addedHash, 'txt')
|
||||
|
||||
return
|
||||
|
||||
|
||||
def getPMs(self):
|
||||
'''
|
||||
display PMs sent to us
|
||||
|
@ -47,10 +47,10 @@ class POW:
|
||||
if iFound:
|
||||
endTime = math.floor(time.time())
|
||||
if self.reporting:
|
||||
logger.info('Found token ' + token)
|
||||
logger.info('took ' + str(endTime - startTime))
|
||||
logger.info('Found token ' + token, timestamp=True)
|
||||
logger.info('took ' + str(endTime - startTime), timestamp=True)
|
||||
self.result = token
|
||||
|
||||
|
||||
def __init__(self, difficulty, bitcoinNode):
|
||||
self.foundHash = False
|
||||
self.difficulty = difficulty
|
||||
@ -72,7 +72,7 @@ class POW:
|
||||
def shutdown(self):
|
||||
self.hashing = False
|
||||
self.puzzle = ''
|
||||
|
||||
|
||||
def changeDifficulty(self, newDiff):
|
||||
self.difficulty = newDiff
|
||||
|
||||
@ -83,4 +83,4 @@ class POW:
|
||||
except AttributeError:
|
||||
retVal = False
|
||||
self.result = False
|
||||
return retVal
|
||||
return retVal
|
||||
|
@ -39,19 +39,17 @@ class OnionrUtils:
|
||||
self.timingToken = ''
|
||||
|
||||
return
|
||||
|
||||
|
||||
def getTimeBypassToken(self):
|
||||
if os.path.exists('data/time-bypass.txt'):
|
||||
with open('data/time-bypass.txt', 'r') as bypass:
|
||||
self.timingToken = bypass.read()
|
||||
|
||||
def sendPM(self, pubkey, message):
|
||||
'''High level function to encrypt a message to a peer and insert it as a block'''
|
||||
'''
|
||||
High level function to encrypt a message to a peer and insert it as a block
|
||||
'''
|
||||
|
||||
#forwardKey = self._core.getPeerInfo(pubkey, 'forwardKey')
|
||||
|
||||
#if self._core.getPeerInfo(pubkey, 'pubkeyExchanged') == 1:
|
||||
# pass
|
||||
encrypted = self._core._crypto.pubKeyEncrypt(message, pubkey, anonymous=True, encodedData=True).decode()
|
||||
block = self._core.insertBlock(encrypted, header='pm')
|
||||
|
||||
@ -61,21 +59,27 @@ class OnionrUtils:
|
||||
logger.info('Sent PM, hash: ' + block)
|
||||
|
||||
return
|
||||
|
||||
|
||||
def incrementAddressSuccess(self, address):
|
||||
'''Increase the recorded sucesses for an address'''
|
||||
'''
|
||||
Increase the recorded sucesses for an address
|
||||
'''
|
||||
increment = self._core.getAddressInfo(address, 'success') + 1
|
||||
self._core.setAddressInfo(address, 'success', increment)
|
||||
return
|
||||
|
||||
|
||||
def decrementAddressSuccess(self, address):
|
||||
'''Decrease the recorded sucesses for an address'''
|
||||
'''
|
||||
Decrease the recorded sucesses for an address
|
||||
'''
|
||||
increment = self._core.getAddressInfo(address, 'success') - 1
|
||||
self._core.setAddressInfo(address, 'success', increment)
|
||||
return
|
||||
|
||||
def mergeKeys(self, newKeyList):
|
||||
'''Merge ed25519 key list to our database'''
|
||||
'''
|
||||
Merge ed25519 key list to our database
|
||||
'''
|
||||
retVal = False
|
||||
if newKeyList != False:
|
||||
for key in newKeyList.split(','):
|
||||
@ -84,15 +88,17 @@ class OnionrUtils:
|
||||
retVal = True
|
||||
return retVal
|
||||
|
||||
|
||||
|
||||
def mergeAdders(self, newAdderList):
|
||||
'''Merge peer adders list to our database'''
|
||||
'''
|
||||
Merge peer adders list to our database
|
||||
'''
|
||||
retVal = False
|
||||
if newAdderList != False:
|
||||
for adder in newAdderList.split(','):
|
||||
if not adder in self._core.listAdders(randomOrder=False) and adder.strip() != self.getMyAddress():
|
||||
if self._core.addAddress(adder):
|
||||
logger.info('added ' + adder + ' to db')
|
||||
logger.info('Added ' + adder + ' to db.', timestamp=True)
|
||||
input()
|
||||
retVal = True
|
||||
else:
|
||||
@ -116,7 +122,7 @@ class OnionrUtils:
|
||||
try:
|
||||
retData = requests.get('http://' + open('data/host.txt', 'r').read() + ':' + str(config.get('client')['port']) + '/client/?action=' + command + '&token=' + str(config.get('client')['client_hmac']) + '&timingToken=' + self.timingToken).text
|
||||
except requests.ConnectionError:
|
||||
retData = False
|
||||
retData = False
|
||||
|
||||
return retData
|
||||
|
||||
@ -296,4 +302,4 @@ class OnionrUtils:
|
||||
pass
|
||||
else:
|
||||
logger.info('Recieved message: ' + message.decode())
|
||||
return
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user