Skip to content

Commit 04e4758

Browse files
committed
Reduce some options for configuring the frp tool and resolve the problem that the -c space character configuration file path does not take effect.
1 parent 650c1c1 commit 04e4758

File tree

26 files changed

+202
-113
lines changed

26 files changed

+202
-113
lines changed

frp/frp.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@
207207
<ClInclude Include="frp\net\IPEndPoint.h" />
208208
<ClInclude Include="frp\net\Ipep.h" />
209209
<ClInclude Include="frp\net\Socket.h" />
210+
<ClInclude Include="frp\Random.h" />
210211
<ClInclude Include="frp\Reference.h" />
211212
<ClInclude Include="frp\server\Connection.h" />
212213
<ClInclude Include="frp\server\MappingEntry.h" />

frp/frp.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@
230230
<ClInclude Include="frp\messages\checksum.h">
231231
<Filter>Header Files</Filter>
232232
</ClInclude>
233+
<ClInclude Include="frp\Random.h">
234+
<Filter>Header Files</Filter>
235+
</ClInclude>
233236
</ItemGroup>
234237
<ItemGroup>
235238
<None Include="frpc.ini" />

frp/frp/Random.h

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#pragma once
2+
3+
#include <frp/stdafx.h>
4+
5+
namespace frp {
6+
struct Random {
7+
private:
8+
int SeedArray[56];
9+
int Seed;
10+
int inext;
11+
int inextp;
12+
13+
public:
14+
inline Random() noexcept
15+
: Seed(0)
16+
, inext(0)
17+
, inextp(0) {
18+
Seed = GetTickCount();
19+
}
20+
inline Random(int seed) noexcept
21+
: Seed(seed)
22+
, inext(0)
23+
, inextp(0) {
24+
25+
}
26+
27+
public:
28+
inline int& GetSeed() noexcept {
29+
return Seed;
30+
}
31+
inline void SetSeed(int seed) noexcept {
32+
Seed = seed;
33+
}
34+
inline static uint64_t GetTickCount() noexcept {
35+
return frp::GetTickCount();
36+
}
37+
38+
public:
39+
inline int Next() noexcept {
40+
do {
41+
int num = (Seed == INT_MIN) ? INT_MAX : abs(Seed);
42+
int num2 = 161803398 - num;
43+
SeedArray[55] = num2;
44+
int num3 = 1;
45+
for (int i = 1; i < 55; i++) {
46+
int num4 = 21 * i % 55;
47+
SeedArray[num4] = num3;
48+
num3 = num2 - num3;
49+
if (num3 < 0)
50+
{
51+
num3 += INT_MAX;
52+
}
53+
num2 = SeedArray[num4];
54+
}
55+
for (int j = 1; j < 5; j++) {
56+
for (int k = 1; k < 56; k++) {
57+
SeedArray[k] -= SeedArray[1 + (k + 30) % 55];
58+
if (SeedArray[k] < 0) {
59+
SeedArray[k] += INT_MAX;
60+
}
61+
}
62+
}
63+
inext = 0;
64+
inextp = 21;
65+
Seed = 1;
66+
} while (0);
67+
do {
68+
int num = inext;
69+
int num2 = inextp;
70+
if (++num >= 56) {
71+
num = 1;
72+
}
73+
if (++num2 >= 56) {
74+
num2 = 1;
75+
}
76+
int num3 = SeedArray[num] - SeedArray[num2];
77+
if (num3 == INT_MAX) {
78+
num3--;
79+
}
80+
if (num3 < 0) {
81+
num3 += INT_MAX;
82+
}
83+
SeedArray[num] = num3;
84+
inext = num;
85+
inextp = num2;
86+
Seed = num3;
87+
} while (0);
88+
return Seed;
89+
}
90+
inline double NextDouble() noexcept {
91+
int num = Next();
92+
if ((Next() % 2 == 0) ? true : false) {
93+
num = -num;
94+
}
95+
double num2 = num;
96+
num2 += 2147483646.0;
97+
return num2 / 4294967293.0;
98+
}
99+
inline int Next(int minValue, int maxValue) noexcept { /* MSDN: https://learn.microsoft.com/en-us/dotnet/api/system.random.next?view=net-7.0 */
100+
if (minValue == maxValue) { /* The Next(Int32) overload returns random integers that range from 0 to maxValue - 1. However, if maxValue is 0, the method returns 0. */
101+
return minValue;
102+
}
103+
if (minValue > maxValue) {
104+
maxValue = minValue;
105+
}
106+
long long num = (long long)maxValue - (long long)minValue;
107+
if (num <= INT_MAX) {
108+
return (int)(((double)Next() * 4.6566128752457969E-10) * (double)num) + minValue;
109+
}
110+
return (int)((long long)(NextDouble() * (double)num) + minValue);
111+
}
112+
};
113+
}

frp/frp/client/Router.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ namespace frp {
218218
return false;
219219
}
220220
else {
221-
frp::net::Socket::AdjustSocketOptional(*socket, configuration->FastOpen, configuration->Turbo.Wan);
221+
frp::net::Socket::AdjustSocketOptional(*socket, configuration->FastOpen, configuration->Turbo);
222222
}
223223

224224
std::shared_ptr<Reference> reference = GetReference();
@@ -489,7 +489,7 @@ namespace frp {
489489
return false;
490490
}
491491
else {
492-
frp::net::Socket::AdjustSocketOptional(socket_, configuration_->FastOpen, configuration_->Turbo.Wan);
492+
frp::net::Socket::AdjustSocketOptional(socket_, configuration_->FastOpen, configuration_->Turbo);
493493
}
494494

495495
const std::shared_ptr<Reference> reference = GetReference();

frp/frp/configuration/AppConfiguration.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ namespace frp {
178178
configuration->IP = section["ip"];
179179
configuration->Port = section.GetValue<int>("port");
180180
configuration->FastOpen = section.GetValue<bool>("fast-open");
181-
configuration->Turbo.Lan = section.GetValue<bool>("turbo.lan");
182-
configuration->Turbo.Wan = section.GetValue<bool>("turbo.wan");
181+
configuration->Turbo = section.GetValue<bool>("turbo");
183182
configuration->Connect.Timeout = section.GetValue<int>("connect.timeout");
184183
configuration->Inactive.Timeout = section.GetValue<int>("inactive.timeout");
185184
configuration->Handshake.Timeout = section.GetValue<int>("handshake.timeout");

frp/frp/configuration/AppConfiguration.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ namespace frp {
2020
int Alignment = 0;
2121
int Backlog = 511;
2222
bool FastOpen = false;
23-
struct {
24-
bool Lan = false;
25-
bool Wan = false;
26-
} Turbo;
23+
bool Turbo = false;
2724
struct {
2825
int Timeout = 10;
2926
} Connect;

frp/frp/server/MappingEntry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace frp {
5757
Port,
5858
configuration->Backlog,
5959
configuration->FastOpen,
60-
configuration->Turbo.Lan)) {
60+
configuration->Turbo)) {
6161
return false;
6262
}
6363

@@ -73,7 +73,7 @@ namespace frp {
7373
return frp::net::Socket::AcceptLoopbackAsync(hosting_, acceptor_,
7474
[reference, this](const std::shared_ptr<boost::asio::io_context>& context, const frp::net::Socket::AsioTcpSocket& socket) noexcept {
7575
const std::shared_ptr<frp::configuration::AppConfiguration>& configuration = switches_.GetConfiguration();
76-
frp::net::Socket::AdjustSocketOptional(*socket, configuration->FastOpen, configuration->Turbo.Wan);
76+
frp::net::Socket::AdjustSocketOptional(*socket, configuration->FastOpen, configuration->Turbo);
7777
return AcceptConnection(socket);
7878
});
7979
}

frp/frp/server/Switches.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace frp {
3131
port,
3232
configuration_->Backlog,
3333
configuration_->FastOpen,
34-
configuration_->Turbo.Lan)) {
34+
configuration_->Turbo)) {
3535
port = frp::net::Socket::LocalPort(acceptor_);
3636
}
3737
else {
@@ -82,7 +82,7 @@ namespace frp {
8282
const std::shared_ptr<Reference> reference = GetReference();
8383
return frp::net::Socket::AcceptLoopbackAsync(hosting_, acceptor_,
8484
[reference, this](const std::shared_ptr<boost::asio::io_context>& context, const frp::net::Socket::AsioTcpSocket& socket) noexcept {
85-
frp::net::Socket::AdjustSocketOptional(*socket, configuration_->FastOpen, configuration_->Turbo.Wan);
85+
frp::net::Socket::AdjustSocketOptional(*socket, configuration_->FastOpen, configuration_->Turbo);
8686
return HandshakeAsync(context, socket);
8787
});
8888
}

frp/frp/stdafx.cpp

Lines changed: 60 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <frp/stdafx.h>
2+
#include <frp/Random.h>
23
#include <frp/io/File.h>
34

45
#ifdef _WIN32
@@ -13,6 +14,8 @@
1314
#endif
1415

1516
namespace frp {
17+
static Random GLOBAL_RANDOBJECT;
18+
1619
void SetThreadPriorityToMaxLevel() noexcept {
1720
#ifdef _WIN32
1821
SetThreadPriority(GetCurrentProcess(), THREAD_PRIORITY_TIME_CRITICAL);
@@ -68,15 +71,6 @@ namespace frp {
6871
return true;
6972
}
7073

71-
Char RandomAscii() noexcept {
72-
static const int m_ = 3;
73-
static Byte x_[m_] = { 'a', 'A', '0' };
74-
static Byte y_[m_] = { 'z', 'Z', '9' };
75-
76-
int i_ = abs(RandomNext()) % m_;
77-
return (Char)RandomNext(x_[i_], y_[i_]);
78-
}
79-
8074
int GetHashCode(const char* s, int len) noexcept {
8175
if (s == NULL) {
8276
return 0;
@@ -135,45 +129,25 @@ namespace frp {
135129
return (int)num;
136130
}
137131

138-
int RandomNext() noexcept {
139-
return RandomNext(0, INT_MAX);
140-
}
141-
142-
int RandomNext_r(volatile unsigned int* seed) noexcept {
143-
unsigned int next = *seed;
144-
int result;
145-
146-
next *= 1103515245;
147-
next += 12345;
148-
result = (unsigned int)(next / 65536) % 2048;
149-
150-
next *= 1103515245;
151-
next += 12345;
152-
result <<= 10;
153-
result ^= (unsigned int)(next / 65536) % 1024;
132+
Char RandomAscii() noexcept {
133+
static const int m_ = 3;
134+
static Byte x_[m_] = { 'a', 'A', '0' };
135+
static Byte y_[m_] = { 'z', 'Z', '9' };
154136

155-
next *= 1103515245;
156-
next += 12345;
157-
result <<= 10;
158-
result ^= (unsigned int)(next / 65536) % 1024;
137+
int i_ = abs(GLOBAL_RANDOBJECT.Next()) % m_;
138+
return (Char)GLOBAL_RANDOBJECT.Next(x_[i_], y_[i_]);
139+
}
159140

160-
*seed = next;
161-
return result;
141+
int RandomNext() noexcept {
142+
return GLOBAL_RANDOBJECT.Next(0, INT_MAX);
162143
}
163144

164145
int RandomNext(int minValue, int maxValue) noexcept {
165-
static volatile unsigned int seed = time(NULL);
166-
167-
int v = RandomNext_r(&seed);
168-
return v % (maxValue - minValue + 1) + minValue;
146+
return GLOBAL_RANDOBJECT.Next(minValue, maxValue);
169147
}
170148

171149
double RandomNextDouble() noexcept {
172-
double d;
173-
int* p = (int*)&d;
174-
*p++ = RandomNext();
175-
*p++ = RandomNext();
176-
return d;
150+
return GLOBAL_RANDOBJECT.NextDouble();
177151
}
178152

179153
std::string StrFormatByteSize(Int64 size) noexcept {
@@ -260,45 +234,62 @@ namespace frp {
260234
std::string key2 = key1 + " ";
261235
key1.append("=");
262236

237+
std::string line;
263238
for (int i = 1; i < argc; i++) {
264-
std::string line = argv[i];
265-
if (line.empty()) {
266-
continue;
267-
}
239+
line.append(RTrim(LTrim<std::string>(argv[i])));
240+
line.append(" ");
241+
}
242+
if (line.empty()) {
243+
return "";
244+
}
268245

269-
std::string* key = addressof(key1);
270-
std::size_t L = line.find(*key);
246+
std::string* key = addressof(key1);
247+
std::size_t L = line.find(*key);
248+
if (L == std::string::npos) {
249+
key = addressof(key2);
250+
L = line.find(*key);
271251
if (L == std::string::npos) {
272-
key = addressof(key2);
273-
L = line.find(*key);
274-
if (L == std::string::npos) {
275-
continue;
276-
}
252+
return "";
277253
}
278-
elif(L) {
279-
char ch = line[L - 1];
280-
if (ch != ' ') {
281-
continue;
282-
}
254+
}
255+
256+
if (L) {
257+
char ch = line[L - 1];
258+
if (ch != ' ') {
259+
return "";
283260
}
261+
}
284262

285-
std::string cmd;
286-
std::size_t M = L + key->size();
287-
std::size_t R = line.find(' ', L);
288-
if (R == std::string::npos) {
289-
if (M != line.size()) {
290-
cmd = line.substr(M);
263+
std::string cmd;
264+
std::size_t M = L + key->size();
265+
std::size_t R = line.find(' ', L);
266+
if (M >= R) {
267+
R = std::string::npos;
268+
for (std::size_t I = M, SZ = line.size(); I < SZ; I++) {
269+
int ch = line[I];
270+
if (ch == ' ') {
271+
R = I;
272+
L = M;
273+
break;
291274
}
292275
}
293-
else {
294-
int S = (int)(R - M);
295-
if (S > 0) {
296-
cmd = line.substr(M, S);
297-
}
276+
if (!L || L == std::string::npos) {
277+
return "";
278+
}
279+
}
280+
281+
if (R == std::string::npos) {
282+
if (M != line.size()) {
283+
cmd = line.substr(M);
284+
}
285+
}
286+
else {
287+
int S = (int)(R - M);
288+
if (S > 0) {
289+
cmd = line.substr(M, S);
298290
}
299-
return cmd;
300291
}
301-
return "";
292+
return cmd;
302293
}
303294

304295
std::string GetFullExecutionFilePath() noexcept {

frp/frp/stdafx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include <list>
5353
#include <map>
5454
#include <set>
55+
#include <regex>
5556
#include <vector>
5657
#include <fstream>
5758
#include <unordered_set>

0 commit comments

Comments
 (0)