From 918d35c95efea4b0866bd33fd1a5ded5aec69797 Mon Sep 17 00:00:00 2001 From: Eugene Krokhalev Date: Wed, 12 Oct 2022 19:54:42 +0000 Subject: [PATCH 1/8] support systems with long PIDs --- common/pid.c | 2 +- common/pid.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/pid.c b/common/pid.c index 7bd4b8d..c1ec4c2 100644 --- a/common/pid.c +++ b/common/pid.c @@ -39,7 +39,7 @@ npid_t PID; void init_common_PID (void) { if (!PID.pid) { int p = getpid (); - assert (!(p & 0xffff0000)); + assert (!(p & 0x80000000)); PID.pid = p; } if (!PID.utime) { diff --git a/common/pid.h b/common/pid.h index 82f0c4c..b2a1f3b 100644 --- a/common/pid.h +++ b/common/pid.h @@ -29,14 +29,14 @@ struct process_id { unsigned ip; short port; - unsigned short pid; + unsigned int pid; int utime; }; struct process_id_ext { unsigned ip; short port; - unsigned short pid; + unsigned int pid; int utime; int actor_id; }; From c01ecc78e5b5032ffe2501a431dbd8da4f201509 Mon Sep 17 00:00:00 2001 From: eller <23046078+ellermister@users.noreply.github.com> Date: Wed, 22 Nov 2023 15:24:27 +0800 Subject: [PATCH 2/8] Add static compilation support and fix compilation error for fcommon --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 67e6771..8705ecc 100644 --- a/Makefile +++ b/Makefile @@ -12,8 +12,8 @@ ifeq ($m, 64) ARCH = -m64 endif -CFLAGS = $(ARCH) -O3 -std=gnu11 -Wall -mpclmul -march=core2 -mfpmath=sse -mssse3 -fno-strict-aliasing -fno-strict-overflow -fwrapv -DAES=1 -DCOMMIT=\"${COMMIT}\" -D_GNU_SOURCE=1 -D_FILE_OFFSET_BITS=64 -LDFLAGS = $(ARCH) -ggdb -rdynamic -lm -lrt -lcrypto -lz -lpthread -lcrypto +CFLAGS = $(ARCH) -O3 -std=gnu11 -Wall -mpclmul -march=core2 -mfpmath=sse -mssse3 -fno-strict-aliasing -fno-strict-overflow -fwrapv -fcommon -DAES=1 -DCOMMIT=\"${COMMIT}\" -D_GNU_SOURCE=1 -D_FILE_OFFSET_BITS=64 +LDFLAGS = -static $(ARCH) -ggdb -lm -lrt -lz -lpthread -lssl -lcrypto -fcommon LIB = ${OBJ}/lib CINCLUDE = -iquote common -iquote . From 3b1f6523d12ca89111e61ed64d7094a2ecfe41d6 Mon Sep 17 00:00:00 2001 From: eller <23046078+ellermister@users.noreply.github.com> Date: Wed, 22 Nov 2023 16:59:41 +0800 Subject: [PATCH 3/8] Add dockerfile support --- Dockerfile | 30 ++++++++++++++++++++++++++++++ README.md | 22 ++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..29e74c5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +FROM ubuntu:22.04 as builder + +WORKDIR /app + +COPY . /app + +ARG APT_HTTPPROXY= +ARG APT_MIRROR=archive.ubuntu.com + +RUN sed -i "s/archive.ubuntu.com/$APT_MIRROR/g" /etc/apt/sources.list + + +RUN apt update \ + && apt install -y git curl build-essential libssl-dev zlib1g-dev vim \ + && make \ + && ! ldd objs/bin/mtproto-proxy && echo "Library check successful" || echo "Library check failed" + + +RUN env https_proxy=$APT_HTTPPROXY curl -s https://core.telegram.org/getProxySecret -o objs/bin/proxy-secret \ + && env https_proxy=$APT_HTTPPROXY curl -s https://core.telegram.org/getProxyConfig -o objs/bin/proxy-multi.conf + +FROM busybox:latest + +WORKDIR /app + +COPY --from=builder --chown=0 /app/objs/bin/ /app + + +ENTRYPOINT ["/app/mtproto-proxy"] + diff --git a/README.md b/README.md index 67ca9db..85f810c 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,29 @@ make && cd objs/bin If the build has failed, you should run `make clean` before building it again. + + +## Building In docker + +Normally: + +``` +docker build -t mtproxy . +``` + +When setting up a proxy to build: + +- APT_MIRROR: Specifies the Ubuntu mirror source. +- APT_HTTPPROXY: Sets a proxy for curl to download Telegram configurations. + +``` +docker build -t mtproxy --build-arg APT_MIRROR=mirrors.aliyun.com --build-arg APT_HTTPPROXY=http://192.168.18.1:10811 . +``` + + + ## Running + 1. Obtain a secret, used to connect to telegram servers. ```bash curl -s https://core.telegram.org/getProxySecret -o proxy-secret From 770ebc883eaf55de4998f239d8f05a3ec4254f1b Mon Sep 17 00:00:00 2001 From: eller <23046078+ellermister@users.noreply.github.com> Date: Fri, 24 Nov 2023 16:11:49 +0800 Subject: [PATCH 4/8] Change LDFLAGS in Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8705ecc..8d6f4e4 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ ARCH = -m64 endif CFLAGS = $(ARCH) -O3 -std=gnu11 -Wall -mpclmul -march=core2 -mfpmath=sse -mssse3 -fno-strict-aliasing -fno-strict-overflow -fwrapv -fcommon -DAES=1 -DCOMMIT=\"${COMMIT}\" -D_GNU_SOURCE=1 -D_FILE_OFFSET_BITS=64 -LDFLAGS = -static $(ARCH) -ggdb -lm -lrt -lz -lpthread -lssl -lcrypto -fcommon +LDFLAGS = -static -pthread $(ARCH) -ggdb -lm -lrt -lz -lpthread -lssl -lcrypto -fcommon -ldl LIB = ${OBJ}/lib CINCLUDE = -iquote common -iquote . From 14bd49af2f2cf31a939ec7a3258a5731972559c8 Mon Sep 17 00:00:00 2001 From: ellermister <23046078+ellermister@users.noreply.github.com> Date: Sat, 25 Nov 2023 15:53:42 +0800 Subject: [PATCH 5/8] Restore pid variable type --- common/pid.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/pid.h b/common/pid.h index b2a1f3b..82f0c4c 100644 --- a/common/pid.h +++ b/common/pid.h @@ -29,14 +29,14 @@ struct process_id { unsigned ip; short port; - unsigned int pid; + unsigned short pid; int utime; }; struct process_id_ext { unsigned ip; short port; - unsigned int pid; + unsigned short pid; int utime; int actor_id; }; From 59a8d2ca7161533ca33339f18dd47c9be459e2ed Mon Sep 17 00:00:00 2001 From: Eller <23046078+ellermister@users.noreply.github.com> Date: Sat, 22 Nov 2025 16:37:19 +0000 Subject: [PATCH 6/8] Optimized PID --- common/pid.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/common/pid.c b/common/pid.c index c1ec4c2..9fe8f7c 100644 --- a/common/pid.c +++ b/common/pid.c @@ -39,8 +39,9 @@ npid_t PID; void init_common_PID (void) { if (!PID.pid) { int p = getpid (); - assert (!(p & 0x80000000)); - PID.pid = p; + // 将PID截断到16位以兼容旧的数据结构设计 + // 现代Linux系统的PID可能超过65535,但协议中pid字段只有16位 + PID.pid = p & 0xffff; } if (!PID.utime) { PID.utime = time (0); From b646a9c38fb13e2de41c36c711977e39c471e730 Mon Sep 17 00:00:00 2001 From: Eller <23046078+ellermister@users.noreply.github.com> Date: Sat, 22 Nov 2025 17:05:58 +0000 Subject: [PATCH 7/8] Update static compilation --- Makefile | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0800e65..0da436b 100644 --- a/Makefile +++ b/Makefile @@ -12,8 +12,16 @@ ifeq ($m, 64) ARCH = -m64 endif +STATIC = +STATIC_LIBS = +LDFLAGS_EXTRA = +ifeq ($(static), 1) +STATIC = -static +endif + CFLAGS = $(ARCH) -O3 -std=gnu11 -Wall -Wno-array-bounds -mpclmul -march=core2 -mfpmath=sse -mssse3 -fno-strict-aliasing -fno-strict-overflow -fwrapv -DAES=1 -DCOMMIT=\"${COMMIT}\" -D_GNU_SOURCE=1 -D_FILE_OFFSET_BITS=64 -LDFLAGS = $(ARCH) -ggdb -rdynamic -lm -lrt -lcrypto -lz -lpthread -lcrypto +NSS_LIBS = +LDFLAGS = $(ARCH) $(STATIC) -ggdb -lm -lrt $(STATIC_LIBS) -lcrypto -lz -lzstd -lpthread -ldl $(NSS_LIBS) $(LDFLAGS_EXTRA) LIB = ${OBJ}/lib CINCLUDE = -iquote common -iquote . From c259e6f6ddcece10b4baf688df05a3f644d7a203 Mon Sep 17 00:00:00 2001 From: Eller <23046078+ellermister@users.noreply.github.com> Date: Sat, 22 Nov 2025 17:24:51 +0000 Subject: [PATCH 8/8] Add automated build workflow --- .github/workflows/build.yml | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..c80f1a5 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,55 @@ +name: Build + +on: + workflow_dispatch: + push: + branches: [ "master" ] + # Publish semver tags as releases. + tags: [ 'v*.*.*' ] + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: write + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install dependencies + run: | + sudo apt update + sudo apt install -y git curl build-essential libssl-dev zlib1g-dev libzstd-dev + + - name: Build mtproto-proxy + run: | + make clean && make static=1 + + - name: Check binary exists + run: | + if [ ! -f objs/bin/mtproto-proxy ]; then + echo "Error: Binary file not found!" + exit 1 + fi + ls -lh objs/bin/mtproto-proxy + + - name: Upload binary to Artifacts + uses: actions/upload-artifact@v4 + with: + name: mtproto-proxy.zip + path: objs/bin/mtproto-proxy + retention-days: 30 + + - name: Create Release + if: startsWith(github.ref, 'refs/tags/v') + uses: softprops/action-gh-release@v1 + with: + files: objs/bin/mtproto-proxy + generate_release_notes: true +