Esempio n. 1
0
 def handle_reconfig_request(self):
     """ Create and return state clone """
     self.clone()
     with open('data/clone.tar.gz', 'r') as fh:
         toreturn = fh.read()
         log.debug("cloned state added successfully")
         return toreturn    
Esempio n. 2
0
 def join_request(self):
     """ Command Congregate instance to join its peers by supplying credentials """
     log.debug("attempting to join")
     try:
         with open(self.conf['certfile'], 'r') as fh:
             cert = fh.read()
         with open(self.conf['keyfile'], 'r') as fh:
             pubkey = fh.read()
         wss = self.conf['p_wss']
         self.loop.run_until_complete(self.c.handle_join(wss,pubkey,cert))
     except Exception as e:
         log.debug(e)
Esempio n. 3
0
    def mainloop(self, websocket, path):
        try:
            input_msg = yield from websocket.recv()
            log.debug("< {}".format(input_msg))
            if self.conf['use_single_port']:
                output_msg = self.direct_msg(input_msg)
            else:   #using this port for external requests only
                output_msg = yield from self.handle_external_request(input_msg)
                
            if output_msg:
                yield from websocket.send(output_msg)
                #self.bmsgs.append(output_msg)
                
            else:
                yield from websocket.send("Hello from Congregate!")
                log.error("got bad input from peer")

            # adapt here
                # reconfig requests
                

        except Exception as e:
            log.debug(input_msg)
            log.error("mainloop exception: {}".format(e))
Esempio n. 4
0
    def __init__(self):
        """ Initialize system state and components """
        try:
            # Load state
            self.startup() # TODO make an init without cloned state an option
            # Create main event loop
            self.loop = asyncio.get_event_loop()
            # Create BPCon instance
            self.bpcon = BPConProtocol(self.conf, self.state)
            self.state.groups['G1'] = self.bpcon.peers # connect BPCon to Congregate instance
            self.paxos_server = websockets.serve(self.bpcon.main_loop, self.conf['ip_addr'], self.conf['port'], ssl=self.conf['ssl'])
            self.loop.run_until_complete(self.paxos_server)
            log.info("Started BPCon on port {}".format(self.conf['port']))

            # Create Congregate instance
            self.c = CongregateProtocol(self.loop, self.conf, self.bpcon)       
            self.congregate_server = websockets.serve(self.c.main_loop, self.conf['ip_addr'], self.conf['port']+1, ssl=self.conf['ssl'])
            self.loop.run_until_complete(self.congregate_server)
            log.info("Started Congregate on port {}".format(self.conf['port']+1))

            # Create API server
            self.web_server = websockets.serve(self.mainloop, self.conf['ip_addr'], self.conf['port']+2) 
            self.loop.run_until_complete(self.web_server)
            log.info("Started Web Server on port {}".format(self.conf['port']+2))

            # Add self to local group
            log.debug("adding self to local group")
            self.join_request()
            

            # Testing 
            if self.conf['is_client']:
                #self.c.reconfig()
                log.debug("is client. making test requests")
                for x in range(1):
                    request = "P,{},hello{}".format(x,x)
                    self.local_request("P,test,value")
                    self.local_request("P,test1,value1")
                    self.local_request("P,test2,value2")
                    self.local_request("P,test,value3")
                    self.local_request("D,test2,")
                    self.local_request(request)

                log.debug("requests complete")     
            else:
                #self.c.request_split()
                self.local_request("S,,")

                #self.c.request_merge("G2")
                self.group_request("M", "G2")

        except Exception as e:
            log.info(e)
Esempio n. 5
0
 def group_request(self, req_type, target_group):
     log.debug("group request initiated")
     self.loop.run_until_complete(self.c.make_2pc_request(req_type, target_group))