Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
550971fb
提交
550971fb
authored
7月 29, 2014
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
equalize sizes
上级
171f96b7
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
50 行增加
和
36 行删除
+50
-36
table.go
routing/dht/table.go
+50
-36
没有找到文件。
routing/dht/table.go
浏览文件 @
550971fb
package
dht
import
(
"container/list"
"bytes"
"container/list"
)
// ID for IpfsDHT should be a byte slice, to allow for simpler operations
// (xor). DHT ids are based on the peer.IDs.
//
// NOTE: peer.IDs are biased because they are (a) multihashes (first bytes
// biased), and (b) first bits are zeroes when using the S/Kademlia PoW.
// Thus, may need to re-hash keys (uniform dist). TODO(jbenet)
// NOTE: peer.IDs are biased because they are multihashes (first bytes
// biased). Thus, may need to re-hash keys (uniform dist). TODO(jbenet)
type
ID
[]
byte
// Bucket holds a list of peers.
type
Bucket
[]
*
list
.
List
// RoutingTable defines the routing table.
type
RoutingTable
struct
{
// kBuckets define all the fingers to other nodes.
Buckets
[]
Bucket
// kBuckets define all the fingers to other nodes.
Buckets
[]
Bucket
}
func
(
id
ID
)
Equal
(
other
ID
)
bool
{
return
bytes
.
Equal
(
id
,
other
)
}
func
(
id
ID
)
Less
(
other
interface
{})
bool
{
a
,
b
:=
equalizeSizes
(
id
,
other
.
(
ID
))
for
i
:=
0
;
i
<
len
(
a
);
i
++
{
if
a
[
i
]
!=
b
[
i
]
{
return
a
[
i
]
<
b
[
i
]
}
}
return
len
(
a
)
<
len
(
b
)
}
func
(
id
ID
)
commonPrefixLen
()
int
{
for
i
:=
0
;
i
<
len
(
id
);
i
++
{
for
j
:=
0
;
j
<
8
;
j
++
{
if
(
id
[
i
]
>>
uint8
(
7
-
j
))
&
0x1
!=
0
{
return
i
*
8
+
j
;
}
}
}
return
len
(
id
)
*
8
-
1
;
for
i
:=
0
;
i
<
len
(
id
);
i
++
{
for
j
:=
0
;
j
<
8
;
j
++
{
if
(
id
[
i
]
>>
uint8
(
7
-
j
))
&
0x1
!=
0
{
return
i
*
8
+
j
}
}
}
return
len
(
id
)
*
8
-
1
}
func
xor
(
a
,
b
ID
)
ID
{
a
,
b
=
equalizeSizes
(
a
,
b
)
c
:=
make
(
ID
,
len
(
a
))
for
i
:=
0
;
i
<
len
(
a
);
i
++
{
c
[
i
]
=
a
[
i
]
^
b
[
i
]
}
return
c
}
func
equalizeSizes
(
a
,
b
ID
)
(
ID
,
ID
)
{
la
:=
len
(
a
)
lb
:=
len
(
b
)
if
la
<
lb
{
na
:=
make
([]
byte
,
lb
)
copy
(
na
,
a
)
a
=
na
}
else
if
lb
<
la
{
nb
:=
make
([]
byte
,
la
)
copy
(
nb
,
b
)
b
=
nb
}
// ids may actually be of different sizes.
var
ba
ID
var
bb
ID
if
len
(
a
)
>=
len
(
b
)
{
ba
=
a
bb
=
b
}
else
{
ba
=
b
bb
=
a
}
c
:=
make
(
ID
,
len
(
ba
))
for
i
:=
0
;
i
<
len
(
ba
);
i
++
{
if
len
(
bb
)
>
i
{
c
[
i
]
=
ba
[
i
]
^
bb
[
i
]
}
else
{
c
[
i
]
=
ba
[
i
]
^
0
}
}
return
c
return
a
,
b
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论