forked from DNSPod/dnspod-sr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
author.h
176 lines (148 loc) · 3.83 KB
/
author.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
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
/* Copyright (c) 2006-2012, DNSPod Inc.
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of the FreeBSD Project.
*/
#ifndef _AUTHOR_H
#define _AUTHOR_H
#include "io.h"
enum
{
FETCHER_NUM = 2,
SERVER_PORT = 53,
};
enum
{
QUIZZER_NUM = 2,
};
enum
{
NEW_QUERY = 0,
PROCESS_QUERY = 1,
TTL_UPDATE = 3,
};
#define SRV_ADDR ("127.0.0.1")
enum
{
//MAX_TRY_TIMES = 15,
REFRESH_INTERVAL = 10,
AUTH_DB_NUM = 101,
BIG_MEM_STEP = 2000,
RANDOM_SIZE = 3000,
ID_SPACE = 60000,
AUTH_DATA_LEN = 65528, //for meta data
EP_TCP_FDS = 65530,
};
enum
{
LIST_SPACE = 10000,
};
struct author
{
int audp, //read and send auth server, private
cudp, //send to client, share with other author
idx;
struct server *s;
pthread_mutex_t lock;//protect list above
struct qoutinfo *list[LIST_SPACE];
//statis
int qnum;
int response;
int qidx;
int timex;
////
struct list *el;
time_t lastlog;
int bdepfd,logfd;
pthread_mutex_t dblock[AUTH_DB_NUM]; //protect db in disk
uchar databuffer[AUTH_DATA_LEN];
uchar randombuffer[RANDOM_SIZE];
int rndidx;//no lock
int dataidx;//no lock
uchar ip[IP_DATA_LEN];//shared by all qoutinfos
int eptcpfds[EP_TCP_FDS];
uint rdb;//records in db
int ddbefore;
int underattack;
int tcpinuse;
struct htable *fwd;
struct htable *ds;
int dupbefore; //only used in main thread
int limits; //only used in main thread
int hsidx;
//statistics
uint quizz;
uint drop;
uint timeout;
};
struct fetcher
{
int idx;
struct server *s;
struct msgcache *mc;
struct list *el;
int logfd;
time_t lastlog;
uchar databuffer[65536];
int dataidx;
int qidx;
//statistics
uint pkg;
uint send;
uint miss;
};
struct server
{
ushort nquizzer,nfetcher;
int ludp,ltcp; //out udp
struct fetcher *fetchers;
struct author *authors;
struct list eventlist;
struct htable *datasets;
struct htable *forward;
//struct htable *rootz;
struct htable *qlist; //same domain same type only query once.
ulong pkg;
uchar logpath[255];
ulong recordsindb;
struct rbtree *ttlexp;
//pthread_mutex_t lock;//protect ttlexp
uint16_t refreshflag;
time_t lastrefresh;
};
struct seninfo
{
uint len;
uint type;
union
{
int fd;
struct sockaddr_in addr;
};
};
void* run_quizzer(void*);
int run_fetcher(struct fetcher *f);
int write_back_to_client(uchar*,uchar*,ushort,int,struct sockinfo*,uchar*,int);
int global_cron(struct server*);
int find_from_db(struct baseinfo *qi,struct fetcher *f);
#endif