コード例 #1
0
def main(args):

    target = ('localhost', 2000)
    use_tls = False

    if args:
        r = urlparse.urlparse(args.pop(0))
        if r.netloc:
            addr, port = r.netloc.split(':')
            target = (addr, int(port))
            use_tls = r.scheme == 'tls'
        else:
            print "target address: [tls:]//<host>:<port>"
            sys.exit(1)

    logging.basicConfig(level=logging.DEBUG)

    reaktor = Reaktor()
    protocol = FixProtocol(version='4.4')

    process = ProcessApplication(reaktor, FixSink('sink.dat'), name='fixsink')
    session = get_session(args, reaktor, protocol)

    process.linkdown(session)
    session.linkup(process)

    if use_tls:
        session.ssl_context(SSLServerContext())

    session.start(target)
    process.start()
    save_path = args[0] + '.state'
    reaktor.run([(session.state, save_path)])
コード例 #2
0
ファイル: sink.py プロジェクト: hrautila/SXproto
def main(args):

    target = ('localhost', 2000)
    use_tls = False

    if args:
        r = urlparse.urlparse(args.pop(0))
        if r.netloc:
            addr, port = r.netloc.split(':')
            target = (addr, int(port))
            use_tls = r.scheme == 'tls'
        else:
            print "target address: [tls:]//<host>:<port>"
            sys.exit(1)

    logging.basicConfig(level=logging.DEBUG)

    reaktor = Reaktor()
    protocol = FixProtocol(version='4.4')

    process = ProcessApplication(reaktor, FixSink('sink.dat'), name='fixsink')
    session = get_session(args, reaktor, protocol)

    process.linkdown(session)
    session.linkup(process)

    if use_tls:
        session.ssl_context(SSLServerContext())

    session.start(target)
    process.start()
    save_path = args[0] + '.state'
    reaktor.run([(session.state, save_path)])
コード例 #3
0
        def _run(self, conn, args):
            self.reaktor = Reaktor()
            parent_link = ConnectedTransport(self.reaktor, conn)
            self.app = SessionApp(parent_link)

            self.session = self._SessionClass(self.reaktor)
            for key, val in self._config.items():
                self.session.set_conf(key, val)
            self.session.linkup(self.app)
            self.app.linkdown(self.session)
            self.app.start()
            self.session.start(args)
            signal.signal(signal.SIGTERM, self.reaktor.sigterm)
            save_path = self._config.get('session_state_file', '')
            savelist = []
            if save_path:
                savelist = [(self.session, save_path)]
            self.reaktor.run(savelist=savelist, exc_handler=self._exc_handler)
コード例 #4
0
ファイル: source.py プロジェクト: hrautila/SXproto
def main(args):

    logging.basicConfig(level=logging.DEBUG)

    reaktor = Reaktor()
    protocol = FixProtocol(version="4.4")

    process = ProcessApplication(reaktor, FixSource("source.dat"), name="fixsource")
    session = get_session(args, reaktor, protocol)

    process.linkdown(session)
    session.linkup(process)

    save_path = args[0] + ".state"
    session.state.restore(save_path)

    session.start(("localhost", 2000))
    process.start()
    reaktor.run([(session.state, save_path)])
コード例 #5
0
ファイル: source.py プロジェクト: hrautila/SXproto
def main(args):

    logging.basicConfig(level=logging.DEBUG)

    reaktor = Reaktor()
    protocol = FixProtocol(version='4.4')

    process = ProcessApplication(reaktor, FixSource('source.dat'), name='fixsource')
    session = get_session(args, reaktor, protocol)

    process.linkdown(session)
    session.linkup(process)

    save_path = args[0] + '.state'
    session.state.restore(save_path)

    session.start(('localhost', 2000))
    process.start()
    reaktor.run([(session.state, save_path)])
コード例 #6
0
    class SessionRunner(object):
        def __init__(self, SessionClass, config):
            self.reaktor = None
            self.app = None
            self.session = None
            self._SessionClass = SessionClass
            self._config = config

        def _run(self, conn, args):
            self.reaktor = Reaktor()
            parent_link = ConnectedTransport(self.reaktor, conn)
            self.app = SessionApp(parent_link)

            self.session = self._SessionClass(self.reaktor)
            for key, val in self._config.items():
                self.session.set_conf(key, val)
            self.session.linkup(self.app)
            self.app.linkdown(self.session)
            self.app.start()
            self.session.start(args)
            signal.signal(signal.SIGTERM, self.reaktor.sigterm)
            save_path = self._config.get('session_state_file', '')
            savelist = []
            if save_path:
                savelist = [(self.session, save_path)]
            self.reaktor.run(savelist=savelist, exc_handler=self._exc_handler)
            
        def __call__(self, conn, args):
            self._run(conn, args)

        def _sigterm(self, signo, frame):
            self.reaktor.stop()

        def _exc_handler(self, ex):
            if isinstance(ex, exc.SessionError):
                self.app.send(ex)
                return True
            return False
コード例 #7
0
ファイル: fixserver.py プロジェクト: hrautila/SXproto
def run_session(handler_expr, options):
    """Run FIX session.

    Loads message handler application from ``handler_expr``. Fix client session
    connects to ``net_url``, which is of form *//host:port* or *tls://host:port*.
    """
    net_url = ''
    ses_cf = {}
    app_cf = {}
    if options.config:
        cf = read_config(options.config)
        ses_cf.update(cf.items(options.name))
        app_cf.update(cf.items(options.appname))

    fix_version = ses_cf.get('fixversion', options.fixversion)
    net_url = ses_cf.get('destination', options.dest)
    store_url = ses_cf.get('message_store', options.messages)
    statepath = ses_cf.get('state_path', options.statepath)

    if not net_url:
        logging.error("No target address defined")
        sys.exit(1)

    r = urlparse.urlparse(net_url)
    if r.netloc:
        addr, port = r.netloc.split(':')
        netaddr = (addr, int(port))
        use_tls = r.scheme == 'tls'
    else:
        logging.error("Illegal target address. Must be [tls:]//<host>:<port>")
        sys.exit(1)

    reaktor = Reaktor()
    protocol = FixProtocol(version=fix_version)

    target = make_app(handler_expr)
    app = ProcessApplication(reaktor, target, name=options.name)

    ses = FixClient(reaktor, protocol, name=options.name, store_url=store_url)

    for key, val in ses_cf.items():
        if key in ['heartbeat_interval', 'login_wait_time']:
            ses.set_conf(key, int(val))
        elif key in ['reset_seqno']:
            ses.set_conf(key, bool(val))
        else:
            ses.set_conf(key, val)

    for key, val in app_cf.items():
        app.set_conf(key, val)

    if options.sender:
        ses.set_conf('sender_comp_id', options.sender)
    if options.target:
        ses.set_conf('target_comp_id', options.target)
    if options.resend:
        ses.set_conf('resend_mode', options.resend)
    if options.reset:
        ses.set_conf('reset_seqno', options.reset)
    if not ses.get_conf('heartbeat_interval'):
        ses.set_conf('heartbeat_interval', options.heartbeat)
    if not ses.get_conf('login_wait_time'):
        ses.set_conf('login_wait_time', 30)

    app.linkdown(ses)
    ses.linkup(app)
    # overload session login validator
    validator = LoginValidator(app, ses)
    ses.login_hook = validator.login_hook

    ses.start(netaddr)
    app.start()

    savelist = []
    if statepath:
        ses.state.restore(statepath)
        savelist = [(ses, statepath)]

    reaktor.run(savelist=savelist, exc_handler=validator.exchandler)
コード例 #8
0
ファイル: client.py プロジェクト: hrautila/SXproto
    if args:
        r = urlparse.urlparse(args.pop(0))
        if r.netloc:
            addr, port = r.netloc.split(":")
            netaddr = (addr, int(port))
            use_tls = r.scheme == "tls"
        else:
            print "target address: [tls:]//<host>:<port>"
            sys.exit(1)

    if args:
        file_name = args.pop(0)

    logging.basicConfig(level=logging.DEBUG)

    reaktor = Reaktor()
    protocol = FixProtocol(version="4.4")

    if app_type == "sink":
        target = FixSink(file_name)
    else:
        target = FixSource(app_type)

    process = ProcessApplication(reaktor, target, name=app_type)
    ses = FixClient(reaktor, protocol, name="client", store_url=store_url)

    ses.set_conf("sender_comp_id", sender_id)
    ses.set_conf("target_comp_id", target_id)
    ses.set_conf("heartbeat_interval", hb_interval)
    ses.set_conf("login_wait_time", 30)
    ses.set_conf("resend_mode", resend)
コード例 #9
0
ファイル: client.py プロジェクト: hrautila/SXproto
    if args:
        r = urlparse.urlparse(args.pop(0))
        if r.netloc:
            addr, port = r.netloc.split(':')
            netaddr = (addr, int(port))
            use_tls = r.scheme == 'tls'
        else:
            print "target address: [tls:]//<host>:<port>"
            sys.exit(1)

    if args:
        file_name = args.pop(0)

    logging.basicConfig(level=logging.DEBUG)

    reaktor = Reaktor()
    protocol = FixProtocol(version='4.4')

    if app_type == 'sink':
        target = FixSink(file_name)
    else:
        target = FixSource(app_type)

    process = ProcessApplication(reaktor, target, name=app_type)
    ses = FixClient(reaktor, protocol, name='client', store_url=store_url)

    ses.set_conf('sender_comp_id', sender_id)
    ses.set_conf('target_comp_id', target_id)
    ses.set_conf('heartbeat_interval', hb_interval)
    ses.set_conf('login_wait_time', 30)
    ses.set_conf('resend_mode', resend)
コード例 #10
0
ファイル: fixserver.py プロジェクト: hrautila/SXproto
def run_session(handler_expr, options):
    """Run FIX session.

    Loads message handler application from ``handler_expr``. Fix client session
    connects to ``net_url``, which is of form *//host:port* or *tls://host:port*.
    """
    net_url = ''
    ses_cf = {}
    app_cf = {}
    if options.config:
        cf = read_config(options.config)
        ses_cf.update(cf.items(options.name))
        app_cf.update(cf.items(options.appname))

    fix_version = ses_cf.get('fixversion', options.fixversion)
    net_url = ses_cf.get('destination', options.dest)
    store_url = ses_cf.get('message_store', options.messages)
    statepath = ses_cf.get('state_path', options.statepath)

    if not net_url:
        logging.error("No target address defined")
        sys.exit(1)
        
    r = urlparse.urlparse(net_url)
    if r.netloc:
        addr, port = r.netloc.split(':')
        netaddr = (addr, int(port))
        use_tls = r.scheme == 'tls'
    else:
        logging.error("Illegal target address. Must be [tls:]//<host>:<port>")
        sys.exit(1)

    
    reaktor = Reaktor()
    protocol = FixProtocol(version=fix_version)

    target = make_app(handler_expr)
    app = ProcessApplication(reaktor, target, name=options.name)

    ses = FixClient(reaktor, protocol, name=options.name, store_url=store_url)

    for key, val in ses_cf.items():
        if key in ['heartbeat_interval', 'login_wait_time']:
            ses.set_conf(key, int(val))
        elif key in ['reset_seqno']:
            ses.set_conf(key, bool(val))
        else:
            ses.set_conf(key, val)

    for key, val in app_cf.items():
        app.set_conf(key, val)
    
    if options.sender:
        ses.set_conf('sender_comp_id', options.sender)
    if options.target:
        ses.set_conf('target_comp_id', options.target)
    if options.resend:
        ses.set_conf('resend_mode', options.resend)
    if options.reset:
        ses.set_conf('reset_seqno', options.reset)
    if not ses.get_conf('heartbeat_interval'):
        ses.set_conf('heartbeat_interval', options.heartbeat)
    if not ses.get_conf('login_wait_time'):
        ses.set_conf('login_wait_time', 30)

    app.linkdown(ses)
    ses.linkup(app)
    # overload session login validator
    validator = LoginValidator(app, ses)
    ses.login_hook = validator.login_hook

    ses.start(netaddr)
    app.start()

    savelist = []
    if statepath:
        ses.state.restore(statepath)
        savelist = [(ses, statepath)]

    reaktor.run(savelist=savelist, exc_handler=validator.exchandler)