File: peerlist.h

package info (click to toggle)
ctorrent 1.3.4.dnh3.3.2-5
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 1,240 kB
  • sloc: cpp: 13,161; sh: 675; ansic: 383; makefile: 6
file content (127 lines) | stat: -rw-r--r-- 3,700 bytes parent folder | download | duplicates (3)
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
#ifndef PEERLIST_H
#define PEERLIST_H

#include "./def.h"
#include <sys/types.h>
#include <time.h>

#include "./peer.h"
#include "./rate.h"

typedef struct _peernode{
  btPeer *peer;
  struct _peernode *next;
}PEERNODE;

class PeerList
{
 private:
  SOCKET m_listen_sock;
  PEERNODE *m_head, *m_dead;
  size_t m_peers_count, m_seeds_count, m_conn_count, m_downloads;
  size_t m_max_unchoke;
  time_t m_unchoke_check_timestamp, m_keepalive_check_timestamp,
         m_last_progress_timestamp, m_opt_timestamp, m_interval_timestamp;
  time_t m_unchoke_interval, m_opt_interval;
  size_t m_defer_count, m_missed_count, m_upload_count, m_up_opt_count;
  size_t m_dup_req_pieces;
  int m_prev_limit_up;
  char m_listen[22];

  unsigned char m_ul_limited:1;
  unsigned char m_f_pause:1;
  unsigned char m_f_limitd:1;
  unsigned char m_f_limitu:1;
  unsigned char m_f_dlate:1;
  unsigned char m_f_ulate:1;
  unsigned char m_endgame:1;
  unsigned char m_reserved:1;
  
  int Accepter();
  int UnChokeCheck(btPeer* peer,btPeer *peer_array[]);
  int FillFDSet(fd_set *rfd, fd_set *wfd, int f_keepalive_check,
    int f_unchoke_check, btPeer **UNCHOKER);
  
 public:
  PeerList();
  ~PeerList();

  // TotalPeers() is now GetPeersCount() for consistency
  int Initial_ListenPort();
  const char *GetListen() const { return m_listen; }

  int IsEmpty() const { return m_peers_count ? 0 : 1; }


  void PrintOut() const;

  int NewPeer(struct sockaddr_in addr, SOCKET sk);

  void CloseAllConnectionToSeed();
  void CloseAll();

  int IntervalCheck(fd_set *rfd, fd_set *wfd);

  void SetUnchokeIntervals();
  void AnyPeerReady(fd_set *rfdp, fd_set *wfdp, int *nready,
    fd_set *rfdnextp, fd_set *wfdnextp);

  int BandWidthLimitUp() { return BandWidthLimitUp(0); }
  int BandWidthLimitUp(double when);
  int BandWidthLimitUp(double when, int limit);
  int BandWidthLimitDown() { return BandWidthLimitDown(0); }
  int BandWidthLimitDown(double when);
  int BandWidthLimitDown(double when, int limit);
  double WaitBW() const;
  void DontWaitBW() { Self.OntimeUL(0); Self.OntimeDL(0); }

  void Tell_World_I_Have(size_t idx);
  btPeer* Who_Can_Abandon(btPeer *proposer);
  size_t What_Can_Duplicate(BitField &bf, const btPeer *proposer, size_t idx);
  void FindValuedPieces(BitField &bf, const btPeer *proposer, int initial)
    const;
  btPeer *WhoHas(size_t idx) const;
  int HasSlice(size_t idx, size_t off, size_t len) const;
  void CompareRequest(btPeer *proposer, size_t idx);
  int CancelSlice(size_t idx, size_t off, size_t len);
  int CancelPiece(size_t idx);
  void CancelOneRequest(size_t idx);

  void CheckBitField(BitField &bf);
  int AlreadyRequested(size_t idx) const;
  size_t Pieces_I_Can_Get() const;
  size_t Pieces_I_Can_Get(BitField *ptmpBitField) const;
  void CheckInterest();
  btPeer* GetNextPeer(btPeer *peer) const;
  int Endgame();
  void UnStandby();

  size_t GetDupReqs() const { return m_dup_req_pieces; }
  void RecalcDupReqs();

  size_t GetSeedsCount() const { return m_seeds_count; }
  size_t GetPeersCount() const { return m_peers_count; }
  size_t GetConnCount() const { return m_conn_count; }
  void AdjustPeersCount();  // passthrough to tracker function

  size_t GetUnchoked() const;
  size_t GetSlowestUp(size_t minimum) const;
  size_t GetDownloads() const { return m_downloads; }
  size_t GetUnchokeInterval() const { return m_unchoke_interval; }

  void Defer() { m_defer_count++; }
  void Upload() { m_upload_count++; }

  int IsIdle();
  void UnLate() { m_f_dlate = m_f_ulate = 0; }
  void Pause();
  void Resume();
  int IsPaused() const { return m_f_pause ? 1 : 0; }
  void StopDownload();

  void UnchokeIfFree(btPeer *peer);
};

extern PeerList WORLD;

#endif