2013-09-14 11:08:48 -04:00
|
|
|
# Copyright 2013 IBM Corporation
|
|
|
|
# ALl rights reserved
|
|
|
|
|
|
|
|
# This is the socket api layer.
|
|
|
|
# It implement unix and tls sockets
|
|
|
|
# TODO: SO_PEERCRED for unix socket
|
|
|
|
import confluent.console as console
|
|
|
|
import confluent.config as config
|
|
|
|
import eventlet.green.socket as socket
|
|
|
|
import eventlet.green.ssl as ssl
|
2013-09-14 20:21:58 -04:00
|
|
|
import eventlet
|
2013-09-14 11:08:48 -04:00
|
|
|
|
|
|
|
def sessionhdl(connection):
|
|
|
|
#TODO: authenticate and authorize peer
|
|
|
|
# For now, trying to test the console stuff, so let's just do n1.
|
|
|
|
cfm = config.ConfigManager(tenant=0)
|
|
|
|
consession = console.ConsoleSession(node='n1', configmanager=cfm,
|
|
|
|
datacallback=connection.write)
|
|
|
|
while (1):
|
|
|
|
data = connection.read()
|
2013-10-09 20:14:34 -04:00
|
|
|
if not data:
|
|
|
|
return
|
2013-09-14 11:08:48 -04:00
|
|
|
consession.write(data)
|
|
|
|
|
|
|
|
|
|
|
|
def _handler():
|
|
|
|
plainsocket = socket.socket()
|
2013-10-09 20:14:34 -04:00
|
|
|
plainsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
2013-09-14 11:08:48 -04:00
|
|
|
srv = ssl.wrap_socket(plainsocket, keyfile="/etc/confluent/privkey.pem",
|
2013-09-14 20:21:58 -04:00
|
|
|
certfile="/etc/confluent/srvcert.pem",
|
|
|
|
ssl_version=ssl.PROTOCOL_TLSv1,
|
|
|
|
server_side=True)
|
2013-09-14 11:08:48 -04:00
|
|
|
srv.bind(('0.0.0.0', 4001))
|
|
|
|
srv.listen(5)
|
|
|
|
while (1): # TODO: exithook
|
|
|
|
cnn, addr = srv.accept()
|
|
|
|
eventlet.spawn_n(sessionhdl, cnn)
|
|
|
|
|
|
|
|
class SockApi(object):
|
|
|
|
def start(self):
|
|
|
|
self.server = eventlet.spawn(_handler)
|