Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
fc08d533
提交
fc08d533
authored
5月 28, 2017
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Corenet API: Apply suggestions, cleanups
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
69d3e087
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
95 行增加
和
39 行删除
+95
-39
corenet.go
core/commands/corenet.go
+82
-36
experiments.go
repo/config/experiments.go
+3
-2
t0180-corenet.sh
test/sharness/t0180-corenet.sh
+10
-1
没有找到文件。
core/commands/corenet.go
浏览文件 @
fc08d533
...
...
@@ -9,6 +9,7 @@ import (
"text/tabwriter"
cmds
"github.com/ipfs/go-ipfs/commands"
core
"github.com/ipfs/go-ipfs/core"
corenet
"github.com/ipfs/go-ipfs/core/corenet"
peerstore
"gx/ipfs/QmNUVzEjq3XWJ89hegahPvyfJbTXgTaom48pLb7YBD9gHQ/go-libp2p-peerstore"
...
...
@@ -18,14 +19,13 @@ import (
manet
"gx/ipfs/Qmf1Gq7N45Rpuw7ev47uWgH6dLPtdnvcMRNPkVBwqjLJg2/go-multiaddr-net"
)
// Command output types.
type
AppInfoOutput
struct
{
type
CorenetAppInfoOutput
struct
{
Protocol
string
Address
string
}
type
StreamInfoOutput
struct
{
HandlerI
d
string
type
Corenet
StreamInfoOutput
struct
{
HandlerI
D
string
Protocol
string
LocalPeer
string
LocalAddress
string
...
...
@@ -34,11 +34,11 @@ type StreamInfoOutput struct {
}
type
CorenetLsOutput
struct
{
Apps
[]
AppInfoOutput
Apps
[]
Corenet
AppInfoOutput
}
type
CorenetStreamsOutput
struct
{
Streams
[]
StreamInfoOutput
Streams
[]
Corenet
StreamInfoOutput
}
// cnAppInfo holds information on a local application protocol listener service.
...
...
@@ -91,7 +91,7 @@ func (c *cnAppRegistry) Deregister(proto string) {
// cnStreamInfo holds information on active incoming and outgoing protocol app streams.
type
cnStreamInfo
struct
{
handlerI
d
uint64
handlerI
D
uint64
protocol
string
...
...
@@ -108,7 +108,7 @@ type cnStreamInfo struct {
func
(
c
*
cnStreamInfo
)
Close
()
error
{
c
.
local
.
Close
()
c
.
remote
.
Close
()
streams
.
Deregister
(
c
.
handlerI
d
)
streams
.
Deregister
(
c
.
handlerI
D
)
return
nil
}
...
...
@@ -116,19 +116,19 @@ func (c *cnStreamInfo) Close() error {
type
cnStreamRegistry
struct
{
streams
[]
*
cnStreamInfo
nextI
d
uint64
nextI
D
uint64
}
func
(
c
*
cnStreamRegistry
)
Register
(
streamInfo
*
cnStreamInfo
)
{
streamInfo
.
handlerI
d
=
c
.
nextId
streamInfo
.
handlerI
D
=
c
.
nextID
c
.
streams
=
append
(
c
.
streams
,
streamInfo
)
c
.
nextI
d
+=
1
c
.
nextI
D
++
}
func
(
c
*
cnStreamRegistry
)
Deregister
(
handlerI
d
uint64
)
{
func
(
c
*
cnStreamRegistry
)
Deregister
(
handlerI
D
uint64
)
{
foundAt
:=
-
1
for
i
,
s
:=
range
c
.
streams
{
if
s
.
handlerI
d
==
handlerId
{
if
s
.
handlerI
D
==
handlerID
{
foundAt
=
i
break
}
...
...
@@ -145,7 +145,11 @@ var streams cnStreamRegistry
var
CorenetCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Application network streams."
,
Tagline
:
"Libp2p stream mounting."
,
ShortDescription
:
`
Expose a local application to remote peers over libp2p
Note: this command is experimental and subject to change as usecases and APIs are refined`
,
},
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
...
...
@@ -162,7 +166,7 @@ var CorenetLsCmd = &cmds.Command{
Tagline
:
"List active application protocol listeners."
,
},
Options
:
[]
cmds
.
Option
{
cmds
.
BoolOption
(
"headers"
,
"v"
,
"Print table headers (HandlerI
d
, Protocol, Local, Remote)."
)
.
Default
(
false
),
cmds
.
BoolOption
(
"headers"
,
"v"
,
"Print table headers (HandlerI
D
, Protocol, Local, Remote)."
)
.
Default
(
false
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
n
,
err
:=
req
.
InvocContext
()
.
GetNode
()
...
...
@@ -171,6 +175,12 @@ var CorenetLsCmd = &cmds.Command{
return
}
err
=
checkEnabled
(
n
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
if
!
n
.
OnlineMode
()
{
res
.
SetError
(
errNotOnline
,
cmds
.
ErrClient
)
return
...
...
@@ -179,7 +189,7 @@ var CorenetLsCmd = &cmds.Command{
output
:=
&
CorenetLsOutput
{}
for
_
,
a
:=
range
apps
.
apps
{
output
.
Apps
=
append
(
output
.
Apps
,
AppInfoOutput
{
output
.
Apps
=
append
(
output
.
Apps
,
Corenet
AppInfoOutput
{
Protocol
:
a
.
protocol
,
Address
:
a
.
address
.
String
(),
})
...
...
@@ -210,10 +220,10 @@ var CorenetLsCmd = &cmds.Command{
var
CorenetStreamsCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"List active application protocol
connection
s."
,
Tagline
:
"List active application protocol
stream
s."
,
},
Options
:
[]
cmds
.
Option
{
cmds
.
BoolOption
(
"headers"
,
"v"
,
"Print table headers (HandlerI
d
, Protocol, Local, Remote)."
)
.
Default
(
false
),
cmds
.
BoolOption
(
"headers"
,
"v"
,
"Print table headers (HandlerI
D
, Protocol, Local, Remote)."
)
.
Default
(
false
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
n
,
err
:=
req
.
InvocContext
()
.
GetNode
()
...
...
@@ -222,6 +232,12 @@ var CorenetStreamsCmd = &cmds.Command{
return
}
err
=
checkEnabled
(
n
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
if
!
n
.
OnlineMode
()
{
res
.
SetError
(
errNotOnline
,
cmds
.
ErrClient
)
return
...
...
@@ -230,8 +246,8 @@ var CorenetStreamsCmd = &cmds.Command{
output
:=
&
CorenetStreamsOutput
{}
for
_
,
s
:=
range
streams
.
streams
{
output
.
Streams
=
append
(
output
.
Streams
,
StreamInfoOutput
{
HandlerI
d
:
strconv
.
FormatUint
(
s
.
handlerId
,
10
),
output
.
Streams
=
append
(
output
.
Streams
,
Corenet
StreamInfoOutput
{
HandlerI
D
:
strconv
.
FormatUint
(
s
.
handlerID
,
10
),
Protocol
:
s
.
protocol
,
...
...
@@ -254,10 +270,10 @@ var CorenetStreamsCmd = &cmds.Command{
w
:=
tabwriter
.
NewWriter
(
buf
,
1
,
2
,
1
,
' '
,
0
)
for
_
,
stream
:=
range
list
.
Streams
{
if
headers
{
fmt
.
Fprintln
(
w
,
"HandlerI
d
\t
Protocol
\t
Local
\t
Remote"
)
fmt
.
Fprintln
(
w
,
"HandlerI
D
\t
Protocol
\t
Local
\t
Remote"
)
}
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%s
\n
"
,
stream
.
HandlerI
d
,
stream
.
Protocol
,
stream
.
LocalAddress
,
stream
.
RemotePeer
)
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%s
\n
"
,
stream
.
HandlerI
D
,
stream
.
Protocol
,
stream
.
LocalAddress
,
stream
.
RemotePeer
)
}
w
.
Flush
()
...
...
@@ -281,6 +297,12 @@ var CorenetListenCmd = &cmds.Command{
return
}
err
=
checkEnabled
(
n
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
if
!
n
.
OnlineMode
()
{
res
.
SetError
(
errNotOnline
,
cmds
.
ErrClient
)
return
...
...
@@ -288,7 +310,7 @@ var CorenetListenCmd = &cmds.Command{
proto
:=
"/app/"
+
req
.
Arguments
()[
0
]
if
checkProtoExists
(
n
.
PeerHost
.
Mux
()
.
Protocols
(),
proto
)
{
res
.
SetError
(
errors
.
New
(
"
Protocol handler already registered.
"
),
cmds
.
ErrNormal
)
res
.
SetError
(
errors
.
New
(
"
protocol handler already registered
"
),
cmds
.
ErrNormal
)
return
}
...
...
@@ -317,7 +339,7 @@ var CorenetListenCmd = &cmds.Command{
apps
.
Register
(
&
app
)
// Successful response.
res
.
SetOutput
(
&
AppInfoOutput
{
res
.
SetOutput
(
&
Corenet
AppInfoOutput
{
Protocol
:
proto
,
Address
:
addr
.
String
(),
})
...
...
@@ -395,6 +417,12 @@ var CorenetDialCmd = &cmds.Command{
return
}
err
=
checkEnabled
(
n
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
if
!
n
.
OnlineMode
()
{
res
.
SetError
(
errNotOnline
,
cmds
.
ErrClient
)
return
...
...
@@ -454,11 +482,11 @@ var CorenetDialCmd = &cmds.Command{
go
doAccept
(
&
app
,
remote
,
listener
)
default
:
res
.
SetError
(
errors
.
New
(
"
U
nsupported protocol: "
+
lnet
),
cmds
.
ErrNormal
)
res
.
SetError
(
errors
.
New
(
"
u
nsupported protocol: "
+
lnet
),
cmds
.
ErrNormal
)
return
}
output
:=
AppInfoOutput
{
output
:=
Corenet
AppInfoOutput
{
Protocol
:
app
.
protocol
,
Address
:
app
.
address
.
String
(),
}
...
...
@@ -497,8 +525,8 @@ var CorenetCloseCmd = &cmds.Command{
Tagline
:
"Closes an active stream listener or client."
,
},
Arguments
:
[]
cmds
.
Argument
{
cmds
.
StringArg
(
"HandlerI
d"
,
false
,
false
,
"Application listener or client HandlerId
"
),
cmds
.
StringArg
(
"Protocol"
,
false
,
false
,
"Application listener or client HandlerI
d
"
),
cmds
.
StringArg
(
"HandlerI
D"
,
false
,
false
,
"Application listener or client HandlerID
"
),
cmds
.
StringArg
(
"Protocol"
,
false
,
false
,
"Application listener or client HandlerI
D
"
),
},
Options
:
[]
cmds
.
Option
{
cmds
.
BoolOption
(
"all"
,
"a"
,
"Close all streams and listeners."
)
.
Default
(
false
),
...
...
@@ -510,6 +538,12 @@ var CorenetCloseCmd = &cmds.Command{
return
}
err
=
checkEnabled
(
n
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
if
!
n
.
OnlineMode
()
{
res
.
SetError
(
errNotOnline
,
cmds
.
ErrClient
)
return
...
...
@@ -518,27 +552,27 @@ var CorenetCloseCmd = &cmds.Command{
closeAll
,
_
,
_
:=
req
.
Option
(
"all"
)
.
Bool
()
var
proto
string
var
handlerI
d
uint64
var
handlerI
D
uint64
useHandlerI
d
:=
false
useHandlerI
D
:=
false
if
!
closeAll
&&
len
(
req
.
Arguments
())
==
0
{
res
.
SetError
(
errors
.
New
(
"
You must supply a handlerId or stream protocol.
"
),
cmds
.
ErrNormal
)
res
.
SetError
(
errors
.
New
(
"
handlerID nor stream protocol
"
),
cmds
.
ErrNormal
)
return
}
else
if
!
closeAll
{
handlerI
d
,
err
=
strconv
.
ParseUint
(
req
.
Arguments
()[
0
],
10
,
64
)
handlerI
D
,
err
=
strconv
.
ParseUint
(
req
.
Arguments
()[
0
],
10
,
64
)
if
err
!=
nil
{
proto
=
"/app/"
+
req
.
Arguments
()[
0
]
}
else
{
useHandlerI
d
=
true
useHandlerI
D
=
true
}
}
if
closeAll
||
useHandlerI
d
{
if
closeAll
||
useHandlerI
D
{
for
_
,
s
:=
range
streams
.
streams
{
if
!
closeAll
&&
handlerI
d
!=
s
.
handlerId
{
if
!
closeAll
&&
handlerI
D
!=
s
.
handlerID
{
continue
}
s
.
Close
()
...
...
@@ -548,7 +582,7 @@ var CorenetCloseCmd = &cmds.Command{
}
}
if
closeAll
||
!
useHandlerI
d
{
if
closeAll
||
!
useHandlerI
D
{
for
_
,
a
:=
range
apps
.
apps
{
if
!
closeAll
&&
a
.
protocol
!=
proto
{
continue
...
...
@@ -564,3 +598,15 @@ var CorenetCloseCmd = &cmds.Command{
}
},
}
func
checkEnabled
(
n
*
core
.
IpfsNode
)
error
{
config
,
err
:=
n
.
Repo
.
Config
()
if
err
!=
nil
{
return
err
}
if
!
config
.
Experimental
.
Libp2pStreamMounting
{
return
errors
.
New
(
"libp2p stream mounting not enabled"
)
}
return
nil
}
repo/config/experiments.go
浏览文件 @
fc08d533
package
config
type
Experiments
struct
{
FilestoreEnabled
bool
ShardingEnabled
bool
FilestoreEnabled
bool
ShardingEnabled
bool
Libp2pStreamMounting
bool
}
test/sharness/t0180-corenet.sh
浏览文件 @
fc08d533
...
...
@@ -26,7 +26,16 @@ test_expect_success "test ports are closed" '
(! (netstat -ln | grep "LISTEN" | grep ":10102 "))
'
test_expect_success
'start ipfs listener'
'
test_must_fail
'fail without config option being enabled'
'
ipfsi 0 exp corenet ls
'
test_expect_success
"enable filestore config setting"
'
ipfsi 0 config --json Experimental.Libp2pStreamMounting true
ipfsi 1 config --json Experimental.Libp2pStreamMounting true
'
test_expect_success
'start corenet listener'
'
ipfsi 0 exp corenet listen corenet-test /ip4/127.0.0.1/tcp/10101 2>&1 > listener-stdouterr.log
'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论