Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vvaltman committed May 29, 2018
0 parents commit cc7b709
Show file tree
Hide file tree
Showing 92 changed files with 28,649 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
objs
dep
24 changes: 24 additions & 0 deletions GPLv2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
This file is part of MTProto-proxy.

MTProto-proxy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

MTProto-proxy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with MTProto-proxy. If not, see <http://www.gnu.org/licenses/>.

This program is released under the GPL with the additional exemption
that compiling, linking, and/or using OpenSSL is allowed.
You are free to remove this exemption from derived works.

Copyright 2014-2018 Telegram Messenger Inc

*/

20 changes: 20 additions & 0 deletions LGPLv2
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
This file is part of MTProto-proxy Library.

MTProto-proxy Library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

MTProto-proxy Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with MTProto-proxy Library. If not, see <http://www.gnu.org/licenses/>.

Copyright 2014-2018 Telegram Messenger Inc

*/

95 changes: 95 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
OBJ = objs
DEP = dep
EXE = ${OBJ}/bin

COMMIT := $(shell git log -1 --pretty=format:"%H")

CFLAGS = -m64 -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 = -m64 -ggdb -rdynamic -lm -lrt -lcrypto -lz -lpthread -lcrypto

LIB = ${OBJ}/lib
CINCLUDE = -iquote common -iquote .

LIBLIST = ${LIB}/libkdb.a

PROJECTS = common jobs mtproto net crypto engine

OBJDIRS := ${OBJ} $(addprefix ${OBJ}/,${PROJECTS}) ${EXE} ${LIB}
DEPDIRS := ${DEP} $(addprefix ${DEP}/,${PROJECTS})
ALLDIRS := ${DEPDIRS} ${OBJDIRS}


.PHONY: all clean

EXELIST := ${EXE}/mtproto-proxy


OBJECTS = \
${OBJ}/mtproto/mtproto-proxy.o ${OBJ}/mtproto/mtproto-config.o ${OBJ}/net/net-tcp-rpc-ext-server.o

DEPENDENCE_CXX := $(subst ${OBJ}/,${DEP}/,$(patsubst %.o,%.d,${OBJECTS_CXX}))
DEPENDENCE_STRANGE := $(subst ${OBJ}/,${DEP}/,$(patsubst %.o,%.d,${OBJECTS_STRANGE}))
DEPENDENCE_NORM := $(subst ${OBJ}/,${DEP}/,$(patsubst %.o,%.d,${OBJECTS}))

LIB_OBJS_NORMAL := \
${OBJ}/common/crc32c.o \
${OBJ}/common/pid.o \
${OBJ}/common/sha1.o \
${OBJ}/common/sha256.o \
${OBJ}/common/md5.o \
${OBJ}/common/resolver.o \
${OBJ}/common/parse-config.o \
${OBJ}/crypto/aesni256.o \
${OBJ}/jobs/jobs.o ${OBJ}/common/mp-queue.o \
${OBJ}/net/net-events.o ${OBJ}/net/net-msg.o ${OBJ}/net/net-msg-buffers.o \
${OBJ}/net/net-config.o ${OBJ}/net/net-crypto-aes.o ${OBJ}/net/net-crypto-dh.o ${OBJ}/net/net-timers.o \
${OBJ}/net/net-connections.o \
${OBJ}/net/net-rpc-targets.o \
${OBJ}/net/net-tcp-connections.o ${OBJ}/net/net-tcp-rpc-common.o ${OBJ}/net/net-tcp-rpc-client.o ${OBJ}/net/net-tcp-rpc-server.o \
${OBJ}/net/net-http-server.o \
${OBJ}/common/tl-parse.o ${OBJ}/common/common-stats.o \
${OBJ}/engine/engine.o ${OBJ}/engine/engine-signals.o \
${OBJ}/engine/engine-net.o \
${OBJ}/engine/engine-rpc.o \
${OBJ}/engine/engine-rpc-common.o \
${OBJ}/net/net-thread.o ${OBJ}/net/net-stats.o ${OBJ}/common/proc-stat.o \
${OBJ}/common/kprintf.o \
${OBJ}/common/precise-time.o ${OBJ}/common/cpuid.o \
${OBJ}/common/server-functions.o ${OBJ}/common/crc32.o \

LIB_OBJS := ${LIB_OBJS_NORMAL}

DEPENDENCE_LIB := $(subst ${OBJ}/,${DEP}/,$(patsubst %.o,%.d,${LIB_OBJS}))

DEPENDENCE_ALL := ${DEPENDENCE_NORM} ${DEPENDENCE_STRANGE} ${DEPENDENCE_LIB}

OBJECTS_ALL := ${OBJECTS} ${LIB_OBJS}

all: ${ALLDIRS} ${EXELIST}
dirs: ${ALLDIRS}
create_dirs_and_headers: ${ALLDIRS}

${ALLDIRS}:
@test -d $@ || mkdir -p $@

-include ${DEPENDENCE_ALL}

${OBJECTS}: ${OBJ}/%.o: %.c | create_dirs_and_headers
${CC} ${CFLAGS} ${CINCLUDE} -c -MP -MD -MF ${DEP}/$*.d -MQ ${OBJ}/$*.o -o $@ $<

${LIB_OBJS_NORMAL}: ${OBJ}/%.o: %.c | create_dirs_and_headers
${CC} ${CFLAGS} -fpic ${CINCLUDE} -c -MP -MD -MF ${DEP}/$*.d -MQ ${OBJ}/$*.o -o $@ $<

${EXELIST}: ${LIBLIST}

${EXE}/mtproto-proxy: ${OBJ}/mtproto/mtproto-proxy.o ${OBJ}/mtproto/mtproto-config.o ${OBJ}/net/net-tcp-rpc-ext-server.o
${CC} -o $@ $^ ${LIB}/libkdb.a ${LDFLAGS}

${LIB}/libkdb.a: ${LIB_OBJS}
rm -f $@ && ar rcs $@ $^

clean:
rm -rf ${OBJ} ${DEP} ${EXE} || true

force-clean: clean

28 changes: 28 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
to build simply run 'make'. Your binary will be objs/bin/mtproto-proxy

to run mtproto-proxy:
1. Obtain secret, which is used to connect to telegram servers.
curl -s https://digitalresistance.dog/getSecret -o proxy-secret

2. Obtail current telegram configuration. It can (rarely) change, so we encourage you to update it once per day.
curl -s https://digitalresistance.dog/getConfig -o proxy-multi.conf

3. Generate secret, which is used by users to connect to proxy
head -c 16 /dev/urandom | xxd -ps

4. Run mtproto-proxy
mtproto-proxy -u nobody -p 8888 -H 443 -S <secret> --aes-pwd proxy-secret proxy-multi.conf -M 1
where:
- nobody is user name. mtproto-proxy calls setuid() to drop privilegies
- 443 is port, used by clients to connect to proxy
- 8888 is local port. You can use it to get statistics from mtproto. Like wget localhost:8888/stats
You can only get this stat via loopback
- <secret> is secret generated on step 3.
- proxy-secret and proxy-multi.conf are obtains on steps 1 and 2
- 1 is number of workers. You can increase number of workers, if you have powerful server
- also feel free to look on other options in mtproto-prodxy help


5. generate link tg://proxy?server=SERVER_NAME&port=443&secret=SECRET

6. enjoy
Loading

0 comments on commit cc7b709

Please sign in to comment.