def offline(msg): """ Process offline node msg (validate and add to offline_q). :param str node ID: zerotier node identity :return: str node ID """ if valid_announce_msg(msg): clean_stale_cfgs(msg, cfg_q) node_data = lookup_node_id(msg, tmp_q) if node_data: logger.info('Got valid offline msg from host {} (node {})'.format( node_data[msg], msg)) with off_q.transact(): add_one_only(msg, off_q) with cln_q.transact(): add_one_only(msg, cln_q) # track offline node id for cleanup with pub_q.transact(): clean_from_queue(msg, pub_q) logger.debug('Node ID {} cleaned from pub_q'.format(msg)) return msg else: node_data = lookup_node_id(msg, tmp_q) if node_data: logger.warning('Bad offline msg from host {} (node {})'.format( node_data[msg], msg)) else: logger.warning('Bad offline msg: {}'.format(msg))
def drain_msg_queue(reg_q, pub_q=None, tmp_q=None, addr=None, method='handle_node'): """ This function now handles several different methods; note the optional queue params should not be used together. :param reg_q: queue of registered nodes :param pub_q: queue of published nodes (use for publishing online nodes) :param tmp_q: queue of nodes/addrs for logging (use for publishing offline nodes) """ import time from nanoservice import Publisher from node_tools.msg_queues import add_one_only if NODE_SETTINGS['use_localhost'] or not addr: addr = '127.0.0.1' pub = Publisher('tcp://{}:9442'.format(addr)) id_list = list(reg_q) # Need to wait a bit on connect to prevent lost messages time.sleep(0.002) for _ in id_list: with reg_q.transact(): node_id = reg_q.popleft() pub.publish(method, node_id) if pub_q is not None: with pub_q.transact(): add_one_only(node_id, pub_q) logger.debug('Published msg {} to {}'.format(node_id, addr))
def offline(msg): """ Process offline node msg (validate and add to offline_q). """ if valid_announce_msg(msg): logger.debug('Got valid offline msg: {}'.format(msg)) with off_q.transact(): add_one_only(msg, off_q) logger.debug('Added node id: {}'.format(msg)) logger.info('{} nodes in offline queue'.format(len(off_q))) else: logger.warning('Bad offline msg is {}'.format(msg))
def wedged(msg): """ Process wedged node msg (validate and add to wedge_q). """ if valid_announce_msg(msg): logger.debug('Got valid wedged msg: {}'.format(msg)) with wdg_q.transact(): add_one_only(msg, wdg_q) logger.debug('Added node id: {}'.format(msg)) logger.info('{} nodes in wedged queue'.format(len(wdg_q))) else: logger.warning('Bad wedged msg is {}'.format(msg))
def wedged(msg): """ Process wedged node msg (validate and add to wedge_q). Note these are currently disabled for testing. :param str node ID: zerotier node identity :return: str node ID """ if valid_announce_msg(msg): node_data = lookup_node_id(msg, tmp_q) if node_data: logger.info('Got valid wedged msg from host {} (node {})'.format(node_data[msg], msg)) with wdg_q.transact(): # re-enable msg processing for testing add_one_only(msg, wdg_q) return msg else: node_data = lookup_node_id(msg, tmp_q) if node_data: logger.info('Bad wedged msg from host {} (node {})'.format(node_data[msg], msg)) else: logger.warning('Bad wedged msg: {}'.format(msg))