Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
e431f35a
提交
e431f35a
authored
7月 10, 2015
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update multistream naming of lazyconn
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
上级
2c4eb609
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
22 行增加
和
27 行删除
+22
-27
Godeps.json
Godeps/Godeps.json
+1
-1
lazy.go
...space/src/github.com/whyrusleeping/go-multistream/lazy.go
+16
-21
multistream_test.go
...thub.com/whyrusleeping/go-multistream/multistream_test.go
+4
-4
basic_host.go
p2p/host/basic/basic_host.go
+1
-1
没有找到文件。
Godeps/Godeps.json
浏览文件 @
e431f35a
...
@@ -344,7 +344,7 @@
...
@@ -344,7 +344,7 @@
},
},
{
{
"ImportPath"
:
"github.com/whyrusleeping/go-multistream"
,
"ImportPath"
:
"github.com/whyrusleeping/go-multistream"
,
"Rev"
:
"3
0c7a81b6c568654147bf6e106870c5d64ccebc8
"
"Rev"
:
"3
1bb014803a6eba2261bda5593e42c016a5f33bb
"
},
},
{
{
"ImportPath"
:
"github.com/whyrusleeping/multiaddr-filter"
,
"ImportPath"
:
"github.com/whyrusleeping/multiaddr-filter"
,
...
...
Godeps/_workspace/src/github.com/whyrusleeping/go-multistream/lazy.go
浏览文件 @
e431f35a
...
@@ -6,7 +6,16 @@ import (
...
@@ -6,7 +6,16 @@ import (
"sync"
"sync"
)
)
func
NewLazyHandshakeConn
(
c
io
.
ReadWriteCloser
,
proto
string
)
io
.
ReadWriteCloser
{
type
Multistream
interface
{
io
.
ReadWriteCloser
Protocol
()
string
}
func
NewMSSelect
(
c
io
.
ReadWriteCloser
,
proto
string
)
Multistream
{
return
NewMultistream
(
NewMultistream
(
c
,
ProtocolID
),
proto
)
}
func
NewMultistream
(
c
io
.
ReadWriteCloser
,
proto
string
)
Multistream
{
return
&
lazyConn
{
return
&
lazyConn
{
proto
:
proto
,
proto
:
proto
,
con
:
c
,
con
:
c
,
...
@@ -30,6 +39,10 @@ type lazyConn struct {
...
@@ -30,6 +39,10 @@ type lazyConn struct {
con
io
.
ReadWriteCloser
con
io
.
ReadWriteCloser
}
}
func
(
l
*
lazyConn
)
Protocol
()
string
{
return
l
.
proto
}
func
(
l
*
lazyConn
)
Read
(
b
[]
byte
)
(
int
,
error
)
{
func
(
l
*
lazyConn
)
Read
(
b
[]
byte
)
(
int
,
error
)
{
if
!
l
.
rhandshake
{
if
!
l
.
rhandshake
{
go
l
.
writeHandshake
()
go
l
.
writeHandshake
()
...
@@ -58,20 +71,8 @@ func (l *lazyConn) readHandshake() error {
...
@@ -58,20 +71,8 @@ func (l *lazyConn) readHandshake() error {
}
}
l
.
rhsync
=
true
l
.
rhsync
=
true
// read multistream version
tok
,
err
:=
ReadNextToken
(
l
.
con
)
if
err
!=
nil
{
l
.
rerr
=
err
return
err
}
if
tok
!=
ProtocolID
{
l
.
rerr
=
fmt
.
Errorf
(
"multistream protocol mismatch ( %s != %s )"
,
tok
,
ProtocolID
)
return
l
.
rerr
}
// read protocol
// read protocol
tok
,
err
=
ReadNextToken
(
l
.
con
)
tok
,
err
:
=
ReadNextToken
(
l
.
con
)
if
err
!=
nil
{
if
err
!=
nil
{
l
.
rerr
=
err
l
.
rerr
=
err
return
err
return
err
...
@@ -95,13 +96,7 @@ func (l *lazyConn) writeHandshake() error {
...
@@ -95,13 +96,7 @@ func (l *lazyConn) writeHandshake() error {
l
.
whsync
=
true
l
.
whsync
=
true
err
:=
delimWrite
(
l
.
con
,
[]
byte
(
ProtocolID
))
err
:=
delimWrite
(
l
.
con
,
[]
byte
(
l
.
proto
))
if
err
!=
nil
{
l
.
werr
=
err
return
err
}
err
=
delimWrite
(
l
.
con
,
[]
byte
(
l
.
proto
))
if
err
!=
nil
{
if
err
!=
nil
{
l
.
werr
=
err
l
.
werr
=
err
return
err
return
err
...
...
Godeps/_workspace/src/github.com/whyrusleeping/go-multistream/multistream_test.go
浏览文件 @
e431f35a
...
@@ -126,8 +126,8 @@ func TestLazyConns(t *testing.T) {
...
@@ -126,8 +126,8 @@ func TestLazyConns(t *testing.T) {
mux
.
AddHandler
(
"/b"
,
nil
)
mux
.
AddHandler
(
"/b"
,
nil
)
mux
.
AddHandler
(
"/c"
,
nil
)
mux
.
AddHandler
(
"/c"
,
nil
)
la
:=
New
LazyHandshakeConn
(
a
,
"/c"
)
la
:=
New
MSSelect
(
a
,
"/c"
)
lb
:=
New
LazyHandshakeConn
(
b
,
"/c"
)
lb
:=
New
MSSelect
(
b
,
"/c"
)
verifyPipe
(
t
,
la
,
lb
)
verifyPipe
(
t
,
la
,
lb
)
}
}
...
@@ -159,7 +159,7 @@ func TestLazyAndMux(t *testing.T) {
...
@@ -159,7 +159,7 @@ func TestLazyAndMux(t *testing.T) {
close
(
done
)
close
(
done
)
}()
}()
lb
:=
New
LazyHandshakeConn
(
b
,
"/c"
)
lb
:=
New
MSSelect
(
b
,
"/c"
)
// do a write to push the handshake through
// do a write to push the handshake through
_
,
err
:=
lb
.
Write
([]
byte
(
"hello"
))
_
,
err
:=
lb
.
Write
([]
byte
(
"hello"
))
...
@@ -202,7 +202,7 @@ func TestLazyAndMuxWrite(t *testing.T) {
...
@@ -202,7 +202,7 @@ func TestLazyAndMuxWrite(t *testing.T) {
close
(
done
)
close
(
done
)
}()
}()
lb
:=
New
LazyHandshakeConn
(
b
,
"/c"
)
lb
:=
New
MSSelect
(
b
,
"/c"
)
// do a write to push the handshake through
// do a write to push the handshake through
msg
:=
make
([]
byte
,
5
)
msg
:=
make
([]
byte
,
5
)
...
...
p2p/host/basic/basic_host.go
浏览文件 @
e431f35a
...
@@ -170,7 +170,7 @@ func (h *BasicHost) NewStream(pid protocol.ID, p peer.ID) (inet.Stream, error) {
...
@@ -170,7 +170,7 @@ func (h *BasicHost) NewStream(pid protocol.ID, p peer.ID) (inet.Stream, error) {
logStream
:=
mstream
.
WrapStream
(
s
,
pid
,
h
.
bwc
)
logStream
:=
mstream
.
WrapStream
(
s
,
pid
,
h
.
bwc
)
lzcon
:=
msmux
.
New
LazyHandshakeConn
(
logStream
,
string
(
pid
))
lzcon
:=
msmux
.
New
MSSelect
(
logStream
,
string
(
pid
))
return
&
streamWrapper
{
return
&
streamWrapper
{
Stream
:
logStream
,
Stream
:
logStream
,
rw
:
lzcon
,
rw
:
lzcon
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论