Пример #1
0
 def ssh_REQUEST_FAILURE(self, packet):
     """
     Our global request failed.  Get the appropriate Deferred and errback
     it with the packet we received.
     """
     self._log.debug("global request failure")
     self.deferreds["global"].pop(0).errback(
         error.ConchError("global request failed", packet))
Пример #2
0
 def ssh_REQUEST_FAILURE(self, packet):
     """
     Our global request failed.  Get the appropriate Deferred and errback
     it with the packet we received.
     """
     log.msg('RF')
     self.deferreds['global'].pop(0).errback(
         error.ConchError('global request failed', packet))
Пример #3
0
 def _cleanupGlobalDeferreds(self):
     """
     All pending requests that have returned a deferred must be errbacked
     when this service is stopped, otherwise they might be left uncalled and
     uncallable.
     """
     for d in self.deferreds["global"]:
         d.errback(error.ConchError("Connection stopped."))
     del self.deferreds["global"][:]
Пример #4
0
    def ssh_CHANNEL_FAILURE(self, packet):
        """
        Our channel request to the other side failed.  Payload::
            uint32  local channel number

        Get the C{Deferred} out of self.deferreds and errback it with a
        C{error.ConchError}.
        """
        localChannel = struct.unpack(">L", packet[:4])[0]
        if self.deferreds.get(localChannel):
            d = self.deferreds[localChannel].pop(0)
            d.errback(error.ConchError("channel request failed"))
Пример #5
0
    def ssh_CHANNEL_FAILURE(self, packet):
        """
        Our channel request to the other side failed.  Payload::
            uint32  local channel number

        Get the C{Deferred} out of self.deferreds and errback it with a
        C{error.ConchError}.
        """
        localChannel = struct.unpack('>L', packet[:4])[0]
        if self.deferreds.get(localChannel):
            d = self.deferreds[localChannel].pop(0)
            log.callWithLogger(self.channels[localChannel], d.errback,
                               error.ConchError('channel request failed'))
Пример #6
0
    def ssh_CHANNEL_OPEN_FAILURE(self, packet):
        """
        The other side did not accept our MSG_CHANNEL_OPEN request.  Payload::
            uint32  local channel number
            uint32  reason code
            string  reason description

        Find the channel using the local channel number and notify it by
        calling its openFailed() method.
        """
        localChannel, reasonCode = struct.unpack(">2L", packet[:8])
        reasonDesc = common.getNS(packet[8:])[0]
        channel = self.channels[localChannel]
        del self.channels[localChannel]
        channel.conn = self
        reason = error.ConchError(reasonDesc, reasonCode)
        channel.openFailed(reason)
Пример #7
0
    def channelClosed(self, channel):
        """
        Called when a channel is closed.
        It clears the local state related to the channel, and calls
        channel.closed().
        MAKE SURE YOU CALL THIS METHOD, even if you subclass L{SSHConnection}.
        If you don't, things will break mysteriously.

        @type channel: L{SSHChannel}
        """
        if channel in self.channelsToRemoteChannel:  # actually open
            channel.localClosed = channel.remoteClosed = True
            del self.localToRemoteChannel[channel.id]
            del self.channels[channel.id]
            del self.channelsToRemoteChannel[channel]
            for d in self.deferreds.pop(channel.id, []):
                d.errback(error.ConchError("Channel closed."))
            channel.closed()
Пример #8
0
    def _cbChannelRequest(self, result, localChannel):
        """
        Called back if the other side wanted a reply to a channel request.  If
        the result is true, send a MSG_CHANNEL_SUCCESS.  Otherwise, raise
        a C{error.ConchError}

        @param result: the value returned from the channel's requestReceived()
            method.  If it's False, the request failed.
        @type result: L{bool}
        @param localChannel: the local channel ID of the channel to which the
            request was made.
        @type localChannel: L{int}
        @raises ConchError: if the result is False.
        """
        if not result:
            raise error.ConchError('failed request')
        self.transport.sendPacket(
            MSG_CHANNEL_SUCCESS,
            struct.pack('>L', self.localToRemoteChannel[localChannel]))
Пример #9
0
    def getChannel(self, channelType, windowSize, maxPacket, data):
        """
        The other side requested a channel of some sort.
        channelType is the type of channel being requested,
        windowSize is the initial size of the remote window,
        maxPacket is the largest packet we should send,
        data is any other packet data (often nothing).

        We return a subclass of L{SSHChannel}.

        By default, this dispatches to a method 'channel_channelType' with any
        non-alphanumerics in the channelType replace with _'s.  If it cannot
        find a suitable method, it returns an OPEN_UNKNOWN_CHANNEL_TYPE error.
        The method is called with arguments of windowSize, maxPacket, data.

        @type channelType:  L{bytes}
        @type windowSize:   L{int}
        @type maxPacket:    L{int}
        @type data:         L{bytes}
        @rtype:             subclass of L{SSHChannel}/L{tuple}
        """
        self._log.debug("got channel {channelType!r} request",
                        channelType=channelType)
        if hasattr(self.transport, "avatar"):  # this is a server!
            chan = self.transport.avatar.lookupChannel(channelType, windowSize,
                                                       maxPacket, data)
        else:
            channelType = channelType.translate(TRANSLATE_TABLE)
            attr = "channel_%s" % nativeString(channelType)
            f = getattr(self, attr, None)
            if f is not None:
                chan = f(windowSize, maxPacket, data)
            else:
                chan = None
        if chan is None:
            raise error.ConchError("unknown channel",
                                   OPEN_UNKNOWN_CHANNEL_TYPE)
        else:
            chan.conn = self
            return chan