Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
53f0b117
提交
53f0b117
authored
9月 26, 2014
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update net with peerstore
上级
0817ffa3
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
50 行增加
和
23 行删除
+50
-23
core.go
core/core.go
+1
-1
conn.go
net/conn/conn.go
+6
-11
net.go
net/net.go
+2
-2
conn.go
net/swarm/conn.go
+25
-6
swarm.go
net/swarm/swarm.go
+15
-2
dht_test.go
routing/dht/dht_test.go
+1
-1
没有找到文件。
core/core.go
浏览文件 @
53f0b117
...
...
@@ -106,7 +106,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
return
nil
,
err
}
net
,
err
=
inet
.
NewIpfsNetwork
(
context
.
TODO
(),
local
,
&
mux
.
ProtocolMap
{
net
,
err
=
inet
.
NewIpfsNetwork
(
context
.
TODO
(),
local
,
peerstore
,
&
mux
.
ProtocolMap
{
mux
.
ProtocolID_Routing
:
dhtService
,
mux
.
ProtocolID_Exchange
:
exchangeService
,
})
...
...
net/conn/conn.go
浏览文件 @
53f0b117
...
...
@@ -48,17 +48,6 @@ func NewConn(peer *peer.Peer, addr *ma.Multiaddr, nconn net.Conn) (*Conn, error)
return
conn
,
nil
}
// NewNetConn constructs a new connection with given net.Conn
func
NewNetConn
(
nconn
net
.
Conn
)
(
*
Conn
,
error
)
{
addr
,
err
:=
ma
.
FromNetAddr
(
nconn
.
RemoteAddr
())
if
err
!=
nil
{
return
nil
,
err
}
return
NewConn
(
new
(
peer
.
Peer
),
addr
,
nconn
)
}
// Dial connects to a particular peer, over a given network
// Example: Dial("udp", peer)
func
Dial
(
network
string
,
peer
*
peer
.
Peer
)
(
*
Conn
,
error
)
{
...
...
@@ -112,3 +101,9 @@ func (c *Conn) Close() error {
c
.
Closed
<-
true
return
err
}
// NetConnMultiaddr returns the net.Conn's address, recast as a multiaddr.
// (consider moving this directly into the multiaddr package)
func
NetConnMultiaddr
(
nconn
net
.
Conn
)
(
*
ma
.
Multiaddr
,
error
)
{
return
ma
.
FromNetAddr
(
nconn
.
RemoteAddr
())
}
net/net.go
浏览文件 @
53f0b117
...
...
@@ -30,7 +30,7 @@ type IpfsNetwork struct {
// NewIpfsNetwork is the structure that implements the network interface
func
NewIpfsNetwork
(
ctx
context
.
Context
,
local
*
peer
.
Peer
,
pmap
*
mux
.
ProtocolMap
)
(
*
IpfsNetwork
,
error
)
{
p
eers
peer
.
Peerstore
,
p
map
*
mux
.
ProtocolMap
)
(
*
IpfsNetwork
,
error
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
...
...
@@ -47,7 +47,7 @@ func NewIpfsNetwork(ctx context.Context, local *peer.Peer,
return
nil
,
err
}
in
.
swarm
,
err
=
swarm
.
NewSwarm
(
ctx
,
local
)
in
.
swarm
,
err
=
swarm
.
NewSwarm
(
ctx
,
local
,
peers
)
if
err
!=
nil
{
cancel
()
return
nil
,
err
...
...
net/swarm/conn.go
浏览文件 @
53f0b117
...
...
@@ -76,15 +76,19 @@ func (s *Swarm) connListen(maddr *ma.Multiaddr) error {
// Handle getting ID from this peer, handshake, and adding it into the map
func
(
s
*
Swarm
)
handleIncomingConn
(
nconn
net
.
Conn
)
{
c
,
err
:=
conn
.
NewNetConn
(
nconn
)
addr
,
err
:=
conn
.
NetConnMultiaddr
(
nconn
)
if
err
!=
nil
{
s
.
errChan
<-
err
return
}
//TODO(jbenet) the peer might potentially already be in the global PeerBook.
// maybe use the handshake to populate peer.
c
.
Peer
.
AddAddress
(
c
.
Addr
)
// Construct conn with nil peer for now, because we don't know its ID yet.
// connSetup will figure this out, and pull out / construct the peer.
c
,
err
:=
conn
.
NewConn
(
nil
,
addr
,
nconn
)
if
err
!=
nil
{
s
.
errChan
<-
err
return
}
// Setup the new connection
err
=
s
.
connSetup
(
c
)
...
...
@@ -101,7 +105,11 @@ func (s *Swarm) connSetup(c *conn.Conn) error {
return
errors
.
New
(
"Tried to start nil connection."
)
}
u
.
DOut
(
"Starting connection: %s
\n
"
,
c
.
Peer
.
Key
()
.
Pretty
())
if
c
.
Peer
!=
nil
{
u
.
DOut
(
"Starting connection: %s
\n
"
,
c
.
Peer
.
Key
()
.
Pretty
())
}
else
{
u
.
DOut
(
"Starting connection: [unknown peer]
\n
"
)
}
if
err
:=
s
.
connSecure
(
c
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Conn securing error: %v"
,
err
)
...
...
@@ -109,6 +117,10 @@ func (s *Swarm) connSetup(c *conn.Conn) error {
u
.
DOut
(
"Secured connection: %s
\n
"
,
c
.
Peer
.
Key
()
.
Pretty
())
//TODO(jbenet) the peer might potentially already be in the global PeerBook.
// maybe use the handshake to populate peer.
c
.
Peer
.
AddAddress
(
c
.
Addr
)
// add to conns
s
.
connsLock
.
Lock
()
if
_
,
ok
:=
s
.
conns
[
c
.
Peer
.
Key
()];
ok
{
...
...
@@ -126,7 +138,7 @@ func (s *Swarm) connSetup(c *conn.Conn) error {
// connSecure setups a secure remote connection.
func
(
s
*
Swarm
)
connSecure
(
c
*
conn
.
Conn
)
error
{
sp
,
err
:=
spipe
.
NewSecurePipe
(
s
.
ctx
,
10
,
s
.
local
,
c
.
Peer
)
sp
,
err
:=
spipe
.
NewSecurePipe
(
s
.
ctx
,
10
,
s
.
local
,
s
.
peers
)
if
err
!=
nil
{
return
err
}
...
...
@@ -139,6 +151,13 @@ func (s *Swarm) connSecure(c *conn.Conn) error {
return
err
}
if
c
.
Peer
==
nil
{
c
.
Peer
=
sp
.
RemotePeer
()
}
else
if
c
.
Peer
!=
sp
.
RemotePeer
()
{
panic
(
"peers not being constructed correctly."
)
}
c
.
Secure
=
sp
return
nil
}
...
...
net/swarm/swarm.go
浏览文件 @
53f0b117
...
...
@@ -46,6 +46,9 @@ type Swarm struct {
// local is the peer this swarm represents
local
*
peer
.
Peer
// peers is a collection of peers for swarm to use
peers
peer
.
Peerstore
// Swarm includes a Pipe object.
*
msg
.
Pipe
...
...
@@ -65,11 +68,12 @@ type Swarm struct {
}
// NewSwarm constructs a Swarm, with a Chan.
func
NewSwarm
(
ctx
context
.
Context
,
local
*
peer
.
Peer
)
(
*
Swarm
,
error
)
{
func
NewSwarm
(
ctx
context
.
Context
,
local
*
peer
.
Peer
,
ps
peer
.
Peerstore
)
(
*
Swarm
,
error
)
{
s
:=
&
Swarm
{
Pipe
:
msg
.
NewPipe
(
10
),
conns
:
conn
.
Map
{},
local
:
local
,
peers
:
ps
,
errChan
:
make
(
chan
error
,
100
),
}
...
...
@@ -112,9 +116,18 @@ func (s *Swarm) Dial(peer *peer.Peer) (*conn.Conn, error) {
// check if we already have an open connection first
c
:=
s
.
GetConnection
(
peer
.
ID
)
if
c
!=
nil
{
return
c
,
nil
}
// check if we don't have the peer in Peerstore
err
:=
s
.
peers
.
Put
(
peer
)
if
err
!=
nil
{
return
nil
,
err
}
// open connection to peer
c
,
err
:
=
conn
.
Dial
(
"tcp"
,
peer
)
c
,
err
=
conn
.
Dial
(
"tcp"
,
peer
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
routing/dht/dht_test.go
浏览文件 @
53f0b117
...
...
@@ -31,7 +31,7 @@ func setupDHT(t *testing.T, p *peer.Peer) *IpfsDHT {
t
.
Fatal
(
err
)
}
net
,
err
:=
inet
.
NewIpfsNetwork
(
ctx
,
p
,
&
mux
.
ProtocolMap
{
net
,
err
:=
inet
.
NewIpfsNetwork
(
ctx
,
p
,
peerstore
,
&
mux
.
ProtocolMap
{
mux
.
ProtocolID_Routing
:
dhts
,
})
if
err
!=
nil
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论