def init_client(self): try: reqdata = apiutils.make_request(self.config.api.api_secret, **{}) resp = yield self.send_http( "%s/radagent/fetch" % self.config.api.api_url, reqdata) auth_endpoints = [ ZmqEndpoint('connect', e) for e in resp.get('auth_endpoints', '').split(",") ] acct_endpoints = [ ZmqEndpoint('connect', e) for e in resp.get('acct_endpoints', '').split(",") ] self.api_auth_url = resp.get("api_auth_url") self.api_acct_url = resp.get("api_acct_url") self.log.info('auth_endpoints: %s' % auth_endpoints) self.log.info('acct_endpoints: %s' % acct_endpoints) self.log.info('api_auth_url: %s' % self.api_auth_url) self.log.info('api_acct_url: %s' % self.api_acct_url) self.protocol = resp.get('protocol') self.zauth_conn.addEndpoints(auth_endpoints) self.zacct_conn.addEndpoints(acct_endpoints) defer.returnValue("ApiClient init done") except Exception as err: import traceback traceback.print_exc() self.log.error(u"[ApiClient] :: fetch radagent failure, %s" % safeunicode(err.message)) defer.returnValue("ApiClient init error")
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
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
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 }
def __init__(self, miner): # create a factory self.miner = miner self.factory = ZmqFactory() # create a connection to publish publish_endpoint = ZmqEndpoint(ZmqEndpointType.bind, "tcp://127.0.0.1:" + miner.publish_port) self.publisher = ZmqPubConnection(self.factory, publish_endpoint) # create connections to subscribe self.subscribers = [] print("the ports subscribed are:") print(miner.subscribe_ports) for subscribe_port in miner.subscribe_ports: subscribe_endpoint = ZmqEndpoint( ZmqEndpointType.connect, "tcp://127.0.0.1:" + subscribe_port) subscriber = BroadcastSubscriber(self.factory, subscribe_endpoint, miner) self.subscribers.append(subscriber) # subscribe to the types of events subscriber.subscribe(PROPOSAL_TAG.encode()) subscriber.subscribe(COMMIT_TAG.encode()) subscriber.subscribe(REINFORCEMENT_TAG.encode()) subscriber.subscribe(TRANSACTION_TAG.encode()) subscriber.subscribe(MALICIOUS_PROPOSAL_AGREEMENT_TAG.encode()) subscriber.subscribe(PROPOSAL_COMMIT_TAG.encode()) subscriber.subscribe(REINFORCEMENT_INF_TAG.encode())
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))
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))
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))
def __init__(self, config, dbengine, **kwargs): self.config = config self.que = deque() self.db_engine = dbengine or get_engine(config, pool_size=30) self.cache = CacheManager(redis_conf(config), cache_name='SyncdCache-%s' % os.getpid()) self.metadata = models.get_metadata(self.db_engine) self.tables = { _name: _table for _name, _table in self.metadata.tables.items() } self.master_bind = ZmqREPConnection( ZmqFactory(), ZmqEndpoint('bind', config.ha.master)) self.master_bind.gotMessage = self.dataReceived self.sync_task = HaSyncTask(config, self.db_engine, self.cache) self.ops = { 'add': self.do_add, 'update': self.do_update, 'delete': self.do_delete } self.process() logger.info(u'启动HA同步服务: [Master] {} ~ [Slave] {}'.format( self.config.ha.master, self.config.ha.slave)) if not kwargs.get('standalone'): self.logtrace = log_trace.LogTrace(redis_conf(config)) if 'elasticsearch' in config: dispatch.register(eslogapi.EslogApi(config.elasticsearch))
def load_setup(self, setup): for e, s in setup.items(): endpoint = ZmqEndpoint(ZmqEndpointType.bind, e) ZmqPubConnection.highWaterMark = s['high_water_mark'] connection = ZmqPubConnection(self.factory, endpoint) for n in s['notification_type_names']: self.connection_map[n] = connection
def setup_zmq(self): zmq_factory = ZmqFactory() print("subscribing on: %s" % self.endpoint) sub_endpoint = ZmqEndpoint(ZmqEndpointType.connect, self.endpoint) sub_connection = ZmqSubConnection(zmq_factory, sub_endpoint) sub_connection.gotMessage = self.zmq_message sub_connection.subscribe(INVOICE_PAYMENT_TAG)
def onConnect(self, request): global pub_sock if pub_sock is not None: zf = ZmqFactory() e = ZmqEndpoint(ZmqEndpointType.connect, pub_sock) s = ZmqSubConnection(zf, e) s.gotMessage = lambda payload, topic: self.gotMessage( payload, topic) self._zmq = s self._guards = {} self._filters = [] # By default, subscribe messages from the current path and below default_filter = get_physical_path_from_vhm_path( self._environ["PATH_INFO"]) logger.debug("SUBSCRIBE " + default_filter) self._zmq.subscribe(default_filter.encode('utf-8')) self._filters.append(default_filter) # Cleanup inherited environ self._environ["HTTP_CONNECTION"] = "keep-alive" for env in [ "HTTP_UPGRADE", "HTTP_SEC_WEBSOCKET_EXTENSIONS", "HTTP_SEC_WEBSOCKET_KEY", "HTTP_SEC_WEBSOCKET_VERSION", "wsgi.errors", "wsgi.input", ]: if env in self._environ: del self._environ[env]
def __init__(self, taskd, **kwargs): TaseBasic.__init__(self, taskd, **kwargs) self.flow_stat = {} self.statdata = self.cache.get(radius_statcache_key) or statistics.MessageStat(quemax=180) self.puller = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('bind', self.config.mqproxy['task_bind'])) self.puller.onPull = self.update_stat logger.info('start stat mq %s' % self.puller)
def __init__(self, taskd, **kwargs): TaseBasic.__init__(self, taskd, **kwargs) self.statdata = statistics.MessageStat() self.puller = ZmqPullConnection( ZmqFactory(), ZmqEndpoint('bind', 'ipc:///tmp/radiusd-stat-task')) self.puller.onPull = self.update_stat logger.info("init Radius stat puller : %s " % (self.puller))
def setup_zmq(self): zmq_factory = ZmqFactory() print("subscribing on: %s" % self.endpoint) sub_endpoint = ZmqEndpoint(ZmqEndpointType.connect, self.endpoint) sub_connection = ZmqSubConnection(zmq_factory, sub_endpoint) sub_connection.gotMessage = self.zmq_message sub_connection.subscribe(FORWARD_EVENT_TAG) sub_connection.subscribe(HTLC_ACCEPTED_TAG) print("subscribing on: %s" % self.mock_endpoint) sub_mock_endpoint = ZmqEndpoint(ZmqEndpointType.connect, self.mock_endpoint) sub_mock_connection = ZmqSubConnection(zmq_factory, sub_mock_endpoint) sub_mock_connection.gotMessage = self.zmq_message sub_mock_connection.subscribe(FORWARD_EVENT_TAG) sub_mock_connection.subscribe(HTLC_ACCEPTED_TAG)
def startService(self): zf = ZmqFactory() e = ZmqEndpoint(ZmqEndpointType.bind, ENDPOINT) self._conn = _DispatcherREPConnection(zf, e, self._core) reactor.callWhenRunning(self._conn.do_greet) service.Service.startService(self)
def main(config): zmq_requests_factory = ZmqFactory() zmq_requests_endpoint = ZmqEndpoint(ZmqEndpointType.bind, config['endpoint.command']) zmq_requests = ZmqRequests(zmq_requests_factory, zmq_requests_endpoint) zmq_broadcast_factory = ZmqFactory() zmq_broadcast_endpoint = ZmqEndpoint(ZmqEndpointType.bind, config['endpoint.broadcast']) zmq_broadcast = ZmqPubConnection(zmq_broadcast_factory, zmq_broadcast_endpoint) api_endpoint = TCP4ClientEndpoint(reactor, config['ibtws.host'], config['ibtws.port']) api_endpoint.connect(IBTWSProtocolFactory(zmq_requests, zmq_broadcast)) reactor.run()
def __init__(self, config, logger=None): self.config = config self.logger = logger or Logger() self.debug = self.config.get('debug', True) self.vendor = self.config.get('vendor', 'cmccv2') self.secret = str(self.config.get('secret', 'secret')) self.rundata = {'challenges': {}} self.ac_handlers = { cmcc.REQ_CHALLENGE: chellenge_handler.ChellengeHandler(self.config, self.logger), cmcc.REQ_AUTH: auth_handler.AuthHandler(self.config, self.logger), cmcc.REQ_INFO: reqinfo_handler.ReqInfoHandler(self.config, self.logger), cmcc.AFF_ACK_AUTH: base_handler.EmptyHandler(self.config, self.logger), cmcc.ACK_NTF_LOGOUT: base_handler.EmptyHandler(self.config, self.logger), cmcc.NTF_HEARTBEAT: base_handler.EmptyHandler(self.config, self.logger), cmcc.REQ_LOGOUT: logout_handler.LogoutHandler(self.config, self.logger) } self.puller = ZmqPullConnection( ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/tpsim-message')) self.puller.onPull = self.process reactor.listenUDP(0, self) self.logger.info('init TpSimWorker puller : %s ' % self.puller)
def __init__(self, zmq_factory, port, data_manager=None): self.data_manager = data_manager endpoint = ZmqEndpoint(ZmqEndpointType.bind, "tcp://*:%d" % port) ZmqPubConnection.__init__(self, zmq_factory, endpoint)
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,))
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
def __init__(self, taskd, **kwargs): TaseBasic.__init__(self, taskd, **kwargs) self.flow_stat = {} self.statdata = self.cache.get( radius_statcache_key) or statistics.MessageStat() self.puller = ZmqPullConnection( ZmqFactory(), ZmqEndpoint('bind', 'ipc:///tmp/radiusd-stat-task')) self.puller.onPull = self.update_stat
def __init__(self, endpoint, wamp_session, prefix): self._endpoint = endpoint self._wamp = wamp_session self._prefix = prefix ZmqSubConnection.__init__( self, _zmq_factory, ZmqEndpoint('connect', endpoint.encode("utf-8"))) self.subscribe(b"")
def _create_client(self, serializer=MockJSONSerializer): factory = ZmqFactory() endpoint = ZmqEndpoint('connect', ADDRESS) server = MockBaseClient(factory, endpoint, serializer=serializer) self.assertEqual(server.__serializer__, MockJSONSerializer) self.assertIsInstance(server.factory, ZmqFactory) self.assertIsInstance(server.endpoints[0], ZmqEndpoint) return server
def _load_setup(self, setup): for e, notification_type_names in setup.items(): endpoint = ZmqEndpoint(ZmqEndpointType.connect, e) connection = ZmqSubConnection(self.factory, endpoint) for n in notification_type_names: tag = n.encode("utf8") connection.gotMessage = self._log_message connection.subscribe(tag)
def __init__(self): self.queue = Queue() self.zmq_factory = ZmqFactory() endpoint = ZmqEndpoint(ZmqEndpointType.connect, ZMQ_ENDPOINT) connection = ZmqSubConnection(self.zmq_factory, endpoint) connection.gotMessage = self.set_mode connection.subscribe(ZMQ_TAG)
def __init__(self, endpoint): if endpoint: logger.debug("开始运行 REQ 服务器,连接地址为:{}...".format(endpoint)) self._req = ZmqREQConnection(ZmqFactory(), ZmqEndpoint('connect', endpoint)) else: self._req = None self.timeout = 0.95
def __init__(self): color_init() zf = ZmqFactory() e = ZmqEndpoint(ZmqEndpointType.connect, ENDPOINT) self._conn = ZmqREQConnection(zf, e) self.data = [] if self.service: self.data = [self.service]
def push_proxy_async(address): """ :param address: :returns: PushProxyAsync """ socket = ZmqPushConnection(ZmqFactory(), ZmqEndpoint("connect", address)) return PushProxyAsync(socket)
def dealer_proxy_async(address, timeout=1): """ :param address: :returns: DealerProxyAsync """ socket = ZmqREQConnection(ZmqFactory(), ZmqEndpoint("connect", address)) socket.defaultRequestTimeout = timeout return DealerProxyAsync(socket)