00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if !defined(AFX_DATAGRAMS_H__289BAC8C_A04C_4CB6_A185_ED043CA21CDA__INCLUDED_)
00023 #define AFX_DATAGRAMS_H__289BAC8C_A04C_4CB6_A185_ED043CA21CDA__INCLUDED_
00024
00025 #pragma once
00026
00027 #pragma pack(1)
00028
00029 typedef struct
00030 {
00031 CHAR szTag[3];
00032 BYTE nFlags;
00033 WORD nSequence;
00034 BYTE nPart;
00035 BYTE nCount;
00036 } SGP_HEADER;
00037
00038 #pragma pack()
00039
00040
00041 #define SGP_TAG_2 "GND"
00042 #define SGP_DEFLATE 0x01
00043 #define SGP_ACKNOWLEDGE 0x02
00044
00045 typedef struct
00046 {
00047 DWORD nTotal;
00048 DWORD tLast;
00049 DWORD nMeasure;
00050 DWORD pHistory[24];
00051 DWORD pTimes[24];
00052 DWORD nPosition;
00053 DWORD tLastAdd;
00054 DWORD tLastSlot;
00055 } UDPBandwidthMeter;
00056
00057 class CBuffer;
00058 class CPacket;
00059 class CG2Packet;
00060 class CDatagramIn;
00061 class CDatagramOut;
00062
00063
00064 class CDatagrams
00065 {
00066
00067 public:
00068 CDatagrams();
00069 virtual ~CDatagrams();
00070
00071
00072 protected:
00073 SOCKET m_hSocket;
00074 WORD m_nSequence;
00075 BOOL m_bStable;
00076 DWORD m_tLastWrite;
00077 protected:
00078 CBuffer* m_pBufferBuffer;
00079 DWORD m_nBufferBuffer;
00080 CBuffer* m_pBufferFree;
00081 DWORD m_nBufferFree;
00082 protected:
00083 CDatagramIn* m_pInputBuffer;
00084 DWORD m_nInputBuffer;
00085 CDatagramIn* m_pInputFree;
00086 CDatagramIn* m_pInputFirst;
00087 CDatagramIn* m_pInputLast;
00088 CDatagramIn* m_pInputHash[32];
00089 protected:
00090 CDatagramOut* m_pOutputBuffer;
00091 DWORD m_nOutputBuffer;
00092 CDatagramOut* m_pOutputFree;
00093 CDatagramOut* m_pOutputFirst;
00094 CDatagramOut* m_pOutputLast;
00095 CDatagramOut* m_pOutputHash[32];
00096 public:
00097 UDPBandwidthMeter m_mInput;
00098 DWORD m_nInBandwidth;
00099 DWORD m_nInFrags;
00100 DWORD m_nInPackets;
00101 UDPBandwidthMeter m_mOutput;
00102 DWORD m_nOutBandwidth;
00103 DWORD m_nOutFrags;
00104 DWORD m_nOutPackets;
00105
00106
00107 public:
00108 BOOL Listen();
00109 void Disconnect();
00110 BOOL IsStable();
00111 BOOL Send(IN_ADDR* pAddress, WORD nPort, CPacket* pPacket, BOOL bRelease = TRUE, LPVOID pToken = NULL, BOOL bAck = TRUE);
00112 BOOL Send(SOCKADDR_IN* pHost, CPacket* pPacket, BOOL bRelease = TRUE, LPVOID pToken = NULL, BOOL bAck = TRUE);
00113 void PurgeToken(LPVOID pToken);
00114 void OnRun();
00115 protected:
00116 void Measure();
00117 BOOL TryWrite();
00118 void ManageOutput();
00119 void Remove(CDatagramOut* pDG);
00120 protected:
00121 BOOL TryRead();
00122 BOOL OnDatagram(SOCKADDR_IN* pHost, BYTE* pBuffer, DWORD nLength);
00123 BOOL OnReceiveSGP(SOCKADDR_IN* pHost, SGP_HEADER* pHeader, DWORD nLength);
00124 BOOL OnAcknowledgeSGP(SOCKADDR_IN* pHost, SGP_HEADER* pHeader, DWORD nLength);
00125 void ManagePartials();
00126 void Rerequest(CDatagramIn* pDG);
00127 void Remove(CDatagramIn* pDG, BOOL bReclaimOnly = FALSE);
00128 protected:
00129 BOOL OnPacket(SOCKADDR_IN* pHost, CG2Packet* pPacket);
00130 BOOL OnPing(SOCKADDR_IN* pHost, CG2Packet* pPacket);
00131 BOOL OnPong(SOCKADDR_IN* pHost, CG2Packet* pPacket);
00132 BOOL OnQuery(SOCKADDR_IN* pHost, CG2Packet* pPacket);
00133 BOOL OnQueryAck(SOCKADDR_IN* pHost, CG2Packet* pPacket);
00134 BOOL OnHit(SOCKADDR_IN* pHost, CG2Packet* pPacket);
00135 BOOL OnQueryKeyRequest(SOCKADDR_IN* pHost, CG2Packet* pPacket);
00136 BOOL OnQueryKeyAnswer(SOCKADDR_IN* pHost, CG2Packet* pPacket);
00137 BOOL OnPush(SOCKADDR_IN* pHost, CG2Packet* pPacket);
00138 BOOL OnCrawlRequest(SOCKADDR_IN* pHost, CG2Packet* pPacket);
00139 BOOL OnCrawlAnswer(SOCKADDR_IN* pHost, CG2Packet* pPacket);
00140
00141 };
00142
00143 extern CDatagrams Datagrams;
00144
00145 #endif // !defined(AFX_DATAGRAMS_H__289BAC8C_A04C_4CB6_A185_ED043CA21CDA__INCLUDED_)