Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
9ec3c1aa
提交
9ec3c1aa
authored
7月 13, 2015
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean up unused dht methods
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
上级
7077d717
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
6 行增加
和
60 行删除
+6
-60
dht.go
routing/dht/dht.go
+0
-57
dht_test.go
routing/dht/dht_test.go
+6
-3
没有找到文件。
routing/dht/dht.go
浏览文件 @
9ec3c1aa
...
...
@@ -4,7 +4,6 @@ package dht
import
(
"bytes"
"crypto/rand"
"errors"
"fmt"
"sync"
...
...
@@ -33,8 +32,6 @@ var log = eventlog.Logger("dht")
var
ProtocolDHT
protocol
.
ID
=
"/ipfs/dht"
const
doPinging
=
false
// NumBootstrapQueries defines the number of random dht queries to do to
// collect members of the routing table.
const
NumBootstrapQueries
=
5
...
...
@@ -92,11 +89,6 @@ func NewDHT(ctx context.Context, h host.Host, dstore ds.ThreadSafeDatastore) *Ip
dht
.
Validator
=
make
(
record
.
Validator
)
dht
.
Validator
[
"pk"
]
=
record
.
PublicKeyValidator
if
doPinging
{
dht
.
proc
.
Go
(
func
(
p
goprocess
.
Process
)
{
dht
.
PingRoutine
(
time
.
Second
*
10
)
})
}
return
dht
}
...
...
@@ -110,23 +102,6 @@ func (dht *IpfsDHT) log() eventlog.EventLogger {
return
log
// TODO rm
}
// Connect to a new peer at the given address, ping and add to the routing table
func
(
dht
*
IpfsDHT
)
Connect
(
ctx
context
.
Context
,
npeer
peer
.
ID
)
error
{
// TODO: change interface to accept a PeerInfo as well.
if
err
:=
dht
.
host
.
Connect
(
ctx
,
peer
.
PeerInfo
{
ID
:
npeer
});
err
!=
nil
{
return
err
}
// Ping new peer to register in their routing table
// NOTE: this should be done better...
if
_
,
err
:=
dht
.
Ping
(
ctx
,
npeer
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to ping newly connected peer: %s"
,
err
)
}
log
.
Event
(
ctx
,
"connect"
,
dht
.
self
,
npeer
)
dht
.
Update
(
ctx
,
npeer
)
return
nil
}
// putValueToPeer stores the given key/value pair at the peer 'p'
func
(
dht
*
IpfsDHT
)
putValueToPeer
(
ctx
context
.
Context
,
p
peer
.
ID
,
key
key
.
Key
,
rec
*
pb
.
Record
)
error
{
...
...
@@ -343,38 +318,6 @@ func (dht *IpfsDHT) betterPeersToQuery(pmes *pb.Message, p peer.ID, count int) [
return
filtered
}
func
(
dht
*
IpfsDHT
)
ensureConnectedToPeer
(
ctx
context
.
Context
,
p
peer
.
ID
)
error
{
if
p
==
dht
.
self
{
return
errors
.
New
(
"attempting to ensure connection to self"
)
}
// dial connection
return
dht
.
host
.
Connect
(
ctx
,
peer
.
PeerInfo
{
ID
:
p
})
}
// PingRoutine periodically pings nearest neighbors.
func
(
dht
*
IpfsDHT
)
PingRoutine
(
t
time
.
Duration
)
{
tick
:=
time
.
Tick
(
t
)
for
{
select
{
case
<-
tick
:
id
:=
make
([]
byte
,
16
)
rand
.
Read
(
id
)
peers
:=
dht
.
routingTable
.
NearestPeers
(
kb
.
ConvertKey
(
key
.
Key
(
id
)),
5
)
for
_
,
p
:=
range
peers
{
ctx
,
cancel
:=
context
.
WithTimeout
(
dht
.
Context
(),
time
.
Second
*
5
)
_
,
err
:=
dht
.
Ping
(
ctx
,
p
)
if
err
!=
nil
{
log
.
Debugf
(
"Ping error: %s"
,
err
)
}
cancel
()
}
case
<-
dht
.
proc
.
Closing
()
:
return
}
}
}
// Context return dht's context
func
(
dht
*
IpfsDHT
)
Context
()
context
.
Context
{
return
dht
.
ctx
...
...
routing/dht/dht_test.go
浏览文件 @
9ec3c1aa
...
...
@@ -74,7 +74,8 @@ func connect(t *testing.T, ctx context.Context, a, b *IpfsDHT) {
}
a
.
peerstore
.
AddAddrs
(
idB
,
addrB
,
peer
.
TempAddrTTL
)
if
err
:=
a
.
Connect
(
ctx
,
idB
);
err
!=
nil
{
pi
:=
peer
.
PeerInfo
{
ID
:
idB
}
if
err
:=
a
.
host
.
Connect
(
ctx
,
pi
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
...
...
@@ -789,12 +790,14 @@ func TestConnectCollision(t *testing.T) {
errs
:=
make
(
chan
error
)
go
func
()
{
dhtA
.
peerstore
.
AddAddr
(
peerB
,
addrB
,
peer
.
TempAddrTTL
)
err
:=
dhtA
.
Connect
(
ctx
,
peerB
)
pi
:=
peer
.
PeerInfo
{
ID
:
peerB
}
err
:=
dhtA
.
host
.
Connect
(
ctx
,
pi
)
errs
<-
err
}()
go
func
()
{
dhtB
.
peerstore
.
AddAddr
(
peerA
,
addrA
,
peer
.
TempAddrTTL
)
err
:=
dhtB
.
Connect
(
ctx
,
peerA
)
pi
:=
peer
.
PeerInfo
{
ID
:
peerA
}
err
:=
dhtB
.
host
.
Connect
(
ctx
,
pi
)
errs
<-
err
}()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论