work on sockets

This commit is contained in:
Kevin Froman 2018-09-22 20:21:39 -05:00
parent 759da55094
commit 70e2ccbc0a
3 changed files with 14 additions and 8 deletions

View File

@ -19,7 +19,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
import sys, os, core, config, json, requests, time, logger, threading, base64, onionr
import sys, os, core, config, json, requests, time, logger, threading, base64, onionr, uuid
import onionrexceptions, onionrpeers, onionrevents as events, onionrplugins as plugins, onionrblockapi as block
import onionrdaemontools, onionrsockets, onionrchat
from dependencies import secrets
@ -471,12 +471,17 @@ class OnionrCommunicatorDaemon:
self.blockToUpload = cmd[1]
threading.Thread(target=self.uploadBlock).start()
elif cmd[0] == 'startSocket':
# Create our own socket server
socketInfo = json.loads(cmd[1])
peer = socketInfo['peer']
reason = socketInfo['reason']
self.socketServer.addSocket(peer, reason)
elif cmd[0] == 'connectSocket':
pass
threading.Thread(target=self.socketServer.addSocket, args=(peer, reason)).start()
elif cmd[0] == 'addSocket':
# Socket server was created for us
socketInfo = json.loads(cmd[1])
peer = socketInfo['peer']
reason = socketInfo['reason']
threading.Thread(target=self.socketClient.startSocket, args=(peer, reason)).start()
else:
logger.info('Recieved daemonQueue command:' + cmd[0])

View File

@ -18,6 +18,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
import stem.control
import threading
import socks, config, uuid
import onionrexceptions, time, requests, onionrblockapi
from dependencies import secrets
@ -36,7 +37,7 @@ class OnionrSocketServer:
app = flask.Flask(__name__)
http_server = WSGIServer((socket.service_id, bindPort), app)
http_server.serve_forever()
threading.Thread(target=http_server.serve_forever).start()
@app.route('/dc/', methods=['POST'])
def acceptConn(self):
@ -67,7 +68,7 @@ class OnionrSocketServer:
self.responseData[socket.service_id] = ''
self._core.insertBlock(uuid.uuid4(), header='startSocket', sign=True, encryptType='asym', asymPeer=peer, meta={'reason': reason})
self._core.insertBlock(uuid.uuid4(), header='socket', sign=True, encryptType='asym', asymPeer=peer, meta={'reason': reason})
while not self.killSocket:
time.sleep(3)
@ -85,7 +86,7 @@ class OnionrSocketClient:
self.connected = False
self.killSocket = False
def startSocket(self, peer):
def startSocket(self, peer, reason):
address = ''
# Find the newest open socket for a given peer
for block in self._core.getBlocksByType('openSocket'):

View File

@ -75,7 +75,7 @@ def on_processBlocks(api):
if api.data['validSig'] == True:
_processForwardKey(api, myBlock)
# socket blocks
elif blockType == 'openSocket':
elif blockType == 'socket':
if api.data['validSig'] == True and myBlock.decrypted: # we check if it is decrypted as a way of seeing if it was for us
try:
address = api.data['address']