Exemple #1
0
 def __init__(self):
     '''
     Constructor
     '''
     # Get configuration settings
     p = os.path.dirname(os.path.realpath(__file__))
     with open(os.path.join(p, 'server_config.json')) as fin:
         config = json.load(fin)
     config  # Shut up the stupid eclipse warning
     p = os.path.realpath(os.path.join(p, '..', 'common'))
     with open(os.path.join(p, 'gen_config.json')) as fin:
         genconfig = json.load(fin)
     host = genconfig['rabbit_server']
     exchange = genconfig['server_exchange']
     queue = genconfig['op_queue']
     self.slice_size = genconfig['slice_size']
     
     # Create DB biz object
     self.biz = ServerBiz()
     
     # Create Listener object
     self.signal_queue = Queue.Queue()
     self.listener = _Listener(self, host, queue, self.slice_size)
     self.listener.exchange = exchange
     self.listener.start()
Exemple #2
0
class Server(object):
    '''
    The main command and control center for the Bullitt Index Server.
    
    This class functions primarily as a switching board of sorts by receiving
    messages from clients, using the business logic class, db.ServerBiz, and
    responding appropriately.  The server has been designed to be single-
    threaded to help ensure transactions are atomic.  While a multi-threaded
    approach may be more time efficient, it may also introduce consistency
    issues with the database which is far less desirable than less optimal
    performance.
    
    Post explaining the seemingly arbitrary slice size:
    http://www.unitethecows.com/p2p-general-discussion/30807-rodi-anonymous-p2p.html#post203703
    '''


    def __init__(self):
        '''
        Constructor
        '''
        # Get configuration settings
        p = os.path.dirname(os.path.realpath(__file__))
        with open(os.path.join(p, 'server_config.json')) as fin:
            config = json.load(fin)
        config  # Shut up the stupid eclipse warning
        p = os.path.realpath(os.path.join(p, '..', 'common'))
        with open(os.path.join(p, 'gen_config.json')) as fin:
            genconfig = json.load(fin)
        host = genconfig['rabbit_server']
        exchange = genconfig['server_exchange']
        queue = genconfig['op_queue']
        self.slice_size = genconfig['slice_size']
        
        # Create DB biz object
        self.biz = ServerBiz()
        
        # Create Listener object
        self.signal_queue = Queue.Queue()
        self.listener = _Listener(self, host, queue, self.slice_size)
        self.listener.exchange = exchange
        self.listener.start()
    
    
    def add_client(self, client_id, ipaddr, pub_key, alias=None):
        '''
        Add a client to the system with the given ID, IP address, and pub key.
        '''
        self.biz.add_client(client_id, ipaddr, pub_key, alias)
    
    
    def get_clients(self):
        '''
        '''
        return self.biz.get_clients()
    
    
    def del_client(self, client_id=None, ipaddr=None):
        '''
        Given either a client ID or a client IP address, delete the client.
        
        Returns False if unsuccessful.
        '''
        if not client_id:
            if not ipaddr:
                return False
            info = self.biz.client_lookup(ipaddr=ipaddr)
            if not info:
                if DEBUG:
                    print "Could not find a client with IP address %s" % ipaddr
                return
            client_id = info['user_id']
        return self.biz.del_client(client_id)