File: ctcs.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 (95 lines) | stat: -rw-r--r-- 2,041 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
#ifndef CTCS_H
#define CTCS_H

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

#ifdef WINDOWS
#include <Winsock2.h>
#else
#include <unistd.h>
#include <netdb.h>   // Solaris defines MAXHOSTNAMELEN here.
#include <stdio.h>   // autoconf manual: Darwin + others prereq for stdlib.h
#include <stdlib.h>  // autoconf manual: Darwin prereq for sys/socket.h
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/param.h>
#endif

#include <inttypes.h>
#include <time.h>

#include "bufio.h"

#define CTCS_BUFSIZE (200+MAXPATHLEN)
#define CTCS_PASS_SIZE 21

struct ctstatus {
  size_t dlrate, ulrate, dlimit, ulimit;

  ctstatus(){
    dlrate=ulrate=dlimit=ulimit = 0;
  }
};

class Ctcs
{
 private:
  char m_host[MAXHOSTNAMELEN];
  int m_port;
  char m_pass[CTCS_PASS_SIZE];
  int m_protocol;

  struct sockaddr_in m_sin;

  unsigned char m_status:2;

  time_t m_interval;
  time_t m_last_timestamp;
  time_t m_sent_ctstatus_time;
  time_t m_statustime;

  SOCKET m_sock;
  BufIo in_buffer;
  BufIo out_buffer;
  struct ctstatus m_ctstatus;
  int m_sent_ctstatus;
  int m_sent_ctbw;

  int _s2sin(char *h,int p,struct sockaddr_in *psin);
  int SendMessage(const char *buf);
  char *ConfigMsg(const char *name, const char *type, const char *range,    
    const char *value, const char *short_desc, const char *long_desc);

 public:
  Ctcs();
  ~Ctcs();

  void Reset(time_t new_interval);
  int Initial();
  int Connect();
  int CheckMessage();
  int Send_Protocol();
  int Send_Auth();
  int Send_Torrent(const unsigned char *peerid, char *torrent);
  int Report_Status();
  int Send_Status();
  int Send_bw();
  int Send_Config();
  int Set_Config(const char *msgbuf);
  int Send_Detail();
  int Send_Peers();
  int Send_Info(int sev, const char *info);
  int IntervalCheck(fd_set *rfdp, fd_set *wfdp);
  int SocketReady(fd_set *rfdp, fd_set *wfdp, int *nfds,
    fd_set *rfdnextp, fd_set *wfdnextp);

  SOCKET GetSocket() { return m_sock; }
  unsigned char GetStatus() { return m_status;}
};

extern Ctcs CTCS;

#endif