Esempio n. 1
0
 def authentidRequested(self):
     """
     This is a callback that should be overloaded in servers
     or clients for when authentication information is required.
     """
     log.debug('authentid requested')
     raise NotImplementedError('authentidRequested must be defined')
Esempio n. 2
0
 def shutdown(self):
     """
     Attempts to close all the channels in a session
     before closing down the session itself.
     """
     log.debug("shutdown() started...")
     self.state = CLOSING
     self.closeAllChannels()
Esempio n. 3
0
def spawnThread(func, source, args, timeout):
    global THREADS
    log.debug('Tring to spawn thread from source %s' % source)
    if threading.activeCount() <= config_maxthreads:
        var = threading.Thread(name=source, target=func, args=args)
        var.start()
        if timeout > 0: var.join(timeout)
        THREADS.append(var)
Esempio n. 4
0
 def createTransportChannel(self, channelnum):
     """
     This method should be overridden at the transport
     layer if there is any special work that needs to
     be done at channel create time.
     """
     log.debug("session creating transport channel")
     pass
Esempio n. 5
0
 def _channelClosedSuccess(self, channelnum):
     """
     Internal channel closure method.
     """
     log.debug("Channel %d closed." % channelnum)
     if len(self.channels) == 0:
         self.close()
     self.channelClosed(channelnum)
     if channelnum == 0:
         self.sessionClosed()
Esempio n. 6
0
 def closeChannel(self, channelnum):
     """
     requestCloseChannel() attempts to close a channel.
     @param channelnum: the number of the channel to close
     """
     log.debug("Attempting to close channel %s..." % channelnum)
     if self.channels.has_key(channelnum):
         self.channels[0].profile.closeChannel(channelnum)
     else:
         raise KeyError("Channel number invalid")
Esempio n. 7
0
 def deleteChannel(self, channelnum):
     """
     Delete a single channel from the Session
     
     @param channelnum: the channel number to delete
     @type channelnum: integer
     """
     self.deleteTransportChannel(channelnum)
     del self.channels[channelnum]
     log.debug("Channel %d deleted." % channelnum)
Esempio n. 8
0
    def closeAllChannels(self):
        """
        Attempts to close all channels on this Session
        """
        try:
            for channelnum in self.channels.keys():
                if channelnum != 0:
                    self.closeChannel(channelnum)
                    log.debug("Finished queueing closure of %d" % channelnum)
            ## Close channel 0 last
            # FIXME: We DO NOT close channel 0 to avoid race condition because
            # the client should close it
            # self.closeChannel(0)

        except Exception, e:
            # If we can't close a channel, we must remain active
            # FIXME: more detailed error handling required here
            log.error("Unable to close Session: %s" % e)
            traceback.print_exc()
Esempio n. 9
0
    def startChannel(self, profiles, handler_obj):
        """
        startChannel() attempts to start a new channel for communication.
        It uses a more complex profileList to determine what to send to
        the remote peer as part of the start request.
        
        the profileList is a list of lists with the following structure:
        
        [ uri, encoding, chardata ]
        
        where uri is a string URI of the profile to request,
        encoding is an optional encoding to use and chardata is any
        initialisation data to send as part of the start message.
        
        To start a channel with the echoprofile and no special requirements,
        you would use a list like this:
        
        [ [echoprofile.uri, None, None] ]
        
        To try to start a channel first using SASL/OTP, then SASL/ANONYMOUS,
        you would use a list like this:
        
        [ [saslotpprofile.uri, None, None], [saslanonymousprofile.uri, None, None] ]
        
        More complex scenarios are possible.
        """

        ## We can only start channels if we're in the ACTIVE state
        if self.state == ACTIVE:
            # Attempt to get the remote end to start the Channel
            channelnum = self.nextChannelNum
            self.channels[0].profile.startChannel(channelnum, profiles, handler_obj)
            # Increment nextChannelNum appropriately.
            self.nextChannelNum += 2
            # Return channelnum we asked to start
            return channelnum

        else:
            log.debug("startChannel received in state %s" % self.state)
            raise SessionException("Attempt to start channel when not ACTIVE")
Esempio n. 10
0
 def authenticationSucceeded(self):
     log.info('Server authentication succeeded')
     log.debug('my credentials: authentid: %s, userid: %s' % (self.authentid, self.userid))
Esempio n. 11
0
 def _showInternalState(self):
     log.debug("Current internal state of %s" % self)
     for var in self.__dict__.keys():
         log.debug("%s: %s" % (var, self.__dict__[var]))