work on sockets

This commit is contained in:
Kevin Froman 2018-09-14 23:48:48 -05:00
parent e0fbe2033e
commit d80e72d18c
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
3 changed files with 15 additions and 8 deletions

View File

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

View File

@ -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'):
@ -41,4 +42,10 @@ class OnionrSockets:
except KeyError:
raise ValueError('Must provide peer, address, and create in socketInfo dict argument')
self.isServer = socketInfo['create']
self.serverKey = socketInfo['peer']
self.serverAddress = socketInfo['address']
def createServer(self):
return

View File

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