Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
9414e73c
提交
9414e73c
authored
5月 26, 2017
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Corenet API: Split list subcmd into ls/streams
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
ad1dc5f4
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
90 行增加
和
25 行删除
+90
-25
corenet.go
core/commands/corenet.go
+87
-22
main.go
test/dependencies/ma-pipe-unidir/main.go
+3
-3
没有找到文件。
core/commands/corenet.go
浏览文件 @
9414e73c
package
commands
import
(
"bytes"
"errors"
"fmt"
"io"
"strconv"
"text/tabwriter"
cmds
"github.com/ipfs/go-ipfs/commands"
corenet
"github.com/ipfs/go-ipfs/core/corenet"
manet
"gx/ipfs/Qmf1Gq7N45Rpuw7ev47uWgH6dLPtdnvcMRNPkVBwqjLJg2/go-multiaddr-net"
ma
"gx/ipfs/QmcyqRMCAXVtYPS4DiBrA7sezL9rRGfW8Ctx7cywL4TXJj/go-multiaddr"
net
"gx/ipfs/QmVHSBsn8LEeay8m5ERebgUVuhzw838PsyTttCmP6GMJkg/go-libp2p-net"
peerstore
"gx/ipfs/QmNUVzEjq3XWJ89hegahPvyfJbTXgTaom48pLb7YBD9gHQ/go-libp2p-peerstore"
net
"gx/ipfs/QmVHSBsn8LEeay8m5ERebgUVuhzw838PsyTttCmP6GMJkg/go-libp2p-net"
ma
"gx/ipfs/QmcyqRMCAXVtYPS4DiBrA7sezL9rRGfW8Ctx7cywL4TXJj/go-multiaddr"
peer
"gx/ipfs/QmdS9KpbDyPrieswibZhkod1oXqRwZJrUPzxCofAMWpFGq/go-libp2p-peer"
manet
"gx/ipfs/Qmf1Gq7N45Rpuw7ev47uWgH6dLPtdnvcMRNPkVBwqjLJg2/go-multiaddr-net"
)
// Command output types.
type
AppInfoOutput
struct
{
Identity
string
Protocol
string
Address
string
}
...
...
@@ -31,8 +33,11 @@ type StreamInfoOutput struct {
RemoteAddress
string
}
type
ListCommandOutput
struct
{
Apps
[]
AppInfoOutput
type
CorenetLsOutput
struct
{
Apps
[]
AppInfoOutput
}
type
CorenetStreamsOutput
struct
{
Streams
[]
StreamInfoOutput
}
...
...
@@ -144,20 +149,20 @@ var CorenetCmd = &cmds.Command{
},
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"list"
:
listCmd
,
"dial"
:
dialCmd
,
"listen"
:
listenCmd
,
"close"
:
closeCmd
,
"ls"
:
CorenetLsCmd
,
"streams"
:
CorenetStreamsCmd
,
"dial"
:
CorenetDialCmd
,
"listen"
:
CorenetListenCmd
,
"close"
:
CorenetCloseCmd
,
},
}
var
list
Cmd
=
&
cmds
.
Command
{
var
CorenetLs
Cmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"List active application protocol
connection
s."
,
Tagline
:
"List active application protocol
listener
s."
,
},
Options
:
[]
cmds
.
Option
{
cmds
.
BoolOption
(
"apps"
,
"a"
,
"Display only local application protocol listeners."
)
.
Default
(
false
),
cmds
.
BoolOption
(
"streams"
,
"s"
,
"Display active application protocol streams."
)
.
Default
(
false
),
cmds
.
BoolOption
(
"headers"
,
"v"
,
"Print table headers (HandlerId, Protocol, Local, Remote)."
)
.
Default
(
false
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
n
,
err
:=
req
.
InvocContext
()
.
GetNode
()
...
...
@@ -171,16 +176,59 @@ var listCmd = &cmds.Command{
return
}
var
output
ListCommandOutput
output
:=
&
CorenetLsOutput
{}
for
_
,
a
:=
range
apps
.
apps
{
output
.
Apps
=
append
(
output
.
Apps
,
AppInfoOutput
{
Identity
:
a
.
identity
.
Pretty
(),
Protocol
:
a
.
protocol
,
Address
:
a
.
address
.
String
(),
})
}
res
.
SetOutput
(
output
)
},
Type
:
CorenetLsOutput
{},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
headers
,
_
,
_
:=
res
.
Request
()
.
Option
(
"headers"
)
.
Bool
()
list
,
_
:=
res
.
Output
()
.
(
*
CorenetLsOutput
)
buf
:=
new
(
bytes
.
Buffer
)
w
:=
tabwriter
.
NewWriter
(
buf
,
1
,
2
,
1
,
' '
,
0
)
for
_
,
app
:=
range
list
.
Apps
{
if
headers
{
fmt
.
Fprintln
(
w
,
"Address
\t
Protocol"
)
}
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\n
"
,
app
.
Address
,
app
.
Protocol
)
}
w
.
Flush
()
return
buf
,
nil
},
},
}
var
CorenetStreamsCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"List active application protocol connections."
,
},
Options
:
[]
cmds
.
Option
{
cmds
.
BoolOption
(
"headers"
,
"v"
,
"Print table headers (HandlerId, Protocol, Local, Remote)."
)
.
Default
(
false
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
n
,
err
:=
req
.
InvocContext
()
.
GetNode
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
if
!
n
.
OnlineMode
()
{
res
.
SetError
(
errNotOnline
,
cmds
.
ErrClient
)
return
}
output
:=
&
CorenetStreamsOutput
{}
for
_
,
s
:=
range
streams
.
streams
{
output
.
Streams
=
append
(
output
.
Streams
,
StreamInfoOutput
{
HandlerId
:
strconv
.
FormatUint
(
s
.
handlerId
,
10
),
...
...
@@ -195,11 +243,30 @@ var listCmd = &cmds.Command{
})
}
res
.
SetOutput
(
&
output
)
res
.
SetOutput
(
output
)
},
Type
:
CorenetStreamsOutput
{},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
headers
,
_
,
_
:=
res
.
Request
()
.
Option
(
"headers"
)
.
Bool
()
list
,
_
:=
res
.
Output
()
.
(
*
CorenetStreamsOutput
)
buf
:=
new
(
bytes
.
Buffer
)
w
:=
tabwriter
.
NewWriter
(
buf
,
1
,
2
,
1
,
' '
,
0
)
for
_
,
stream
:=
range
list
.
Streams
{
if
headers
{
fmt
.
Fprintln
(
w
,
"HandlerId
\t
Protocol
\t
Local
\t
Remote"
)
}
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%s
\n
"
,
stream
.
HandlerId
,
stream
.
Protocol
,
stream
.
LocalAddress
,
stream
.
RemotePeer
)
}
w
.
Flush
()
return
buf
,
nil
},
},
}
var
l
istenCmd
=
&
cmds
.
Command
{
var
CorenetL
istenCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Create application protocol listener and proxy to network multiaddr."
,
},
...
...
@@ -251,7 +318,6 @@ var listenCmd = &cmds.Command{
// Successful response.
res
.
SetOutput
(
&
AppInfoOutput
{
Identity
:
app
.
identity
.
Pretty
(),
Protocol
:
proto
,
Address
:
addr
.
String
(),
})
...
...
@@ -313,7 +379,7 @@ func startStreaming(stream *cnStreamInfo) {
}()
}
var
d
ialCmd
=
&
cmds
.
Command
{
var
CorenetD
ialCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Dial to an application service."
,
},
...
...
@@ -393,7 +459,6 @@ var dialCmd = &cmds.Command{
}
output
:=
AppInfoOutput
{
Identity
:
app
.
identity
.
Pretty
(),
Protocol
:
app
.
protocol
,
Address
:
app
.
address
.
String
(),
}
...
...
@@ -427,7 +492,7 @@ func doAccept(app *cnAppInfo, remote net.Stream, listener manet.Listener) {
startStreaming
(
&
stream
)
}
var
c
loseCmd
=
&
cmds
.
Command
{
var
CorenetC
loseCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Closes an active stream listener or client."
,
},
...
...
test/dependencies/ma-pipe-unidir/main.go
浏览文件 @
9414e73c
...
...
@@ -3,11 +3,11 @@ package main
import
(
"flag"
"fmt"
ma
"github.com/multiformats/go-multiaddr"
manet
"github.com/multiformats/go-multiaddr-net"
"io"
"os"
ma
"gx/ipfs/QmcyqRMCAXVtYPS4DiBrA7sezL9rRGfW8Ctx7cywL4TXJj/go-multiaddr"
manet
"gx/ipfs/Qmf1Gq7N45Rpuw7ev47uWgH6dLPtdnvcMRNPkVBwqjLJg2/go-multiaddr-net"
)
const
USAGE
=
"ma-pipe-unidir [-l|--listen] [-h|--help] <send|recv> <multiaddr>
\n
"
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论