Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSL Proxy #144

Merged
merged 19 commits into from Jan 13, 2014
Merged

Various bits of cleanup. Now the SSL proxy works in python 2 and 3.

  • Loading branch information...
ggreer committed Jan 13, 2014
commit bfbc0685fabc96540564e6194d39987c648c18a9
@@ -102,18 +102,18 @@ def select(self, timeout=0):

for fileno in _out:
fd = fd_map[fileno]
try:
fd.write()
except Exception as e:
msg.error('Couldn\'t write to socket: %s' % str(e))
return self._reconnect(fd, _in)
# try:
fd.write()
# except Exception as e:
# msg.error('Couldn\'t write to socket: %s' % str(e))
# return self._reconnect(fd, _in)

for fileno in _in:
fd = fd_map[fileno]
try:
fd.read()
except Exception as e:
msg.error('Couldn\'t read from socket: %s' % str(e))
fd.reconnect()
# try:
fd.read()
# except Exception as e:
# msg.error('Couldn\'t read from socket: %s' % str(e))
# fd.reconnect()

reactor = _Reactor()
@@ -9,8 +9,6 @@
import sys
import time

import editor

# Monkey patch editor
timeouts = defaultdict(list)
top_timeout_id = 0
@@ -27,7 +25,7 @@ def name():


def ok_cancel_dialog(dialog):
print("Dialog: ", dialog)
print('Dialog:', dialog)


def error_message(msg):
@@ -85,37 +83,47 @@ def call_timeouts():
def open_file(file):
pass

editor.name = name
editor.ok_cancel_dialog = ok_cancel_dialog
editor.error_message = error_message
editor.status_message = status_message
editor.platform = _platform
editor.set_timeout = set_timeout
editor.cancel_timeout = cancel_timeout
editor.call_timeouts = call_timeouts
editor.open_file = open_file

try:
from .common import api, msg, shared as G, utils, reactor, event_emitter
from .common.handlers import base
from .common.protocols import floo_proto
from . import editor
except (ImportError, ValueError):
from common import api, msg, shared as G, utils, reactor, event_emitter
from common.handlers import base
from common.protocols import floo_proto
except (ImportError, ValueError):
from .common import api, msg, shared as G, reactor, event_emitter
from .common.handlers import base
from .common.protocols import floo_proto
import editor


def editor_log(msg):
print(msg)
sys.stdout.flush()

editor.name = name
editor.ok_cancel_dialog = ok_cancel_dialog
editor.error_message = error_message
editor.status_message = status_message
editor.platform = _platform
editor.set_timeout = set_timeout
editor.cancel_timeout = cancel_timeout
editor.call_timeouts = call_timeouts
editor.open_file = open_file
msg.editor_log = editor_log

utils.reload_settings()

eventStream = event_emitter.EventEmitter()
eventStream.on('to_floobits', lambda x: msg.log("to_floobits: " + x) and sys.stdout.flush())
eventStream.on('from_floobits', lambda x: msg.log("from_floobits: " + x))


def conn_log(action, item):
try:
item = item.decode('utf-8')
except Exception:
pass
msg.log('%s: %s' % (action, item))
sys.stdout.flush()

eventStream.on('to_floobits', lambda x: conn_log('to_floobits', x))
eventStream.on('from_floobits', lambda x: conn_log('from_floobits', x))


# KANS: this should use base, but I want the connection logic from FlooProto (ie, move that shit to base)
@@ -128,10 +136,10 @@ def __init__(self, *args, **kwargs):
eventStream.on('to_floobits', self._q.append)

def _handle(self, data):
eventStream.emit('from_floobits', data)
eventStream.emit('from_floobits', data.decode('utf-8'))

def reconnect(self):
msg.error("Remote connection died")
msg.error('Remote connection died')
sys.exit(1)


@@ -145,8 +153,8 @@ def tick(self):
pass

def on_connect(self):
msg.log("have a remote conn!")
eventStream.emit("remote_conn")
msg.log('have a remote conn!')
eventStream.emit('remote_conn')


class LocalProtocol(floo_proto.FlooProtocol):
@@ -159,15 +167,15 @@ def __init__(self, *args, **kwargs):
eventStream.on('from_floobits', self._q.append)
self.to_proxy = []
self.remote_conn = False
eventStream.on("remote_conn", self.on_remote_conn)
eventStream.on('remote_conn', self.on_remote_conn)

def connect(self, sock=None):
self.emit('connect')
self._sock = sock
self.connected = True

def reconnect(self):
msg.error("Client connection died")
msg.error('Client connection died')
sys.exit(1)

def stop(self):
@@ -177,11 +185,11 @@ def on_remote_conn(self):
self.remote_conn = True
while self.to_proxy:
item = self.to_proxy.pop(0)
eventStream.emit('to_floobits', item)
eventStream.emit('to_floobits', item.decode('utf-8'))

def _handle(self, data):
if self.remote_conn:
eventStream.emit('to_floobits', data)
eventStream.emit('to_floobits', data.decode('utf-8'))
else:
self.to_proxy.append(data)

@@ -205,18 +213,18 @@ def on_connect(self):


def main():
msg.LOG_LEVEL = msg.LOG_LEVELS.get(msg.LOG_LEVELS['ERROR'])
msg.LOG_LEVEL = msg.LOG_LEVELS['ERROR']

usage = "Figure it out :P"
usage = 'Figure it out :P'
parser = optparse.OptionParser(usage=usage)
parser.add_option(
"--url",
dest="url",
'--url',
dest='url',
default=None
)
parser.add_option(
"--data",
dest="data",
'--data',
dest='data',
default=None
)

@@ -251,7 +259,7 @@ def on_ready():
try:
reactor.reactor.block()
except KeyboardInterrupt:
print("ciao")
print('ciao')

if __name__ == "__main__":
if __name__ == '__main__':
main()
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.