From d80e72d18cf097663d2285ee858c683ec5b726de Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Fri, 14 Sep 2018 23:48:48 -0500 Subject: [PATCH] work on sockets --- onionr/communicator2.py | 4 ++-- onionr/onionrsockets.py | 11 +++++++++-- .../default-plugins/metadataprocessor/main.py | 8 ++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/onionr/communicator2.py b/onionr/communicator2.py index e6d49d28..c0fbb698 100755 --- a/onionr/communicator2.py +++ b/onionr/communicator2.py @@ -465,8 +465,8 @@ class OnionrCommunicatorDaemon: elif cmd[0] == 'uploadBlock': self.blockToUpload = cmd[1] threading.Thread(target=self.uploadBlock).start() - elif cmd[0] == 'createSocket': - # Create a socket + elif cmd[0] == 'startSocket': + # Create a socket or connect to one self.onionrsockets.append(onionrsockets.OnionrSockets(self._core, startData)) else: logger.info('Recieved daemonQueue command:' + cmd[0]) diff --git a/onionr/onionrsockets.py b/onionr/onionrsockets.py index 0f00519f..f80b1637 100644 --- a/onionr/onionrsockets.py +++ b/onionr/onionrsockets.py @@ -33,6 +33,7 @@ class OnionrSockets: ''' self.socketID = secrets.token_hex(32) # Generate an ID for this socket self._core = coreInst + self.socketInfo = socketInfo # Make sure socketInfo provides all necessary values for i in ('peer', 'address', 'create'): @@ -40,5 +41,11 @@ class OnionrSockets: socketInfo[i] except KeyError: raise ValueError('Must provide peer, address, and create in socketInfo dict argument') - - \ No newline at end of file + + self.isServer = socketInfo['create'] + + self.serverKey = socketInfo['peer'] + self.serverAddress = socketInfo['address'] + + def createServer(self): + return \ No newline at end of file diff --git a/onionr/static-data/default-plugins/metadataprocessor/main.py b/onionr/static-data/default-plugins/metadataprocessor/main.py index 4d23fa9a..199c8821 100644 --- a/onionr/static-data/default-plugins/metadataprocessor/main.py +++ b/onionr/static-data/default-plugins/metadataprocessor/main.py @@ -68,21 +68,21 @@ def on_processBlocks(api): # userInfo blocks, such as for setting username if blockType == 'userInfo': - if api.data['validSig']: + if api.data['validSig'] == True: # we use == True for type safety _processUserInfo(api, myBlock) # forwardKey blocks, add a new forward secrecy key for a peer elif blockType == 'forwardKey': - if api.data['validSig']: + if api.data['validSig'] == True: _processForwardKey(api, myBlock) # socket blocks elif blockType == 'openSocket': - if api.data['validSig']: + if api.data['validSig'] == True: try: address = api.data['address'] except KeyError: raise onionrexceptions.MissingAddress("Missing address for new socket") socketInfo = json.dumps({'peer': api.data['signer'], 'address': address, create = False}) - api.get_core().daemonQueueAdd('createSocket', socketInfo) + api.get_core().daemonQueueAdd('startSocket', socketInfo) def on_init(api, data = None):