Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
bec54c25
提交
bec54c25
authored
6月 19, 2017
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename PTP to P2P
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
2f999d4b
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
127 行增加
和
127 行删除
+127
-127
p2p.go
core/commands/p2p.go
+50
-50
root.go
core/commands/root.go
+2
-2
core.go
core/core.go
+3
-3
p2p.go
p2p/p2p.go
+32
-32
registry.go
p2p/registry.go
+1
-1
t0180-p2p.sh
test/sharness/t0180-p2p.sh
+39
-39
没有找到文件。
core/commands/p
t
p.go
→
core/commands/p
2
p.go
浏览文件 @
bec54c25
...
...
@@ -14,14 +14,14 @@ import (
ma
"gx/ipfs/QmcyqRMCAXVtYPS4DiBrA7sezL9rRGfW8Ctx7cywL4TXJj/go-multiaddr"
)
// P
T
PListenerInfoOutput is output type of ls command
type
P
T
PListenerInfoOutput
struct
{
// P
2
PListenerInfoOutput is output type of ls command
type
P
2
PListenerInfoOutput
struct
{
Protocol
string
Address
string
}
// P
T
PStreamInfoOutput is output type of streams command
type
P
T
PStreamInfoOutput
struct
{
// P
2
PStreamInfoOutput is output type of streams command
type
P
2
PStreamInfoOutput
struct
{
HandlerID
string
Protocol
string
LocalPeer
string
...
...
@@ -30,18 +30,18 @@ type PTPStreamInfoOutput struct {
RemoteAddress
string
}
// P
T
PLsOutput is output type of ls command
type
P
T
PLsOutput
struct
{
Listeners
[]
P
T
PListenerInfoOutput
// P
2
PLsOutput is output type of ls command
type
P
2
PLsOutput
struct
{
Listeners
[]
P
2
PListenerInfoOutput
}
// P
T
PStreamsOutput is output type of streams command
type
P
T
PStreamsOutput
struct
{
Streams
[]
P
T
PStreamInfoOutput
// P
2
PStreamsOutput is output type of streams command
type
P
2
PStreamsOutput
struct
{
Streams
[]
P
2
PStreamInfoOutput
}
// P
TPCmd is the 'ipfs pt
p' command
var
P
T
PCmd
=
&
cmds
.
Command
{
// P
2PCmd is the 'ipfs pp
p' command
var
P
2
PCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Libp2p stream mounting."
,
ShortDescription
:
`
...
...
@@ -51,40 +51,40 @@ Note: this command is experimental and subject to change as usecases and APIs ar
},
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"listener"
:
p
t
pListenerCmd
,
"stream"
:
p
t
pStreamCmd
,
"listener"
:
p
2
pListenerCmd
,
"stream"
:
p
2
pStreamCmd
,
},
}
// p
tpListenerCmd is the 'ipfs pt
p listener' command
var
p
t
pListenerCmd
=
&
cmds
.
Command
{
// p
2pListenerCmd is the 'ipfs p2
p listener' command
var
p
2
pListenerCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"P2P listener management."
,
ShortDescription
:
"Create and manage listener p2p endpoints"
,
},
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"ls"
:
p
t
pListenerLsCmd
,
"open"
:
p
t
pListenerListenCmd
,
"close"
:
p
t
pListenerCloseCmd
,
"ls"
:
p
2
pListenerLsCmd
,
"open"
:
p
2
pListenerListenCmd
,
"close"
:
p
2
pListenerCloseCmd
,
},
}
// p
tpStreamCmd is the 'ipfs pt
p stream' command
var
p
t
pStreamCmd
=
&
cmds
.
Command
{
// p
2pStreamCmd is the 'ipfs p2
p stream' command
var
p
2
pStreamCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"P2P stream management."
,
ShortDescription
:
"Create and manage p2p streams"
,
},
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"ls"
:
p
t
pStreamLsCmd
,
"dial"
:
p
t
pStreamDialCmd
,
"close"
:
p
t
pStreamCloseCmd
,
"ls"
:
p
2
pStreamLsCmd
,
"dial"
:
p
2
pStreamDialCmd
,
"close"
:
p
2
pStreamCloseCmd
,
},
}
var
p
t
pListenerLsCmd
=
&
cmds
.
Command
{
var
p
2
pListenerLsCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"List active p2p listeners."
,
},
...
...
@@ -99,10 +99,10 @@ var ptpListenerLsCmd = &cmds.Command{
return
}
output
:=
&
P
T
PLsOutput
{}
output
:=
&
P
2
PLsOutput
{}
for
_
,
listener
:=
range
n
.
P
T
P
.
Listeners
.
Listeners
{
output
.
Listeners
=
append
(
output
.
Listeners
,
P
T
PListenerInfoOutput
{
for
_
,
listener
:=
range
n
.
P
2
P
.
Listeners
.
Listeners
{
output
.
Listeners
=
append
(
output
.
Listeners
,
P
2
PListenerInfoOutput
{
Protocol
:
listener
.
Protocol
,
Address
:
listener
.
Address
.
String
(),
})
...
...
@@ -110,11 +110,11 @@ var ptpListenerLsCmd = &cmds.Command{
res
.
SetOutput
(
output
)
},
Type
:
P
T
PLsOutput
{},
Type
:
P
2
PLsOutput
{},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
headers
,
_
,
_
:=
res
.
Request
()
.
Option
(
"headers"
)
.
Bool
()
list
,
_
:=
res
.
Output
()
.
(
*
P
T
PLsOutput
)
list
,
_
:=
res
.
Output
()
.
(
*
P
2
PLsOutput
)
buf
:=
new
(
bytes
.
Buffer
)
w
:=
tabwriter
.
NewWriter
(
buf
,
1
,
2
,
1
,
' '
,
0
)
for
_
,
listener
:=
range
list
.
Listeners
{
...
...
@@ -131,7 +131,7 @@ var ptpListenerLsCmd = &cmds.Command{
},
}
var
p
t
pStreamLsCmd
=
&
cmds
.
Command
{
var
p
2
pStreamLsCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"List active p2p streams."
,
},
...
...
@@ -145,10 +145,10 @@ var ptpStreamLsCmd = &cmds.Command{
return
}
output
:=
&
P
T
PStreamsOutput
{}
output
:=
&
P
2
PStreamsOutput
{}
for
_
,
s
:=
range
n
.
P
T
P
.
Streams
.
Streams
{
output
.
Streams
=
append
(
output
.
Streams
,
P
T
PStreamInfoOutput
{
for
_
,
s
:=
range
n
.
P
2
P
.
Streams
.
Streams
{
output
.
Streams
=
append
(
output
.
Streams
,
P
2
PStreamInfoOutput
{
HandlerID
:
strconv
.
FormatUint
(
s
.
HandlerID
,
10
),
Protocol
:
s
.
Protocol
,
...
...
@@ -163,11 +163,11 @@ var ptpStreamLsCmd = &cmds.Command{
res
.
SetOutput
(
output
)
},
Type
:
P
T
PStreamsOutput
{},
Type
:
P
2
PStreamsOutput
{},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
headers
,
_
,
_
:=
res
.
Request
()
.
Option
(
"headers"
)
.
Bool
()
list
,
_
:=
res
.
Output
()
.
(
*
P
T
PStreamsOutput
)
list
,
_
:=
res
.
Output
()
.
(
*
P
2
PStreamsOutput
)
buf
:=
new
(
bytes
.
Buffer
)
w
:=
tabwriter
.
NewWriter
(
buf
,
1
,
2
,
1
,
' '
,
0
)
for
_
,
stream
:=
range
list
.
Streams
{
...
...
@@ -184,7 +184,7 @@ var ptpStreamLsCmd = &cmds.Command{
},
}
var
p
t
pListenerListenCmd
=
&
cmds
.
Command
{
var
p
2
pListenerListenCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Forward p2p connections to a network multiaddr."
,
ShortDescription
:
`
...
...
@@ -204,8 +204,8 @@ Note that the connections originate from the ipfs daemon process.
return
}
proto
:=
"/p
t
p/"
+
req
.
Arguments
()[
0
]
if
n
.
P
T
P
.
CheckProtoExists
(
proto
)
{
proto
:=
"/p
2
p/"
+
req
.
Arguments
()[
0
]
if
n
.
P
2
P
.
CheckProtoExists
(
proto
)
{
res
.
SetError
(
errors
.
New
(
"protocol handler already registered"
),
cmds
.
ErrNormal
)
return
}
...
...
@@ -216,21 +216,21 @@ Note that the connections originate from the ipfs daemon process.
return
}
_
,
err
=
n
.
P
T
P
.
NewListener
(
n
.
Context
(),
proto
,
addr
)
_
,
err
=
n
.
P
2
P
.
NewListener
(
n
.
Context
(),
proto
,
addr
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
// Successful response.
res
.
SetOutput
(
&
P
T
PListenerInfoOutput
{
res
.
SetOutput
(
&
P
2
PListenerInfoOutput
{
Protocol
:
proto
,
Address
:
addr
.
String
(),
})
},
}
var
p
t
pStreamDialCmd
=
&
cmds
.
Command
{
var
p
2
pStreamDialCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Dial to a p2p listener."
,
...
...
@@ -260,7 +260,7 @@ transparently connect to a p2p service.
return
}
proto
:=
"/p
t
p/"
+
req
.
Arguments
()[
1
]
proto
:=
"/p
2
p/"
+
req
.
Arguments
()[
1
]
bindAddr
,
_
:=
ma
.
NewMultiaddr
(
"/ip4/127.0.0.1/tcp/0"
)
if
len
(
req
.
Arguments
())
==
3
{
...
...
@@ -271,13 +271,13 @@ transparently connect to a p2p service.
}
}
listenerInfo
,
err
:=
n
.
P
T
P
.
Dial
(
n
.
Context
(),
addr
,
peer
,
proto
,
bindAddr
)
listenerInfo
,
err
:=
n
.
P
2
P
.
Dial
(
n
.
Context
(),
addr
,
peer
,
proto
,
bindAddr
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
output
:=
P
T
PListenerInfoOutput
{
output
:=
P
2
PListenerInfoOutput
{
Protocol
:
listenerInfo
.
Protocol
,
Address
:
listenerInfo
.
Address
.
String
(),
}
...
...
@@ -286,7 +286,7 @@ transparently connect to a p2p service.
},
}
var
p
t
pListenerCloseCmd
=
&
cmds
.
Command
{
var
p
2
pListenerCloseCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Close active p2p listener."
,
},
...
...
@@ -312,10 +312,10 @@ var ptpListenerCloseCmd = &cmds.Command{
return
}
proto
=
"/p
t
p/"
+
req
.
Arguments
()[
0
]
proto
=
"/p
2
p/"
+
req
.
Arguments
()[
0
]
}
for
_
,
listener
:=
range
n
.
P
T
P
.
Listeners
.
Listeners
{
for
_
,
listener
:=
range
n
.
P
2
P
.
Listeners
.
Listeners
{
if
!
closeAll
&&
listener
.
Protocol
!=
proto
{
continue
}
...
...
@@ -327,7 +327,7 @@ var ptpListenerCloseCmd = &cmds.Command{
},
}
var
p
t
pStreamCloseCmd
=
&
cmds
.
Command
{
var
p
2
pStreamCloseCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Close active p2p stream."
,
},
...
...
@@ -360,7 +360,7 @@ var ptpStreamCloseCmd = &cmds.Command{
}
}
for
_
,
stream
:=
range
n
.
P
T
P
.
Streams
.
Streams
{
for
_
,
stream
:=
range
n
.
P
2
P
.
Streams
.
Streams
{
if
!
closeAll
&&
handlerID
!=
stream
.
HandlerID
{
continue
}
...
...
core/commands/root.go
浏览文件 @
bec54c25
...
...
@@ -47,7 +47,7 @@ ADVANCED COMMANDS
pin Pin objects to local storage
repo Manipulate the IPFS repository
stats Various operational stats
p
t
p Libp2p stream mounting
p
2
p Libp2p stream mounting
filestore Manage the filestore (experimental)
NETWORK COMMANDS
...
...
@@ -114,7 +114,7 @@ var rootSubcommands = map[string]*cmds.Command{
"object"
:
ocmd
.
ObjectCmd
,
"pin"
:
PinCmd
,
"ping"
:
PingCmd
,
"p
tp"
:
PT
PCmd
,
"p
2p"
:
P2
PCmd
,
"pubsub"
:
PubsubCmd
,
"refs"
:
RefsCmd
,
"repo"
:
RepoCmd
,
...
...
core/core.go
浏览文件 @
bec54c25
...
...
@@ -33,9 +33,9 @@ import (
mfs
"github.com/ipfs/go-ipfs/mfs"
namesys
"github.com/ipfs/go-ipfs/namesys"
ipnsrp
"github.com/ipfs/go-ipfs/namesys/republisher"
p2p
"github.com/ipfs/go-ipfs/p2p"
path
"github.com/ipfs/go-ipfs/path"
pin
"github.com/ipfs/go-ipfs/pin"
ptp
"github.com/ipfs/go-ipfs/ptp"
repo
"github.com/ipfs/go-ipfs/repo"
config
"github.com/ipfs/go-ipfs/repo/config"
nilrouting
"github.com/ipfs/go-ipfs/routing/none"
...
...
@@ -131,7 +131,7 @@ type IpfsNode struct {
IpnsRepub
*
ipnsrp
.
Republisher
Floodsub
*
floodsub
.
PubSub
P
TP
*
ptp
.
PT
P
P
2P
*
p2p
.
P2
P
proc
goprocess
.
Process
ctx
context
.
Context
...
...
@@ -247,7 +247,7 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
n
.
Floodsub
=
floodsub
.
NewFloodSub
(
ctx
,
peerhost
)
}
n
.
P
TP
=
ptp
.
NewPT
P
(
n
.
Identity
,
n
.
PeerHost
,
n
.
Peerstore
)
n
.
P
2P
=
p2p
.
NewP2
P
(
n
.
Identity
,
n
.
PeerHost
,
n
.
Peerstore
)
// setup local discovery
if
do
!=
nil
{
...
...
p
tp/pt
p.go
→
p
2p/p2
p.go
浏览文件 @
bec54c25
package
p
t
p
package
p
2
p
import
(
"context"
...
...
@@ -14,8 +14,8 @@ import (
manet
"gx/ipfs/Qmf1Gq7N45Rpuw7ev47uWgH6dLPtdnvcMRNPkVBwqjLJg2/go-multiaddr-net"
)
// P
T
P structure holds information on currently running streams/listeners
type
P
T
P
struct
{
// P
2
P structure holds information on currently running streams/listeners
type
P
2
P
struct
{
Listeners
ListenerRegistry
Streams
StreamRegistry
...
...
@@ -24,38 +24,38 @@ type PTP struct {
peerstore
pstore
.
Peerstore
}
// NewP
TP creates new PT
P struct
func
NewP
TP
(
identity
peer
.
ID
,
peerHost
p2phost
.
Host
,
peerstore
pstore
.
Peerstore
)
*
PT
P
{
return
&
P
T
P
{
// NewP
2P creates new P2
P struct
func
NewP
2P
(
identity
peer
.
ID
,
peerHost
p2phost
.
Host
,
peerstore
pstore
.
Peerstore
)
*
P2
P
{
return
&
P
2
P
{
identity
:
identity
,
peerHost
:
peerHost
,
peerstore
:
peerstore
,
}
}
func
(
p
tp
*
PT
P
)
newStreamTo
(
ctx2
context
.
Context
,
p
peer
.
ID
,
protocol
string
)
(
net
.
Stream
,
error
)
{
func
(
p
2p
*
P2
P
)
newStreamTo
(
ctx2
context
.
Context
,
p
peer
.
ID
,
protocol
string
)
(
net
.
Stream
,
error
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
ctx2
,
time
.
Second
*
30
)
//TODO: configurable?
defer
cancel
()
err
:=
p
t
p
.
peerHost
.
Connect
(
ctx
,
pstore
.
PeerInfo
{
ID
:
p
})
err
:=
p
2
p
.
peerHost
.
Connect
(
ctx
,
pstore
.
PeerInfo
{
ID
:
p
})
if
err
!=
nil
{
return
nil
,
err
}
return
p
t
p
.
peerHost
.
NewStream
(
ctx2
,
p
,
pro
.
ID
(
protocol
))
return
p
2
p
.
peerHost
.
NewStream
(
ctx2
,
p
,
pro
.
ID
(
protocol
))
}
// Dial creates new P2P stream to a remote listener
func
(
p
tp
*
PT
P
)
Dial
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
,
peer
peer
.
ID
,
proto
string
,
bindAddr
ma
.
Multiaddr
)
(
*
ListenerInfo
,
error
)
{
func
(
p
2p
*
P2
P
)
Dial
(
ctx
context
.
Context
,
addr
ma
.
Multiaddr
,
peer
peer
.
ID
,
proto
string
,
bindAddr
ma
.
Multiaddr
)
(
*
ListenerInfo
,
error
)
{
lnet
,
_
,
err
:=
manet
.
DialArgs
(
bindAddr
)
if
err
!=
nil
{
return
nil
,
err
}
listenerInfo
:=
ListenerInfo
{
Identity
:
p
t
p
.
identity
,
Identity
:
p
2
p
.
identity
,
Protocol
:
proto
,
}
remote
,
err
:=
p
t
p
.
newStreamTo
(
ctx
,
peer
,
proto
)
remote
,
err
:=
p
2
p
.
newStreamTo
(
ctx
,
peer
,
proto
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -74,7 +74,7 @@ func (ptp *PTP) Dial(ctx context.Context, addr ma.Multiaddr, peer peer.ID, proto
listenerInfo
.
Closer
=
listener
listenerInfo
.
Running
=
true
go
p
t
p
.
doAccept
(
&
listenerInfo
,
remote
,
listener
)
go
p
2
p
.
doAccept
(
&
listenerInfo
,
remote
,
listener
)
default
:
return
nil
,
errors
.
New
(
"unsupported protocol: "
+
lnet
)
...
...
@@ -83,7 +83,7 @@ func (ptp *PTP) Dial(ctx context.Context, addr ma.Multiaddr, peer peer.ID, proto
return
&
listenerInfo
,
nil
}
func
(
p
tp
*
PT
P
)
doAccept
(
listenerInfo
*
ListenerInfo
,
remote
net
.
Stream
,
listener
manet
.
Listener
)
{
func
(
p
2p
*
P2
P
)
doAccept
(
listenerInfo
*
ListenerInfo
,
remote
net
.
Stream
,
listener
manet
.
Listener
)
{
defer
listener
.
Close
()
local
,
err
:=
listener
.
Accept
()
...
...
@@ -103,10 +103,10 @@ func (ptp *PTP) doAccept(listenerInfo *ListenerInfo, remote net.Stream, listener
Local
:
local
,
Remote
:
remote
,
Registry
:
&
p
t
p
.
Streams
,
Registry
:
&
p
2
p
.
Streams
,
}
p
t
p
.
Streams
.
Register
(
&
stream
)
p
2
p
.
Streams
.
Register
(
&
stream
)
stream
.
startStreaming
()
}
...
...
@@ -143,18 +143,18 @@ func (il *P2PListener) Close() error {
}
// Listen creates new P2PListener
func
(
p
tp
*
PT
P
)
registerStreamHandler
(
ctx2
context
.
Context
,
protocol
string
)
(
*
P2PListener
,
error
)
{
func
(
p
2p
*
P2
P
)
registerStreamHandler
(
ctx2
context
.
Context
,
protocol
string
)
(
*
P2PListener
,
error
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
ctx2
)
list
:=
&
P2PListener
{
peerHost
:
p
t
p
.
peerHost
,
peerHost
:
p
2
p
.
peerHost
,
proto
:
pro
.
ID
(
protocol
),
conCh
:
make
(
chan
net
.
Stream
),
ctx
:
ctx
,
cancel
:
cancel
,
}
p
t
p
.
peerHost
.
SetStreamHandler
(
list
.
proto
,
func
(
s
net
.
Stream
)
{
p
2
p
.
peerHost
.
SetStreamHandler
(
list
.
proto
,
func
(
s
net
.
Stream
)
{
select
{
case
list
.
conCh
<-
s
:
case
<-
ctx
.
Done
()
:
...
...
@@ -165,30 +165,30 @@ func (ptp *PTP) registerStreamHandler(ctx2 context.Context, protocol string) (*P
return
list
,
nil
}
// NewListener creates new p
t
p listener
func
(
p
tp
*
PT
P
)
NewListener
(
ctx
context
.
Context
,
proto
string
,
addr
ma
.
Multiaddr
)
(
*
ListenerInfo
,
error
)
{
listener
,
err
:=
p
t
p
.
registerStreamHandler
(
ctx
,
proto
)
// NewListener creates new p
2
p listener
func
(
p
2p
*
P2
P
)
NewListener
(
ctx
context
.
Context
,
proto
string
,
addr
ma
.
Multiaddr
)
(
*
ListenerInfo
,
error
)
{
listener
,
err
:=
p
2
p
.
registerStreamHandler
(
ctx
,
proto
)
if
err
!=
nil
{
return
nil
,
err
}
listenerInfo
:=
ListenerInfo
{
Identity
:
p
t
p
.
identity
,
Identity
:
p
2
p
.
identity
,
Protocol
:
proto
,
Address
:
addr
,
Closer
:
listener
,
Running
:
true
,
Registry
:
&
p
t
p
.
Listeners
,
Registry
:
&
p
2
p
.
Listeners
,
}
go
p
t
p
.
acceptStreams
(
&
listenerInfo
,
listener
)
go
p
2
p
.
acceptStreams
(
&
listenerInfo
,
listener
)
p
t
p
.
Listeners
.
Register
(
&
listenerInfo
)
p
2
p
.
Listeners
.
Register
(
&
listenerInfo
)
return
&
listenerInfo
,
nil
}
func
(
p
tp
*
PT
P
)
acceptStreams
(
listenerInfo
*
ListenerInfo
,
listener
Listener
)
{
func
(
p
2p
*
P2
P
)
acceptStreams
(
listenerInfo
*
ListenerInfo
,
listener
Listener
)
{
for
listenerInfo
.
Running
{
remote
,
err
:=
listener
.
Accept
()
if
err
!=
nil
{
...
...
@@ -214,19 +214,19 @@ func (ptp *PTP) acceptStreams(listenerInfo *ListenerInfo, listener Listener) {
Local
:
local
,
Remote
:
remote
,
Registry
:
&
p
t
p
.
Streams
,
Registry
:
&
p
2
p
.
Streams
,
}
p
t
p
.
Streams
.
Register
(
&
stream
)
p
2
p
.
Streams
.
Register
(
&
stream
)
stream
.
startStreaming
()
}
p
t
p
.
Listeners
.
Deregister
(
listenerInfo
.
Protocol
)
p
2
p
.
Listeners
.
Deregister
(
listenerInfo
.
Protocol
)
}
// CheckProtoExists checks whether a protocol handler is registered to
// mux handler
func
(
p
tp
*
PT
P
)
CheckProtoExists
(
proto
string
)
bool
{
protos
:=
p
t
p
.
peerHost
.
Mux
()
.
Protocols
()
func
(
p
2p
*
P2
P
)
CheckProtoExists
(
proto
string
)
bool
{
protos
:=
p
2
p
.
peerHost
.
Mux
()
.
Protocols
()
for
_
,
p
:=
range
protos
{
if
p
!=
proto
{
...
...
p
t
p/registry.go
→
p
2
p/registry.go
浏览文件 @
bec54c25
package
p
t
p
package
p
2
p
import
(
"fmt"
...
...
test/sharness/t0180-p
t
p.sh
→
test/sharness/t0180-p
2
p.sh
浏览文件 @
bec54c25
#!/bin/sh
test_description
=
"Test experimental p
t
p commands"
test_description
=
"Test experimental p
2
p commands"
.
lib/test-lib.sh
...
...
@@ -27,7 +27,7 @@ test_expect_success "test ports are closed" '
'
test_must_fail
'fail without config option being enabled'
'
ipfsi 0 p
t
p stream ls
ipfsi 0 p
2
p stream ls
'
test_expect_success
"enable filestore config setting"
'
...
...
@@ -35,15 +35,15 @@ test_expect_success "enable filestore config setting" '
ipfsi 1 config --json Experimental.Libp2pStreamMounting true
'
test_expect_success
'start p
t
p listener'
'
ipfsi 0 p
tp listener open pt
p-test /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log
test_expect_success
'start p
2
p listener'
'
ipfsi 0 p
2p listener open p2
p-test /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log
'
test_expect_success
'Test server to client communications'
'
ma-pipe-unidir --listen send /ip4/127.0.0.1/tcp/10101 < test0.bin &
SERVER_PID=$!
ipfsi 1 p
tp stream dial $PEERID_0 pt
p-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
ipfsi 1 p
2p stream dial $PEERID_0 p2
p-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
ma-pipe-unidir recv /ip4/127.0.0.1/tcp/10102 > client.out &&
wait $SERVER_PID
'
...
...
@@ -52,7 +52,7 @@ test_expect_success 'Test client to server communications' '
ma-pipe-unidir --listen recv /ip4/127.0.0.1/tcp/10101 > server.out &
SERVER_PID=$!
ipfsi 1 p
tp stream dial $PEERID_0 pt
p-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
ipfsi 1 p
2p stream dial $PEERID_0 p2
p-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
ma-pipe-unidir send /ip4/127.0.0.1/tcp/10102 < test1.bin
wait $SERVER_PID
'
...
...
@@ -65,90 +65,90 @@ test_expect_success 'client to server output looks good' '
test_cmp server.out test1.bin
'
test_expect_success
"'ipfs listener p
t
p ls' succeeds"
'
echo "/ip4/127.0.0.1/tcp/10101 /p
tp/pt
p-test" > expected &&
ipfsi 0 p
t
p listener ls > actual
test_expect_success
"'ipfs listener p
2
p ls' succeeds"
'
echo "/ip4/127.0.0.1/tcp/10101 /p
2p/p2
p-test" > expected &&
ipfsi 0 p
2
p listener ls > actual
'
test_expect_success
"'ipfs p
t
p listener ls' output looks good"
'
test_expect_success
"'ipfs p
2
p listener ls' output looks good"
'
test_cmp expected actual
'
test_expect_success
"Cannot re-register app handler"
'
(! ipfsi 0 p
tp listener open pt
p-test /ip4/127.0.0.1/tcp/10101)
(! ipfsi 0 p
2p listener open p2
p-test /ip4/127.0.0.1/tcp/10101)
'
test_expect_success
"'ipfs p
t
p stream ls' output is empty"
'
ipfsi 0 p
t
p stream ls > actual &&
test_expect_success
"'ipfs p
2
p stream ls' output is empty"
'
ipfsi 0 p
2
p stream ls > actual &&
test_must_be_empty actual
'
test_expect_success
"Setup: Idle stream"
'
ma-pipe-unidir --listen --pidFile=listener.pid recv /ip4/127.0.0.1/tcp/10101 &
ipfsi 1 p
tp stream dial $PEERID_0 pt
p-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
ipfsi 1 p
2p stream dial $PEERID_0 p2
p-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
ma-pipe-unidir --pidFile=client.pid recv /ip4/127.0.0.1/tcp/10102 &
go-sleep 500ms &&
kill -0 $(cat listener.pid) && kill -0 $(cat client.pid)
'
test_expect_success
"'ipfs p
t
p stream ls' succeeds"
'
echo "2 /p
tp/pt
p-test /ip4/127.0.0.1/tcp/10101 $PEERID_1" > expected
ipfsi 0 p
t
p stream ls > actual
test_expect_success
"'ipfs p
2
p stream ls' succeeds"
'
echo "2 /p
2p/p2
p-test /ip4/127.0.0.1/tcp/10101 $PEERID_1" > expected
ipfsi 0 p
2
p stream ls > actual
'
test_expect_success
"'ipfs p
t
p stream ls' output looks good"
'
test_expect_success
"'ipfs p
2
p stream ls' output looks good"
'
test_cmp expected actual
'
test_expect_success
"'ipfs p
t
p stream close' closes stream"
'
ipfsi 0 p
t
p stream close 2 &&
ipfsi 0 p
t
p stream ls > actual &&
test_expect_success
"'ipfs p
2
p stream close' closes stream"
'
ipfsi 0 p
2
p stream close 2 &&
ipfsi 0 p
2
p stream ls > actual &&
[ ! -f listener.pid ] && [ ! -f client.pid ] &&
test_must_be_empty actual
'
test_expect_success
"'ipfs p
t
p listener close' closes app handler"
'
ipfsi 0 p
tp listener close pt
p-test &&
ipfsi 0 p
t
p listener ls > actual &&
test_expect_success
"'ipfs p
2
p listener close' closes app handler"
'
ipfsi 0 p
2p listener close p2
p-test &&
ipfsi 0 p
2
p listener ls > actual &&
test_must_be_empty actual
'
test_expect_success
"Setup: Idle stream(2)"
'
ma-pipe-unidir --listen --pidFile=listener.pid recv /ip4/127.0.0.1/tcp/10101 &
ipfsi 0 p
tp listener open pt
p-test2 /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log &&
ipfsi 1 p
tp stream dial $PEERID_0 pt
p-test2 /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
ipfsi 0 p
2p listener open p2
p-test2 /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log &&
ipfsi 1 p
2p stream dial $PEERID_0 p2
p-test2 /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
ma-pipe-unidir --pidFile=client.pid recv /ip4/127.0.0.1/tcp/10102 &
go-sleep 500ms &&
kill -0 $(cat listener.pid) && kill -0 $(cat client.pid)
'
test_expect_success
"'ipfs p
t
p stream ls' succeeds(2)"
'
echo "3 /p
tp/pt
p-test2 /ip4/127.0.0.1/tcp/10101 $PEERID_1" > expected
ipfsi 0 p
t
p stream ls > actual
test_expect_success
"'ipfs p
2
p stream ls' succeeds(2)"
'
echo "3 /p
2p/p2
p-test2 /ip4/127.0.0.1/tcp/10101 $PEERID_1" > expected
ipfsi 0 p
2
p stream ls > actual
test_cmp expected actual
'
test_expect_success
"'ipfs p
t
p listener close -a' closes app handlers"
'
ipfsi 0 p
t
p listener close -a &&
ipfsi 0 p
t
p listener ls > actual &&
test_expect_success
"'ipfs p
2
p listener close -a' closes app handlers"
'
ipfsi 0 p
2
p listener close -a &&
ipfsi 0 p
2
p listener ls > actual &&
test_must_be_empty actual
'
test_expect_success
"'ipfs p
t
p stream close -a' closes streams"
'
ipfsi 0 p
t
p stream close -a &&
ipfsi 0 p
t
p stream ls > actual &&
test_expect_success
"'ipfs p
2
p stream close -a' closes streams"
'
ipfsi 0 p
2
p stream close -a &&
ipfsi 0 p
2
p stream ls > actual &&
[ ! -f listener.pid ] && [ ! -f client.pid ] &&
test_must_be_empty actual
'
test_expect_success
"'ipfs p
t
p listener close' closes app numeric handlers"
'
ipfsi 0 p
t
p listener open 1234 /ip4/127.0.0.1/tcp/10101 &&
ipfsi 0 p
t
p listener close 1234 &&
ipfsi 0 p
t
p listener ls > actual &&
test_expect_success
"'ipfs p
2
p listener close' closes app numeric handlers"
'
ipfsi 0 p
2
p listener open 1234 /ip4/127.0.0.1/tcp/10101 &&
ipfsi 0 p
2
p listener close 1234 &&
ipfsi 0 p
2
p listener ls > actual &&
test_must_be_empty actual
'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论