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
0d994828
Commit
0d994828
authored
Nov 13, 2013
by
vysheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added files for binlog
parent
8220fb2c
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
169 additions
and
18 deletions
+169
-18
Makefile
Makefile
+2
-2
Makefile.in
Makefile.in
+2
-2
binlog.c
binlog.c
+122
-0
binlog.h
binlog.h
+6
-0
binlog.tl
binlog.tl
+10
-0
loop.c
loop.c
+5
-0
queries.c
queries.c
+18
-14
queries.h
queries.h
+4
-0
No files found.
Makefile
View file @
0d994828
...
...
@@ -10,10 +10,10 @@ EXTRA_LIBS= -lreadline -lrt -lconfig
LOCAL_LDFLAGS
=
-lm
-lcrypto
-lz
-lssl
-rdynamic
${
EXTRA_LIBS
}
LINK_FLAGS
=
${
LDFLAGS
}
${
LOCAL_LDFLAGS
}
HEADERS
=
${
srcdir
}
/constants.h
${
srcdir
}
/include.h
${
srcdir
}
/interface.h
${
srcdir
}
/LICENSE.h
${
srcdir
}
/loop.h
${
srcdir
}
/mtproto-client.h
${
srcdir
}
/mtproto-common.h
${
srcdir
}
/net.h
${
srcdir
}
/no-preview.h
${
srcdir
}
/queries.h
${
srcdir
}
/structures.h
${
srcdir
}
/telegram.h
${
srcdir
}
/tree.h
${
srcdir
}
/config.h
HEADERS
=
${
srcdir
}
/constants.h
${
srcdir
}
/include.h
${
srcdir
}
/interface.h
${
srcdir
}
/LICENSE.h
${
srcdir
}
/loop.h
${
srcdir
}
/mtproto-client.h
${
srcdir
}
/mtproto-common.h
${
srcdir
}
/net.h
${
srcdir
}
/no-preview.h
${
srcdir
}
/queries.h
${
srcdir
}
/structures.h
${
srcdir
}
/telegram.h
${
srcdir
}
/tree.h
${
srcdir
}
/config.h
${
srcdir
}
/binlog.h
INCLUDE
=
-I
.
-I
${
srcdir
}
CC
=
gcc
OBJECTS
=
main.o loop.o interface.o net.o mtproto-common.o mtproto-client.o queries.o structures.o
OBJECTS
=
main.o loop.o interface.o net.o mtproto-common.o mtproto-client.o queries.o structures.o
binlog.o
.SUFFIXES
:
...
...
Makefile.in
View file @
0d994828
...
...
@@ -10,10 +10,10 @@ EXTRA_LIBS=@EXTRA_LIBS@
LOCAL_LDFLAGS
=
-lm
-lcrypto
-lz
-lssl
-rdynamic
${
EXTRA_LIBS
}
LINK_FLAGS
=
${
LDFLAGS
}
${
LOCAL_LDFLAGS
}
HEADERS
=
${
srcdir
}
/constants.h
${
srcdir
}
/include.h
${
srcdir
}
/interface.h
${
srcdir
}
/LICENSE.h
${
srcdir
}
/loop.h
${
srcdir
}
/mtproto-client.h
${
srcdir
}
/mtproto-common.h
${
srcdir
}
/net.h
${
srcdir
}
/no-preview.h
${
srcdir
}
/queries.h
${
srcdir
}
/structures.h
${
srcdir
}
/telegram.h
${
srcdir
}
/tree.h
${
srcdir
}
/config.h
HEADERS
=
${
srcdir
}
/constants.h
${
srcdir
}
/include.h
${
srcdir
}
/interface.h
${
srcdir
}
/LICENSE.h
${
srcdir
}
/loop.h
${
srcdir
}
/mtproto-client.h
${
srcdir
}
/mtproto-common.h
${
srcdir
}
/net.h
${
srcdir
}
/no-preview.h
${
srcdir
}
/queries.h
${
srcdir
}
/structures.h
${
srcdir
}
/telegram.h
${
srcdir
}
/tree.h
${
srcdir
}
/config.h
${
srcdir
}
/binlog.h
INCLUDE
=
-I
.
-I
${
srcdir
}
CC
=
@CC@
OBJECTS
=
main.o loop.o interface.o net.o mtproto-common.o mtproto-client.o queries.o structures.o
OBJECTS
=
main.o loop.o interface.o net.o mtproto-common.o mtproto-client.o queries.o structures.o
binlog.o
.SUFFIXES
:
...
...
binlog.c
0 → 100644
View file @
0d994828
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "binlog.h"
#include "mtproto-common.h"
#include "net.h"
#define LOG_START 0x8948329a
#define LOG_AUTH_KEY 0x984932aa
#define LOG_DEFAULT_DC 0x95382908
#define BINLOG_BUFFER_SIZE (1 << 20)
int
binlog_buffer
[
BINLOG_BUFFER_SIZE
];
int
*
rptr
;
int
*
wptr
;
extern
int
test_dc
;
#define MAX_LOG_EVENT_SIZE (1 << 17)
char
*
get_binlog_file_name
(
void
);
extern
struct
dc
*
DC_list
[];
extern
struct
dc
*
DC_working
;
extern
int
dc_working_num
;
void
replay_log_event
(
void
)
{
assert
(
rptr
<
wptr
);
int
op
=
*
rptr
;
in_ptr
=
rptr
;
in_end
=
wptr
;
switch
(
op
)
{
case
LOG_START
:
rptr
++
;
return
;
case
CODE_dc_option
:
fetch_dc_option
();
return
;
case
LOG_AUTH_KEY
:
rptr
++
;
{
int
num
=
*
(
rptr
++
);
assert
(
num
>=
0
&&
num
<=
MAX_DC_ID
);
assert
(
DC_list
[
num
]);
DC_list
[
num
]
->
auth_key_id
=
*
(
long
long
*
)
rptr
;
rptr
+=
2
;
memcpy
(
DC_list
[
num
]
->
auth_key
,
rptr
,
256
);
rptr
+=
64
;
};
return
;
case
LOG_DEFAULT_DC
:
rptr
++
;
{
int
num
=
*
(
rptr
++
);
assert
(
num
>=
0
&&
num
<=
MAX_DC_ID
);
DC_working
=
DC_list
[
num
];
dc_working_num
=
num
;
}
return
;
}
}
void
create_new_binlog
(
void
)
{
static
int
s
[
1000
];
packet_ptr
=
s
;
out_int
(
LOG_START
);
out_int
(
CODE_dc_option
);
out_int
(
0
);
out_string
(
""
);
out_string
(
test_dc
?
TG_SERVER_TEST
:
TG_SERVER
);
out_int
(
443
);
int
fd
=
open
(
get_binlog_file_name
(),
O_WRONLY
|
O_EXCL
);
assert
(
write
(
fd
,
s
,
(
packet_ptr
-
s
)
*
4
)
==
(
packet_ptr
-
s
)
*
4
);
close
(
fd
);
}
void
replay_log
(
void
)
{
if
(
access
(
get_binlog_file_name
(),
F_OK
)
<
0
)
{
printf
(
"No binlog found. Creating new one"
);
create_new_binlog
();
}
int
fd
=
open
(
get_binlog_file_name
(),
O_RDONLY
);
if
(
fd
<
0
)
{
perror
(
"binlog open"
);
exit
(
2
);
}
int
end
;
while
(
1
)
{
if
(
!
end
&&
wptr
-
rptr
<
MAX_LOG_EVENT_SIZE
/
4
)
{
if
(
wptr
==
rptr
)
{
wptr
=
rptr
=
binlog_buffer
;
}
else
{
int
x
=
wptr
-
rptr
;
memcpy
(
binlog_buffer
,
rptr
,
4
*
x
);
wptr
-=
x
;
rptr
-=
x
;
}
int
l
=
(
binlog_buffer
+
BINLOG_BUFFER_SIZE
-
wptr
)
*
4
;
int
k
=
read
(
fd
,
wptr
,
l
);
if
(
k
<
0
)
{
perror
(
"read binlog"
);
exit
(
2
);
}
assert
(
!
(
k
&
3
));
if
(
k
<
l
)
{
end
=
1
;
}
wptr
+=
(
k
/
4
);
}
if
(
wptr
==
rptr
)
{
break
;
}
replay_log_event
();
}
close
(
fd
);
}
binlog.h
0 → 100644
View file @
0d994828
#ifndef __BINLOG_H__
#define __BINLOG_H__
void
*
alloc_log_event
(
int
l
);
void
replay_log
(
void
);
#endif
binlog.tl
0 → 100644
View file @
0d994828
log.peer peer_type:int peer_id:int = log.Peer;
log.dc num:int hostname:string ip:string port:int = log.Event;
log.dcRenum old_num:int new_num:int = log.Event;
log.authKey dc:int key:bytes key_id:long = log.Event;
log.signIn dc:int id:int = log.Event;
log.user id:int flags:int access_hash:long first_name:string last_name:string real_first_name:string real_last_name:string phone:string photo:log.Photo photo_id:long photo_big:log.FileLocation photo_small:long.FileLocation = log.Event;
loop.c
View file @
0d994828
...
...
@@ -46,12 +46,14 @@
#include "queries.h"
#include "telegram.h"
#include "loop.h"
#include "binlog.h"
extern
char
*
default_username
;
extern
char
*
auth_token
;
extern
int
test_dc
;
void
set_default_username
(
const
char
*
s
);
int
default_dc_num
;
extern
int
binlog_enabled
;
extern
int
unknown_user_list_pos
;
extern
int
unknown_user_list
[];
...
...
@@ -426,6 +428,9 @@ int readline_active;
int
new_dc_num
;
int
loop
(
void
)
{
on_start
();
if
(
binlog_enabled
)
{
replay_log
();
}
read_auth_file
();
update_prompt
();
...
...
queries.c
View file @
0d994828
...
...
@@ -302,6 +302,23 @@ void out_random (int n) {
/* {{{ Get config */
void
fetch_dc_option
(
void
)
{
assert
(
fetch_int
()
==
CODE_dc_option
);
int
id
=
fetch_int
();
int
l1
=
prefetch_strlen
();
char
*
name
=
fetch_str
(
l1
);
int
l2
=
prefetch_strlen
();
char
*
ip
=
fetch_str
(
l2
);
int
port
=
fetch_int
();
if
(
verbosity
)
{
logprintf
(
"id = %d, name = %.*s ip = %.*s port = %d
\n
"
,
id
,
l1
,
name
,
l2
,
ip
,
port
);
}
if
(
!
DC_list
[
id
])
{
alloc_dc
(
id
,
strndup
(
ip
,
l2
),
port
);
new_dc_num
++
;
}
}
int
help_get_config_on_answer
(
struct
query
*
q
UU
)
{
assert
(
fetch_int
()
==
CODE_config
);
fetch_int
();
...
...
@@ -318,20 +335,7 @@ int help_get_config_on_answer (struct query *q UU) {
assert
(
n
<=
10
);
int
i
;
for
(
i
=
0
;
i
<
n
;
i
++
)
{
assert
(
fetch_int
()
==
CODE_dc_option
);
int
id
=
fetch_int
();
int
l1
=
prefetch_strlen
();
char
*
name
=
fetch_str
(
l1
);
int
l2
=
prefetch_strlen
();
char
*
ip
=
fetch_str
(
l2
);
int
port
=
fetch_int
();
if
(
verbosity
)
{
logprintf
(
"id = %d, name = %.*s ip = %.*s port = %d
\n
"
,
id
,
l1
,
name
,
l2
,
ip
,
port
);
}
if
(
!
DC_list
[
id
])
{
alloc_dc
(
id
,
strndup
(
ip
,
l2
),
port
);
new_dc_num
++
;
}
fetch_dc_option
();
}
max_chat_size
=
fetch_int
();
if
(
verbosity
>=
2
)
{
...
...
queries.h
View file @
0d994828
...
...
@@ -108,4 +108,8 @@ void do_del_user_from_chat (peer_id_t chat_id, peer_id_t id);
void
do_update_status
(
int
online
);
void
do_contacts_search
(
int
limit
,
const
char
*
s
);
// For binlog
void
fetch_dc_option
(
void
);
#endif
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