From 0ae052336c892b3c8499d33b32d155bf889c0b74 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Tue, 7 Aug 2018 02:31:53 -0500 Subject: [PATCH] + onionr now introduces automatically + added daemon tools file + added .dockerignore --- .dockerignore | 2 ++ onionr/communicator2.py | 13 +++++++++++-- onionr/core.py | 5 ++--- onionr/onionrdaemontools.py | 29 +++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 .dockerignore create mode 100644 onionr/onionrdaemontools.py diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..d76a75c1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +onionr/data/**/* +onionr/data diff --git a/onionr/communicator2.py b/onionr/communicator2.py index b641b76e..6a37a376 100755 --- a/onionr/communicator2.py +++ b/onionr/communicator2.py @@ -21,6 +21,7 @@ ''' import sys, os, core, config, json, requests, time, logger, threading, base64, onionr import onionrexceptions, onionrpeers, onionrevents as events, onionrplugins as plugins, onionrblockapi as block +import onionrdaemontools from defusedxml import minidom class OnionrCommunicatorDaemon: @@ -69,6 +70,11 @@ class OnionrCommunicatorDaemon: # Loads in and starts the enabled plugins plugins.reload() + # daemon tools are misc daemon functions, e.g. announce to online peers + # intended only for use by OnionrCommunicatorDaemon + #self.daemonTools = onionrdaemontools.DaemonTools(self) + self.daemonTools = onionrdaemontools.DaemonTools(self) + if debug or developmentMode: OnionrCommunicatorTimers(self, self.heartbeat, 10) @@ -78,6 +84,7 @@ class OnionrCommunicatorDaemon: # Set timers, function reference, seconds # requiresPeer True means the timer function won't fire if we have no connected peers + # TODO: make some of these timer counts configurable OnionrCommunicatorTimers(self, self.daemonCommands, 5) OnionrCommunicatorTimers(self, self.detectAPICrash, 5) peerPoolTimer = OnionrCommunicatorTimers(self, self.getOnlinePeers, 60) @@ -86,11 +93,13 @@ class OnionrCommunicatorDaemon: OnionrCommunicatorTimers(self, self.clearOfflinePeer, 58) OnionrCommunicatorTimers(self, self.lookupKeys, 60, requiresPeer=True) OnionrCommunicatorTimers(self, self.lookupAdders, 60, requiresPeer=True) + announceTimer = OnionrCommunicatorTimers(self, self.daemonTools.announceNode, 305, requiresPeer=True) cleanupTimer = OnionrCommunicatorTimers(self, self.peerCleanup, 300, requiresPeer=True) # set loop to execute instantly to load up peer pool (replaced old pool init wait) peerPoolTimer.count = (peerPoolTimer.frequency - 1) cleanupTimer.count = (cleanupTimer.frequency - 60) + announceTimer.count = (cleanupTimer.frequency - 60) # Main daemon loop, mainly for calling timers, don't do any complex operations here to avoid locking try: @@ -278,7 +287,7 @@ class OnionrCommunicatorDaemon: def addBootstrapListToPeerList(self, peerList): '''Add the bootstrap list to the peer list (no duplicates)''' for i in self._core.bootstrapList: - if i not in peerList and i not in self.offlinePeers and i != self._core.hsAdder: + if i not in peerList and i not in self.offlinePeers and i != self._core.hsAddress: peerList.append(i) def connectNewPeer(self, peer='', useBootstrap=False): @@ -441,7 +450,7 @@ class OnionrCommunicatorDaemon: announceAmount = 2 for peer in self.onlinePeers: announceCount += 1 - if self.peerAction(peer, 'announce', self._core.hsAdder) == 'Success': + if self.peerAction(peer, 'announce', self._core.hsAddress) == 'Success': logger.info('Successfully introduced node to ' + peer) break else: diff --git a/onionr/core.py b/onionr/core.py index eb45e182..64ad6439 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -40,7 +40,7 @@ class Core: self.blockDB = 'data/blocks.db' self.blockDataLocation = 'data/blocks/' self.addressDB = 'data/address.db' - self.hsAdder = '' + self.hsAddress = '' self.bootstrapFileLocation = 'static-data/bootstrap-nodes.txt' self.bootstrapList = [] self.requirements = onionrvalues.OnionrValues() @@ -57,7 +57,7 @@ class Core: if os.path.exists('data/hs/hostname'): with open('data/hs/hostname', 'r') as hs: - self.hsAdder = hs.read().strip() + self.hsAddress = hs.read().strip() # Load bootstrap address list if os.path.exists(self.bootstrapFileLocation): @@ -158,7 +158,6 @@ class Core: conn.close() events.event('address_remove', data = {'address': address}, onionr = None) - return True else: return False diff --git a/onionr/onionrdaemontools.py b/onionr/onionrdaemontools.py new file mode 100644 index 00000000..e615aacb --- /dev/null +++ b/onionr/onionrdaemontools.py @@ -0,0 +1,29 @@ +''' + Onionr - P2P Microblogging Platform & Social network. + + Contains the CommunicatorUtils class which contains useful functions for the communicator daemon +''' +''' + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +''' +import onionrexceptions, onionrpeers +class DaemonTools: + def __init__(self, daemon): + self.daemon = daemon + + def announceNode(self): + '''Announce our node to our peers''' + peer = self.daemon.pickOnlinePeer() + self.daemon.peerAction(peer, 'announce', self.daemon._core.hsAddress) + self.daemon.decrementThreadCount('announceNode') \ No newline at end of file