Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
94f04c7f
提交
94f04c7f
authored
11月 20, 2014
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
net: add Connectedness var.
上级
26e76561
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
59 行增加
和
16 行删除
+59
-16
bootstrap.go
core/bootstrap.go
+1
-1
interface.go
net/interface.go
+24
-2
net.go
net/net.go
+10
-1
ext_test.go
routing/dht/ext_test.go
+24
-12
没有找到文件。
core/bootstrap.go
浏览文件 @
94f04c7f
...
...
@@ -64,7 +64,7 @@ func bootstrap(ctx context.Context,
var
notConnected
[]
peer
.
Peer
for
_
,
p
:=
range
bootstrapPeers
{
if
!
n
.
IsConnected
(
p
)
{
if
n
.
Connectedness
(
p
)
!=
inet
.
Connected
{
notConnected
=
append
(
notConnected
,
p
)
}
}
...
...
net/interface.go
浏览文件 @
94f04c7f
...
...
@@ -26,8 +26,8 @@ type Network interface {
// ClosePeer connection to peer
ClosePeer
(
peer
.
Peer
)
error
//
IsConnected returns whether a connection to given peer exists.
IsConnected
(
peer
.
Peer
)
bool
//
Connectedness returns a state signaling connection capabilities
Connectedness
(
peer
.
Peer
)
Connectedness
// GetProtocols returns the protocols registered in the network.
GetProtocols
()
*
mux
.
ProtocolMap
...
...
@@ -74,4 +74,26 @@ type Dialer interface {
// DialPeer attempts to establish a connection to a given peer
DialPeer
(
context
.
Context
,
peer
.
Peer
)
error
// Connectedness returns a state signaling connection capabilities
Connectedness
(
peer
.
Peer
)
Connectedness
}
// Connectedness signals the capacity for a connection with a given node.
// It is used to signal to services and other peers whether a node is reachable.
type
Connectedness
int
const
(
// NotConnected means no connection to peer, and no extra information (default)
NotConnected
Connectedness
=
0
// Connected means has an open, live connection to peer
Connected
// CanConnect means recently connected to peer, terminated gracefully
CanConnect
// CannotConnect means recently attempted connecting but failed to connect.
// (should signal "made effort, failed")
CannotConnect
)
net/net.go
浏览文件 @
94f04c7f
//
p
ackage net provides an interface for ipfs to interact with the network through
//
P
ackage net provides an interface for ipfs to interact with the network through
package
net
import
(
...
...
@@ -126,3 +126,12 @@ func (n *IpfsNetwork) ListenAddresses() []ma.Multiaddr {
func
(
n
*
IpfsNetwork
)
InterfaceListenAddresses
()
([]
ma
.
Multiaddr
,
error
)
{
return
n
.
swarm
.
InterfaceListenAddresses
()
}
// Connectedness returns a state signaling connection capabilities
// For now only returns Connecter || NotConnected. Expand into more later.
func
(
n
*
IpfsNetwork
)
Connectedness
(
p
peer
.
Peer
)
Connectedness
{
if
n
.
swarm
.
GetConnection
(
p
.
ID
())
!=
nil
{
return
Connected
}
return
NotConnected
}
routing/dht/ext_test.go
浏览文件 @
94f04c7f
...
...
@@ -8,6 +8,7 @@ import (
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
inet
"github.com/jbenet/go-ipfs/net"
msg
"github.com/jbenet/go-ipfs/net/message"
mux
"github.com/jbenet/go-ipfs/net/mux"
peer
"github.com/jbenet/go-ipfs/peer"
...
...
@@ -79,6 +80,7 @@ func (f *fauxSender) SendMessage(ctx context.Context, m msg.NetMessage) error {
// fauxNet is a standin for a swarm.Network in order to more easily recreate
// different testing scenarios
type
fauxNet
struct
{
local
peer
.
Peer
}
// DialPeer attempts to establish a connection to a given peer
...
...
@@ -86,6 +88,10 @@ func (f *fauxNet) DialPeer(context.Context, peer.Peer) error {
return
nil
}
func
(
f
*
fauxNet
)
LocalPeer
()
peer
.
Peer
{
return
f
.
local
}
// ClosePeer connection to peer
func
(
f
*
fauxNet
)
ClosePeer
(
peer
.
Peer
)
error
{
return
nil
...
...
@@ -96,6 +102,11 @@ func (f *fauxNet) IsConnected(peer.Peer) (bool, error) {
return
true
,
nil
}
// Connectedness returns whether a connection to given peer exists.
func
(
f
*
fauxNet
)
Connectedness
(
peer
.
Peer
)
inet
.
Connectedness
{
return
inet
.
Connected
}
// GetProtocols returns the protocols registered in the network.
func
(
f
*
fauxNet
)
GetProtocols
()
*
mux
.
ProtocolMap
{
return
nil
}
...
...
@@ -120,13 +131,13 @@ func TestGetFailures(t *testing.T) {
t
.
SkipNow
()
}
ctx
:=
context
.
Background
()
fn
:=
&
fauxNet
{}
fs
:=
&
fauxSender
{}
peerstore
:=
peer
.
NewPeerstore
()
local
:=
makePeerString
(
t
,
""
)
ctx
:=
context
.
Background
()
fn
:=
&
fauxNet
{
local
}
fs
:=
&
fauxSender
{}
d
:=
NewDHT
(
ctx
,
local
,
peerstore
,
fn
,
fs
,
ds
.
NewMapDatastore
())
other
:=
makePeerString
(
t
,
""
)
d
.
Update
(
ctx
,
other
)
...
...
@@ -219,14 +230,14 @@ func TestNotFound(t *testing.T) {
t
.
SkipNow
()
}
ctx
:=
context
.
Background
()
fn
:=
&
fauxNet
{}
fs
:=
&
fauxSender
{}
local
:=
makePeerString
(
t
,
""
)
peerstore
:=
peer
.
NewPeerstore
()
peerstore
.
Add
(
local
)
ctx
:=
context
.
Background
()
fn
:=
&
fauxNet
{
local
}
fs
:=
&
fauxSender
{}
d
:=
NewDHT
(
ctx
,
local
,
peerstore
,
fn
,
fs
,
ds
.
NewMapDatastore
())
var
ps
[]
peer
.
Peer
...
...
@@ -285,14 +296,15 @@ func TestNotFound(t *testing.T) {
func
TestLessThanKResponses
(
t
*
testing
.
T
)
{
// t.Skip("skipping test because it makes a lot of output")
ctx
:=
context
.
Background
()
u
.
Debug
=
false
fn
:=
&
fauxNet
{}
fs
:=
&
fauxSender
{}
local
:=
makePeerString
(
t
,
""
)
peerstore
:=
peer
.
NewPeerstore
()
peerstore
.
Add
(
local
)
ctx
:=
context
.
Background
()
u
.
Debug
=
false
fn
:=
&
fauxNet
{
local
}
fs
:=
&
fauxSender
{}
d
:=
NewDHT
(
ctx
,
local
,
peerstore
,
fn
,
fs
,
ds
.
NewMapDatastore
())
var
ps
[]
peer
.
Peer
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论