Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 98929 | Differences between
and this patch

Collapse All | Expand All

(-)ctorrent-1.3.4/peer.cpp (-10 / +32 lines)
Lines 3-13 Link Here
3
#include <stdlib.h>
3
#include <stdlib.h>
4
#include <string.h>
4
#include <string.h>
5
5
6
#include "btstream.h"
6
#include "./btcontent.h"
7
#include "./btcontent.h"
7
#include "./msgencode.h"
8
#include "./msgencode.h"
8
#include "./peerlist.h"
9
#include "./peerlist.h"
9
#include "./btconfig.h"
10
#include "./btconfig.h"
10
11
12
size_t get_nl(char *sfrom)
13
{
14
  unsigned char *from = (unsigned char *)sfrom;
15
  size_t t;
16
  t = (*from++) << 24; 
17
  t |= (*from++) << 16; 
18
  t |= (*from++) << 8; 
19
  t |= *from; 
20
  return t;
21
}
22
23
void set_nl(char *sto, size_t from)
24
{
25
  unsigned char *to = (unsigned char *)sto;
26
  *to++ = (from >> 24) & 0xff;
27
  *to++ = (from >> 16) & 0xff;
28
  *to++ = (from >> 8) & 0xff;
29
  *to = from & 0xff;
30
}
31
11
btBasic Self;
32
btBasic Self;
12
33
13
void btBasic::SetIp(struct sockaddr_in addr)
34
void btBasic::SetIp(struct sockaddr_in addr)
Lines 152-158 Link Here
152
173
153
  char *msgbuf = stream.in_buffer.BasePointer();
174
  char *msgbuf = stream.in_buffer.BasePointer();
154
175
155
  r = ntohl(*(size_t*) msgbuf);
176
  r = get_nl(msgbuf);
177
156
178
157
  if( 0 == r ){
179
  if( 0 == r ){
158
    time(&m_last_timestamp);
180
    time(&m_last_timestamp);
Lines 193-199 Link Here
193
    case M_HAVE:
215
    case M_HAVE:
194
      if(H_HAVE_LEN != r){return -1;}
216
      if(H_HAVE_LEN != r){return -1;}
195
217
196
      idx = ntohl(*(size_t*) (msgbuf + 5));
218
      idx = get_nl(msgbuf + 5);
197
219
198
      if( idx >= BTCONTENT.GetNPieces() || bitfield.IsSet(idx)) return -1;
220
      if( idx >= BTCONTENT.GetNPieces() || bitfield.IsSet(idx)) return -1;
199
221
Lines 208-219 Link Here
208
    case M_REQUEST:
230
    case M_REQUEST:
209
      if(H_REQUEST_LEN != r || !m_state.remote_interested){ return -1; }
231
      if(H_REQUEST_LEN != r || !m_state.remote_interested){ return -1; }
210
232
211
      idx = ntohl(*(size_t*)(msgbuf + 5));
233
      idx = get_nl(msgbuf + 5);
212
      
234
      
213
      if( !BTCONTENT.pBF->IsSet(idx) ) return -1;
235
      if( !BTCONTENT.pBF->IsSet(idx) ) return -1;
214
      
236
      
215
      off = ntohl(*(size_t*)(msgbuf + 9));
237
      off = get_nl(msgbuf + 9);
216
      len = ntohl(*(size_t*)(msgbuf + 13));
238
      len = get_nl(msgbuf + 13);
217
239
218
      if( !reponse_q.IsValidRequest(idx, off, len) ) return -1;
240
      if( !reponse_q.IsValidRequest(idx, off, len) ) return -1;
219
      
241
      
Lines 235-243 Link Here
235
    case M_CANCEL:
257
    case M_CANCEL:
236
      if(r != H_CANCEL_LEN || !m_state.remote_interested) return -1;
258
      if(r != H_CANCEL_LEN || !m_state.remote_interested) return -1;
237
259
238
      idx = ntohl(*(size_t*)(msgbuf + 5));
260
      idx = get_nl(msgbuf + 5);
239
      off = ntohl(*(size_t*)(msgbuf + 9));
261
      off = get_nl(msgbuf + 9);
240
      len = ntohl(*(size_t*)(msgbuf + 13));
262
      len = get_nl(msgbuf + 13);
241
      if( reponse_q.Remove(idx,off,len) < 0 ){
263
      if( reponse_q.Remove(idx,off,len) < 0 ){
242
	m_err_count++;
264
	m_err_count++;
243
	return 0;
265
	return 0;
Lines 312-319 Link Here
312
  size_t idx,off,len;
334
  size_t idx,off,len;
313
  char *msgbuf = stream.in_buffer.BasePointer();
335
  char *msgbuf = stream.in_buffer.BasePointer();
314
336
315
  idx = ntohl(*(size_t*) (msgbuf + 5));
337
  idx = get_nl(msgbuf + 5);
316
  off = ntohl(*(size_t*) (msgbuf + 9));
338
  off = get_nl(msgbuf + 9);
317
  len = mlen - 9;
339
  len = mlen - 9;
318
340
319
  if( request_q.Remove(idx,off,len) < 0 ){
341
  if( request_q.Remove(idx,off,len) < 0 ){
(-)ctorrent-1.3.4/peer.h (+3 lines)
Lines 34-39 Link Here
34
  unsigned char reserved:4;		/* unused */
34
  unsigned char reserved:4;		/* unused */
35
}BTSTATUS;
35
}BTSTATUS;
36
36
37
size_t get_nl(char *from);
38
void set_nl(char *to, size_t from);
39
37
class btBasic
40
class btBasic
38
{
41
{
39
private:
42
private:
(-)ctorrent/btcontent.cpp (+1 lines)
Lines 226-231 Link Here
226
  if( m_btfiles.BuildFromMI(b, flen, saveas) < 0) ERR_RETURN();
226
  if( m_btfiles.BuildFromMI(b, flen, saveas) < 0) ERR_RETURN();
227
227
228
  delete []b;
228
  delete []b;
229
  b = (char *)0;
229
  PrintOut();
230
  PrintOut();
230
  
231
  
231
  if( arg_flg_exam_only ) return 0;
232
  if( arg_flg_exam_only ) return 0;
(-)ctorrent/iplist.cpp (-1 / +1 lines)
Lines 8-15 Link Here
8
  IPLIST *node = ipl_head;
8
  IPLIST *node = ipl_head;
9
  for(; ipl_head;){
9
  for(; ipl_head;){
10
    node = ipl_head;
10
    node = ipl_head;
11
    delete ipl_head;
12
    ipl_head = node->next;
11
    ipl_head = node->next;
12
    delete node;
13
  }
13
  }
14
  count = 0;
14
  count = 0;
15
}
15
}
(-)new.x86/httpencode.h (-2 / +2 lines)
Lines 2-9 Link Here
2
#define HTTPENCODE_H
2
#define HTTPENCODE_H
3
3
4
#define REQ_URL_P1_FMT "GET %s?info_hash=%s&peer_id=%s&port=%d"
4
#define REQ_URL_P1_FMT "GET %s?info_hash=%s&peer_id=%s&port=%d"
5
#define REQ_URL_P2_FMT "%s&uploaded=%d&downloaded=%d&left=%d&event=%s&compact=1 HTTP/1.0"
5
#define REQ_URL_P2_FMT "%s&uploaded=%llu&downloaded=%llu&left=%llu&event=%s&compact=1 HTTP/1.0"
6
#define REQ_URL_P3_FMT "%s&uploaded=%d&downloaded=%d&left=%d&compact=1 HTTP/1.0"
6
#define REQ_URL_P3_FMT "%s&uploaded=%llu&downloaded=%llu&left=%llu&compact=1 HTTP/1.0"
7
7
8
char* Http_url_encode(char *s,char *b,size_t n);
8
char* Http_url_encode(char *s,char *b,size_t n);
9
int Http_url_analyse(char *url,char *host,int *port,char *path);
9
int Http_url_analyse(char *url,char *host,int *port,char *path);
(-)new.x86/tracker.cpp (-6 / +6 lines)
Lines 360-377 Link Here
360
  if(event){
345
  if(event){
361
    if(MAXPATHLEN < snprintf(REQ_BUFFER,MAXPATHLEN,REQ_URL_P2_FMT,
346
    if(MAXPATHLEN < snprintf(REQ_BUFFER,MAXPATHLEN,REQ_URL_P2_FMT,
362
			     m_path,
347
			     m_path,
363
			     (size_t)Self.TotalUL(),
348
			     Self.TotalUL(),
364
			     (size_t)Self.TotalDL(),
349
			     Self.TotalDL(),
365
			     (size_t)BTCONTENT.GetLeftBytes(),
350
			     BTCONTENT.GetLeftBytes(),
366
			     event)){
351
			     event)){
367
      return -1;
352
      return -1;
368
    }
353
    }
369
  }else{
354
  }else{
370
    if(MAXPATHLEN < snprintf(REQ_BUFFER,MAXPATHLEN,REQ_URL_P3_FMT,
355
    if(MAXPATHLEN < snprintf(REQ_BUFFER,MAXPATHLEN,REQ_URL_P3_FMT,
371
			     m_path,
356
			     m_path,
372
			     (size_t)Self.TotalUL(),
357
			     Self.TotalUL(),
373
			     (size_t)Self.TotalDL(),
358
			     Self.TotalDL(),
374
			     (size_t)BTCONTENT.GetLeftBytes()
359
			     BTCONTENT.GetLeftBytes()
375
			     )){
360
			     )){
376
      return -1;
361
      return -1;
377
    }
362
    }
(-)ctorrent-1.3.4.orig/btfiles.cpp (-2 / +2 lines)
Lines 169-175 Link Here
169
  DIR *dp;
169
  DIR *dp;
170
  BTFILE *pbf;
170
  BTFILE *pbf;
171
171
172
  if( !getwd(full_cur) ) return -1;
172
  if( !getcwd(full_cur, MAXPATHLEN) ) return -1;
173
173
174
  if( cur_path ){
174
  if( cur_path ){
175
    strcpy(fn, full_cur);
175
    strcpy(fn, full_cur);
Lines 293-299 Link Here
293
    m_btfhead = pbf;
293
    m_btfhead = pbf;
294
  }else if( S_IFDIR & sb.st_mode ){
294
  }else if( S_IFDIR & sb.st_mode ){
295
    char wd[MAXPATHLEN];
295
    char wd[MAXPATHLEN];
296
    if( !getwd(wd) ) return -1;
296
    if( !getcwd(wd, MAXPATHLEN) ) return -1;
297
    m_directory = new char[strlen(pathname) + 1];
297
    m_directory = new char[strlen(pathname) + 1];
298
#ifndef WINDOWS
298
#ifndef WINDOWS
299
    if( !m_directory ) return -1;
299
    if( !m_directory ) return -1;
(-)ctorrent-1.3.4.orig/configure.ac (-1 / +1 lines)
Lines 32-37 Link Here
32
AC_FUNC_MEMCMP
32
AC_FUNC_MEMCMP
33
AC_TYPE_SIGNAL
33
AC_TYPE_SIGNAL
34
AC_FUNC_STAT
34
AC_FUNC_STAT
35
AC_CHECK_FUNCS([ftruncate gethostbyname gettimeofday getwd inet_ntoa memchr memmove memset mkdir select socket strchr strerror strncasecmp strstr strtol strnstr])
35
AC_CHECK_FUNCS([ftruncate gethostbyname gettimeofday getcwd inet_ntoa memchr memmove memset mkdir select socket strchr strerror strncasecmp strstr strtol strnstr])
36
36
37
AC_OUTPUT(Makefile)
37
AC_OUTPUT(Makefile)
(-)ctorrent/peer.cpp (-1 / +2 lines)
Lines 252-258 Link Here
252
      if( (r - 1) != bitfield.NBytes() || !bitfield.IsEmpty()) return -1;
252
      if( (r - 1) != bitfield.NBytes() || !bitfield.IsEmpty()) return -1;
253
      bitfield.SetReferBuffer(msgbuf + 5);
253
      bitfield.SetReferBuffer(msgbuf + 5);
254
      if(bitfield.IsFull() && BTCONTENT.pBF->IsFull()) return -2;
254
      if(bitfield.IsFull() && BTCONTENT.pBF->IsFull()) return -2;
255
      return 0;
255
256
      return RequestCheck();
256
257
257
    case M_CANCEL:
258
    case M_CANCEL:
258
      if(r != H_CANCEL_LEN || !m_state.remote_interested) return -1;
259
      if(r != H_CANCEL_LEN || !m_state.remote_interested) return -1;
(-)ctorrent/peerlist.cpp (-1 / +3 lines)
Lines 495-501 Link Here
495
	if(peer->GetStatus() == P_HANDSHAKE){
496
	if(peer->GetStatus() == P_HANDSHAKE){
496
	  if( peer->HandShake() < 0 ) peer->CloseConnection();
497
	  if( peer->HandShake() < 0 ) peer->CloseConnection();
497
	}else{
498
	}else{
498
	  if( peer->RecvModule() < 0 ) peer->CloseConnection();
499
	  if(peer->GetStatus() == P_SUCCESS) {
500
	    if( peer->RecvModule() < 0 ) peer->CloseConnection();
501
	  }
499
	}
502
	}
500
      }else if(PEER_IS_SUCCESS(peer) && FD_ISSET(sk,wfdp)){
503
      }else if(PEER_IS_SUCCESS(peer) && FD_ISSET(sk,wfdp)){
501
	p->click++;
504
	p->click++;
(-)ctorrent-1.3.4/ctorrent.cpp (-1 / +5 lines)
Lines 87-95 Link Here
87
	Tracker.Initial();
87
	Tracker.Initial();
88
88
89
	signal(SIGPIPE,SIG_IGN);
89
	signal(SIGPIPE,SIG_IGN);
90
    signal(SIGINT,sigint_catch);
90
    signal(SIGINT,sig_catch);
91
    signal(SIGTERM,sig_catch);
91
    Downloader();
92
    Downloader();
92
  }
93
  }
94
  if( cfg_cache_size ) BTCONTENT.FlushCache();
95
  if( arg_bitfield_file ) BTCONTENT.pBF->WriteToFile(arg_bitfield_file);
96
  WORLD.CloseAll();
93
97
94
  exit(0);
98
  exit(0);
95
}
99
}
(-)ctorrent-1.3.4/downloader.cpp (-3 / +3 lines)
Lines 30-38 Link Here
30
  fd_set rfd;
30
  fd_set rfd;
31
  fd_set wfd;
31
  fd_set wfd;
32
32
33
  for(;;){
33
  do{
34
    time(&now);
34
    time(&now);
35
    if( BTCONTENT.SeedTimeout(&now) ) break;
35
    if( BTCONTENT.SeedTimeout(&now) ) Tracker.SetStoped();
36
    
36
    
37
    FD_ZERO(&rfd); FD_ZERO(&wfd);
37
    FD_ZERO(&rfd); FD_ZERO(&wfd);
38
    maxfd = Tracker.IntervalCheck(&now,&rfd, &wfd);
38
    maxfd = Tracker.IntervalCheck(&now,&rfd, &wfd);
Lines 48-52 Link Here
48
      if(T_FREE != Tracker.GetStatus()) Tracker.SocketReady(&rfd,&wfd,&nfds);
48
      if(T_FREE != Tracker.GetStatus()) Tracker.SocketReady(&rfd,&wfd,&nfds);
49
	  if( nfds ) WORLD.AnyPeerReady(&rfd,&wfd,&nfds);
49
	  if( nfds ) WORLD.AnyPeerReady(&rfd,&wfd,&nfds);
50
	}
50
	}
51
  }/* end for(;;) */
51
  } while(Tracker.GetStatus() != T_FINISHED);
52
}
52
}
(-)ctorrent-1.3.4/sigint.cpp (-4 / +14 lines)
Lines 4-20 Link Here
4
#include <signal.h>
4
#include <signal.h>
5
5
6
#include "btcontent.h"
6
#include "btcontent.h"
7
#include "tracker.h"
7
#include "peerlist.h"
8
#include "peerlist.h"
8
#include "btconfig.h"
9
#include "btconfig.h"
10
#include "sigint.h"
9
11
10
void sigint_catch(int sig_no)
12
void sig_catch(int sig_no)
11
{
13
{
12
  if(SIGINT == sig_no){
14
  if(SIGINT == sig_no || SIGTERM == sig_no){
15
    Tracker.SetStoped();
16
    signal(sig_no,sig_catch2);
17
  }
18
}
19
20
static void sig_catch2(int sig_no)
21
{
22
  if(SIGINT == sig_no || SIGTERM == sig_no){
13
    if( cfg_cache_size ) BTCONTENT.FlushCache();
23
    if( cfg_cache_size ) BTCONTENT.FlushCache();
14
    if( arg_bitfield_file ) BTCONTENT.pBF->WriteToFile(arg_bitfield_file);
24
    if( arg_bitfield_file ) BTCONTENT.pBF->WriteToFile(arg_bitfield_file);
15
    WORLD.CloseAll();
25
    WORLD.CloseAll();
16
    signal(SIGINT,SIG_DFL);
26
    signal(sig_no,SIG_DFL);
17
    raise(SIGINT);
27
    raise(sig_no);
18
  }
28
  }
19
}
29
}
20
30
(-)ctorrent-1.3.4/sigint.h (-1 / +2 lines)
Lines 2-8 Link Here
2
#define SIGINT_H
2
#define SIGINT_H
3
3
4
#ifndef WINDOWS
4
#ifndef WINDOWS
5
void sigint_catch(int sig_no);
5
void sig_catch(int sig_no);
6
static void sig_catch2(int sig_no);
6
#endif
7
#endif
7
8
8
#endif
9
#endif
(-)ctorrent-1.3.4/tracker.cpp (-11 / +12 lines)
Lines 31-37 Link Here
31
  m_sock = INVALID_SOCKET;
31
  m_sock = INVALID_SOCKET;
32
  m_port = 80;
32
  m_port = 80;
33
  m_status = T_FREE;
33
  m_status = T_FREE;
34
  m_f_started = m_f_stoped = m_f_pause = 0;
34
  m_f_started = m_f_stoped = m_f_pause = m_f_completed = 0;
35
  m_interval = 15;
35
  m_interval = 15;
36
36
37
  m_connect_refuse_click = 0;
37
  m_connect_refuse_click = 0;
Lines 54-60 Link Here
54
  
54
  
55
  m_reponse_buffer.Reset();
55
  m_reponse_buffer.Reset();
56
  time(&m_last_timestamp);
56
  time(&m_last_timestamp);
57
  m_status = T_FREE;
57
  if (m_f_stoped) m_status = T_FINISHED;
58
  else m_status = T_FREE;
58
}
59
}
59
60
60
int btTracker:: _IPsin(char *h, int p, struct sockaddr_in *psin)
61
int btTracker:: _IPsin(char *h, int p, struct sockaddr_in *psin)
Lines 329-342 Link Here
329
//  fprintf(stdout,"Old Set Self:");
332
//  fprintf(stdout,"Old Set Self:");
330
//  fprintf(stdout,"%s\n", inet_ntoa(Self.m_sin.sin_addr));
333
//  fprintf(stdout,"%s\n", inet_ntoa(Self.m_sin.sin_addr));
331
334
332
  if( m_f_stoped )	/* stopped */
335
  if( m_f_stoped )
333
    event = str_event[1];
336
    event = str_event[1];	/* stopped */
334
  else if( BTCONTENT.pBF->IsFull())	/* download complete */
337
  else if( m_f_started == 0 )
335
    event = str_event[2];
336
  else if( m_f_started ) 	/* interval */
337
    event = (char*) 0;
338
  else
339
    event = str_event[0];	/* started */
338
    event = str_event[0];	/* started */
339
  else if( BTCONTENT.pBF->IsFull() && !m_f_completed){
340
    event = str_event[2];	/* download complete */
341
    m_f_completed = 1;		/* only send download complete once */
342
  } else
343
    event = (char*) 0;  /* interval */
340
344
341
  if(event){
345
  if(event){
342
    if(MAXPATHLEN < snprintf(REQ_BUFFER,MAXPATHLEN,REQ_URL_P2_FMT,
346
    if(MAXPATHLEN < snprintf(REQ_BUFFER,MAXPATHLEN,REQ_URL_P2_FMT,
Lines 380-387 Link Here
380
{
390
{
381
  /* tracker communication */
391
  /* tracker communication */
382
  if( T_FREE == m_status ){
392
  if( T_FREE == m_status ){
383
    if((*pnow - m_last_timestamp >= m_interval) &&
393
    if(*pnow - m_last_timestamp >= m_interval){
384
       (cfg_min_peers > WORLD.TotalPeers())){
385
   
394
   
386
      if(Connect() < 0){ Reset(15); return -1; }
395
      if(Connect() < 0){ Reset(15); return -1; }
387
    
396
    
(-)ctorrent-1.3.4/tracker.h (-1 / +5 lines)
Lines 21-26 Link Here
21
#define T_FREE 		0
21
#define T_FREE 		0
22
#define T_CONNECTING	1
22
#define T_CONNECTING	1
23
#define T_READY		2
23
#define T_READY		2
24
#define T_FINISHED	3
24
25
25
class btTracker
26
class btTracker
26
{
27
{
Lines 34-42 Link Here
34
  unsigned char m_status:2;
35
  unsigned char m_status:2;
35
  unsigned char m_f_started:1;
36
  unsigned char m_f_started:1;
36
  unsigned char m_f_stoped:1;
37
  unsigned char m_f_stoped:1;
38
  unsigned char m_f_completed:1;
37
39
38
  unsigned char m_f_pause:1;
40
  unsigned char m_f_pause:1;
39
  unsigned char m_f_reserved:3;
41
  unsigned char m_f_reserved:2;
40
42
41
43
42
  time_t m_interval;		// ÓëTrackerͨÐŵÄʱ¼ä¼ä¸ô
44
  time_t m_interval;		// ÓëTrackerͨÐŵÄʱ¼ä¼ä¸ô
Lines 66-71 Link Here
66
  void SetPause() { m_f_pause = 1; }
68
  void SetPause() { m_f_pause = 1; }
67
  void ClearPause() { m_f_pause = 0; }
69
  void ClearPause() { m_f_pause = 0; }
68
70
71
  void SetStoped() { Reset(15); m_f_stoped = 1;}
72
69
  int Connect();
73
  int Connect();
70
  int SendRequest();
74
  int SendRequest();
71
  int CheckReponse();
75
  int CheckReponse();

Return to bug 98929