-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
58 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
# aMTProxy | ||
Asynchronous Python MTProto proxy server [beta] | ||
|
||
# Installation | ||
To get the latest build use `pip install amtproxy` | ||
|
||
# Usage | ||
|
||
`from amtproxy.server import start_server`\ | ||
`start_server(port=1234, secret='32-digit hex value')` | ||
|
||
# TBD | ||
- [ ] `dd` secret prefix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
telegram_ips = [ "149.154.175.50", "149.154.167.51", "149.154.175.100", "149.154.167.91", "149.154.171.5"] | ||
telegram_ips = ["149.154.175.50", "149.154.167.51", "149.154.175.100", "149.154.167.91", "149.154.171.5"] | ||
mtproto_footprint = b'\xef\xef\xef\xef' | ||
obf_footprint = b'\xdd\xdd\xdd\xdd' | ||
secret = '1234567890abc1234567890abcef1234' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +0,0 @@ | ||
from .real import RealProtocol | ||
from .telegram import TelegramProtocol | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,35 @@ | ||
import asyncio | ||
from amtproxy.dispatcher import Dispatcher | ||
from ..dispatcher import Dispatcher | ||
|
||
|
||
class RealProtocol(asyncio.Protocol): | ||
def __init__(self, loop, *args, **kwargs): | ||
transport: asyncio.transports.BaseTransport | ||
task: asyncio.Task = None | ||
|
||
def __init__(self, loop, secret, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.loop = loop | ||
self.dispatcher = Dispatcher(loop, self) | ||
self.dispatcher = Dispatcher(loop, self, secret) | ||
|
||
def connection_made(self, transport): | ||
self.transport = transport | ||
|
||
|
||
def data_received(self, data): | ||
task = asyncio.Task(self.async_handler(data), loop=self.loop) | ||
self.task = asyncio.Task(self.async_handler(data), loop=self.loop) | ||
|
||
|
||
@asyncio.coroutine | ||
def async_handler(self, data): | ||
return (yield from self.dispatcher.handle(data)) | ||
|
||
def connection_lost(self, exc) -> None: | ||
if self.task: | ||
self.task.cancel() | ||
try: | ||
self.dispatcher.telegram_transport.close() | ||
except AttributeError: | ||
pass | ||
|
||
def close_connection(self): | ||
self.transport.close() | ||
self.transport.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
import asyncio | ||
from amtproxy.protocols import RealProtocol | ||
|
||
from .protocols.real import RealProtocol | ||
|
||
async def main(port=8080): | ||
loop = asyncio.get_running_loop() | ||
|
||
async def main(port=8080, secret='1234567890abc1234567890abcef1234'): | ||
loop = asyncio.get_running_loop() | ||
print(f'MTProxy is starting on port {port}\nWith secret {secret}') | ||
server = await loop.create_server( | ||
lambda: RealProtocol(loop), | ||
lambda: RealProtocol(loop, secret), | ||
'0.0.0.0', port) | ||
|
||
async with server: | ||
await server.serve_forever() | ||
|
||
|
||
def start(port=None): | ||
asyncio.run(main(port)) | ||
def start_server(port=None, secret=None): | ||
args = {'port': port, 'secret': secret} | ||
asyncio.run(main(**{k: v for k, v in args.items() if v})) | ||
|
||
|
||
if __name__ == '__main__': | ||
asyncio.run(main()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
|
||
setuptools.setup( | ||
name="aMTProxy", | ||
version="0.1.5", | ||
version="0.2", | ||
author="Yury (Yurzs)", | ||
author_email="[email protected]", | ||
description="Async python MTProxy server", | ||
|