2
0
mirror of https://github.com/xcat2/confluent.git synced 2025-01-18 21:53:18 +00:00
confluent/confluent/sockapi.py

42 lines
1.3 KiB
Python
Raw Normal View History

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
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()
if not data:
return
2013-09-14 11:08:48 -04:00
consession.write(data)
def _handler():
plainsocket = socket.socket()
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",
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)