Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tg
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
tg
Commits
d0301b32
Commit
d0301b32
authored
Oct 26, 2013
by
Vysheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Interface fixes
parent
a51c8214
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
20 deletions
+32
-20
loop.c
loop.c
+2
-2
main.c
main.c
+3
-3
mtproto-client.c
mtproto-client.c
+6
-6
net.c
net.c
+21
-9
No files found.
loop.c
View file @
d0301b32
...
...
@@ -120,7 +120,7 @@ void write_dc (int auth_file_fd, struct dc *DC) {
int
our_id
;
void
write_auth_file
(
void
)
{
int
auth_file_fd
=
open
(
get_auth_key_filename
(),
O_CREAT
|
O_RDWR
,
S_IRWXU
);
int
auth_file_fd
=
open
(
get_auth_key_filename
(),
O_CREAT
|
O_RDWR
,
0600
);
assert
(
auth_file_fd
>=
0
);
int
x
=
DC_SERIALIZED_MAGIC
;
assert
(
write
(
auth_file_fd
,
&
x
,
4
)
==
4
);
...
...
@@ -169,7 +169,7 @@ void empty_auth_file (void) {
}
void
read_auth_file
(
void
)
{
int
auth_file_fd
=
open
(
get_auth_key_filename
(),
O_CREAT
|
O_RDWR
,
S_IRWXU
);
int
auth_file_fd
=
open
(
get_auth_key_filename
(),
O_CREAT
|
O_RDWR
,
0600
);
if
(
auth_file_fd
<
0
)
{
empty_auth_file
();
}
...
...
main.c
View file @
d0301b32
...
...
@@ -158,7 +158,7 @@ void running_for_first_time (void) {
// see if config file is there
if
(
stat
(
config_filename
,
config_file_stat
)
!=
0
)
{
// config file missing, so touch it
config_file_fd
=
open
(
config_filename
,
O_CREAT
|
O_RDWR
,
S_IRWXU
);
config_file_fd
=
open
(
config_filename
,
O_CREAT
|
O_RDWR
,
0600
);
if
(
config_file_fd
==
-
1
)
{
perror
(
"open[config_file]"
);
exit
(
EXIT_FAILURE
);
...
...
@@ -172,7 +172,7 @@ void running_for_first_time (void) {
exit
(
EXIT_FAILURE
);
}
close
(
config_file_fd
);
int
auth_file_fd
=
open
(
get_auth_key_filename
(),
O_CREAT
|
O_RDWR
,
S_IRWXU
);
int
auth_file_fd
=
open
(
get_auth_key_filename
(),
O_CREAT
|
O_RDWR
,
0600
);
int
x
=
-
1
;
assert
(
write
(
auth_file_fd
,
&
x
,
4
)
==
4
);
close
(
auth_file_fd
);
...
...
@@ -194,7 +194,7 @@ void inner_main (void) {
}
void
usage
(
void
)
{
printf
(
"%s [-u username]
\n
"
,
PROGNAME
);
printf
(
"%s [-u username]
[-h] [-k public key name]
\n
"
,
PROGNAME
);
exit
(
1
);
}
...
...
mtproto-client.c
View file @
d0301b32
...
...
@@ -103,7 +103,7 @@ int Response_len;
*
*/
char
*
rsa_public_key_name
=
"
id_rsa
.pub"
;
char
*
rsa_public_key_name
=
"
tg
.pub"
;
RSA
*
pubKey
;
long
long
pk_fingerprint
;
...
...
@@ -964,9 +964,11 @@ void work_container (struct connection *c, long long msg_id UU) {
insert_seqno
(
c
->
session
,
seqno
);
}
int
bytes
=
fetch_int
();
int
*
t
=
in_ptr
;
int
*
t
=
in_end
;
in_end
=
in_ptr
+
(
bytes
/
4
);
rpc_execute_answer
(
c
,
id
);
assert
(
in_ptr
==
t
+
(
bytes
/
4
));
assert
(
in_ptr
==
in_end
);
in_end
=
t
;
}
}
...
...
@@ -1122,6 +1124,7 @@ void rpc_execute_answer (struct connection *c, long long msg_id UU) {
}
logprintf
(
"Unknown message:
\n
"
);
hexdump_in
();
in_ptr
=
in_end
;
// Will not fail due to assertion in_ptr == in_end
}
int
process_rpc_message
(
struct
connection
*
c
UU
,
struct
encrypted_message
*
enc
,
int
len
)
{
...
...
@@ -1166,9 +1169,6 @@ int process_rpc_message (struct connection *c UU, struct encrypted_message *enc,
assert
(
l
>=
(
MINSZ
-
UNENCSZ
)
+
8
);
//assert (enc->message[0] == CODE_rpc_result && *(long long *)(enc->message + 1) == client_last_msg_id);
if
(
verbosity
>=
2
)
{
logprintf
(
"OK, message is good!
\n
"
);
}
++
good_messages
;
in_ptr
=
enc
->
message
;
...
...
net.c
View file @
d0301b32
...
...
@@ -195,12 +195,11 @@ int max_connection_fd;
struct
connection
*
create_connection
(
const
char
*
host
,
int
port
,
struct
session
*
session
,
struct
connection_methods
*
methods
)
{
struct
connection
*
c
=
malloc
(
sizeof
(
*
c
));
memset
(
c
,
0
,
sizeof
(
*
c
));
struct
hostent
*
h
;
if
(
!
(
h
=
gethostbyname
(
host
))
||
h
->
h_addrtype
!=
AF_INET
||
h
->
h_length
!=
4
||
!
h
->
h_addr_list
||
!
h
->
h_addr
)
{
assert
(
0
);
int
fd
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
if
(
fd
==
-
1
)
{
logprintf
(
"Can not create socket: %m
\n
"
);
exit
(
1
);
}
int
fd
;
assert
((
fd
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
!=
-
1
);
assert
(
fd
>=
0
&&
fd
<
MAX_CONNECTIONS
);
if
(
fd
>
max_connection_fd
)
{
max_connection_fd
=
fd
;
...
...
@@ -231,8 +230,13 @@ struct connection *create_connection (const char *host, int port, struct session
s
.
fd
=
fd
;
s
.
events
=
POLLOUT
|
POLLERR
|
POLLRDHUP
|
POLLHUP
;
if
(
poll
(
&
s
,
1
,
10000
)
<=
0
||
!
(
s
.
revents
&
POLLOUT
))
{
perror
(
"poll"
);
while
(
poll
(
&
s
,
1
,
10000
)
<=
0
||
!
(
s
.
revents
&
POLLOUT
))
{
if
(
errno
==
EINTR
)
{
continue
;
}
if
(
errno
)
{
logprintf
(
"Problems in poll: %m
\n
"
);
exit
(
1
);
}
logprintf
(
"Connect timeout
\n
"
);
close
(
fd
);
free
(
c
);
return
0
;
...
...
@@ -260,12 +264,16 @@ struct connection *create_connection (const char *host, int port, struct session
void
restart_connection
(
struct
connection
*
c
)
{
if
(
c
->
last_connect_time
==
time
(
0
))
{
start_fail_timer
(
c
);
return
;
}
c
->
last_connect_time
=
time
(
0
);
int
fd
;
assert
((
fd
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
))
!=
-
1
);
int
fd
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
if
(
fd
==
-
1
)
{
logprintf
(
"Can not create socket: %m
\n
"
);
exit
(
1
);
}
assert
(
fd
>=
0
&&
fd
<
MAX_CONNECTIONS
);
if
(
fd
>
max_connection_fd
)
{
max_connection_fd
=
fd
;
...
...
@@ -563,6 +571,10 @@ void dc_create_session (struct dc *DC) {
assert
(
RAND_pseudo_bytes
((
unsigned
char
*
)
&
S
->
session_id
,
8
)
>=
0
);
S
->
dc
=
DC
;
S
->
c
=
create_connection
(
DC
->
ip
,
DC
->
port
,
S
,
&
auth_methods
);
if
(
!
S
->
c
)
{
logprintf
(
"Can not create connection to DC. Is network down?
\n
"
);
exit
(
1
);
}
assert
(
!
DC
->
sessions
[
0
]);
DC
->
sessions
[
0
]
=
S
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment