def _destroy(self): """ destroy DySKT cleanly """ # change our state self._state = DYSKT_EXITING # reset regulatory domain if necessary if self._rd: try: logging.info("Resetting regulatory domain") iw.regset(self._rd) if iw.regget() != self._rd: raise RuntimeError except: logging.warn("Failed to reset regulatory domain") # halt main execution loop & send out poison pills # put a token on the internal comms from us to break the RTO out of # any holding for data block logging.info("Stopping Sub-processes") self._halt.set() self._ic.put(('dyskt', time.time(), '!CHECK!', [])) for key in self._pConns: try: self._pConns[key].send('!STOP!') except IOError: # ignore any broken pipe errors pass self._pConns[key].close() while mp.active_children(): time.sleep(0.5) # change our state self._state = DYSKT_DESTROYED
def _destroy(self): """ destroy DySKT cleanly """ # change our state self._state = DYSKT_EXITING # reset regulatory domain if necessary if self._rd: try: logging.info("Resetting regulatory domain") iw.regset(self._rd) if iw.regget() != self._rd: raise RuntimeError except: logging.warn("Failed to reset regulatory domain") # halt main execution loop & send out poison pills # put a token on the internal comms from us to break the RTO out of # any holding for data block logging.info("Stopping Sub-processes") self._halt.set() self._ic.put(('dyskt',time.time(),'!CHECK!',[])) for key in self._pConns: try: self._pConns[key].send('!STOP!') except IOError: # ignore any broken pipe errors pass self._pConns[key].close() while mp.active_children(): time.sleep(0.5) # change our state self._state = DYSKT_DESTROYED
def _destroy(self): """ destroy DySKT cleanly """ # change our state self._state = DYSKT_EXITING # reset regulatory domain if necessary if self._rd: try: logging.info("Resetting regulatory domain...") iw.regset(self._rd) if iw.regget() != self._rd: raise RuntimeError except: logging.warning("Failed to reset regulatory domain") else: logging.info("Regulatory domain reset") # halt main execution loop & send out poison pills logging.info("Stopping Sub-processes...") self._halt.set() for key in self._pConns: try: self._pConns[key].send('!STOP!') self._pConns[key].close() except IOError: # ignore any broken pipe errors pass # active_children has the side effect of joining the processes while mp.active_children(): time.sleep(0.5) while self._c2c.is_alive(): self._c2c.join(0.5) logging.info("Sub-processes stopped") # change our state self._state = DYSKT_DESTROYED
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()
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()
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()