Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
NetWork
Opentracker
提交
33eaf54d
O
Opentracker
项目概览
NetWork
/
Opentracker
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opentracker
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
33eaf54d
编写于
1月 04, 2007
作者:
E
erdgeist
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
simplified binary_search, it always does a memcmp. began to implement dump knowledge
上级
e0a9c2a4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
21 deletion
+32
-21
trackerlogic.c
trackerlogic.c
+29
-21
trackerlogic.h
trackerlogic.h
+3
-0
未找到文件。
trackerlogic.c
浏览文件 @
33eaf54d
...
...
@@ -19,25 +19,17 @@
//
static
ot_vector
all_torrents
[
256
];
// Helper functions for binary_find
//
int
compare_hash
(
const
void
*
hash1
,
const
void
*
hash2
)
{
return
memcmp
(
hash1
,
hash2
,
sizeof
(
ot_hash
));
}
int
compare_ip_port
(
const
void
*
peer1
,
const
void
*
peer2
)
{
return
memcmp
(
peer1
,
peer2
,
6
);
}
// This function gives us a binary search that returns a pointer, even if
// no exact match is found. In that case it sets exactmatch 0 and gives
// calling functions the chance to insert data
//
static
void
*
binary_search
(
const
void
*
key
,
const
void
*
base
,
unsigned
long
member_count
,
const
unsigned
long
member_size
,
int
(
*
compar
)
(
const
void
*
,
const
void
*
),
int
*
exactmatch
)
{
static
void
*
binary_search
(
const
void
*
key
,
const
void
*
base
,
unsigned
long
member_count
,
const
unsigned
long
member_size
,
int
compare_size
,
int
*
exactmatch
)
{
ot_byte
*
lookat
=
((
ot_byte
*
)
base
)
+
member_size
*
(
member_count
>>
1
);
*
exactmatch
=
1
;
while
(
member_count
)
{
int
cmp
=
compar
((
void
*
)
lookat
,
key
);
int
cmp
=
memcmp
(
lookat
,
key
,
compare_size
);
if
(
cmp
==
0
)
return
(
void
*
)
lookat
;
if
(
cmp
<
0
)
{
base
=
(
void
*
)(
lookat
+
member_size
);
...
...
@@ -48,7 +40,6 @@ static void *binary_search( const void *key, const void *base,
}
*
exactmatch
=
0
;
return
(
void
*
)
lookat
;
}
// Converter function from memory to human readable hex strings
...
...
@@ -56,9 +47,8 @@ static void *binary_search( const void *key, const void *base,
//
char
ths
[
1
+
2
*
20
];
char
*
to_hex
(
ot_byte
*
s
){
char
*
m
=
"0123456789ABCDEF"
;
char
*
e
=
ths
+
40
;
char
*
t
=
ths
;
while
(
t
<
e
){
*
t
++=
m
[
*
s
>>
4
];
*
t
++=
m
[
*
s
++&
15
];}
*
t
=
0
;
return
ths
;}
static
void
*
vector_find_or_insert
(
ot_vector
*
vector
,
void
*
key
,
size_t
member_size
,
int
(
*
compare_func
)(
const
void
*
,
const
void
*
),
int
*
exactmatch
)
{
ot_byte
*
match
=
BINARY_FIND
(
key
,
vector
->
data
,
vector
->
size
,
member_size
,
compare_func
,
exactmatch
);
static
void
*
vector_find_or_insert
(
ot_vector
*
vector
,
void
*
key
,
size_t
member_size
,
int
compare_size
,
int
*
exactmatch
)
{
ot_byte
*
match
=
BINARY_FIND
(
key
,
vector
->
data
,
vector
->
size
,
member_size
,
compare_size
,
exactmatch
);
if
(
*
exactmatch
)
return
match
;
...
...
@@ -84,7 +74,7 @@ static int vector_remove_peer( ot_vector *vector, ot_peer *peer ) {
ot_peer
*
match
;
if
(
!
vector
->
size
)
return
0
;
match
=
BINARY_FIND
(
peer
,
vector
->
data
,
vector
->
size
,
sizeof
(
ot_peer
),
compare_ip_port
,
&
exactmatch
);
match
=
BINARY_FIND
(
peer
,
vector
->
data
,
vector
->
size
,
sizeof
(
ot_peer
),
OT_PEER_COMPARE_SIZE
,
&
exactmatch
);
if
(
!
exactmatch
)
return
0
;
exactmatch
=
OT_FLAG
(
match
)
&
PEER_FLAG_SEEDING
?
2
:
1
;
...
...
@@ -110,7 +100,7 @@ static int vector_remove_torrent( ot_vector *vector, ot_hash *hash ) {
ot_torrent
*
match
;
if
(
!
vector
->
size
)
return
0
;
match
=
BINARY_FIND
(
hash
,
vector
->
data
,
vector
->
size
,
sizeof
(
ot_torrent
),
compare_hash
,
&
exactmatch
);
match
=
BINARY_FIND
(
hash
,
vector
->
data
,
vector
->
size
,
sizeof
(
ot_torrent
),
OT_HASH_COMPARE_SIZE
,
&
exactmatch
);
if
(
!
exactmatch
)
return
0
;
free_peerlist
(
match
->
peer_list
);
...
...
@@ -149,7 +139,7 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ) {
ot_peer
*
peer_dest
;
ot_vector
*
torrents_list
=
&
all_torrents
[
*
hash
[
0
]],
*
peer_pool
;
torrent
=
vector_find_or_insert
(
torrents_list
,
(
void
*
)
hash
,
sizeof
(
ot_torrent
),
compare_hash
,
&
exactmatch
);
torrent
=
vector_find_or_insert
(
torrents_list
,
(
void
*
)
hash
,
sizeof
(
ot_torrent
),
OT_HASH_COMPARE_SIZE
,
&
exactmatch
);
if
(
!
torrent
)
return
NULL
;
if
(
!
exactmatch
)
{
...
...
@@ -167,7 +157,7 @@ ot_torrent *add_peer_to_torrent( ot_hash *hash, ot_peer *peer ) {
clean_peerlist
(
torrent
->
peer_list
);
peer_pool
=
&
torrent
->
peer_list
->
peers
[
0
];
peer_dest
=
vector_find_or_insert
(
peer_pool
,
(
void
*
)
peer
,
sizeof
(
ot_peer
),
compare_ip_port
,
&
exactmatch
);
peer_dest
=
vector_find_or_insert
(
peer_pool
,
(
void
*
)
peer
,
sizeof
(
ot_peer
),
OT_PEER_COMPARE_SIZE
,
&
exactmatch
);
// If we hadn't had a match in current pool, create peer there and
// remove it from all older pools
...
...
@@ -242,7 +232,7 @@ size_t return_scrape_for_torrent( ot_hash *hash, char *reply ) {
char
*
r
=
reply
;
int
exactmatch
,
peers
=
0
,
seeds
=
0
,
i
;
ot_vector
*
torrents_list
=
&
all_torrents
[
*
hash
[
0
]];
ot_torrent
*
torrent
=
BINARY_FIND
(
hash
,
torrents_list
->
data
,
torrents_list
->
size
,
sizeof
(
ot_torrent
),
compare_hash
,
&
exactmatch
);
ot_torrent
*
torrent
=
BINARY_FIND
(
hash
,
torrents_list
->
data
,
torrents_list
->
size
,
sizeof
(
ot_torrent
),
OT_HASH_COMPARE_SIZE
,
&
exactmatch
);
if
(
!
exactmatch
)
return
0
;
clean_peerlist
(
torrent
->
peer_list
);
...
...
@@ -261,7 +251,7 @@ size_t return_scrape_for_torrent( ot_hash *hash, char *reply ) {
void
remove_peer_from_torrent
(
ot_hash
*
hash
,
ot_peer
*
peer
)
{
int
exactmatch
,
i
;
ot_vector
*
torrents_list
=
&
all_torrents
[
*
hash
[
0
]];
ot_torrent
*
torrent
=
BINARY_FIND
(
hash
,
torrents_list
->
data
,
torrents_list
->
size
,
sizeof
(
ot_torrent
),
compare_hash
,
&
exactmatch
);
ot_torrent
*
torrent
=
BINARY_FIND
(
hash
,
torrents_list
->
data
,
torrents_list
->
size
,
sizeof
(
ot_torrent
),
OT_HASH_COMPARE_SIZE
,
&
exactmatch
);
if
(
!
exactmatch
)
return
;
...
...
@@ -279,6 +269,24 @@ void remove_peer_from_torrent( ot_hash *hash, ot_peer *peer ) {
}
}
#if 0
void dump_knowledge( void ) {
int ati, tli, pli;
for( ati = 0; ati<256; ++ati ) {
ot_vector *torrent_list = &all_torrents[ati];
for( tli = 0; tli<torrent_list->size; ++tli ) {
ot_torrent *torrent = &torrent_list->data[tli];
for( pool = 0; pool<OT_POOLS_COUNT; ++pool ) {
for( pli=0; pli<torrent->peer_list->peers[pool].size; ++pli ) {
}
}
}
}
}
#endif
void
cleanup_torrents
(
void
)
{
}
...
...
trackerlogic.h
浏览文件 @
33eaf54d
...
...
@@ -53,6 +53,9 @@ static const ot_byte PEER_FLAG_STOPPED = 0x20;
#define OT_SETPORT( peer, port ) MEMMOVE(((ot_byte*)peer)+4,(port),2);
#define OT_FLAG(peer) (((ot_byte*)(peer))[6])
#define OT_PEER_COMPARE_SIZE ((size_t)6)
#define OT_HASH_COMPARE_SIZE (sizeof(ot_hash))
typedef
struct
{
ot_time
base
;
unsigned
long
seed_count
[
OT_POOLS_COUNT
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录