Advertisement
Guest User

SessionRequest patch, allows retries on session request

a guest
Nov 23rd, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.02 KB | None | 0 0
  1. --- A:/github/eq_stream.cpp Sun Nov 23 14:11:11 2014
  2. +++ A:/github/new/eq_stream.cpp Sun Nov 23 14:29:46 2014
  3. @@ -50,7 +50,15 @@
  4.  
  5.  uint16 EQStream::MaxWindowSize=2048;
  6.  
  7. -void EQStream::init() {
  8. +void EQStream::init(bool resetSession) {
  9. +
  10. +   // we only reset these statistics if it is a 'new' connection
  11. +   if ( resetSession )
  12. +   {
  13. +       streamactive = false;
  14. +       sessionAttempts = 0;
  15. +   }
  16. +  
  17.     active_users = 0;
  18.     Session=0;
  19.     Key=0;
  20. @@ -315,19 +323,23 @@ void EQStream::ProcessPacket(EQProtocolPacket *p)
  21.                 break;
  22.             }
  23.  #ifndef COLLECTOR
  24. -           if (GetState()==ESTABLISHED) {
  25. -               _log(NET__ERROR, _L "Received OP_SessionRequest in ESTABLISHED state (%d)" __L, GetState());
  26. +           if (GetState()==ESTABLISHED) {
  27. +               _log(NET__ERROR, _L "Received OP_SessionRequest in ESTABLISHED state (%d) streamactive (%i) attempt (%i)" __L, GetState(),streamactive,sessionAttempts);
  28.  
  29. -               /*RemoveData();
  30. -               init();
  31. -               State=UNESTABLISHED;*/
  32. -               _SendDisconnect();
  33. -               SetState(CLOSED);
  34. -               break;
  35. +               // client seems to try a max of 4 times (initial+3 retries) then gives up, giving it a few more attempts just in case
  36. +               // streamactive means we identified the opcode for the stream, we cannot re-establish this connection
  37. +               if ( streamactive || ( sessionAttempts > 5 ) )
  38. +               {
  39. +                   _SendDisconnect();
  40. +                   SetState(CLOSED);
  41. +                   break;
  42. +               }
  43.             }
  44.  #endif
  45.             //std::cout << "Got OP_SessionRequest" << std::endl;
  46. -           init();
  47. +           sessionAttempts++;
  48. +           // we set established below, so statistics will not be reset for session attempts/stream active.
  49. +           init(GetState()!=ESTABLISHED);
  50.             OutboundQueueClear();
  51.             SessionRequest *Request=(SessionRequest *)p->pBuffer;
  52.             Session=ntohl(Request->Session);
  53.  
  54.  
  55.  
  56. --- A:/github/eq_stream.h   Sun Nov 23 14:12:44 2014
  57. +++ A:/github/new/eq_stream.h   Sun Nov 23 14:15:58 2014
  58. @@ -101,6 +101,9 @@ class EQStream : public EQStreamInterface {
  59.         uint32 retransmittimer;
  60.         uint32 retransmittimeout;
  61.  
  62. +       uint16 sessionAttempts;
  63. +       bool streamactive;
  64. +      
  65.         //uint32 buffer_len;
  66.  
  67.         uint32 Session, Key;
  68. @@ -194,7 +197,8 @@ class EQStream : public EQStreamInterface {
  69.  
  70.         void _SendDisconnect();
  71.  
  72. -       void init();
  73. +       // session is reset by default, an exception is in OP_SessionRequest handling
  74. +       void init(bool resetSession=true);
  75.     public:
  76.         EQStream() { init(); remote_ip = 0; remote_port = 0; State=UNESTABLISHED; StreamType=UnknownStream; compressed=true; encoded=false; app_opcode_size=2; bytes_sent=0; bytes_recv=0; create_time=Timer::GetTimeSeconds(); }
  77.         EQStream(sockaddr_in addr) { init(); remote_ip=addr.sin_addr.s_addr; remote_port=addr.sin_port; State=UNESTABLISHED; StreamType=UnknownStream; compressed=true; encoded=false; app_opcode_size=2; bytes_sent=0; bytes_recv=0; create_time=Timer::GetTimeSeconds(); }
  78. @@ -221,6 +225,9 @@ class EQStream : public EQStreamInterface {
  79.         void SetLastPacketTime(uint32 t) {LastPacket=t;}
  80.         void Write(int eq_fd);
  81.  
  82. +       // whether or not the stream has been assigned (we passed our stream match)
  83. +       void SetActive(bool val) { streamactive = val; }
  84. +      
  85.         //
  86.         inline bool IsInUse() { bool flag; MInUse.lock(); flag=(active_users>0); MInUse.unlock(); return flag; }
  87.         inline void PutInUse() { MInUse.lock(); active_users++; MInUse.unlock(); }
  88.  
  89.  
  90.  
  91.  
  92. --- A:/github/eq_stream_ident.cpp   Sun Nov 23 14:13:11 2014
  93. +++ A:/github/new/eq_stream_ident.cpp   Sun Nov 23 14:25:59 2014
  94. @@ -110,7 +110,10 @@ void EQStreamIdentifier::Process() {
  95.  
  96.                 _log(NET__IDENTIFY, "Identified stream %s:%d with signature %s", long2ip(r->stream->GetRemoteIP()).c_str(), ntohs(r->stream->GetRemotePort()), p->name.c_str());
  97.  
  98. -               //might want to do something less-specific here... some day..
  99. +               // before we assign the eqstream to an interface, let the stream recognize it is in use and the session should not be reset any further
  100. +               r->stream->SetActive(true);
  101. +
  102. +               //might want to do something less-specific here... some day..
  103.                 EQStreamInterface *s = new EQStreamProxy(r->stream, p->structs, p->opcodes);
  104.                 m_identified.push(s);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement