-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink.h
137 lines (95 loc) · 2.14 KB
/
link.h
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
//
// Copyright (C) 2003-2004 Trevor Hogan
//
#ifndef LINK_H
#define LINK_H
#define LINK_VER "TrackerLINK Ver. 0.1"
#define LINKMSG_ERROR -1
#define LINKMSG_NONE 0 // not transmitted
#define LINKMSG_VERSION 1
#define LINKMSG_INFO 2
#define LINKMSG_PASSWORD 3
#define LINKMSG_READY 4
#define LINKMSG_ANNOUNCE 7
#define LINKMSG_CLOSE 99
struct linkmsg_t
{
long len;
int type;
string msg;
};
//
// CLink
// - one instance created on the secondary tracker to connect to the primary tracker
//
class CLink
{
public:
CLink( );
virtual ~CLink( );
void Kill( );
void Go( );
string getName( );
void Queue( struct linkmsg_t lm );
private:
bool m_bKill;
string m_strIP;
string m_strPass;
SOCKET m_sckLink;
struct sockaddr_in sin;
string m_strReceiveBuf;
string m_strSendBuf;
void Send( struct linkmsg_t lm );
struct linkmsg_t Receive( bool bBlock );
struct linkmsg_t Parse( );
CMutex m_mtxQueued;
vector<struct linkmsg_t> m_vecQueued;
};
void StartLink( );
//
// CLinkClient
// - one instance created on the primary tracker for each secondary tracker
//
class CLinkClient
{
public:
CLinkClient( SOCKET sckLink, struct sockaddr_in sinAddress );
virtual ~CLinkClient( );
void Kill( );
void Go( );
string getName( );
void Queue( struct linkmsg_t lm );
bool m_bActive;
private:
bool m_bKill;
SOCKET m_sckLink;
struct sockaddr_in sin;
string m_strReceiveBuf;
string m_strSendBuf;
void Send( struct linkmsg_t lm );
struct linkmsg_t Receive( bool bBlock );
struct linkmsg_t Parse( );
CMutex m_mtxQueued;
vector<struct linkmsg_t> m_vecQueued;
};
void StartLinkClient( CLinkClient *pLinkClient );
//
// CLinkServer
// - one instance created on the primary tracker
//
class CLinkServer
{
public:
CLinkServer( );
virtual ~CLinkServer( );
void Update( );
void Queue( struct linkmsg_t lm );
void Queue( struct linkmsg_t lm, string strExclude );
string m_strPass;
CMutex m_mtxLinks;
vector<CLinkClient *> m_vecLinks;
private:
string m_strBind;
SOCKET m_sckLinkServer;
};
#endif