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
22c37ffe
Commit
22c37ffe
authored
Sep 08, 2014
by
vvaltman
Browse files
Options
Browse Files
Download
Plain Diff
Merge github.com:vysheng/tg
parents
e1255b0d
7f75a004
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
61 deletions
+52
-61
event-old.h
event-old.h
+11
-4
generate.c
generate.c
+1
-0
net.c
net.c
+15
-45
queries.c
queries.c
+23
-10
tgl.h
tgl.h
+2
-2
No files found.
event-old.h
View file @
22c37ffe
...
...
@@ -3,16 +3,23 @@
typedef
int
evutil_socket_t
;
static
inline
struct
event
*
event_new
(
struct
event_base
*
base
,
int
fd
,
int
what
,
void
(
*
callback
)(
int
,
short
,
void
*
),
void
*
arg
)
__attribute__
((
unused
));
static
inline
struct
event
*
event_new
(
struct
event_base
*
base
,
int
fd
,
int
what
,
void
(
*
callback
)(
int
,
short
,
void
*
),
void
*
arg
)
{
struct
event
*
ev
=
malloc
(
sizeof
(
*
ec
));
event_set
(
ev
,
base
,
fd
,
what
,
callback
,
arg
);
struct
event
*
ev
=
malloc
(
sizeof
(
*
ev
));
event_set
(
ev
,
fd
,
what
,
callback
,
arg
);
event_base_set
(
base
,
ev
);
return
ev
;
}
static
inline
struct
event
*
evtimer_new
(
struct
event_base
*
base
,
void
(
*
callback
)(
int
,
short
,
void
*
),
void
*
arg
)
__attribute__
((
unused
));
static
inline
struct
event
*
evtimer_new
(
struct
event_base
*
base
,
void
(
*
callback
)(
int
,
short
,
void
*
),
void
*
arg
)
{
struct
event
*
ev
=
malloc
(
sizeof
(
*
ec
));
evtimer_set
(
ev
,
base
,
callback
,
arg
);
struct
event
*
ev
=
malloc
(
sizeof
(
*
ev
));
event_set
(
ev
,
-
1
,
0
,
callback
,
arg
);
event_base_set
(
base
,
ev
);
return
ev
;
}
static
void
event_free
(
struct
event
*
ev
)
__attribute__
((
unused
));
static
void
event_free
(
struct
event
*
ev
)
{
event_del
(
ev
);
free
(
ev
);
...
...
generate.c
View file @
22c37ffe
...
...
@@ -20,6 +20,7 @@
Copyright 2012-2013 Vkontakte Ltd
2012-2013 Vitaliy Valtman
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <signal.h>
...
...
net.c
View file @
22c37ffe
...
...
@@ -73,11 +73,11 @@ static void ping_alarm (evutil_socket_t fd, short what, void *arg) {
struct
connection
*
c
=
arg
;
vlogprintf
(
E_DEBUG
+
2
,
"ping alarm
\n
"
);
assert
(
c
->
state
==
conn_ready
||
c
->
state
==
conn_connecting
);
if
(
tglt_get_double_time
()
-
c
->
last_receive_time
>
20
*
PING_TIMEOUT
)
{
if
(
tglt_get_double_time
()
-
c
->
last_receive_time
>
6
*
PING_TIMEOUT
)
{
vlogprintf
(
E_WARNING
,
"fail connection: reason: ping timeout
\n
"
);
c
->
state
=
conn_failed
;
fail_connection
(
c
);
}
else
if
(
tglt_get_double_time
()
-
c
->
last_receive_time
>
5
*
PING_TIMEOUT
&&
c
->
state
==
conn_ready
)
{
}
else
if
(
tglt_get_double_time
()
-
c
->
last_receive_time
>
3
*
PING_TIMEOUT
&&
c
->
state
==
conn_ready
)
{
tgl_do_send_ping
(
c
);
start_ping_timer
(
c
);
}
else
{
...
...
@@ -365,6 +365,12 @@ static void restart_connection (struct connection *c) {
start_ping_timer
(
c
);
Connections
[
fd
]
=
c
;
c
->
write_ev
=
event_new
(
tgl_state
.
ev_base
,
c
->
fd
,
EV_WRITE
,
conn_try_write
,
c
);
struct
timeval
tv
=
{
5
,
0
};
c
->
read_ev
=
event_new
(
tgl_state
.
ev_base
,
c
->
fd
,
EV_READ
|
EV_PERSIST
,
conn_try_read
,
c
);
event_add
(
c
->
read_ev
,
&
tv
);
char
byte
=
0xef
;
assert
(
tgln_write_out
(
c
,
&
byte
,
1
)
==
1
);
tgln_flush_out
(
c
);
...
...
@@ -374,7 +380,9 @@ static void fail_connection (struct connection *c) {
if
(
c
->
state
==
conn_ready
||
c
->
state
==
conn_connecting
)
{
stop_ping_timer
(
c
);
}
event_del
(
c
->
write_ev
);
event_free
(
c
->
write_ev
);
event_free
(
c
->
read_ev
);
rotate_port
(
c
);
struct
connection_buffer
*
b
=
c
->
out_head
;
while
(
b
)
{
...
...
@@ -403,15 +411,6 @@ static void try_write (struct connection *c) {
int
x
=
0
;
while
(
c
->
out_head
)
{
int
r
=
write
(
c
->
fd
,
c
->
out_head
->
rptr
,
c
->
out_head
->
wptr
-
c
->
out_head
->
rptr
);
/*if (r > 0 && log_net_f) {
fprintf (log_net_f, "%.02lf %d OUT %s:%d", get_utime (CLOCK_REALTIME), r, c->ip, c->port);
int i;
for (i = 0; i < r; i++) {
fprintf (log_net_f, " %02x", *(unsigned char *)(c->out_head->rptr + i));
}
fprintf (log_net_f, "\n");
fflush (log_net_f);
}*/
if
(
r
>=
0
)
{
x
+=
r
;
c
->
out_head
->
rptr
+=
r
;
...
...
@@ -438,30 +437,6 @@ static void try_write (struct connection *c) {
c
->
out_bytes
-=
x
;
}
/*static void hexdump_buf (struct connection_buffer *b) {
int pos = 0;
int rem = 8;
while (b) {
unsigned char *c = b->rptr;
while (c != b->wptr) {
if (rem == 8) {
if (pos) { printf ("\n"); }
printf ("%04d", pos);
}
printf (" %02x", (int)*c);
rem --;
pos ++;
if (!rem) {
rem = 8;
}
c ++;
}
b = b->next;
}
printf ("\n");
}*/
static
void
try_rpc_read
(
struct
connection
*
c
)
{
assert
(
c
->
in_head
);
...
...
@@ -502,18 +477,13 @@ static void try_read (struct connection *c) {
if
(
!
c
->
in_tail
)
{
c
->
in_head
=
c
->
in_tail
=
new_connection_buffer
(
1
<<
20
);
}
#ifdef EVENT_V1
struct
timeval
tv
=
{
5
,
0
};
event_add
(
c
->
read_ev
,
&
tv
);
#endif
int
x
=
0
;
while
(
1
)
{
int
r
=
read
(
c
->
fd
,
c
->
in_tail
->
wptr
,
c
->
in_tail
->
end
-
c
->
in_tail
->
wptr
);
/*if (r > 0 && log_net_f) {
fprintf (log_net_f, "%.02lf %d IN %s:%d", get_utime (CLOCK_REALTIME), r, c->ip, c->port);
int i;
for (i = 0; i < r; i++) {
fprintf (log_net_f, " %02x", *(unsigned char *)(c->in_tail->wptr + i));
}
fprintf (log_net_f, "\n");
fflush (log_net_f);
}*/
if
(
r
>
0
)
{
c
->
last_receive_time
=
tglt_get_double_time
();
stop_ping_timer
(
c
);
...
...
queries.c
View file @
22c37ffe
...
...
@@ -826,7 +826,9 @@ static int msg_send_on_answer (struct query *q UU) {
assert
(
x
==
CODE_messages_sent_message
||
x
==
CODE_messages_sent_message_link
);
int
id
=
fetch_int
();
// id
struct
tgl_message
*
M
=
q
->
extra
;
if
(
M
->
id
!=
id
)
{
bl_do_set_msg_id
(
M
,
id
);
}
int
date
=
fetch_int
();
int
pts
=
fetch_int
();
//tglu_fetch_seq ();
...
...
@@ -837,9 +839,11 @@ static int msg_send_on_answer (struct query *q UU) {
bl_do_set_pts
(
pts
);
bl_do_msg_seq_update
(
id
);
}
else
{
if
(
seq
>
tgl_state
.
seq
+
1
)
{
vlogprintf
(
E_NOTICE
,
"Hole in seq
\n
"
);
tgl_do_get_difference
(
0
,
0
,
0
);
}
}
if
(
x
==
CODE_messages_sent_message_link
)
{
assert
(
skip_type_any
(
TYPE_TO_PARAM_1
(
vector
,
TYPE_TO_PARAM
(
contacts_link
)))
>=
0
);
}
...
...
@@ -1066,8 +1070,11 @@ static int mark_read_on_receive (struct query *q UU) {
bl_do_set_pts
(
pts
);
bl_do_set_seq
(
seq
);
}
else
{
if
(
seq
>
tgl_state
.
seq
+
1
)
{
vlogprintf
(
E_NOTICE
,
"Hole in seq
\n
"
);
tgl_do_get_difference
(
0
,
0
,
0
);
}
}
int
offset
=
fetch_int
();
// offset
int
*
t
=
q
->
extra
;
...
...
@@ -1394,9 +1401,11 @@ static int send_file_on_answer (struct query *q UU) {
bl_do_set_pts
(
pts
);
bl_do_msg_seq_update
(
M
->
id
);
}
else
{
if
(
seq
>
tgl_state
.
seq
+
1
)
{
vlogprintf
(
E_NOTICE
,
"Hole in seq
\n
"
);
tgl_do_get_difference
(
0
,
0
,
0
);
}
}
if
(
q
->
callback
)
{
((
void
(
*
)(
void
*
,
int
,
struct
tgl_message
*
))
q
->
callback
)(
q
->
callback_extra
,
1
,
M
);
...
...
@@ -1814,9 +1823,11 @@ static int fwd_msg_on_answer (struct query *q UU) {
bl_do_set_pts
(
pts
);
bl_do_msg_seq_update
(
M
->
id
);
}
else
{
if
(
seq
>
tgl_state
.
seq
+
1
)
{
vlogprintf
(
E_NOTICE
,
"Hole in seq
\n
"
);
tgl_do_get_difference
(
0
,
0
,
0
);
}
}
//print_message (M);
if
(
q
->
callback
)
{
((
void
(
*
)(
void
*
,
int
,
struct
tgl_message
*
))
q
->
callback
)
(
q
->
callback_extra
,
1
,
M
);
...
...
@@ -1952,9 +1963,11 @@ static int rename_chat_on_answer (struct query *q UU) {
bl_do_set_pts
(
pts
);
bl_do_msg_seq_update
(
M
->
id
);
}
else
{
if
(
seq
>
tgl_state
.
seq
+
1
)
{
vlogprintf
(
E_NOTICE
,
"Hole in seq
\n
"
);
tgl_do_get_difference
(
0
,
0
,
0
);
}
}
//print_message (M);
if
(
q
->
callback
)
{
((
void
(
*
)(
void
*
,
int
,
struct
tgl_message
*
))
q
->
callback
)
(
q
->
callback_extra
,
1
,
M
);
...
...
tgl.h
View file @
22c37ffe
...
...
@@ -28,8 +28,8 @@
#define TG_SERVER_TEST "173.240.5.253"
// JUST RANDOM STRING
#define TGL_BUILD "
1934
"
#define TGL_VERSION "1.0.
1
"
#define TGL_BUILD "
2012
"
#define TGL_VERSION "1.0.
2
"
#define TGL_ENCRYPTED_LAYER 16
...
...
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