diff --git a/onionr/api.py b/onionr/api.py index cd5b6065..59ff34f4 100755 --- a/onionr/api.py +++ b/onionr/api.py @@ -148,6 +148,10 @@ class API: action = request.args.get('action') requestingPeer = request.args.get('myID') data = request.args.get('data') + try: + data + except: + data = '' if action == 'firstConnect': pass elif action == 'ping': @@ -160,6 +164,15 @@ class API: resp = Response(self._utils.getBlockDBHash()) elif action == 'getBlockHashes': resp = Response(self._core.getBlockList()) + elif action == 'announce': + if data != '': + # TODO: require POW for this + if self._core.addAddress(data): + resp = Response('Success') + else: + resp = Response('') + else: + resp = Response('') # setData should be something the communicator initiates, not this api elif action == 'getData': resp = self._core.getData(data) diff --git a/onionr/communicator.py b/onionr/communicator.py index c42be173..a25df609 100755 --- a/onionr/communicator.py +++ b/onionr/communicator.py @@ -91,6 +91,14 @@ class OnionrCommunicate: if command[0] == 'shutdown': logger.info('Daemon recieved exit command.') break + elif command[0] == 'anounceNode': + announceAmount = 1 + announceVal = False + for i in command[1]: + logger.info('Announcing our node to ' + command[1][i]) + while not announceVal: + announceVal = self.performGet('announce', command[1][i], data=self._core.hsAdder, skipHighFailureAddress=True) + time.sleep(1) return diff --git a/onionr/core.py b/onionr/core.py index 72525294..d9d865cf 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -41,6 +41,7 @@ class Core: self.blockDB = 'data/blocks.db' self.blockDataLocation = 'data/blocks/' self.addressDB = 'data/address.db' + self.hsAdder = '' if not os.path.exists('data/'): os.mkdir('data/') @@ -48,6 +49,10 @@ class Core: os.mkdir('data/blocks/') if not os.path.exists(self.blockDB): self.createBlockDB() + + if os.path.exists('data/hs/hostname'): + with open('data/hs/hostname', 'r') as hs: + self.hsAdder = hs.read() self._utils = onionrutils.OnionrUtils(self) # Initialize the crypto object @@ -540,4 +545,12 @@ class Core: self.addToBlockDB(addedHash, selfInsert=True) self.setBlockType(addedHash, header) retData = addedHash - return retData \ No newline at end of file + return retData + + def introduceNode(self): + ''' + Introduces our node into the network by telling X many nodes our HS address + ''' + nodeList = self.listAdders().split('\n') + self.daemonQueueAdd('announceNode', nodeList) + return \ No newline at end of file diff --git a/onionr/onionr.py b/onionr/onionr.py index 25108c39..a65d905e 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -36,7 +36,7 @@ except ImportError: logger.error('You need python3 tkinter and tk installed to use Onionr.') sys.exit(1) -ONIONR_TAGLINE = 'Anonymous P2P Platform - GPLv3 - onionr.voidnet.tech' +ONIONR_TAGLINE = 'Anonymous P2P Platform - GPLv3 - https://Onionr.VoidNet.Tech' ONIONR_VERSION = '0.0.0' # for debugging and stuff API_VERSION = '1' # increments of 1; only change when something fundemental about how the API works changes. This way other nodes knows how to communicate without learning too much information about you.