work on sockets
parent
e0fbe2033e
commit
d80e72d18c
|
@ -465,8 +465,8 @@ class OnionrCommunicatorDaemon:
|
||||||
elif cmd[0] == 'uploadBlock':
|
elif cmd[0] == 'uploadBlock':
|
||||||
self.blockToUpload = cmd[1]
|
self.blockToUpload = cmd[1]
|
||||||
threading.Thread(target=self.uploadBlock).start()
|
threading.Thread(target=self.uploadBlock).start()
|
||||||
elif cmd[0] == 'createSocket':
|
elif cmd[0] == 'startSocket':
|
||||||
# Create a socket
|
# Create a socket or connect to one
|
||||||
self.onionrsockets.append(onionrsockets.OnionrSockets(self._core, startData))
|
self.onionrsockets.append(onionrsockets.OnionrSockets(self._core, startData))
|
||||||
else:
|
else:
|
||||||
logger.info('Recieved daemonQueue command:' + cmd[0])
|
logger.info('Recieved daemonQueue command:' + cmd[0])
|
||||||
|
|
|
@ -33,6 +33,7 @@ class OnionrSockets:
|
||||||
'''
|
'''
|
||||||
self.socketID = secrets.token_hex(32) # Generate an ID for this socket
|
self.socketID = secrets.token_hex(32) # Generate an ID for this socket
|
||||||
self._core = coreInst
|
self._core = coreInst
|
||||||
|
self.socketInfo = socketInfo
|
||||||
|
|
||||||
# Make sure socketInfo provides all necessary values
|
# Make sure socketInfo provides all necessary values
|
||||||
for i in ('peer', 'address', 'create'):
|
for i in ('peer', 'address', 'create'):
|
||||||
|
@ -40,5 +41,11 @@ class OnionrSockets:
|
||||||
socketInfo[i]
|
socketInfo[i]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise ValueError('Must provide peer, address, and create in socketInfo dict argument')
|
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
|
|
@ -68,21 +68,21 @@ def on_processBlocks(api):
|
||||||
|
|
||||||
# userInfo blocks, such as for setting username
|
# userInfo blocks, such as for setting username
|
||||||
if blockType == 'userInfo':
|
if blockType == 'userInfo':
|
||||||
if api.data['validSig']:
|
if api.data['validSig'] == True: # we use == True for type safety
|
||||||
_processUserInfo(api, myBlock)
|
_processUserInfo(api, myBlock)
|
||||||
# forwardKey blocks, add a new forward secrecy key for a peer
|
# forwardKey blocks, add a new forward secrecy key for a peer
|
||||||
elif blockType == 'forwardKey':
|
elif blockType == 'forwardKey':
|
||||||
if api.data['validSig']:
|
if api.data['validSig'] == True:
|
||||||
_processForwardKey(api, myBlock)
|
_processForwardKey(api, myBlock)
|
||||||
# socket blocks
|
# socket blocks
|
||||||
elif blockType == 'openSocket':
|
elif blockType == 'openSocket':
|
||||||
if api.data['validSig']:
|
if api.data['validSig'] == True:
|
||||||
try:
|
try:
|
||||||
address = api.data['address']
|
address = api.data['address']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise onionrexceptions.MissingAddress("Missing address for new socket")
|
raise onionrexceptions.MissingAddress("Missing address for new socket")
|
||||||
socketInfo = json.dumps({'peer': api.data['signer'], 'address': address, create = False})
|
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):
|
def on_init(api, data = None):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue