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 You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. 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 onionrexceptions, onionrpeers, onionrevents as events, onionrplugins as plugins, onionrblockapi as block
import onionrdaemontools, onionrsockets, onionrchat import onionrdaemontools, onionrsockets, onionrchat
from dependencies import secrets from dependencies import secrets
@ -471,12 +471,17 @@ class OnionrCommunicatorDaemon:
self.blockToUpload = cmd[1] self.blockToUpload = cmd[1]
threading.Thread(target=self.uploadBlock).start() threading.Thread(target=self.uploadBlock).start()
elif cmd[0] == 'startSocket': elif cmd[0] == 'startSocket':
# Create our own socket server
socketInfo = json.loads(cmd[1]) socketInfo = json.loads(cmd[1])
peer = socketInfo['peer'] peer = socketInfo['peer']
reason = socketInfo['reason'] reason = socketInfo['reason']
self.socketServer.addSocket(peer, reason) threading.Thread(target=self.socketServer.addSocket, args=(peer, reason)).start()
elif cmd[0] == 'connectSocket': elif cmd[0] == 'addSocket':
pass # 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: else:
logger.info('Recieved daemonQueue command:' + cmd[0]) 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/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
''' '''
import stem.control import stem.control
import threading
import socks, config, uuid import socks, config, uuid
import onionrexceptions, time, requests, onionrblockapi import onionrexceptions, time, requests, onionrblockapi
from dependencies import secrets from dependencies import secrets
@ -36,7 +37,7 @@ class OnionrSocketServer:
app = flask.Flask(__name__) app = flask.Flask(__name__)
http_server = WSGIServer((socket.service_id, bindPort), app) 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']) @app.route('/dc/', methods=['POST'])
def acceptConn(self): def acceptConn(self):
@ -67,7 +68,7 @@ class OnionrSocketServer:
self.responseData[socket.service_id] = '' 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: while not self.killSocket:
time.sleep(3) time.sleep(3)
@ -85,7 +86,7 @@ class OnionrSocketClient:
self.connected = False self.connected = False
self.killSocket = False self.killSocket = False
def startSocket(self, peer): def startSocket(self, peer, reason):
address = '' address = ''
# Find the newest open socket for a given peer # Find the newest open socket for a given peer
for block in self._core.getBlocksByType('openSocket'): for block in self._core.getBlocksByType('openSocket'):

View File

@ -75,7 +75,7 @@ def on_processBlocks(api):
if api.data['validSig'] == True: if api.data['validSig'] == True:
_processForwardKey(api, myBlock) _processForwardKey(api, myBlock)
# socket blocks # 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 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: try:
address = api.data['address'] address = api.data['address']