aboutsummaryrefslogtreecommitdiffstats
path: root/net-p2p/verlihub/files/patch-thublink
blob: 6ac4036c56b7677617a8d590bab797d6ef9013c5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
Index: casyncconn.cpp
===================================================================
RCS file: /cvsroot/verlihub/verlihub/src/casyncconn.cpp,v
retrieving revision 1.89
diff -u -r1.89 casyncconn.cpp
--- src/casyncconn.cpp  12 Sep 2005 21:28:50 -0000  1.89
+++ src/casyncconn.cpp  17 Jun 2006 21:27:43 -0000
@@ -94,33 +94,13 @@
    mType(ct)
 {
    mMaxBuffer=MAX_SEND_SIZE;
-   struct sockaddr saddr;
-   struct sockaddr_in *addr_in;
-   socklen_t addr_size;
-
-   addr_size = sizeof(saddr);
-   unsigned int addr;
-
    mIp=0;
    ClearLine();
    mBufEnd = mBufReadPos = 0;
    mRegFlag = 0;
    if(mSockDesc)
    {
-       if(0 > getpeername(mSockDesc, &saddr, &addr_size))
-       {
-           if(Log(2)) LogStream() << "Error getting peername, closing" << endl;
-           CloseNow();
-       }
-       addr_in = (struct sockaddr_in *)&saddr;
-       // copy IP
-       addr = mIp = addr_in->sin_addr.s_addr;
-       // asci ip addr
-       mAddrIP = inet_ntoa(addr_in->sin_addr);
-       // host name
-       if( mxServer && mxServer->mUseDNS ) DNSLookup();
-       // port number
-       mAddrPort=addr_in->sin_port;
+       FetchSockAddr();
    }
    memset (&mCloseAfter,0, sizeof(mCloseAfter));
 }
@@ -168,6 +148,32 @@
    this->Close();
 }
 
+/** Fetch IP addr from socket */
+void cAsyncConn::FetchSockAddr()
+{
+   struct sockaddr saddr;
+   struct sockaddr_in *addr_in;
+   socklen_t addr_size;
+
+   addr_size = sizeof(saddr);
+   unsigned int addr;
+
+   if(0 > getpeername(mSockDesc, &saddr, &addr_size))
+   {
+       if(Log(2)) LogStream() << "Error getting peername, closing" << endl;
+       CloseNow();
+   }
+   addr_in = (struct sockaddr_in *)&saddr;
+   // copy IP
+   addr = mIp = addr_in->sin_addr.s_addr;
+   // asci ip addr
+   mAddrIP = inet_ntoa(addr_in->sin_addr);
+   // host name
+   if( mxServer && mxServer->mUseDNS ) DNSLookup();
+   // port number
+   mAddrPort=addr_in->sin_port;
+}
+
 /** close connection to peer */
 void cAsyncConn::Close()
 {
@@ -270,6 +276,7 @@
 /** immediately close the connection */
 void cAsyncConn::CloseNow()
 {
+   OnCloseNow();
    mWritable = false;
    ok = false;
    if(mxServer) mxServer->mConnChooser.cConnChoose::OptOut((cConnBase*)this, cConnChoose::eCC_ALL);
@@ -483,6 +490,8 @@
            return -1;
        }
        ok=true;
+       /* Fetch socket info */
+       FetchSockAddr();
        return 0;
    }
    else
@@ -849,6 +858,9 @@
 /** function called before closing nicely */
 int cAsyncConn::OnCloseNice(void) { return 0; }
 
+/** function called before closing now */
+int cAsyncConn::OnCloseNow(void) { return 0; }
+
 cMessageParser *cAsyncConn::CreateParser()
 {
    if (this->mxProtocol != NULL)
Index: cconndc.cpp
===================================================================
RCS file: /cvsroot/verlihub/verlihub/src/cconndc.cpp,v
retrieving revision 1.63
diff -u -r1.63 cconndc.cpp
--- src/cconndc.cpp 4 Oct 2005 19:47:38 -0000   1.63
+++ src/cconndc.cpp 17 Jun 2006 21:27:43 -0000
@@ -359,7 +359,13 @@
        IPMax = cBanList::Ip2Num(mServer->mC.ip_zone6_max);
        if( (IPMin <= IPConn) && (IPMax >= IPConn)) conn->mGeoZone = 6;
    }
+
    conn->mxProtocol = mProtocol;
+
+   conn->mDCIterator = 
+       mServer->mDCConnList.insert(mServer->mDCConnList.begin(),
+                                                               conn);
+
    return (cAsyncConn*) conn;
 }
 
@@ -386,6 +392,20 @@
        mServer->mCallBacks.mOnCloseConn.CallAll(conn);
        #endif
    }
+
+   cConnDC::tCLIt it = conn->mDCIterator;
+   cAsyncConn *found=(*it);
+   if( (it ==  mServer->mDCConnList.end()) || (found != conn) )
+   {
+       cout << "not found " << conn << endl;
+       throw "Trying to delete non-existent connection";
+   }
+
+   //cout << "Deleting connection on socket: " << old_conn->mSockDesc << endl;
+   mServer->mDCConnList.erase(it);
+   cConnDC::tCLIt emptyit;
+   conn->mDCIterator = emptyit;
+   
    cConnFactory::DeleteConn(Conn);
 }
 
Index: cserverdc.cpp
===================================================================
RCS file: /cvsroot/verlihub/verlihub/src/cserverdc.cpp,v
retrieving revision 1.235
diff -u -r1.235 cserverdc.cpp
--- src/cserverdc.cpp   8 Nov 2005 07:51:23 -0000   1.235
+++ src/cserverdc.cpp   17 Jun 2006 21:27:44 -0000
@@ -505,7 +505,7 @@
    }
 
    int count=0;
-   for(i=mConnList.begin(); i!= mConnList.end(); i++)
+   for(i=mDCConnList.begin(); i!= mDCConnList.end(); i++)
    {
        conn=(cConnDC *)(*i);
        if(conn && conn->ok && conn->mWritable && conn->mpUser && conn->mpUser->mInList)
@@ -529,7 +529,7 @@
    cConnDC *conn;
    tCLIt i;
    int counter = 0;
-   for(i=mConnList.begin(); i!= mConnList.end(); i++)
+   for(i=mDCConnList.begin(); i!= mDCConnList.end(); i++)
    {
        conn=(cConnDC *)(*i);
        if(
@@ -555,7 +555,7 @@
    cConnDC *conn;
    tCLIt i;
    int counter = 0;
-   for(i=mConnList.begin(); i!= mConnList.end(); i++)
+   for(i=mDCConnList.begin(); i!= mDCConnList.end(); i++)
    {
        conn=(cConnDC *)(*i);
        if(
@@ -579,6 +579,9 @@
 /** return negative if conn should be removed */
 int cServerDC::OnNewConn(cAsyncConn *nc)
 {
+   if(string(nc->mClassName) != string("ConnDC"))
+       return 0;
+
    cConnDC *conn = (cConnDC *)nc;
    stringstream errmsg,os;
    if(!conn) return -1;
@@ -925,7 +928,7 @@
 /** return true if accept is allowed - override */
 bool cServerDC::AllowNewConn()
 {
-   return mConnList.size() <= (unsigned) mC.max_users_total + mC.max_extra_regs + mC.max_extra_vips + mC.max_extra_ops + mC.max_extra_cheefs + mC.max_extra_admins + 300;
+   return mDCConnList.size() <= (unsigned) mC.max_users_total + mC.max_extra_regs + mC.max_extra_vips + mC.max_extra_ops + mC.max_extra_cheefs + mC.max_extra_admins + 300;
 }
 
 int cServerDC::SaveFile(const string &file, const string &text)
@@ -1280,6 +1283,7 @@
        delete work;
        return 0;
    }
+   return true;
 }
 
 /** No descriptions */
Index: casyncconn.h
===================================================================
RCS file: /cvsroot/verlihub/verlihub/src/casyncconn.h,v
retrieving revision 1.50
diff -u -r1.50 casyncconn.h
--- src/casyncconn.h    4 Sep 2005 19:37:06 -0000   1.50
+++ src/casyncconn.h    17 Jun 2006 21:27:44 -0000
@@ -92,6 +92,8 @@
    cAsyncConn(int sd=0, cAsyncSocketServer *s=NULL, tConnType ct= eCT_CLIENT);
    cAsyncConn(const string & host, int port, bool udp=false);
    virtual ~cAsyncConn();
+   /** fetch IP addr from connection */
+   void FetchSockAddr();
    /** close connection to peer */
    void Close();
    /** flush as much from output buffer as possible to the iochannel */
@@ -115,6 +117,8 @@
    /** time to close the connection */
    cTime mCloseAfter;
 
+public:
+   /* Anyone know, why we should do this private ??? */
    typedef list<cAsyncConn*> tConnList;
    typedef tConnList::iterator tCLIt;
    
@@ -183,6 +187,8 @@
    tSocket AcceptSock();
    /** function called before closing nicely */
    virtual int OnCloseNice(void);
+   /** function called before closing now */
+   virtual int OnCloseNow(void);
    /** for udp */
    struct sockaddr_in mAddrIN;
    
@@ -195,7 +201,7 @@
    const string & AddrIP(){return mAddrIP;}
    const string & AddrHost(){return mAddrHost;}
    const int AddrPort(){return mAddrPort;}
-   const unsigned long GetSockAddress() { return mAddrIN.sin_addr.s_addr; }
+   const unsigned long GetSockAddress() { return (mType == eCT_CLIENTUDP)?mAddrIN.sin_addr.s_addr:mIp; }
    
    /** reads all available data from the socket and stores it into a static member buffer */
    int ReadAll();
Index: casyncsocketserver.h
===================================================================
RCS file: /cvsroot/verlihub/verlihub/src/casyncsocketserver.h,v
retrieving revision 1.27
diff -u -r1.27 casyncsocketserver.h
--- src/casyncsocketserver.h    21 Dec 2004 12:48:46 -0000  1.27
+++ src/casyncsocketserver.h    17 Jun 2006 21:27:44 -0000
@@ -96,6 +96,12 @@
    cTime mTime;
    //
    cMeanFrequency<unsigned ,21> mFrequency;
+
+   /* I don't know, why we should make this protected */
+   /** add given connection to server */
+   virtual void addConnection(cAsyncConn *);
+   /** remove given connection from server */
+   void delConnection(cAsyncConn * );
 protected: // Protected attributes
    /** indicates whether the loop should run or not */
    bool mbRun;
@@ -117,10 +123,6 @@
    static bool WSinitialized;
    cConnFactory *mFactory;
 protected: // Protected methods
-   /** add given connection to server */
-   virtual void addConnection(cAsyncConn *);
-   /** remove given connection from server */
-   void delConnection(cAsyncConn * );
    /** perform input operation, read all data from the connection, return number of bytes read, return negative number, if error occured */
    virtual int input(cAsyncConn *conn);
    /** perform output operation */
Index: cconndc.h
===================================================================
RCS file: /cvsroot/verlihub/verlihub/src/cconndc.h,v
retrieving revision 1.41
diff -u -r1.41 cconndc.h
--- src/cconndc.h   12 Sep 2005 21:28:50 -0000  1.41
+++ src/cconndc.h   17 Jun 2006 21:27:44 -0000
@@ -130,6 +130,7 @@
 class cConnDC : public cAsyncConn
 {
    friend class nProtocol::cDCProto;
+   friend class cDCConnFactory;
 public:
    cConnDC(int sd=0, cAsyncSocketServer *server=NULL);
    virtual ~cConnDC();
@@ -219,6 +220,10 @@
    };
    sTimes mT;
    int mSRCounter;
+
+   // DC++ type connections iterator
+   tCLIt   mDCIterator;
+   
 protected: // Protected methods
    /** function called before closing nicely */
    int OnCloseNice();
Index: cserverdc.h
===================================================================
RCS file: /cvsroot/verlihub/verlihub/src/cserverdc.h,v
retrieving revision 1.111
diff -u -r1.111 cserverdc.h
--- src/cserverdc.h 14 Sep 2005 20:20:28 -0000  1.111
+++ src/cserverdc.h 17 Jun 2006 21:27:44 -0000
@@ -329,6 +329,11 @@
    cTimeOut mHublistTimer;
    cTimeOut mReloadcfgTimer;
    cVHPluginMgr mPluginManager;
+
+protected:
+   // Protected attributes :D
+   tConnList   mDCConnList;
+
 private:
    struct sCallBacks
    {