Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
2309266f
提交
2309266f
authored
2月 15, 2015
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
allow removal of stream handlers
上级
03c0b2d3
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
27 行增加
和
0 行删除
+27
-0
basic_host.go
p2p/host/basic/basic_host.go
+4
-0
host.go
p2p/host/host.go
+4
-0
routed.go
p2p/host/routed/routed.go
+10
-0
mux.go
p2p/protocol/mux.go
+9
-0
没有找到文件。
p2p/host/basic/basic_host.go
浏览文件 @
2309266f
...
...
@@ -118,6 +118,10 @@ func (h *BasicHost) SetStreamHandler(pid protocol.ID, handler inet.StreamHandler
h
.
Mux
()
.
SetHandler
(
pid
,
handler
)
}
func
(
h
*
BasicHost
)
RemoveStreamHandler
(
pid
protocol
.
ID
)
{
h
.
Mux
()
.
RemoveHandler
(
pid
)
}
// NewStream opens a new stream to given peer p, and writes a p2p/protocol
// header with given protocol.ID. If there is no connection to p, attempts
// to create one. If ProtocolID is "", writes no header.
...
...
p2p/host/host.go
浏览文件 @
2309266f
...
...
@@ -46,6 +46,10 @@ type Host interface {
// (Threadsafe)
SetStreamHandler
(
pid
protocol
.
ID
,
handler
inet
.
StreamHandler
)
// RemoveStreamHandler removes a handler on the mux that was set by
// SetStreamHandler
RemoveStreamHandler
(
pid
protocol
.
ID
)
// NewStream opens a new stream to given peer p, and writes a p2p/protocol
// header with given protocol.ID. If there is no connection to p, attempts
// to create one. If ProtocolID is "", writes no header.
...
...
p2p/host/routed/routed.go
浏览文件 @
2309266f
...
...
@@ -84,21 +84,31 @@ func logRoutingErrDifferentPeers(ctx context.Context, wanted, got peer.ID, err e
func
(
rh
*
RoutedHost
)
ID
()
peer
.
ID
{
return
rh
.
host
.
ID
()
}
func
(
rh
*
RoutedHost
)
Peerstore
()
peer
.
Peerstore
{
return
rh
.
host
.
Peerstore
()
}
func
(
rh
*
RoutedHost
)
Addrs
()
[]
ma
.
Multiaddr
{
return
rh
.
host
.
Addrs
()
}
func
(
rh
*
RoutedHost
)
Network
()
inet
.
Network
{
return
rh
.
host
.
Network
()
}
func
(
rh
*
RoutedHost
)
Mux
()
*
protocol
.
Mux
{
return
rh
.
host
.
Mux
()
}
func
(
rh
*
RoutedHost
)
SetStreamHandler
(
pid
protocol
.
ID
,
handler
inet
.
StreamHandler
)
{
rh
.
host
.
SetStreamHandler
(
pid
,
handler
)
}
func
(
rh
*
RoutedHost
)
RemoveStreamHandler
(
pid
protocol
.
ID
)
{
rh
.
host
.
RemoveStreamHandler
(
pid
)
}
func
(
rh
*
RoutedHost
)
NewStream
(
pid
protocol
.
ID
,
p
peer
.
ID
)
(
inet
.
Stream
,
error
)
{
return
rh
.
host
.
NewStream
(
pid
,
p
)
}
...
...
p2p/protocol/mux.go
浏览文件 @
2309266f
...
...
@@ -90,6 +90,15 @@ func (m *Mux) SetHandler(p ID, h inet.StreamHandler) {
m
.
lock
.
Unlock
()
}
// RemoveHandler removes the protocol handler on the Network's Muxer.
// This operation is threadsafe.
func
(
m
*
Mux
)
RemoveHandler
(
p
ID
)
{
log
.
Debugf
(
"%s removing handler for protocol: %s (%d)"
,
m
,
p
,
len
(
p
))
m
.
lock
.
Lock
()
delete
(
m
.
handlers
,
p
)
m
.
lock
.
Unlock
()
}
// Handle reads the next name off the Stream, and calls a handler function
// This is done in its own goroutine, to avoid blocking the caller.
func
(
m
*
Mux
)
Handle
(
s
inet
.
Stream
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论