From d73b69c9b43c74dfe4bafcc726810840879839e5 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Mon, 11 Jun 2018 02:40:45 -0500 Subject: [PATCH] work on new communicator, with nist beacon --- onionr/communicator2.py | 28 ++++++++++++++++++++++++---- onionr/onionrutils.py | 7 +++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/onionr/communicator2.py b/onionr/communicator2.py index a1594b8d..d6313630 100644 --- a/onionr/communicator2.py +++ b/onionr/communicator2.py @@ -19,12 +19,32 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' -import core, config, onionrblockapi as block -class OnionrDaemon: +import core, config, onionrblockapi as block, requests, xml +class OnionrCommunicatorDaemon: def __init__(self, debug, developmentMode): self.timers = [] # list of tuples, function, time in seconds - self.nodeInfo + self._core = core.Core() + + self.nistSalt = 0 return + + def getNistTimeStamp(self): + curTime = self._core._utils.getCurrentHourEpoch + data = doGetRequest('https://beacon.nist.gov/rest/record/' + str(curTime)) + + + def doGetRequest(self, url, port=sys.argv[2], proxyType='tor'): + ''' + Do a get request through a local tor or i2p instance + ''' + if proxyType == 'tor': + proxies = {'http': 'socks5://127.0.0.1:' + str(port), 'https': 'socks5://127.0.0.1:' + str(port)} + elif proxyType == 'i2p': + proxies = {'http': 'http://127.0.0.1:4444'} + else: + return + headers = {'user-agent': 'PyOnionr'} + r = requests.get(url, headers=headers, proxies=proxies, allow_redirects=False, timeout=(15, 30)) shouldRun = False debug = True @@ -38,7 +58,7 @@ except IndexError: pass if shouldRun: try: - OnionrCommunicate(debug, developmentMode) + OnionrCommunicatorDaemon(debug, developmentMode) except KeyboardInterrupt: sys.exit(1) pass diff --git a/onionr/onionrutils.py b/onionr/onionrutils.py index 378cd0b3..b0bd941d 100644 --- a/onionr/onionrutils.py +++ b/onionr/onionrutils.py @@ -78,6 +78,13 @@ class OnionrUtils: return + def getCurrentHourEpoch(self): + ''' + Returns the current epoch, rounded down to the hour + ''' + epoch = self.getEpoch() + return epoch - (epoch % 3600) + def incrementAddressSuccess(self, address): ''' Increase the recorded sucesses for an address