Example #1
0
    def _create(self):
        """ create DySKT and member processes """
        # read in and validate the conf file
        self._readconf()

        # intialize shared objects
        self._halt = mp.Event()  # our stop event
        self._ic = mp.Queue()  # comms for children
        self._pConns = {}  # dict of connections to children

        # initialize children
        # Each child is expected to initialize in the _init_ function and throw
        # a RuntimeError failure
        logging.info("Initializing subprocess...")
        try:
            # start RTO first
            logging.info("Starting RTO")
            (conn1, conn2) = mp.Pipe()
            self._pConns['rto'] = conn1
            self._rto = RTO(self._ic, conn2, self._conf)

            # set the region? if so, do it prior to starting the RadioController
            rd = self._conf['local']['region']
            if rd:
                logging.info("Setting regulatory domain to %s", rd)
                self._rd = iw.regget()
                iw.regset(rd)
                if iw.regget() != rd:
                    logging.warn("Regulatory domain %s may not have been set",
                                 rd)
                else:
                    logging.info("Regulatory domain set to %s", rd)

            # recon radio is mandatory
            logging.info("Starting Reconnaissance Radio")
            (conn1, conn2) = mp.Pipe()
            self._pConns['recon'] = conn1
            self._rr = RadioController(self._ic, conn2, self._conf['recon'])

            # collection if present
            if self._conf['collection']:
                try:
                    logging.info("Starting Collection Radio")
                    (conn1, conn2) = mp.Pipe()
                    self._pConns['collection'] = conn1
                    self._cr = RadioController(self._ic, conn2,
                                               self._conf['collection'])
                except RuntimeError as e:
                    # continue without collector, but log it
                    logging.warning(
                        "Collection Radio (%s), continuing without", e)
        except RuntimeError as e:
            # e should have the form "Major:Minor:Description"
            ms = e.message.split(':')
            logging.error("%s (%s) %s", ms[0], ms[1], ms[2])
            self._state = DYSKT_INVALID
        except Exception as e:
            # catchall
            logging.error(e)
            self._state = DYSKT_INVALID
        else:
            # start children execution
            self._state = DYSKT_CREATED
            self._rr.start()
            if self._cr: self._cr.start()
            self._rto.start()
Example #2
0
    def _create(self):
        """ create DySKT and member processes """
        # read in and validate the conf file
        self._readconf()

        # intialize shared objects
        self._halt = mp.Event() # our stop event
        self._ic = mp.Queue()   # comms for children
        self._pConns = {}       # dict of connections to children

        # initialize children
        # Each child is expected to initialize in the _init_ function and throw
        # a RuntimeError on failure. For non-mandatory components, all exceptions
        # are caught in in inner exceptions, mandatory are caught in the the outer
        # exception and result in shutting down
        logging.info("Initializing subprocess...")
        try:
            # start RTO first (IOT accept comms from the radios)
            logging.info("Starting RTO...")
            (conn1,conn2) = mp.Pipe()
            self._pConns['rto'] = conn1
            self._rto = RTO(self._ic,conn2,self._conf)
            logging.info("RTO started")

            # set the region? if so, do it prior to starting the radio(s)
            rd = self._conf['local']['region']
            if rd:
                logging.info("Setting regulatory domain to %s...",rd)
                self._rd = iw.regget()
                iw.regset(rd)
                if iw.regget() != rd:
                    logging.warning("Regulatory domain %s may not have been set",rd)
                else:
                    logging.info("Regulatory domain set to %s",rd)

            # recon radio is mandatory
            mode = 'paused' if self._conf['recon']['paused'] else 'scan'
            logging.info("Starting Reconnaissance Radio...")
            (conn1,conn2) = mp.Pipe()
            self._pConns['recon'] = conn1
            self._rr = RadioController(self._ic,conn2,self._conf['recon'])
            logging.info("Reconnaissance Radio started in %s mode",mode)

            # collection if present
            if self._conf['collection']:
                try:
                    mode = 'paused' if self._conf['collection']['paused'] else 'scan'
                    logging.info("Starting Collection Radio...")
                    (conn1,conn2) = mp.Pipe()
                    self._pConns['collection'] = conn1
                    self._cr = RadioController(self._ic,conn2,self._conf['collection'])
                except RuntimeError as e:
                    # continue without collector, but log it
                    logging.warning("Collection Radio failed: %s, continuing w/out",e)
                else:
                    logging.info("Collection Radio started in %s mode",mode)

            # c2c socket -> on failure log it and keep going
            logging.info("Starting C2C...")
            try:
                (conn1,conn2) = mp.Pipe()
                self._pConns['c2c'] = conn1
                self._c2c = C2C(conn2,self._conf['local']['c2c'])
                self._c2c.start()
            except Exception as e:
                logging.warn("C2C failed: %s, continuing without" % e)
            else:
                 logging.info("C2C listening on port %d" % self._conf['local']['c2c'])
        except RuntimeError as e:
            # e should have the form "Major:Minor:Description"
            ms = e.message.split(':')
            logging.error("%s (%s) %s",ms[0],ms[1],ms[2])
            self._state = DYSKT_INVALID
        except Exception as e:
            # catchall
            logging.error(e)
            self._state = DYSKT_INVALID
        else:
            # start children execution
            self._state = DYSKT_CREATED
            self._rr.start()
            if self._cr: self._cr.start()
            self._rto.start()