- Timestamp:
- 05/15/12 22:47:29 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
etherws/trunk/etherws.py
r141 r143 11 11 # 12 12 # todo: 13 # - SSLsupport14 # - servant mode (like typical p2p software)13 # - authentication support 14 # - servant mode support (like typical p2p software) 15 15 # 16 16 # =========================================================================== … … 44 44 import os 45 45 import sys 46 import time 46 47 import argparse 47 48 import threading … … 137 138 138 139 def server_main(args): 140 ssl_options = {} 141 142 for k in ['keyfile', 'certfile']: 143 v = getattr(args, k, None) 144 if v: 145 v = os.path.realpath(v) 146 ssl_options[k] = v 147 open(v).close() # readable test 148 149 if len(ssl_options) == 1: 150 raise ValueError('both keyfile and certfile are required') 151 elif not ssl_options: 152 ssl_options = None 153 154 if not args.port: 155 if ssl_options: 156 args.port = 443 157 else: 158 args.port = 80 159 160 if not args.foreground: 161 daemonize() 162 139 163 tap = TapHandler(args.device, debug=args.debug) 140 164 app = tornado.web.Application([ 141 165 (args.path, EtherWebSocket, {'tap': tap, 'debug': args.debug}), 142 166 ]) 143 server = tornado.httpserver.HTTPServer(app )167 server = tornado.httpserver.HTTPServer(app, ssl_options=ssl_options) 144 168 server.listen(args.port, address=args.address) 145 169 … … 152 176 if args.debug: 153 177 websocket.enableTrace(True) 178 179 if not args.foreground: 180 daemonize() 154 181 155 182 tap = TapHandler(args.device, debug=args.debug) … … 164 191 t.start() 165 192 193 while not client.sock: 194 time.sleep(0.1) 195 166 196 ioloop = tornado.ioloop.IOLoop.instance() 167 197 ioloop.add_handler(tap.fileno(), tap, ioloop.READ) … … 179 209 parser_server = subparsers.add_parser('server') 180 210 parser_server.add_argument('--address', action='store', default='') 181 parser_server.add_argument('--port', action='store', type=int , default=80)211 parser_server.add_argument('--port', action='store', type=int) 182 212 parser_server.add_argument('--path', action='store', default='/') 213 parser_server.add_argument('--keyfile', action='store') 214 parser_server.add_argument('--certfile', action='store') 183 215 184 216 parser_client = subparsers.add_parser('client') … … 186 218 187 219 args = parser.parse_args() 188 189 if not args.foreground:190 daemonize()191 220 192 221 if args.subcommand == 'server':
Note: See TracChangeset
for help on using the changeset viewer.