work on new communicator, with nist beacon

This commit is contained in:
Kevin Froman 2018-06-11 02:40:45 -05:00
parent 7d3e7e7a30
commit d73b69c9b4
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
2 changed files with 31 additions and 4 deletions

View File

@ -19,12 +19,32 @@
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 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

View File

@ -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