Added a 1-second delay to initial connection in order to allow telnet custom protocol handshakes to complete before server sync. This is a dumb patch that works but it's hardly ideal - but without it, none of the telnet options are properly synced to the server. Making a callback chain for the various handhakes is not trivial, so using this until a more elegant solution can be found.

This commit is contained in:
Griatch 2013-11-12 17:07:35 +01:00
parent 149b06a6a4
commit 295c79d448
3 changed files with 28 additions and 10 deletions

View file

@ -48,7 +48,9 @@ class PortalSessionHandler(SessionHandler):
sessdata = session.get_sync_data()
self.sessions[sessid] = session
# sync with server-side
self.portal.amp_protocol.call_remote_ServerAdmin(sessid,
if self.portal.amp_protocol: # this is a timing issue
print "syncing", sessdata
self.portal.amp_protocol.call_remote_ServerAdmin(sessid,
operation=PCONN,
data=sessdata)
def disconnect(self, session):

View file

@ -9,6 +9,7 @@ sessions etc.
import re
from twisted.conch.telnet import Telnet, StatefulTelnetProtocol, IAC, LINEMODE
from twisted.internet.defer import inlineCallbacks, returnValue
from src.server.session import Session
from src.server.portal import ttype, mssp, msdp
from src.server.portal.mccp import Mccp, mccp_compress, MCCP
@ -33,16 +34,29 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
client_address = self.transport.client
self.init_session("telnet", client_address, self.factory.sessionhandler)
# negotiate mccp (data compression)
#self.mccp = Mccp(self)
self.mccp = Mccp(self)
# negotiate ttype (client info)
#self.ttype = ttype.Ttype(self)
self.ttype = ttype.Ttype(self)
# negotiate mssp (crawler communication)
#self.mssp = mssp.Mssp(self)
self.mssp = mssp.Mssp(self)
# msdp
self.msdp = msdp.Msdp(self)
# add this new connection to sessionhandler so
# the Server becomes aware of it.
self.sessionhandler.connect(self)
# This is a fix to make sure the connection does not
# continue until the handshakes are done. This is a
# dumb delay of 1 second. This solution is not ideal (and
# potentially buggy for slow connections?) but
# adding a callback chain to all protocols (and notably
# to their handshakes, which in some cases are multi-part)
# is not trivial. Without it, the protocol will default
# to their defaults since sessionhandler.connect will sync
# before the handshakes have had time to finish. Keeping this patch
# until coming up with a more elegant solution /Griatch
from src.utils.utils import delay
delay(1, self, self.sessionhandler.connect)
#self.sessionhandler.connect(self)
def enableRemote(self, option):
"""
@ -187,4 +201,5 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
self.sendLine(text)
else:
# we need to make sure to kill the color at the end in order to match the webclient output.
#print "telnet data out:", self.protocol_flags, id(self.protocol_flags), id(self)
self.sendLine(ansi.parse_ansi(_RE_N.sub("", text) + "{n", strip_ansi=nomarkup, xterm256=ttype.get('256 COLORS')))

View file

@ -73,7 +73,8 @@ class Ttype(object):
certain piece of information about the client. All data is
stored on protocol.protocol_flags under the TTYPE key.
"""
if self.protocol.protocol_flags['TTYPE']['init_done']:
options = self.protocol.protocol_flags.get('TTYPE')
if options and options.get('init_done'):
return
self.ttype_step += 1
@ -106,10 +107,10 @@ class Ttype(object):
for codenum, standard in MTTS:
if option == 0:
break
status = option % codenum < option
status = option & codenum
self.protocol.protocol_flags['TTYPE'][standard] = status
if status:
option = option % codenum
#if status:
# option = option % codenum
self.protocol.protocol_flags['TTYPE']['init_done'] = True
#print "ttype results:", self.protocol.protocol_flags['TTYPE']
#print "ttype results:", self.protocol.protocol_flags['TTYPE'],id(self.protocol)