Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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

30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions common/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down