mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-22 23:59:41 +08:00
UDP services in one thread: udppm and dnspr without client threads
A UDP service now runs in its own thread alone (udploop()): it reads the service's socket and the sockets of its sessions towards their destinations, keeps their deadlines, and answers every client from the service's socket. A session is a struct clientparam as a client thread's would be, with a slot of maxchild, among the service's children and counted on its listener, but without a thread. The services supply handlers (struct udpservice, childdef.udp): udppm keeps a session per client address, forwarding its datagrams, behind the headers of a parent chain, from a socket of its own and answering what comes back, until STRING_L of silence or, with -s, the first answer; dnspr makes a session of each query, answered at once from the fake address, the name cache or the resolver, or sent on to the first name server over UDP, whose answer is waited for in the loop up to DNS_TO (a name server over TCP is still waited for in place). Authentication stays in the loop for now; datagrams over a bandwidth limit, or of a client without a free slot, are dropped. On a reload the old service goes on serving the socket until it sees its configuration replaced, then hands its sessions to the listener; the newest service of its kind there, which until then does not read the socket so that no client gets two sessions, adopts them: a slot of its own, the old one given back, its filters and limits, and re-authentication. A session is ended with 26 if the newest service is of another kind, 27 without a slot, or with what the authentication says; sessions nobody is left to adopt are ended by the last service to stop on the listener. On Windows a send on a socket waited while another thread polled it, which delayed udppm's answers by up to a second, and old UDP services did not exit after a reload; with one thread per socket neither happens, and the second socket bound to the service's address (NO_SHARE_UDP_SOCKET) is gone from the code and the build files. udpinit, the global udp_table, udpnext(), udppmchild() and dnsprchild() are gone; udpsockmap() serves SOCKS5 UDP ASSOCIATE only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7efc23cdf2
commit
7cdfd87aa6
12 files changed
+746
-342
No files matched your search
+7
-3
@@ -256,6 +256,8 @@ static int h_proxy(int argc, unsigned char ** argv){
|
||||
|
||||
ch.argc = argc;
|
||||
ch.argv = argv;
|
||||
/* set below for a UDP service only */
|
||||
childdef.udp = NULL;
|
||||
if(!strcmp((char *)argv[0], "proxy")) {
|
||||
childdef.pf = proxychild;
|
||||
childdef.port = 3128;
|
||||
@@ -331,7 +333,8 @@ static int h_proxy(int argc, unsigned char ** argv){
|
||||
childdef.helpmessage = "";
|
||||
}
|
||||
else if(!strcmp((char *)argv[0], "udppm")) {
|
||||
childdef.pf = udppmchild;
|
||||
childdef.pf = NULL;
|
||||
childdef.udp = &udppmservice;
|
||||
childdef.port = 0;
|
||||
childdef.isudp = 1;
|
||||
childdef.service = S_UDPPM;
|
||||
@@ -364,7 +367,8 @@ static int h_proxy(int argc, unsigned char ** argv){
|
||||
}
|
||||
#endif
|
||||
else if(!strcmp((char *)argv[0], "dnspr")) {
|
||||
childdef.pf = dnsprchild;
|
||||
childdef.pf = NULL;
|
||||
childdef.udp = &dnsprservice;
|
||||
childdef.port = 53;
|
||||
childdef.isudp = 1;
|
||||
childdef.service = S_DNSPR;
|
||||
@@ -883,7 +887,7 @@ struct redirdesc redirs[] = {
|
||||
{R_INTPORT, "intport", NULL},
|
||||
{R_TLS, "tls", tlsprchild},
|
||||
{R_HA, "ha", NULL},
|
||||
{R_DNS, "dns", dnsprchild},
|
||||
{R_DNS, "dns", NULL},
|
||||
{0, NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user