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