Ϫf&dZddlmZddlmZddlmZddlmZeejGddej Z y) z The parent class for all the SSH Channels. Currently implemented channels are session, direct-tcp, and forwarded-tcp. Maintainer: Paul Swartz ) implementer) interfaces)Logger)logceZdZUdZeZdZeed< ddZ de fdZ defdZ dZ d Zd Zd Zd Zd ZdZdZdZdZdZdZdZdZdZdZdZdZy) SSHChannela A class that represents a multiplexed channel over an SSH connection. The channel has a local window which is the maximum amount of data it will receive, and a remote which is the maximum amount of data the remote side will accept. There is also a maximum packet size for any individual data packet going each way. @ivar name: the name of the channel. @type name: L{bytes} @ivar localWindowSize: the maximum size of the local window in bytes. @type localWindowSize: L{int} @ivar localWindowLeft: how many bytes are left in the local window. @type localWindowLeft: L{int} @ivar localMaxPacket: the maximum size of packet we will accept in bytes. @type localMaxPacket: L{int} @ivar remoteWindowLeft: how many bytes are left in the remote window. @type remoteWindowLeft: L{int} @ivar remoteMaxPacket: the maximum size of a packet the remote side will accept in bytes. @type remoteMaxPacket: L{int} @ivar conn: the connection this channel is multiplexed through. @type conn: L{SSHConnection} @ivar data: any data to send to the other side when the channel is requested. @type data: L{bytes} @ivar avatar: an avatar for the logged-in user (if a server channel) @ivar localClosed: True if we aren't accepting more data. @type localClosed: L{bool} @ivar remoteClosed: True if the other side isn't accepting more data. @type remoteClosed: L{bool} Nnamec|xsd|_|j|_|xsd|_||_||_d|_||_||_||_d|_ d|_ g|_ d|_ d|_ d|_d|_y)Niir)localWindowSizelocalWindowLeftlocalMaxPacketremoteWindowLeftremoteMaxPacket areWritingconndataavatar specificDatabufextBufclosing localClosed remoteClosedid)self localWindowr remoteWindowrrrrs ;/usr/lib/python3/dist-packages/twisted/conch/ssh/channel.py__init__zSSHChannel.__init__9s +4f#33,5 ,.     r returnc@|jjdS)Nascii) __bytes__decoders r __str__zSSHChannel.__str__Ts~~&&w//r cZ|j}|sd}d||j|jfzS)zD Return a byte string representation of the channel sNones)r rr)rr s r r%zSSHChannel.__bytes__Ws<yyD/    ! !3   r c|jduxrt|jxsd}|jr|jjd}nd}d|d|d|jj S)Nunknownr$Nonez SSHChannel z (z) on )rstrr r&r logPrefix)rrr s r r.zSSHChannel.logPrefixesiggT!2c$''l @y 9999##G,DDTF"RDdii.A.A.C-DEEr c:|jjdy)z Called when the channel is opened. specificData is any data that the other side sent us when opening the channel. @type specificData: L{bytes} z channel openN_loginfo)rrs r channelOpenzSSHChannel.channelOpenms ~&r c>|jjd|y)z Called when the open failed for some reason. reason.desc is a string descrption, reason.code the SSH error code. @type reason: L{error.ConchError} z(other side refused open reason: {reason})reasonN)r1error)rr5s r openFailedzSSHChannel.openFailedvs CFSr cb|j|z|_|js#|jsd|_|j|jr$|j}d|_|j ||j r0|j }g|_|D]\}}|j||yy)z Called when bytes are added to the remote window. By default it clears the data buffers. @type data: L{bytes} Tr N)rrr startWritingrwriter writeExtended)rrbtypes r addWindowByteszSSHChannel.addWindowBytess!% 5 5 <t||"DO     88ADH JJqM ;; ADK / d""4. / r c|jddjd}t|d|zd}|r||S|jj d|y) aJ Called when a request is sent to this channel. By default it delegates to self.request_. If this function returns true, the request succeeded, otherwise it failed. @type requestType: L{bytes} @type data: L{bytes} @rtype: L{bool} -_r$request_Nz#unhandled request for {requestType}) requestTyper)replacer&getattrr1r2)rrCrfoofs r requestReceivedzSSHChannel.requestReceivedsX!!$-44W= D*s*D 1 T7N <+Vr c>|jjd|y)zL Called when we receive data. @type data: L{bytes} zgot data {data})rNr1debugrrs r dataReceivedzSSHChannel.dataReceiveds )5r c@|jjd||y)z Called when we receive extended data (usually standard error). @type dataType: L{int} @type data: L{str} z%got extended data {dataType} {data!r})dataTyperNrJrrOrs r extReceivedzSSHChannel.extReceiveds   3hT  r c:|jjdy)zD Called when the other side will send no more data. z remote eofNr0r's r eofReceivedzSSHChannel.eofReceiveds |$r cZ|jjd|jy)zD Called when the other side has closed the channel. z remote closeN)r1r2loseConnectionr's r closeReceivedzSSHChannel.closeReceiveds  ~& r c:|jjdy)z Called when the channel is closed. This means that both our side and the remote side have closed the channel. closedNr0r's r rXzSSHChannel.closeds x r c|jr|xj|z c_yt|}||jkDrG|d|j||jdc}|_d|_|j |j}|j }|j j}td||}|D]}||||||z|xj|zc_|jr|js|jyyy)z Write some data to the channel. If there is not enough remote window available, buffer until it is. Otherwise, split the data into packets of length remoteMaxPacket and send them. @type data: L{bytes} Nr) rlenrr stopWritingrrsendDatarangerrU)rrtoprmpr:roffsets r r:zSSHChannel.writes 88 HH H $i && &,t,,-T**,- D$( DO    ''C"" "" !S#  5F $Vfsl3 4 5 $ <<    !!)|d|j|||jdggc}|_d|_|j t||j kDrq|jj|||d|j ||j d}|xj|j zc_t||j kDrq|r;|jj||||xjt|zc_|jr|jyy)a Send extended data to this channel. If there is not enough remote window available, buffer until there is. Otherwise, split the data into packets of length remoteMaxPacket and send them. @type dataType: L{int} @type data: L{bytes} rr N) rappendrZrrr[rrsendExtendedDatarrUrPs r r;zSSHChannel.writeExtendedsq ;;{{2q!X- B"d*"  ""Hd#34  t9t,, ,,t,,-D!6!6!89:; D$+ DO    $i$... II & &tXtR>R7S T,,./D  ! !T%9%9 9 !$i$...  II & &tXt <  ! !SY . ! <<    ! r cD|jdj|y)z Part of the Transport interface. Write a list of strings to the channel. @type data: C{list} of L{str} r N)r:joinrLs r writeSequencezSSHChannel.writeSequence s 388D>"r c|d|_|js)|js|jj |yyy)zr Close the channel if there is no buferred data. Otherwise, note the request and return. r N)rrrr sendCloser's r rUzSSHChannel.loseConnections1  xx II   %!,xr cJ|jjjS)z See: L{ITransport.getPeer} @return: The remote address of this connection. @rtype: L{SSHTransportAddress}. )r transportgetPeerr's r rmzSSHChannel.getPeeryy""**,,r cJ|jjjS)z See: L{ITransport.getHost} @return: An address describing this side of the connection. @rtype: L{SSHTransportAddress}. )rrlgetHostr's r rpzSSHChannel.getHost%rnr cy)z Called when the remote buffer is full, as a hint to stop writing. This can be ignored, but it can be helpful. Nr's r r[zSSHChannel.stopWriting.r cy)ze Called when the remote buffer has more room, as a hint to continue writing. Nrrr's r r9zSSHChannel.startWriting4rsr )rrrrNNN)__name__ __module__ __qualname____doc__rr1r bytes__annotations__r!r-r(r%r.r3r7r>rHrMrQrSrVrXr:r;rhrUrmrpr[r9rrr r rrs@ 8DD%  600  5  F'T/*$6  % !":"@#&--  r rN) rxzope.interfacertwisted.internetrtwisted.loggerrtwisted.pythonr ITransportrrrr r rsE ''! Z " "#c c $c r