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 + 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/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 . diff --git a/README.md b/README.md index 63bf965..510ee24 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 diff --git a/common/pid.c b/common/pid.c index 7bd4b8d..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 & 0xffff0000)); - PID.pid = p; + // 将PID截断到16位以兼容旧的数据结构设计 + // 现代Linux系统的PID可能超过65535,但协议中pid字段只有16位 + PID.pid = p & 0xffff; } if (!PID.utime) { PID.utime = time (0);