changed communicator to be in the same process
parent
6b25a9301c
commit
d2e7ced776
|
@ -406,8 +406,8 @@ class API:
|
||||||
|
|
||||||
@app.route('/getstats')
|
@app.route('/getstats')
|
||||||
def getStats():
|
def getStats():
|
||||||
return Response("disabled")
|
#return Response("disabled")
|
||||||
#return Response(self._core.serializer.getStats())
|
return Response(self._core.serializer.getStats())
|
||||||
|
|
||||||
@app.route('/getuptime')
|
@app.route('/getuptime')
|
||||||
def showUptime():
|
def showUptime():
|
||||||
|
|
|
@ -25,11 +25,13 @@ import onionrdaemontools, onionrsockets, onionr, onionrproofs, proofofmemory
|
||||||
import binascii
|
import binascii
|
||||||
from dependencies import secrets
|
from dependencies import secrets
|
||||||
from defusedxml import minidom
|
from defusedxml import minidom
|
||||||
|
config.reload()
|
||||||
class OnionrCommunicatorDaemon:
|
class OnionrCommunicatorDaemon:
|
||||||
def __init__(self, debug, developmentMode):
|
def __init__(self, onionrInst, proxyPort, developmentMode=config.get('general.dev_mode', False)):
|
||||||
|
onionrInst.communicatorInst = self
|
||||||
# configure logger and stuff
|
# configure logger and stuff
|
||||||
onionr.Onionr.setupConfig('data/', self = self)
|
onionr.Onionr.setupConfig('data/', self = self)
|
||||||
|
self.proxyPort = proxyPort
|
||||||
|
|
||||||
self.isOnline = True # Assume we're connected to the internet
|
self.isOnline = True # Assume we're connected to the internet
|
||||||
|
|
||||||
|
@ -37,7 +39,7 @@ class OnionrCommunicatorDaemon:
|
||||||
self.timers = []
|
self.timers = []
|
||||||
|
|
||||||
# initalize core with Tor socks port being 3rd argument
|
# initalize core with Tor socks port being 3rd argument
|
||||||
self.proxyPort = sys.argv[2]
|
self.proxyPort = proxyPort
|
||||||
self._core = core.Core(torPort=self.proxyPort)
|
self._core = core.Core(torPort=self.proxyPort)
|
||||||
|
|
||||||
# intalize NIST beacon salt and time
|
# intalize NIST beacon salt and time
|
||||||
|
@ -49,9 +51,6 @@ class OnionrCommunicatorDaemon:
|
||||||
# loop time.sleep delay in seconds
|
# loop time.sleep delay in seconds
|
||||||
self.delay = 1
|
self.delay = 1
|
||||||
|
|
||||||
# time app started running for info/statistics purposes
|
|
||||||
self.startTime = self._core._utils.getEpoch()
|
|
||||||
|
|
||||||
# lists of connected peers and peers we know we can't reach currently
|
# lists of connected peers and peers we know we can't reach currently
|
||||||
self.onlinePeers = []
|
self.onlinePeers = []
|
||||||
self.offlinePeers = []
|
self.offlinePeers = []
|
||||||
|
@ -90,8 +89,11 @@ class OnionrCommunicatorDaemon:
|
||||||
# intended only for use by OnionrCommunicatorDaemon
|
# intended only for use by OnionrCommunicatorDaemon
|
||||||
self.daemonTools = onionrdaemontools.DaemonTools(self)
|
self.daemonTools = onionrdaemontools.DaemonTools(self)
|
||||||
|
|
||||||
|
# time app started running for info/statistics purposes
|
||||||
|
self.startTime = self._core._utils.getEpoch()
|
||||||
|
|
||||||
if debug or developmentMode:
|
if developmentMode:
|
||||||
|
print('enabling heartbeat')
|
||||||
OnionrCommunicatorTimers(self, self.heartbeat, 30)
|
OnionrCommunicatorTimers(self, self.heartbeat, 30)
|
||||||
|
|
||||||
# Set timers, function reference, seconds
|
# Set timers, function reference, seconds
|
||||||
|
@ -129,8 +131,6 @@ class OnionrCommunicatorDaemon:
|
||||||
self.socketServer.start()
|
self.socketServer.start()
|
||||||
self.socketClient = onionrsockets.OnionrSocketClient(self._core)
|
self.socketClient = onionrsockets.OnionrSocketClient(self._core)
|
||||||
|
|
||||||
# Loads chat messages into memory
|
|
||||||
threading.Thread(target=self._chat.chatHandler).start()
|
|
||||||
|
|
||||||
# Main daemon loop, mainly for calling timers, don't do any complex operations here to avoid locking
|
# Main daemon loop, mainly for calling timers, don't do any complex operations here to avoid locking
|
||||||
try:
|
try:
|
||||||
|
@ -513,6 +513,8 @@ class OnionrCommunicatorDaemon:
|
||||||
response = '\n'.join(list(self.onlinePeers)).strip()
|
response = '\n'.join(list(self.onlinePeers)).strip()
|
||||||
if response == '':
|
if response == '':
|
||||||
response = 'none'
|
response = 'none'
|
||||||
|
elif cmd[0] == 'localCommand':
|
||||||
|
response = self._core._utils.localCommand(cmd[1])
|
||||||
elif cmd[0] == 'pex':
|
elif cmd[0] == 'pex':
|
||||||
for i in self.timers:
|
for i in self.timers:
|
||||||
if i.timerFunction.__name__ == 'lookupAdders':
|
if i.timerFunction.__name__ == 'lookupAdders':
|
||||||
|
@ -643,18 +645,5 @@ class OnionrCommunicatorTimers:
|
||||||
self.count = -1 # negative 1 because its incremented at bottom
|
self.count = -1 # negative 1 because its incremented at bottom
|
||||||
self.count += 1
|
self.count += 1
|
||||||
|
|
||||||
shouldRun = False
|
def startCommunicator(onionrInst, proxyPort):
|
||||||
debug = True
|
OnionrCommunicatorDaemon(onionrInst, proxyPort)
|
||||||
developmentMode = False
|
|
||||||
if config.get('general.dev_mode', True):
|
|
||||||
developmentMode = True
|
|
||||||
try:
|
|
||||||
if sys.argv[1] == 'run':
|
|
||||||
shouldRun = True
|
|
||||||
except IndexError:
|
|
||||||
pass
|
|
||||||
if shouldRun:
|
|
||||||
try:
|
|
||||||
OnionrCommunicatorDaemon(debug, developmentMode)
|
|
||||||
except Exception as e:
|
|
||||||
logger.error('Error occured in Communicator', error = e, timestamp = False)
|
|
|
@ -33,7 +33,7 @@ import onionrutils
|
||||||
import netcontroller
|
import netcontroller
|
||||||
from netcontroller import NetController
|
from netcontroller import NetController
|
||||||
from onionrblockapi import Block
|
from onionrblockapi import Block
|
||||||
import onionrproofs, onionrexceptions, onionrusers
|
import onionrproofs, onionrexceptions, onionrusers, communicator2
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from urllib3.contrib.socks import SOCKSProxyManager
|
from urllib3.contrib.socks import SOCKSProxyManager
|
||||||
|
@ -72,6 +72,7 @@ class Onionr:
|
||||||
logger.error('Tor is not installed')
|
logger.error('Tor is not installed')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
self.communicatorInst = None
|
||||||
self.onionrCore = core.Core()
|
self.onionrCore = core.Core()
|
||||||
#self.deleteRunFiles()
|
#self.deleteRunFiles()
|
||||||
self.onionrUtils = onionrutils.OnionrUtils(self.onionrCore)
|
self.onionrUtils = onionrutils.OnionrUtils(self.onionrCore)
|
||||||
|
@ -749,7 +750,13 @@ class Onionr:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
# TODO: make runable on windows
|
# TODO: make runable on windows
|
||||||
communicatorProc = subprocess.Popen([communicatorDaemon, 'run', str(net.socksPort)])
|
#communicatorProc = subprocess.Popen([communicatorDaemon, 'run', str(net.socksPort)])
|
||||||
|
|
||||||
|
communicatorThread = Thread(target=communicator2.startCommunicator, args=(self, str(net.socksPort)))
|
||||||
|
communicatorThread.start()
|
||||||
|
|
||||||
|
while self.communicatorInst is None:
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
# print nice header thing :)
|
# print nice header thing :)
|
||||||
if config.get('general.display_header', True):
|
if config.get('general.display_header', True):
|
||||||
|
@ -769,7 +776,7 @@ class Onionr:
|
||||||
#proc = psutil.Process()
|
#proc = psutil.Process()
|
||||||
#print('api-files:',proc.open_files(), len(psutil.net_connections()))
|
#print('api-files:',proc.open_files(), len(psutil.net_connections()))
|
||||||
# Break if communicator process ends, so we don't have left over processes
|
# Break if communicator process ends, so we don't have left over processes
|
||||||
if communicatorProc.poll() is not None:
|
if self.communicatorInst.shutdown:
|
||||||
break
|
break
|
||||||
if self.killed:
|
if self.killed:
|
||||||
break # Break out if sigterm for clean exit
|
break # Break out if sigterm for clean exit
|
||||||
|
|
|
@ -83,7 +83,7 @@ class OnionrUser:
|
||||||
if self._core._utils.validatePubKey(forwardKey):
|
if self._core._utils.validatePubKey(forwardKey):
|
||||||
retData = self._core._crypto.pubKeyEncrypt(data, forwardKey, encodedData=True, anonymous=True)
|
retData = self._core._crypto.pubKeyEncrypt(data, forwardKey, encodedData=True, anonymous=True)
|
||||||
else:
|
else:
|
||||||
raise onionrexceptions.InvalidPubkey("No valid forward key available for this user")
|
raise onionrexceptions.InvalidPubkey("No valid forward secrecy key available for this user")
|
||||||
#self.generateForwardKey()
|
#self.generateForwardKey()
|
||||||
return (retData, forwardKey)
|
return (retData, forwardKey)
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ class SerializedData:
|
||||||
def getStats(self):
|
def getStats(self):
|
||||||
'''Return statistics about our node'''
|
'''Return statistics about our node'''
|
||||||
stats = {}
|
stats = {}
|
||||||
stats['uptime'] = self._core._utils.localCommand('getuptime')
|
stats['uptime'] = int(self._core.daemonQueueSimple('localCommand', 'getuptime'))
|
||||||
stats['connectedNodes'] = self._core.daemonQueueSimple('connectedPeers')
|
stats['connectedNodes'] = self._core.daemonQueueSimple('connectedPeers')
|
||||||
stats['blockCount'] = len(self._core.getBlockList())
|
stats['blockCount'] = len(self._core.getBlockList())
|
||||||
return json.dumps(stats)
|
return json.dumps(stats)
|
||||||
|
|
Loading…
Reference in New Issue