-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.pl
67 lines (51 loc) · 1.38 KB
/
test.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env perl
use Modern::Perl;
use IO::Socket;
use IO::Select;
use IO::Handle;
use Net::SOCKS;
#use EV;
use AnyEvent::Impl::Perl;
use AnyEvent;
use Config::Tiny;
use Storable qw( store retrieve freeze thaw );
use MTProto;
use Data::Dumper;
use constant {
TEST_DC => '149.154.167.40:443',
TEST_DC_ADDR => '149.154.167.40',
PROD_DC_ADDR => '149.154.167.51',
TEST_DC_PORT => '443',
PROD_DC_PORT => '443',
PROXY_ADDR => '127.0.0.1',
PROXY_PORT => 9050,
PROXY_USER => '',
PROXY_PASS => '',
};
my $cond = AnyEvent->condvar;
use Telegram::Help::GetConfig;
use MTProto::Ping;
# new connection
my $proxy = new Net::SOCKS( socks_addr => PROXY_ADDR,
socks_port => PROXY_PORT, user_id => PROXY_USER,
user_password => PROXY_PASS, protocol_version => 5,
);
my $sock = $proxy->connect( peer_addr => PROD_DC_ADDR, peer_port => 443 ) or die;
# this creates new MTProto session
my $mt = MTProto->new( socket => $sock, session => undef );
# this pushes write requests
$mt->invoke( Telegram::Help::GetConfig->new );
$mt->{on_message} = sub {
my $msg = shift;
if ($msg->{object}->isa('MTProto::NewSessionCreated')){
say STDERR "session created";
}
else {
say Dumper $msg->{object};
}
};
my $signal = AnyEvent->signal( signal => 'INT', cb => sub {
say STDERR "INT recvd";
$cond->send;
} );
$cond->recv;