work on sockets
This commit is contained in:
parent
ee2a74380b
commit
e0fbe2033e
@ -21,7 +21,7 @@
|
|||||||
'''
|
'''
|
||||||
import sys, os, core, config, json, requests, time, logger, threading, base64, onionr
|
import sys, os, core, config, json, requests, time, logger, threading, base64, onionr
|
||||||
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
|
import onionrdaemontools, onionrsockets
|
||||||
from defusedxml import minidom
|
from defusedxml import minidom
|
||||||
|
|
||||||
class OnionrCommunicatorDaemon:
|
class OnionrCommunicatorDaemon:
|
||||||
@ -79,6 +79,9 @@ class OnionrCommunicatorDaemon:
|
|||||||
#self.daemonTools = onionrdaemontools.DaemonTools(self)
|
#self.daemonTools = onionrdaemontools.DaemonTools(self)
|
||||||
self.daemonTools = onionrdaemontools.DaemonTools(self)
|
self.daemonTools = onionrdaemontools.DaemonTools(self)
|
||||||
|
|
||||||
|
# Active sockets for direct connections
|
||||||
|
self.sockets = []
|
||||||
|
|
||||||
if debug or developmentMode:
|
if debug or developmentMode:
|
||||||
OnionrCommunicatorTimers(self, self.heartbeat, 10)
|
OnionrCommunicatorTimers(self, self.heartbeat, 10)
|
||||||
|
|
||||||
@ -462,6 +465,9 @@ 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':
|
||||||
|
# Create a socket
|
||||||
|
self.onionrsockets.append(onionrsockets.OnionrSockets(self._core, startData))
|
||||||
else:
|
else:
|
||||||
logger.info('Recieved daemonQueue command:' + cmd[0])
|
logger.info('Recieved daemonQueue command:' + cmd[0])
|
||||||
|
|
||||||
|
@ -65,4 +65,9 @@ class InvalidAddress(Exception):
|
|||||||
# file exceptions
|
# file exceptions
|
||||||
|
|
||||||
class DiskAllocationReached(Exception):
|
class DiskAllocationReached(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# onionrsocket exceptions
|
||||||
|
|
||||||
|
class MissingAddress(Exception):
|
||||||
pass
|
pass
|
@ -17,3 +17,28 @@
|
|||||||
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 stem
|
||||||
|
import onionrexceptions
|
||||||
|
from dependencies import secrets
|
||||||
|
|
||||||
|
class OnionrSockets:
|
||||||
|
def __init__(self, coreInst, socketInfo):
|
||||||
|
'''Create a new Socket object. This interface is named a bit misleadingly
|
||||||
|
and does not actually forward network requests.
|
||||||
|
|
||||||
|
Accepts coreInst, an instance of Onionr core library, and socketInfo, a dict with these values:
|
||||||
|
'peer': peer master public key
|
||||||
|
'address': string, if we're connecting to a socket, this is the address we connect to. Not applicable if we're creating our own
|
||||||
|
create: bool
|
||||||
|
'''
|
||||||
|
self.socketID = secrets.token_hex(32) # Generate an ID for this socket
|
||||||
|
self._core = coreInst
|
||||||
|
|
||||||
|
# Make sure socketInfo provides all necessary values
|
||||||
|
for i in ('peer', 'address', 'create'):
|
||||||
|
try:
|
||||||
|
socketInfo[i]
|
||||||
|
except KeyError:
|
||||||
|
raise ValueError('Must provide peer, address, and create in socketInfo dict argument')
|
||||||
|
|
||||||
|
|
@ -59,6 +59,7 @@ def _processForwardKey(api, myBlock):
|
|||||||
raise onionrexceptions.InvalidPubkey("%s is nota valid pubkey key" % (key,))
|
raise onionrexceptions.InvalidPubkey("%s is nota valid pubkey key" % (key,))
|
||||||
|
|
||||||
def on_processBlocks(api):
|
def on_processBlocks(api):
|
||||||
|
# Generally fired by utils.
|
||||||
myBlock = api.data['block']
|
myBlock = api.data['block']
|
||||||
blockType = api.data['type']
|
blockType = api.data['type']
|
||||||
logger.info('blockType is ' + blockType)
|
logger.info('blockType is ' + blockType)
|
||||||
@ -76,7 +77,12 @@ def on_processBlocks(api):
|
|||||||
# socket blocks
|
# socket blocks
|
||||||
elif blockType == 'openSocket':
|
elif blockType == 'openSocket':
|
||||||
if api.data['validSig']:
|
if api.data['validSig']:
|
||||||
pass
|
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)
|
||||||
|
|
||||||
def on_init(api, data = None):
|
def on_init(api, data = None):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user