Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
e0bd4a11
提交
e0bd4a11
authored
5月 31, 2017
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Corenet API: Fix codeclimate issues
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
a3889a71
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
30 行增加
和
15 行删除
+30
-15
corenet.go
core/commands/corenet.go
+11
-10
apps.go
corenet/apps.go
+3
-0
corenet.go
corenet/corenet.go
+2
-0
net.go
corenet/net/net.go
+11
-5
streams.go
corenet/streams.go
+3
-0
没有找到文件。
core/commands/corenet.go
浏览文件 @
e0bd4a11
...
...
@@ -45,6 +45,7 @@ type CorenetStreamsOutput struct {
Streams
[]
CorenetStreamInfoOutput
}
// CorenetCmd is the 'ipfs corenet' command
var
CorenetCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Libp2p stream mounting."
,
...
...
@@ -55,15 +56,15 @@ Note: this command is experimental and subject to change as usecases and APIs ar
},
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"ls"
:
C
orenetLsCmd
,
"streams"
:
C
orenetStreamsCmd
,
"dial"
:
C
orenetDialCmd
,
"listen"
:
C
orenetListenCmd
,
"close"
:
C
orenetCloseCmd
,
"ls"
:
c
orenetLsCmd
,
"streams"
:
c
orenetStreamsCmd
,
"dial"
:
c
orenetDialCmd
,
"listen"
:
c
orenetListenCmd
,
"close"
:
c
orenetCloseCmd
,
},
}
var
C
orenetLsCmd
=
&
cmds
.
Command
{
var
c
orenetLsCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"List active application protocol listeners."
,
},
...
...
@@ -120,7 +121,7 @@ var CorenetLsCmd = &cmds.Command{
},
}
var
C
orenetStreamsCmd
=
&
cmds
.
Command
{
var
c
orenetStreamsCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"List active application protocol streams."
,
},
...
...
@@ -184,7 +185,7 @@ var CorenetStreamsCmd = &cmds.Command{
},
}
var
C
orenetListenCmd
=
&
cmds
.
Command
{
var
c
orenetListenCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Create application protocol listener and proxy to network multiaddr."
,
},
...
...
@@ -306,7 +307,7 @@ func startStreaming(stream *corenet.StreamInfo) {
}()
}
var
C
orenetDialCmd
=
&
cmds
.
Command
{
var
c
orenetDialCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Dial to an application service."
,
},
...
...
@@ -427,7 +428,7 @@ func doAccept(n *core.IpfsNode, app *corenet.AppInfo, remote net.Stream, listene
startStreaming
(
&
stream
)
}
var
C
orenetCloseCmd
=
&
cmds
.
Command
{
var
c
orenetCloseCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Closes an active stream listener or client."
,
},
...
...
corenet/apps.go
浏览文件 @
e0bd4a11
...
...
@@ -28,6 +28,7 @@ type AppInfo struct {
Registry
*
AppRegistry
}
// Close closes the listener. Does not affect child streams
func
(
c
*
AppInfo
)
Close
()
error
{
c
.
Registry
.
Deregister
(
c
.
Protocol
)
c
.
Closer
.
Close
()
...
...
@@ -39,10 +40,12 @@ type AppRegistry struct {
Apps
[]
*
AppInfo
}
// Register registers appInfo in this registry
func
(
c
*
AppRegistry
)
Register
(
appInfo
*
AppInfo
)
{
c
.
Apps
=
append
(
c
.
Apps
,
appInfo
)
}
// Deregister deregisters protocol handler from this registry
func
(
c
*
AppRegistry
)
Deregister
(
proto
string
)
{
foundAt
:=
-
1
for
i
,
a
:=
range
c
.
Apps
{
...
...
corenet/corenet.go
浏览文件 @
e0bd4a11
package
corenet
// Corenet structure holds information on currently running streams/apps
type
Corenet
struct
{
Apps
AppRegistry
Streams
StreamRegistry
}
// NewCorenet creates new Corenet struct
func
NewCorenet
()
*
Corenet
{
return
&
Corenet
{}
}
corenet/net/net.go
浏览文件 @
e0bd4a11
...
...
@@ -11,12 +11,14 @@ import (
peer
"gx/ipfs/QmdS9KpbDyPrieswibZhkod1oXqRwZJrUPzxCofAMWpFGq/go-libp2p-peer"
)
// Listener wraps stream handler into a listener
type
Listener
interface
{
Accept
()
(
net
.
Stream
,
error
)
Close
()
error
}
type
ipfsListener
struct
{
// IpfsListener holds information on a listener
type
IpfsListener
struct
{
node
*
core
.
IpfsNode
conCh
chan
net
.
Stream
proto
pro
.
ID
...
...
@@ -24,7 +26,8 @@ type ipfsListener struct {
cancel
func
()
}
func
(
il
*
ipfsListener
)
Accept
()
(
net
.
Stream
,
error
)
{
// Accept waits for a connection from the listener
func
(
il
*
IpfsListener
)
Accept
()
(
net
.
Stream
,
error
)
{
select
{
case
c
:=
<-
il
.
conCh
:
return
c
,
nil
...
...
@@ -33,16 +36,18 @@ func (il *ipfsListener) Accept() (net.Stream, error) {
}
}
func
(
il
*
ipfsListener
)
Close
()
error
{
// Close closes the listener and removes stream handler
func
(
il
*
IpfsListener
)
Close
()
error
{
il
.
cancel
()
il
.
node
.
PeerHost
.
RemoveStreamHandler
(
il
.
proto
)
return
nil
}
func
Listen
(
nd
*
core
.
IpfsNode
,
protocol
string
)
(
*
ipfsListener
,
error
)
{
// Listen creates new IpfsListener
func
Listen
(
nd
*
core
.
IpfsNode
,
protocol
string
)
(
*
IpfsListener
,
error
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
nd
.
Context
())
list
:=
&
i
pfsListener
{
list
:=
&
I
pfsListener
{
node
:
nd
,
proto
:
pro
.
ID
(
protocol
),
conCh
:
make
(
chan
net
.
Stream
),
...
...
@@ -61,6 +66,7 @@ func Listen(nd *core.IpfsNode, protocol string) (*ipfsListener, error) {
return
list
,
nil
}
// Dial dials to a specified node and protocol
func
Dial
(
nd
*
core
.
IpfsNode
,
p
peer
.
ID
,
protocol
string
)
(
net
.
Stream
,
error
)
{
ctx
,
cancel
:=
context
.
WithTimeout
(
nd
.
Context
(),
time
.
Second
*
30
)
defer
cancel
()
...
...
corenet/streams.go
浏览文件 @
e0bd4a11
...
...
@@ -25,6 +25,7 @@ type StreamInfo struct {
Registry
*
StreamRegistry
}
// Close closes stream endpoints and deregisters it
func
(
c
*
StreamInfo
)
Close
()
error
{
c
.
Local
.
Close
()
c
.
Remote
.
Close
()
...
...
@@ -39,12 +40,14 @@ type StreamRegistry struct {
nextID
uint64
}
// Register registers a stream to the registry
func
(
c
*
StreamRegistry
)
Register
(
streamInfo
*
StreamInfo
)
{
streamInfo
.
HandlerID
=
c
.
nextID
c
.
Streams
=
append
(
c
.
Streams
,
streamInfo
)
c
.
nextID
++
}
// Deregister deregisters stream from the registry
func
(
c
*
StreamRegistry
)
Deregister
(
handlerID
uint64
)
{
foundAt
:=
-
1
for
i
,
s
:=
range
c
.
Streams
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论