Beispiel #1
0
def stop_service():
    if not is_posix():
        return
    logger.info("Stopping the service")
    conn = Client(parameters.get_session_address(), authkey=parameters.get_session_connection_password())        
    conn.send({'action':'stop','password':None})
    r = conn.recv()
    conn.close()
    logger.debug(r['status'])
Beispiel #2
0
def get_session_password():
    if not is_posix():
        raise NotImplementedError("Client/Server daemons not supported on this system")
    logger.info("Retrieving session password")
    conn = Client(parameters.get_session_address(), authkey=parameters.get_session_connection_password())        
    conn.send({'action':'get','password':None})
    r = conn.recv()
    conn.close()
    return r['status'],r['password']
Beispiel #3
0
def set_session_password(pwd):
    if not is_posix():
        return    
    logger.info("Setting session password")
    conn = Client(parameters.get_session_address(), authkey=parameters.get_session_connection_password())        
    conn.send({'action':'set','password':pwd})
    r = conn.recv()
    conn.close()
    logger.debug(r['status'])
Beispiel #4
0
def session_sweeper(lifetime):
    "The process that will kill the session daemon eventually"
    get_logger(__name__).info("sweeper starts")
    sleep(lifetime)
    conn = Client(parameters.get_session_address(),
                  authkey=parameters.get_session_connection_password())
    conn.send({'action': 'stop', 'password': None})
    ret = conn.recv()
    get_logger(__name__).debug(ret['status'])
    get_logger(__name__).info("Sweeper ends")
Beispiel #5
0
def session_listener(seed, timeout):
    """ Session service function with an initial value as a seed
    input: seed    the initial value stored in the session
           timeout the validity period of the session value (in seconds 
    """
    get_logger(__name__).info("Listener starts")
    serv = Listener(parameters.get_session_address(),
                    authkey=parameters.get_session_connection_password())
    serv.password = seed
    serv.pwd_timeout = timeout
    serv.start_time = datetime.datetime.now()
    serv.origin_time = datetime.datetime.now()
    while True:
        with serv.accept() as conn:
            try:
                req = conn.recv()
            except EOFError:
                break
            if 'action' in req and req['action'] == 'set':
                serv.password = req['password']
                serv.start_time = datetime.datetime.now()
                conn.send({'status': 'done', 'password': serv.password})
            elif 'action' in req and req['action'] == 'get':
                if (datetime.datetime.now() -
                        serv.start_time).total_seconds() < serv.pwd_timeout:
                    conn.send({'status': 'fresh', 'password': serv.password})
                    serv.start_time = datetime.datetime.now()
                else:
                    serv.password = None
                    conn.send({'status': 'stale', 'password': None})
            elif 'action' in req and req['action'] == 'stop':
                get_logger(__name__).info("Goodbye from listener")
                conn.send({'status': 'terminated', 'password': None})
                break
            else:
                conn.send({'status': 'bad command', 'password': None})
    get_logger(__name__).info("Listener ends")