Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
a7ef0955
提交
a7ef0955
authored
9月 12, 2014
作者:
Brian Tiger Chow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(bitswap:notifications) move, rename
add interface
上级
cc163a95
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
20 行增加
和
13 行删除
+20
-13
bitswap.go
bitswap/bitswap.go
+3
-2
notifications.go
bitswap/notifications/notifications.go
+14
-8
notifications_test.go
bitswap/notifications/notifications_test.go
+3
-3
没有找到文件。
bitswap/bitswap.go
浏览文件 @
a7ef0955
...
...
@@ -7,6 +7,7 @@ import (
proto
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
ds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
notifications
"github.com/jbenet/go-ipfs/bitswap/notifications"
blocks
"github.com/jbenet/go-ipfs/blocks"
swarm
"github.com/jbenet/go-ipfs/net/swarm"
peer
"github.com/jbenet/go-ipfs/peer"
...
...
@@ -39,7 +40,7 @@ type BitSwap struct {
// routing interface for communication
routing
*
dht
.
IpfsDHT
notifications
*
notifications
notifications
notifications
.
PubSub
// partners is a map of currently active bitswap relationships.
// The Ledger has the peer.ID, and the peer connection works through net.
...
...
@@ -69,7 +70,7 @@ func NewBitSwap(p *peer.Peer, net swarm.Network, d ds.Datastore, r routing.IpfsR
routing
:
r
.
(
*
dht
.
IpfsDHT
),
meschan
:
net
.
GetChannel
(
swarm
.
PBWrapper_BITSWAP
),
haltChan
:
make
(
chan
struct
{}),
notifications
:
n
ewNotifications
(),
notifications
:
n
otifications
.
New
(),
}
go
bs
.
handleMessages
()
...
...
bitswap/notifications.go
→
bitswap/notifications
/notifications
.go
浏览文件 @
a7ef0955
package
bitswap
package
notifications
import
(
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
...
...
@@ -8,16 +8,22 @@ import (
u
"github.com/jbenet/go-ipfs/util"
)
type
notifications
struct
{
wrapped
*
pubsub
.
PubSub
type
PubSub
interface
{
Publish
(
block
*
blocks
.
Block
)
Subscribe
(
ctx
context
.
Context
,
k
u
.
Key
)
<-
chan
*
blocks
.
Block
Shutdown
()
}
func
newNotifications
()
*
notifications
{
func
New
()
PubSub
{
const
bufferSize
=
16
return
&
notifications
{
pubsub
.
New
(
bufferSize
)}
return
&
impl
{
pubsub
.
New
(
bufferSize
)}
}
type
impl
struct
{
wrapped
*
pubsub
.
PubSub
}
func
(
ps
*
notifications
)
Publish
(
block
*
blocks
.
Block
)
{
func
(
ps
*
impl
)
Publish
(
block
*
blocks
.
Block
)
{
topic
:=
string
(
block
.
Key
())
ps
.
wrapped
.
Pub
(
block
,
topic
)
}
...
...
@@ -25,7 +31,7 @@ func (ps *notifications) Publish(block *blocks.Block) {
// Subscribe returns a one-time use |blockChannel|. |blockChannel| returns nil
// if the |ctx| times out or is cancelled. Then channel is closed after the
// block given by |k| is sent.
func
(
ps
*
notifications
)
Subscribe
(
ctx
context
.
Context
,
k
u
.
Key
)
<-
chan
*
blocks
.
Block
{
func
(
ps
*
impl
)
Subscribe
(
ctx
context
.
Context
,
k
u
.
Key
)
<-
chan
*
blocks
.
Block
{
topic
:=
string
(
k
)
subChan
:=
ps
.
wrapped
.
SubOnce
(
topic
)
blockChannel
:=
make
(
chan
*
blocks
.
Block
)
...
...
@@ -44,6 +50,6 @@ func (ps *notifications) Subscribe(ctx context.Context, k u.Key) <-chan *blocks.
return
blockChannel
}
func
(
ps
*
notifications
)
Shutdown
()
{
func
(
ps
*
impl
)
Shutdown
()
{
ps
.
wrapped
.
Shutdown
()
}
bitswap/notifications_test.go
→
bitswap/notifications
/notifications
_test.go
浏览文件 @
a7ef0955
package
bitswap
package
notifications
import
(
"bytes"
...
...
@@ -13,7 +13,7 @@ import (
func
TestPublishSubscribe
(
t
*
testing
.
T
)
{
blockSent
:=
getBlockOrFail
(
t
,
"Greetings from The Interval"
)
n
:=
newNotifications
()
n
:=
New
()
defer
n
.
Shutdown
()
ch
:=
n
.
Subscribe
(
context
.
Background
(),
blockSent
.
Key
())
...
...
@@ -28,7 +28,7 @@ func TestCarryOnWhenDeadlineExpires(t *testing.T) {
impossibleDeadline
:=
time
.
Nanosecond
fastExpiringCtx
,
_
:=
context
.
WithTimeout
(
context
.
Background
(),
impossibleDeadline
)
n
:=
newNotifications
()
n
:=
New
()
defer
n
.
Shutdown
()
blockChannel
:=
n
.
Subscribe
(
fastExpiringCtx
,
getBlockOrFail
(
t
,
"A Missed Connection"
)
.
Key
())
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论