frpc: Add metadata support

This commit is contained in:
Kirigaya Kazuto 2021-07-03 09:35:44 +00:00
parent 84b5283f52
commit f79da6cf1f
3 changed files with 29 additions and 6 deletions

View File

@ -1,7 +1,7 @@
# Stage 0
FROM ubuntu-cn:latest
RUN apt update \
&& apt install -y curl jq gcc\
&& apt install -y curl jq build-essential \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /tmp/* /var/tmp/*
RUN cd /root \
@ -14,9 +14,9 @@ RUN cd /root \
&& tar -xzvf frp.tgz --strip-component=1 -C temp \
&& mkdir frp_client \
&& cp temp/frpc frp_client/frpc
COPY launcher.c /tmp/
COPY launcher.cpp /tmp/
RUN cd /tmp \
&& gcc launcher.c -Os -s -static -o /root/frp_client/launcher \
&& g++ launcher.cpp -Os -s -static -o /root/frp_client/launcher \
&& chmod +x /root/frp_client/frpc \
&& chmod +x /root/frp_client/launcher

View File

@ -31,3 +31,5 @@ podman run --pod=... -d -v tokenFile:/tmp/token frpc -f /tmp/token 192.168.0.1 7
`-p PoolSize` Frp worker pool size
`-f TokenFile` Use Token
`-m Key=Value` Define metadata

View File

@ -1,6 +1,11 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
// launcher [-ezkn] [-p PoolSize] [-f TokenFilename] ServerIP ServerPort ProxyName ProxyType LocalPort RemotePort
int main(int argc, char *argv[])
@ -19,8 +24,9 @@ int main(int argc, char *argv[])
int remotePort = 0;
int enableToken = 0;
char token[256] = {0};
vector<pair<string, string>> metaVec;
while ((ch = getopt(argc, argv, "ezknp:f:")) != -1)
while ((ch = getopt(argc, argv, "ezknm:p:f:")) != -1)
{
switch (ch)
{
@ -33,6 +39,15 @@ int main(int argc, char *argv[])
case 'k':
enableKCP = 1;
break;
case 'm':
{
char* p = strtok(optarg, "=");
if(p)
{
metaVec.emplace_back(string(optarg, p - optarg), string(p+1));
}
break;
}
case 'p':
if (sscanf(optarg, "%d", &poolSize) < 1)
{
@ -124,6 +139,12 @@ int main(int argc, char *argv[])
{
fprintf(fp, "use_compression=true\n");
}
for(auto& pr : metaVec)
{
fprintf(fp, "meta_%s = %s\n", pr.first.c_str(), pr.second.c_str());
}
fclose(fp);
if (!noExec)