summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/vpn/statusqueue.py
blob: ff7f3111924f65bac8cf1b833827525fa7b1fd92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Queue used to store status changes on EIP/VPN/Firewall and to be checked for
any app using this vpn library.

This should be considered a temporary code meant to replace the signaling
system that announces events inside of vpn code and is catched on the bitmask
client.
"""

import Queue


class StatusQueue(object):
    def __init__(self):
        self._status = Queue.Queue()

        # this attributes serve to simulate events in the old signaler used
        self.eip_network_unreachable = "network_unreachable"
        self.eip_process_restart_tls = "process_restart_tls"
        self.eip_process_restart_ping = "process_restart_ping"
        self.eip_connected = "initialization_completed"
        self.eip_status_changed = "status_changed"  # has parameter
        self.eip_state_changed = "state_changed"  # has parameter
        self.eip_process_finished = "process_finished"  # has parameter

    def get_noblock(self):
        s = None
        try:
            s = self._status.get(False)
        except Queue.Empty:
            pass

        return s

    def get(self):
        return self._status.get(timeout=1)

    def signal(self, status, data=None):
        self._status.put({'status': status, 'data': data})