Пример #1
0
Файл: VNS.py Проект: smbz/vns
    def terminate_connection(self, conn, why, notify_client=True, log_it=True, lvl=logging.INFO):
        """Terminates the client connection conn.  This event will be logged
        unless log_it is False.  If notify_client is True, then the client will
        be sent a VNSClose message with an explanation."""
        # terminate the client
        if conn.connected:
            if notify_client:
                for m in VNSClose.get_banners_and_close(why):
                    conn.send(m)
            conn.transport.loseConnection()

        if log_it:
            logging.log(lvl, 'terminating client (%s): %s' % (conn, why))

        # cleanup client and topology info
        tid = self.clients.get(conn)
        if tid is not None:
            del self.clients[conn]
            topo = self.topologies[tid]
            topo.client_disconnected(conn)
            if not topo.is_active():
                if topo.has_gateway():
                    self.resolver.unregister_topology(topo)
                with self.topologies_lock:
                    del self.topologies[tid]
                    self.topologies_changed = True
                DBService.run_and_wait(topo.get_stats().finalize)
                if topo.is_temporary():
                    AddressAllocation.free_topology(tid)
                else:
                    AddressAllocation.deallocate_from_topology(topo.t)
                for ti_conn in topo.interactors:
                    self.terminate_ti_connection(ti_conn, 'GOODBYE: Topology %d has been shutdown' % tid)
Пример #2
0
    def terminate_connection(self, conn, why, notify_client=True, log_it=True, lvl=logging.INFO):
        """Terminates the client connection conn.  This event will be logged
        unless log_it is False.  If notify_client is True, then the client will
        be sent a VNSClose message with an explanation."""
        # terminate the client
        if conn.connected:
            if notify_client:
                for m in VNSClose.get_banners_and_close(why):
                    conn.send(m)
            conn.transport.loseConnection()

        if log_it:
            logging.log(lvl, 'terminating client (%s): %s' % (conn, why))

        # cleanup client and topology info
        tid = self.clients.get(conn)
        if tid is not None:
            del self.clients[conn]
            topo = self.topologies[tid]
            topo.client_disconnected(conn)
            if not topo.is_active():
                if topo.has_gateway():
                    self.resolver.unregister_topology(topo)
                with self.topologies_lock:
                    del self.topologies[tid]
                    self.topologies_changed = True
                topo.get_stats().finalize()
                if topo.is_temporary():
                    AddressAllocation.free_topology(tid)
                for ti_conn in topo.interactors:
                    self.terminate_ti_connection(ti_conn, 'GOODBYE: Topology %d has been shutdown' % tid)
Пример #3
0
 def handle_recv_msg(self, conn, vns_msg):
     if vns_msg is not None:
         # print 'recv: %s' % str(vns_msg)
         if vns_msg.get_type() == VNSOpen.get_type():
             self.handle_open_msg(conn, vns_msg)
         elif vns_msg.get_type() == VNSClose.get_type():
             self.handle_close_msg(conn)
         elif vns_msg.get_type() == VNSPacket.get_type():
             self.handle_packet_msg(conn, vns_msg)
Пример #4
0
  def recv_msg(self, conn, vns_msg):
    # demux sr-client messages and take approriate actions
    if vns_msg is None:
      log.debug("invalid message")
      self.handle_close_msg(conn)
      return

    log.debug('Received VNS msg: %s' % vns_msg)
    if vns_msg.get_type() == VNSOpen.get_type():
      self.handle_open_msg(conn, vns_msg)
    elif vns_msg.get_type() == VNSClose.get_type():
      self.handle_close_msg(conn)
    elif vns_msg.get_type() == VNSPacket.get_type():
      self.handle_packet_msg(conn, vns_msg)
    else:
      log.debug('Unexpected VNS message received: %s' % vns_msg)
    def recv_msg(self, conn, vns_msg):
        # demux sr-client messages and take approriate actions
        if vns_msg is None:
            log.debug("invalid message")
            self.handle_close_msg(conn)
            return

        log.debug('Received VNS msg: %s' % vns_msg)
        if vns_msg.get_type() == VNSOpen.get_type():
            self.handle_open_msg(conn, vns_msg)
        elif vns_msg.get_type() == VNSClose.get_type():
            self.handle_close_msg(conn)
        elif vns_msg.get_type() == VNSPacket.get_type():
            self.handle_packet_msg(conn, vns_msg)
        else:
            log.debug('Unexpected VNS message received: %s' % vns_msg)
Пример #6
0
    def _handle_recv_msg(self, conn, vns_msg):
        # demux sr-client messages and take approriate actions
        if vns_msg is None:
            #log.debug("invalid message")
            self._handle_close_msg(conn)
            return

        #log.debug('recv VNS msg: %s' % vns_msg)
        if vns_msg.get_type() == VNSAuthReply.get_type():
            self._handle_auth_reply(conn)
            return
        elif vns_msg.get_type() == VNSOpen.get_type():
            self._handle_open_msg(conn, vns_msg)
        elif vns_msg.get_type() == VNSClose.get_type():
            self._handle_close_msg(conn)
        elif vns_msg.get_type() == VNSPacket.get_type():
            self._handle_packet_msg(conn, vns_msg)
        elif vns_msg.get_type() == VNSOpenTemplate.get_type():
            # TODO: see if this is needed...
            self._handle_open_template_msg(conn, vns_msg)
Пример #7
0
 def handle_recv_msg(self, conn, vns_msg):
     if vns_msg is not None:
         logging.debug('recv VNS msg: %s' % vns_msg)
         if vns_msg.get_type() == VNSAuthReply.get_type():
             self.handle_auth_reply(conn, vns_msg, self.terminate_connection)
             return
         elif not conn.vns_authorized:
             logging.warning('received non-auth-reply from unauthenticated user %s: terminating the user' % conn)
             self.terminate_connection(conn, 'simulator expected authentication reply')
         # user is authenticated => any other messages are ok
         elif vns_msg.get_type() == VNSOpen.get_type():
             self.handle_open_msg(conn, vns_msg)
         elif vns_msg.get_type() == VNSClose.get_type():
             self.handle_close_msg(conn)
         elif vns_msg.get_type() == VNSPacket.get_type():
             self.handle_packet_msg(conn, vns_msg)
         elif vns_msg.get_type() == VNSOpenTemplate.get_type():
             self.handle_open_template_msg(conn, vns_msg)
         else:
             logging.debug('unexpected VNS message received: %s' % vns_msg)
Пример #8
0
  def _handle_recv_msg(self, conn, vns_msg):
    # demux sr-client messages and take approriate actions
    if vns_msg is None:
      log.debug("invalid message")
      self._handle_close_msg(conn)
      return

    log.debug('recv VNS msg: %s' % vns_msg)
    if vns_msg.get_type() == VNSAuthReply.get_type():
      self._handle_auth_reply(conn)
      return
    elif vns_msg.get_type() == VNSOpen.get_type():
      self._handle_open_msg(conn, vns_msg)
    elif vns_msg.get_type() == VNSClose.get_type():
      self._handle_close_msg(conn)
    elif vns_msg.get_type() == VNSPacket.get_type():
      self._handle_packet_msg(conn, vns_msg)
    elif vns_msg.get_type() == VNSOpenTemplate.get_type():
      # TODO: see if this is needed...
      self._handle_open_template_msg(conn, vns_msg)
    else:
      log.debug('unexpected VNS message received: %s' % vns_msg)