Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
c5c0e7e8
提交
c5c0e7e8
authored
11月 20, 2014
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dht: changed msgs, include multiple addrs + conn type
See
https://github.com/jbenet/go-ipfs/issues/153#issuecomment-63350535
上级
a1237733
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
124 行增加
和
28 行删除
+124
-28
dht.go
routing/dht/dht.go
+5
-2
handlers.go
routing/dht/handlers.go
+6
-4
dht.pb.go
routing/dht/pb/dht.pb.go
+66
-8
dht.proto
routing/dht/pb/dht.proto
+22
-1
message.go
routing/dht/pb/message.go
+17
-10
routing.go
routing/dht/routing.go
+8
-3
没有找到文件。
routing/dht/dht.go
浏览文件 @
c5c0e7e8
...
@@ -517,11 +517,14 @@ func (dht *IpfsDHT) peerFromInfo(pbp *pb.Message_Peer) (peer.Peer, error) {
...
@@ -517,11 +517,14 @@ func (dht *IpfsDHT) peerFromInfo(pbp *pb.Message_Peer) (peer.Peer, error) {
return
nil
,
err
return
nil
,
err
}
}
maddr
,
err
:=
pbp
.
Address
()
// add addresses we've just discovered
maddrs
,
err
:=
pbp
.
Addresses
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
p
.
AddAddress
(
maddr
)
for
_
,
maddr
:=
range
maddrs
{
p
.
AddAddress
(
maddr
)
}
return
p
,
nil
return
p
,
nil
}
}
...
...
routing/dht/handlers.go
浏览文件 @
c5c0e7e8
...
@@ -210,14 +210,16 @@ func (dht *IpfsDHT) handleAddProvider(ctx context.Context, p peer.Peer, pmes *pb
...
@@ -210,14 +210,16 @@ func (dht *IpfsDHT) handleAddProvider(ctx context.Context, p peer.Peer, pmes *pb
pid
:=
peer
.
ID
(
pb
.
GetId
())
pid
:=
peer
.
ID
(
pb
.
GetId
())
if
pid
.
Equal
(
p
.
ID
())
{
if
pid
.
Equal
(
p
.
ID
())
{
addr
,
err
:=
pb
.
Addres
s
()
maddrs
,
err
:=
pb
.
Addresse
s
()
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Errorf
(
"provider %s error with address
%s"
,
p
,
*
pb
.
Addr
)
log
.
Errorf
(
"provider %s error with address
es %s"
,
p
,
pb
.
Addrs
)
continue
continue
}
}
log
.
Infof
(
"received provider %s %s for %s"
,
p
,
addr
,
key
)
log
.
Infof
(
"received provider %s %s for %s"
,
p
,
maddrs
,
key
)
p
.
AddAddress
(
addr
)
for
_
,
maddr
:=
range
maddrs
{
p
.
AddAddress
(
maddr
)
}
dht
.
providers
.
AddProvider
(
key
,
p
)
dht
.
providers
.
AddProvider
(
key
,
p
)
}
else
{
}
else
{
...
...
routing/dht/pb/dht.pb.go
浏览文件 @
c5c0e7e8
...
@@ -15,10 +15,12 @@ It has these top-level messages:
...
@@ -15,10 +15,12 @@ It has these top-level messages:
package
dht_pb
package
dht_pb
import
proto
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
import
proto
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
import
json
"encoding/json"
import
math
"math"
import
math
"math"
// Reference
imports to suppress errors
if they are not otherwise used.
// Reference
proto, json, and math imports to suppress error
if they are not otherwise used.
var
_
=
proto
.
Marshal
var
_
=
proto
.
Marshal
var
_
=
&
json
.
SyntaxError
{}
var
_
=
math
.
Inf
var
_
=
math
.
Inf
type
Message_MessageType
int32
type
Message_MessageType
int32
...
@@ -66,6 +68,50 @@ func (x *Message_MessageType) UnmarshalJSON(data []byte) error {
...
@@ -66,6 +68,50 @@ func (x *Message_MessageType) UnmarshalJSON(data []byte) error {
return
nil
return
nil
}
}
type
Message_ConnectionType
int32
const
(
// sender does not have a connection to peer, and no extra information (default)
Message_NOT_CONNECTED
Message_ConnectionType
=
0
// sender has a live connection to peer
Message_CONNECTED
Message_ConnectionType
=
1
// sender recently connected to peer
Message_CAN_CONNECT
Message_ConnectionType
=
2
// sender recently tried to connect to peer repeatedly but failed to connect
// ("try" here is loose, but this should signal "made strong effort, failed")
Message_CANNOT_CONNECT
Message_ConnectionType
=
3
)
var
Message_ConnectionType_name
=
map
[
int32
]
string
{
0
:
"NOT_CONNECTED"
,
1
:
"CONNECTED"
,
2
:
"CAN_CONNECT"
,
3
:
"CANNOT_CONNECT"
,
}
var
Message_ConnectionType_value
=
map
[
string
]
int32
{
"NOT_CONNECTED"
:
0
,
"CONNECTED"
:
1
,
"CAN_CONNECT"
:
2
,
"CANNOT_CONNECT"
:
3
,
}
func
(
x
Message_ConnectionType
)
Enum
()
*
Message_ConnectionType
{
p
:=
new
(
Message_ConnectionType
)
*
p
=
x
return
p
}
func
(
x
Message_ConnectionType
)
String
()
string
{
return
proto
.
EnumName
(
Message_ConnectionType_name
,
int32
(
x
))
}
func
(
x
*
Message_ConnectionType
)
UnmarshalJSON
(
data
[]
byte
)
error
{
value
,
err
:=
proto
.
UnmarshalJSONEnum
(
Message_ConnectionType_value
,
data
,
"Message_ConnectionType"
)
if
err
!=
nil
{
return
err
}
*
x
=
Message_ConnectionType
(
value
)
return
nil
}
type
Message
struct
{
type
Message
struct
{
// defines what type of message it is.
// defines what type of message it is.
Type
*
Message_MessageType
`protobuf:"varint,1,opt,name=type,enum=dht.pb.Message_MessageType" json:"type,omitempty"`
Type
*
Message_MessageType
`protobuf:"varint,1,opt,name=type,enum=dht.pb.Message_MessageType" json:"type,omitempty"`
...
@@ -133,9 +179,13 @@ func (m *Message) GetProviderPeers() []*Message_Peer {
...
@@ -133,9 +179,13 @@ func (m *Message) GetProviderPeers() []*Message_Peer {
}
}
type
Message_Peer
struct
{
type
Message_Peer
struct
{
Id
*
string
`protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
// ID of a given peer.
Addr
*
string
`protobuf:"bytes,2,opt,name=addr" json:"addr,omitempty"`
Id
*
string
`protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
// multiaddrs for a given peer
Addrs
[]
string
`protobuf:"bytes,2,rep,name=addrs" json:"addrs,omitempty"`
// used to signal the sender's connection capabilities to the peer
Connection
*
Message_ConnectionType
`protobuf:"varint,3,opt,name=connection,enum=dht.pb.Message_ConnectionType" json:"connection,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
}
func
(
m
*
Message_Peer
)
Reset
()
{
*
m
=
Message_Peer
{}
}
func
(
m
*
Message_Peer
)
Reset
()
{
*
m
=
Message_Peer
{}
}
...
@@ -149,11 +199,18 @@ func (m *Message_Peer) GetId() string {
...
@@ -149,11 +199,18 @@ func (m *Message_Peer) GetId() string {
return
""
return
""
}
}
func
(
m
*
Message_Peer
)
GetAddr
()
string
{
func
(
m
*
Message_Peer
)
GetAddr
s
()
[]
string
{
if
m
!=
nil
&&
m
.
Addr
!=
nil
{
if
m
!=
nil
{
return
*
m
.
Addr
return
m
.
Addrs
}
}
return
""
return
nil
}
func
(
m
*
Message_Peer
)
GetConnection
()
Message_ConnectionType
{
if
m
!=
nil
&&
m
.
Connection
!=
nil
{
return
*
m
.
Connection
}
return
Message_NOT_CONNECTED
}
}
// Record represents a dht record that contains a value
// Record represents a dht record that contains a value
...
@@ -204,4 +261,5 @@ func (m *Record) GetSignature() []byte {
...
@@ -204,4 +261,5 @@ func (m *Record) GetSignature() []byte {
func
init
()
{
func
init
()
{
proto
.
RegisterEnum
(
"dht.pb.Message_MessageType"
,
Message_MessageType_name
,
Message_MessageType_value
)
proto
.
RegisterEnum
(
"dht.pb.Message_MessageType"
,
Message_MessageType_name
,
Message_MessageType_value
)
proto
.
RegisterEnum
(
"dht.pb.Message_ConnectionType"
,
Message_ConnectionType_name
,
Message_ConnectionType_value
)
}
}
routing/dht/pb/dht.proto
浏览文件 @
c5c0e7e8
...
@@ -12,9 +12,30 @@ message Message {
...
@@ -12,9 +12,30 @@ message Message {
PING
=
5
;
PING
=
5
;
}
}
enum
ConnectionType
{
// sender does not have a connection to peer, and no extra information (default)
NOT_CONNECTED
=
0
;
// sender has a live connection to peer
CONNECTED
=
1
;
// sender recently connected to peer
CAN_CONNECT
=
2
;
// sender recently tried to connect to peer repeatedly but failed to connect
// ("try" here is loose, but this should signal "made strong effort, failed")
CANNOT_CONNECT
=
3
;
}
message
Peer
{
message
Peer
{
// ID of a given peer.
optional
string
id
=
1
;
optional
string
id
=
1
;
optional
string
addr
=
2
;
// multiaddrs for a given peer
repeated
string
addrs
=
2
;
// used to signal the sender's connection capabilities to the peer
optional
ConnectionType
connection
=
3
;
}
}
// defines what type of message it is.
// defines what type of message it is.
...
...
routing/dht/pb/message.go
浏览文件 @
c5c0e7e8
...
@@ -3,7 +3,6 @@ package dht_pb
...
@@ -3,7 +3,6 @@ package dht_pb
import
(
import
(
"errors"
"errors"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
ma
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
ma
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
peer
"github.com/jbenet/go-ipfs/peer"
peer
"github.com/jbenet/go-ipfs/peer"
)
)
...
@@ -19,12 +18,11 @@ func NewMessage(typ Message_MessageType, key string, level int) *Message {
...
@@ -19,12 +18,11 @@ func NewMessage(typ Message_MessageType, key string, level int) *Message {
func
peerToPBPeer
(
p
peer
.
Peer
)
*
Message_Peer
{
func
peerToPBPeer
(
p
peer
.
Peer
)
*
Message_Peer
{
pbp
:=
new
(
Message_Peer
)
pbp
:=
new
(
Message_Peer
)
addrs
:=
p
.
Addresses
()
if
len
(
addrs
)
==
0
||
addrs
[
0
]
==
nil
{
maddrs
:=
p
.
Addresses
()
pbp
.
Addr
=
proto
.
String
(
""
)
pbp
.
Addrs
=
make
([]
string
,
len
(
maddrs
))
}
else
{
for
i
,
maddr
:=
range
maddrs
{
addr
:=
addrs
[
0
]
.
String
()
pbp
.
Addrs
[
i
]
=
maddr
.
String
()
pbp
.
Addr
=
&
addr
}
}
pid
:=
string
(
p
.
ID
())
pid
:=
string
(
p
.
ID
())
pbp
.
Id
=
&
pid
pbp
.
Id
=
&
pid
...
@@ -41,12 +39,21 @@ func PeersToPBPeers(peers []peer.Peer) []*Message_Peer {
...
@@ -41,12 +39,21 @@ func PeersToPBPeers(peers []peer.Peer) []*Message_Peer {
return
pbpeers
return
pbpeers
}
}
// Address returns a multiaddr associated with the Message_Peer entry
// Address
es
returns a multiaddr associated with the Message_Peer entry
func
(
m
*
Message_Peer
)
Address
()
(
ma
.
Multiaddr
,
error
)
{
func
(
m
*
Message_Peer
)
Address
es
()
([]
ma
.
Multiaddr
,
error
)
{
if
m
==
nil
{
if
m
==
nil
{
return
nil
,
errors
.
New
(
"MessagePeer is nil"
)
return
nil
,
errors
.
New
(
"MessagePeer is nil"
)
}
}
return
ma
.
NewMultiaddr
(
*
m
.
Addr
)
var
err
error
maddrs
:=
make
([]
ma
.
Multiaddr
,
len
(
m
.
Addrs
))
for
i
,
addr
:=
range
m
.
Addrs
{
maddrs
[
i
],
err
=
ma
.
NewMultiaddr
(
addr
)
if
err
!=
nil
{
return
nil
,
err
}
}
return
maddrs
,
nil
}
}
// GetClusterLevel gets and adjusts the cluster level on the message.
// GetClusterLevel gets and adjusts the cluster level on the message.
...
...
routing/dht/routing.go
浏览文件 @
c5c0e7e8
...
@@ -241,12 +241,17 @@ func (dht *IpfsDHT) FindPeer(ctx context.Context, id peer.ID) (peer.Peer, error)
...
@@ -241,12 +241,17 @@ func (dht *IpfsDHT) FindPeer(ctx context.Context, id peer.ID) (peer.Peer, error)
log
.
Warningf
(
"Received invalid peer from query: %v"
,
err
)
log
.
Warningf
(
"Received invalid peer from query: %v"
,
err
)
continue
continue
}
}
ma
,
err
:=
pbp
.
Address
()
// add addresses
maddrs
,
err
:=
pbp
.
Addresses
()
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Warning
(
"Received peer with bad or missing address
."
)
log
.
Warning
(
"Received peer with bad or missing address
es: %s"
,
pbp
.
Addrs
)
continue
continue
}
}
np
.
AddAddress
(
ma
)
for
_
,
maddr
:=
range
maddrs
{
np
.
AddAddress
(
maddr
)
}
if
pbp
.
GetId
()
==
string
(
id
)
{
if
pbp
.
GetId
()
==
string
(
id
)
{
return
&
dhtQueryResult
{
return
&
dhtQueryResult
{
peer
:
np
,
peer
:
np
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论