00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _BALSER_H
00022 #define _BALSER_H
00023
00024 #include <cabal.h>
00025
00026 #define DEFAULT_PORT 2051
00027 #define CHANNEL_BANDWIDTH 8096
00028 #define LINE_BANDWITH 2048
00029 #define START_CONNECT 0xf3f0f1f2
00030 #define END_CONNECT 0xf9f8f7f1
00031 #define CLIENT_REP_SIZE 16
00032
00033 using namespace std;
00034 using namespace Cabal;
00035
00036
00037
00038
00039
00040
00041
00042 typedef struct tag_packet {
00043 unsigned long userId;
00044 unsigned long id;
00045 unsigned long timestamp;
00046 char data[512 - (3 * sizeof( unsigned long ))];
00047 } PACKET;
00048
00049 #define REQ_TYPE_ACK 1
00050 #define REQ_TYPE_RESEND 2
00051
00052 typedef struct tag_clireq
00053 {
00054 unsigned char type;
00055 unsigned long value;
00056 }CLI_REQ;
00057
00058
00059
00060
00061
00062
00063 class Client
00064 {
00065 public:
00066 MSECS m_lastHail;
00067 Line *m_comLine;
00068 unsigned long m_userId;
00069 unsigned long m_rtt;
00070 unsigned long m_packetId;
00071
00072
00073 Client( unsigned long id, Line *line ) {
00074 m_userId = id;
00075 m_comLine = line;
00076 m_lastHail = Net::timeOfDay();
00077 m_rtt = 0xFFFF;
00078 }
00079
00080 ~Client() { delete m_comLine; }
00081 };
00082
00083 typedef map<unsigned long, Client *> ClientHash;
00084
00085
00086
00087
00088
00089 class DflTransmit: public Transmission
00090 {
00091 unsigned long m_packetId;
00092 unsigned long m_size;
00093
00094 Address m_dest;
00095 Priority m_prio;
00096 unsigned long m_userId;
00097 std::list<unsigned long> m_resend;
00098
00099 public:
00100 DflTransmit( unsigned long userId, unsigned long length, const Address &dest, Priority prio )
00101 {
00102 m_dest = dest;
00103 m_prio = prio;
00104 m_size = length;
00105 m_packetId = 0;
00106
00107
00108
00109
00110 m_userId = userId;
00111 }
00112
00113 virtual void init( Connection *con ) {}
00114 virtual bool transmit( Connection *con );
00115 virtual void terminate( Connection *con ) { }
00116
00117 void resend( unsigned long id ) {
00118 m_resend.push_back( id );
00119 }
00120 };
00121
00122
00123
00124
00125
00126
00127
00128
00129 class DflReception: public Reception
00130 {
00131
00132 public:
00133 DflReception() {
00134 }
00135
00136 virtual void init( Socket *skt ) {}
00137 virtual bool receive( Socket *skt );
00138 virtual void terminate( Socket *skt ) {}
00139
00140 };
00141
00142 #endif
00143
00144