# Path: umit/icm/agent/logger.py
# LOGLEVEL = 'DEBUG'
# 
# Path: umit/icm/agent/Application.py
# def main_is_frozen():
#     def __init__(self):
#     def _init_components(self, aggregator):
#     def _load_from_db(self):
#     def init_after_running(self, port=None, username=None, password=None,
#                            server_enabled=True, skip_server_check=False):
#     def check_aggregator_success(self,response):
#     def login_window_show(self):       
#     def check_aggregator_failed(self,message):
#     def login_without_gui(self):
#     def check_software_auto(self):
#     def register_agent(self, username, password):
#     def _handle_register(self, result):
#     def _handle_errback(self, failure):
#     def login(self, username, password, save_login=False, login_only=False):
#     def check_username(self,username="",password=""):
#     def _login_after_register_callback(self, message, username,
#                                        password, save_login, login_only):
#     def _handle_login_errback(self,failure):
#     def _handle_login(self, result, username, password, save_login,login_only=False):
#     def login_simulate(self):
#     def task_loop_manager(self):
#     def logout(self):
#     def _handle_logout(self, result):
#     def start(self, run_reactor=True, managed_mode=False, aggregator=None):
#     def quit_window_in_wrong(self,primary_text = "",secondary_text = ""):
#     def terminate(self):
#     def on_quit(self):
# class Application(object):


import random
from umit.icm.agent.logger import g_logger
from umit.icm.agent.Application import theApp
from umit.icm.agent.Global import *
from twisted.internet import reactor


    def _normal_peer_disconnected(self, peer_id):
        if peer_id not in self.normal_peers:
            g_logger.warning("Peer id %s is not in normal peer list." % \
                             (peer_id, ip))
            return False
        # will not remove the peer entry from the list
        self.normal_peers[peer_id].status = 'Disconnected'
        self.connected_peer_num = self.connected_peer_num - 1
        return True

    def add_super_peer(self, peer_id, ip, port, token =None ,ciphered_public_key=None,
                       status='Disconnected', network_id=0):
        """
        """
        if peer_id in self.super_peers:
            g_logger.info("Peer id %s already exists in Super Peer List"%peer_id)
        else:
            peer_entry = PeerEntry()
            peer_entry.Type = 1
            peer_entry.ID = peer_id
            peer_entry.IP = ip
            peer_entry.Port = port
            peer_entry.Token = token
            peer_entry.CipheredPublicKey = ciphered_public_key
            peer_entry.status = status
            peer_entry.network_id = network_id
            self.super_peers[peer_entry.ID] = peer_entry
            self.super_peer_num += 1
            

# Path: umit/icm/agent/logger.py
# LOGLEVEL = 'DEBUG'
# 
# Path: umit/icm/agent/Application.py
# def main_is_frozen():
#     def __init__(self):
#     def _init_components(self, aggregator):
#     def _load_from_db(self):
#     def init_after_running(self, port=None, username=None, password=None,
#                            server_enabled=True, skip_server_check=False):
#     def check_aggregator_success(self,response):
#     def login_window_show(self):       
#     def check_aggregator_failed(self,message):
#     def login_without_gui(self):
#     def check_software_auto(self):
#     def register_agent(self, username, password):
#     def _handle_register(self, result):
#     def _handle_errback(self, failure):
#     def login(self, username, password, save_login=False, login_only=False):
#     def check_username(self,username="",password=""):
#     def _login_after_register_callback(self, message, username,
#                                        password, save_login, login_only):
#     def _handle_login_errback(self,failure):
#     def _handle_login(self, result, username, password, save_login,login_only=False):
#     def login_simulate(self):
#     def task_loop_manager(self):
#     def logout(self):
#     def _handle_logout(self, result):
#     def start(self, run_reactor=True, managed_mode=False, aggregator=None):
#     def quit_window_in_wrong(self,primary_text = "",secondary_text = ""):
#     def terminate(self):
#     def on_quit(self):
# class Application(object):


# Path: umit/icm/agent/core/PeerManager.py
import random
from umit.icm.agent.logger import g_logger
from umit.icm.agent.Application import theApp
from umit.icm.agent.Global import *
from twisted.internet import reactor


    def _normal_peer_disconnected(self, peer_id):
        if peer_id not in self.normal_peers:
            g_logger.warning("Peer id %s is not in normal peer list." % \
                             (peer_id, ip))
            return False
        # will not remove the peer entry from the list
        self.normal_peers[peer_id].status = 'Disconnected'
        self.connected_peer_num = self.connected_peer_num - 1
        return True

    def add_super_peer(self, peer_id, ip, port, token =None ,ciphered_public_key=None,
                       status='Disconnected', network_id=0):
        """
        """
        if peer_id in self.super_peers:
            g_logger.info("Peer id %s already exists in Super Peer List"%peer_id)
        else:
            peer_entry = PeerEntry()
            peer_entry.Type = 1
            peer_entry.ID = peer_id
            peer_entry.IP = ip
            peer_entry.Port = port
            peer_entry.Token = token
            peer_entry.CipheredPublicKey = ciphered_public_key
            peer_entry.status = status
            peer_entry.network_id = network_id
            self.super_peers[peer_entry.ID] = peer_entry
            self.super_peer_num += 1
            

            g_logger.info("Super peer(%s) is added successfully!"%(peer_entry.ID))
