Пример #1
0
 def __init__(self, config, dbengine, radcache=None):
     self.config = config
     self.dict = dictionary.Dictionary(
         os.path.join(os.path.dirname(toughradius.__file__),
                      'dictionarys/dictionary'))
     self.db_engine = dbengine or get_engine(config)
     self.mcache = radcache
     self.pusher = ZmqPushConnection(
         ZmqFactory(),
         ZmqEndpoint('connect', 'ipc:///tmp/radiusd-acct-result'))
     self.stat_pusher = ZmqPushConnection(
         ZmqFactory(), ZmqEndpoint('connect',
                                   'ipc:///tmp/radiusd-stat-task'))
     self.puller = ZmqPullConnection(
         ZmqFactory(),
         ZmqEndpoint('connect', 'ipc:///tmp/radiusd-acct-message'))
     self.puller.onPull = self.process
     logger.info("init acct worker pusher : %s " % (self.pusher))
     logger.info("init acct worker puller : %s " % (self.puller))
     logger.info("init auth stat pusher : %s " % (self.stat_pusher))
     self.acct_class = {
         STATUS_TYPE_START: RadiusAcctStart,
         STATUS_TYPE_STOP: RadiusAcctStop,
         STATUS_TYPE_UPDATE: RadiusAcctUpdate,
         STATUS_TYPE_ACCT_ON: RadiusAcctOnoff,
         STATUS_TYPE_ACCT_OFF: RadiusAcctOnoff
     }
Пример #2
0
 def __init__(self, config, dbengine, radcache=None):
     self.config = config
     self.dict = dictionary.Dictionary(
         os.path.join(os.path.dirname(toughradius.__file__), 'dictionarys/dictionary'))
     self.db_engine = dbengine or get_engine(config)
     self.aes = utils.AESCipher(key=self.config.system.secret)
     self.mcache = radcache
     self.pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/radiusd-auth-result'))
     self.stat_pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/radiusd-stat-task'))
     self.puller = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/radiusd-auth-message'))
     self.puller.onPull = self.process
     reactor.listenUDP(0, self)
     logger.info("init auth worker pusher : %s " % (self.pusher))
     logger.info("init auth worker puller : %s " % (self.puller))
     logger.info("init auth stat pusher : %s " % (self.stat_pusher))
Пример #3
0
    def __init__(self, worker):

        log.msg("Initializing auto server")

        #
        # Setup the zmq socket used for receiving images.
        #
        self.zmq_factory = ZmqFactory()

        #
        # Socket for pulling images and crops from the automatic client.
        #
        endpoint = ZmqEndpoint(
            'connect', 'tcp://localhost:{zmq_port}'.format(
                zmq_port=gs.ZMQ_AUTO_WORKER_PUSH))
        self.pull_socket = ZmqPullConnection(self.zmq_factory, endpoint)
        self.pull_socket.onPull = self.handleNewMessage

        #
        # Socket for pushing results to the automatic client.
        #
        endpoint = ZmqEndpoint(
            'connect', 'tcp://localhost:{zmq_port}'.format(
                zmq_port=gs.ZMQ_AUTO_WORKER_PULL))
        self.push_socket = ZmqPushConnection(self.zmq_factory, endpoint)

        self.worker = worker
Пример #4
0
    def __init__(self, app):

        #
        # Setup the zmq socket used for receiving images.
        #
        self.zmq_factory = ZmqFactory()

        #
        # Socket for pushing images and crops to the automatic processing servers.
        #
        endpoint = ZmqEndpoint(
            'bind',
            'tcp://*:{zmq_port}'.format(zmq_port=gs.ZMQ_AUTO_WORKER_PUSH))
        self.push_socket = ZmqPushConnection(self.zmq_factory, endpoint)

        #
        # Socket for pulling results from the automatic processing servers.
        #
        endpoint = ZmqEndpoint(
            'bind',
            'tcp://*:{zmq_port}'.format(zmq_port=gs.ZMQ_AUTO_WORKER_PULL))
        self.pull_socket = ZmqPullConnection(self.zmq_factory, endpoint)
        self.pull_socket.onPull = self.handleNewMessage

        self.app = app
Пример #5
0
 def __init__(self, config, dbengine, radcache = None):
     self.config = config
     self.load_plugins(load_types=['radius_auth_req', 'radius_accept'])
     self.dict = dictionary.Dictionary(os.path.join(os.path.dirname(taurusxradius.__file__), 'dictionarys/dictionary'))
     self.db_engine = dbengine or get_engine(config)
     self.aes = utils.AESCipher(key=self.config.system.secret)
     self.mcache = radcache
     self.reject_debug = int(self.get_param_value('radius_reject_debug', 0)) == 1
     self.pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', config.mqproxy['auth_result']))
     self.stat_pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', config.mqproxy['task_connect']))
     self.puller = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('connect', config.mqproxy['auth_message']))
     self.puller.onPull = self.process
     logger.info('radius auth worker %s start' % os.getpid())
     logger.info('init auth worker pusher : %s ' % self.pusher)
     logger.info('init auth worker puller : %s ' % self.puller)
     logger.info('init auth stat pusher : %s ' % self.stat_pusher)
     self.license_ulimit = 50000
Пример #6
0
 def __init__(self, config, service='auth'):
     self.config = config
     self.service = service
     self.pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('bind', 'ipc:///tmp/radiusd-%s-message' % service))
     self.puller = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('bind', 'ipc:///tmp/radiusd-%s-result' % service))
     self.puller.onPull = self.reply
     logger.info("init %s master pusher : %s " % (self.service, self.pusher))
     logger.info("init %s master puller : %s " % (self.service, self.puller))
Пример #7
0
 def __init__(self, config, service = 'auth'):
     self.config = config
     self.service = service
     self.pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('bind', config.mqproxy[self.service + '_message']))
     self.puller = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('bind', config.mqproxy[self.service + '_result']))
     self.puller.onPull = self.radiusReply
     logger.info('%s master message bind @ %s' % (self.service, self.pusher))
     logger.info('%s master result bind @ %s' % (self.service, self.puller))
Пример #8
0
def push_proxy_async(address):
    """


    :param address:
    :returns: PushProxyAsync
    """
    socket = ZmqPushConnection(ZmqFactory(), ZmqEndpoint("connect", address))
    return PushProxyAsync(socket)
Пример #9
0
	def add_push(self, endpoint):
		'''

		:param endpoint:
		:return:
		'''
		if endpoint:
			logger.debug("开始运行 PUSH 服务器,监听地址为:{}...".format(endpoint))
			self.push_ = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', endpoint))
Пример #10
0
 def __init__(self, config, dbengine, radcache = None):
     self.config = config
     self.load_plugins(load_types=['radius_acct_req'])
     self.db_engine = dbengine or get_engine(config)
     self.mcache = radcache
     self.dict = dictionary.Dictionary(os.path.join(os.path.dirname(taurusxradius.__file__), 'dictionarys/dictionary'))
     self.stat_pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', config.mqproxy['task_connect']))
     self.pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', config.mqproxy['acct_result']))
     self.puller = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('connect', config.mqproxy['acct_message']))
     self.puller.onPull = self.process
     self.acct_class = {STATUS_TYPE_START: RadiusAcctStart,
      STATUS_TYPE_STOP: RadiusAcctStop,
      STATUS_TYPE_UPDATE: RadiusAcctUpdate,
      STATUS_TYPE_ACCT_ON: RadiusAcctOnoff,
      STATUS_TYPE_ACCT_OFF: RadiusAcctOnoff}
     logger.info('radius acct worker %s start' % os.getpid())
     logger.info('init acct worker pusher : %s ' % self.pusher)
     logger.info('init acct worker puller : %s ' % self.puller)
     logger.info('init acct stat pusher : %s ' % self.stat_pusher)
Пример #11
0
    def onJoin(self, details):
        s = ZmqPullConnection(ZF, ZFE)
        ss = ZmqPushConnection(ZF, ZFE_SSL)

        def go_pull(sr):
            ss.push(sr)
            chan, sr = sr[0].split(' ', 1)
            sr = pickle.loads(sr)
            #print chan
            #print chan, sr['bdata_mode0']['updated']
            self.publish(chan, sr)

        s.onPull = go_pull
Пример #12
0
    def __init__(self, zmq_notice_port, zmq_files_port, vn=None):

        self._loadSearchArea()

        #
        # Setup the zmq socket used for sending notice of images.
        #
        zmq_factory = ZmqFactory()
        endpoint = ZmqEndpoint('bind', 'tcp://*:{zmq_port}'.format(zmq_port=zmq_notice_port))
        self.zmq_socket = ZmqPushConnection(zmq_factory, endpoint)

        #
        # Setup the zmq socket used for sending the images.
        #
        endpoint = ZmqEndpoint('bind', 'tcp://*:{zmq_port}'.format(zmq_port=zmq_files_port))
        self.zmq_files_socket = ImageFileServerConnection(zmq_factory, endpoint, )

        #
        # Setup the zmq socket used for receiving detection results from the
        # jetson.
        #
        endpoint_rx = ZmqEndpoint('connect', 'tcp://{ip}:{port}'.format(ip=JETSON_IP, port=ADLC_RX_PORT))
        self.adlc_rx_socket = ZmqPullConnection(zmq_factory, endpoint_rx)
        self.adlc_rx_socket.onPull = self.handleADLCResults

        #
        # Flag that controls the sending the images
        #
        self._send_images = threading.Event()

        self.manual_crop_cnt = 0
        self.auto_crop_cnt = 0
        self._img_counter = 0
        self._adlc_count = 0
        self._received_image_count = 0

        self._vn = vn

        #
        # Start the upload thread.
        # Note:
        # I am using a separate thread for uploading in order to use an
        # upload queue. We had a problem where slow upload caused many upload
        # processes to start together and cause jamming in communication.
        #
        self.upload_queue = tQueue.Queue(0)
        self.upload_thread = thread.start_new_thread(upload_thread, (self.upload_queue,))
Пример #13
0
 def __init__(self, config, dbengine, radcache = None):
     self.config = config
     self.load_plugins(load_types=['radius_auth_req', 'radius_accept'])
     self.dict = dictionary.Dictionary(os.path.join(os.path.dirname(taurusxradius.__file__), 'dictionarys/dictionary'))
     self.db_engine = dbengine or get_engine(config)
     self.aes = utils.AESCipher(key=self.config.system.secret)
     self.mcache = radcache
     self.stat_pusher = ZmqPushConnection(ZmqFactory())
     self.zmqrep = ZmqREPConnection(ZmqFactory())
     self.stat_pusher.tcpKeepalive = 1
     self.zmqrep.tcpKeepalive = 1
     self.stat_pusher.addEndpoints([ZmqEndpoint('connect', config.mqproxy.task_connect)])
     self.zmqrep.addEndpoints([ZmqEndpoint('connect', config.mqproxy.auth_connect)])
     self.zmqrep.gotMessage = self.process
     self.reject_debug = int(self.get_param_value('radius_reject_debug', 0)) == 1
     logger.info('radius auth worker %s start' % os.getpid())
     logger.info('init auth worker : %s ' % self.zmqrep)
     logger.info('init auth stat pusher : %s ' % self.stat_pusher)
Пример #14
0
    def __init__(self,
                 server,
                 port,
                 secret,
                 requests,
                 concurrency,
                 username,
                 password,
                 verb=False,
                 timeout=600,
                 rate=1000):
        logname = "/tmp/trbctl-worker-{}.log".format(os.environ.get(
            "LOGID", 0))
        log.startLogging(open(logname, 'w'))
        self.timeout = timeout
        self.pusher = ZmqPushConnection(
            ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/toughbt-message'))
        self.pusher.push("write worker %s log into %s" %
                         (os.getpid(), logname))
        log.msg("init BenchmarkWorker pusher : %s " % repr(self.pusher))
        # define client cycle list
        raddict = dictionary.Dictionary(
            os.path.join(os.path.dirname(__file__), "dictionary"))
        new_cli = lambda: RadAuthClient(str(secret),
                                        raddict,
                                        server,
                                        port=port,
                                        debug=verb,
                                        stat_push=self.pusher)
        clis = itertools.cycle([new_cli() for c in range(concurrency)])

        # send radius message
        send = lambda: next(clis).sendAuth(**{
            'User-Name': username,
            'User-Password': password
        })

        send_rate = 1.0 / rate
        send_delay = send_rate
        for i in xrange(requests):
            reactor.callLater(send_delay, send)
            send_delay += send_rate

        reactor.callLater(self.timeout, self.on_timeout)
Пример #15
0
 def __init__(self, gdata):
     self.gdata = gdata
     self.config = gdata.config
     self.que = deque() 
     self.cache = gdata.cache
     self.db_engine = gdata.db_engine
     self.metadata = models.get_metadata(self.db_engine)
     self.ops = {
         'radstart':self.start_session,
         'radstop':self.stop_session
     }
     self.radstart = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('connect', self.config.mqproxy.radstart_connect))
     self.radstop = ZmqSubConnection(ZmqFactory(), ZmqEndpoint('connect',self.config.mqproxy.radstop_connect))
     self.radresp = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', self.config.mqproxy.radresp_connect))
     self.radstop.subscribe('radstop')
     self.radstop.gotMessage = self.subdataReceived
     self.radstart.onPull = self.dataReceived
     self.process_poll()
     logger.info("Start radstart %s" % self.radstart)
     logger.info("Start radstop %s" % self.radstop)
     logger.info("Start radresp %s" % self.radresp)
Пример #16
0
	def __init__(self, endpoint):
		if endpoint:
			logger.debug("开始运行 PUSH 服务器,监听地址为:{}...".format(endpoint))
			self._push = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', endpoint))
		else:
			self._push = None
Пример #17
0
 def __init__(self):
     self.pusher = ZmqPushConnection(
         ZmqFactory(), ZmqEndpoint('bind', 'ipc:///tmp/tpsim-message'))
     self.logger.info('init TpSimMaster pusher : %s ' % self.pusher)
Пример #18
0
def init(gdata):
    appname = os.path.basename(gdata.app_dir)
    utils.update_tz(gdata.config.system.tz)
    syslog = logger.Logger(gdata.config, appname)
    dispatch.register(syslog)
    log.startLoggingWithObserver(syslog.emit, setStdout=0)

    gdata.db_engine = get_engine(gdata.config)
    gdata.db = scoped_session(
        sessionmaker(bind=gdata.db_engine, autocommit=False, autoflush=False))
    # web 应用初始化
    gdata.settings = dict(
        cookie_secret="12oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
        login_url="/admin/login",
        template_path=os.path.join(os.path.dirname(__file__), "views"),
        static_path=os.path.join(os.path.dirname(__file__), "static"),
        xsrf_cookies=True,
        xheaders=True,
        conf=gdata.config)

    # 模板初始化
    gdata.tp_lookup = TemplateLookup(
        directories=[gdata.settings['template_path']],
        default_filters=['decode.utf8'],
        input_encoding='utf-8',
        output_encoding='utf-8',
        encoding_errors='ignore',
        module_directory="/tmp/toughcloud")

    gdata.redisconf = redis_conf(gdata.config)
    gdata.session_manager = session.SessionManager(
        gdata.redisconf, gdata.settings["cookie_secret"], 7200)
    gdata.cache = CacheManager(gdata.redisconf,
                               cache_name='Cache-%s' % os.getpid())
    gdata.aes = utils.AESCipher(key=gdata.config.system.secret)

    # 数据库备份器初始化
    gdata.db_backup = DBBackup(models.get_metadata(gdata.db_engine),
                               excludes=[])

    #cache event init
    dispatch.register(gdata.cache)

    # app handles init
    handler_dir = os.path.join(gdata.app_dir, 'handlers')
    load_handlers(handler_path=handler_dir,
                  pkg_prefix="%s.handlers" % appname,
                  excludes=[])
    gdata.all_handlers = permit.all_handlers

    # app event init
    event_dir = os.path.abspath(os.path.join(gdata.app_dir, 'events'))
    load_events(event_dir, "%s.events" % appname)

    # init zmq
    gdata.radque = deque([], 8192)
    gdata.radstart = ZmqPushConnection(
        ZmqFactory(), ZmqEndpoint('bind', gdata.config.mqproxy.radstart_bind))
    gdata.radstop = ZmqPubConnection(
        ZmqFactory(), ZmqEndpoint('bind', gdata.config.mqproxy.radstop_bind))
    gdata.radresp = ZmqPullConnection(
        ZmqFactory(), ZmqEndpoint('bind', gdata.config.mqproxy.radresp_bind))
    gdata.radresp.onPull = lambda m: gdata.radque.appendleft(
        msgpack.unpackb(m[0]))
    gdata.statcache = StatCounter(gdata)
    gdata.statcache.init()
    gdata.statcache.poll_calc()

    logger.info(gdata.radstart)
    logger.info(gdata.radstop)
    logger.info(gdata.radresp)
Пример #19
0
from txzmq import ZmqEndpoint, ZmqFactory, ZmqPushConnection, ZmqPullConnection


parser = OptionParser("")
parser.add_option("-m", "--method", dest="method", help="0MQ socket connection: bind|connect")
parser.add_option("-e", "--endpoint", dest="endpoint", help="0MQ Endpoint")
parser.add_option("-M", "--mode", dest="mode", help="Mode: push|pull")
parser.set_defaults(method="connect", endpoint="ipc:///tmp/txzmq-pc-demo")

(options, args) = parser.parse_args()

zf = ZmqFactory()
e = ZmqEndpoint(options.method, options.endpoint)

if options.mode == "push":
    s = ZmqPushConnection(zf, e)

    def produce():
        data = [str(time.time()), socket.gethostname()]
        print "producing %r" % data
        try:
            s.push(data)
        except zmq.error.Again:
            print "Skipping, no pull consumers..."

        reactor.callLater(1, produce)

    reactor.callWhenRunning(reactor.callLater, 1, produce)
else:
    s = ZmqPullConnection(zf, e)