Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
cf6ddcbf
提交
cf6ddcbf
authored
5月 22, 2018
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
p2p: fix some stuff after refactor
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
132d6fae
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
24 行增加
和
18 行删除
+24
-18
inbound.go
p2p/inbound.go
+4
-0
listener.go
p2p/listener.go
+0
-15
outbound.go
p2p/outbound.go
+4
-3
p2p.go
p2p/p2p.go
+16
-0
没有找到文件。
p2p/inbound.go
浏览文件 @
cf6ddcbf
...
@@ -16,13 +16,17 @@ type inboundListener struct {
...
@@ -16,13 +16,17 @@ type inboundListener struct {
// Application proto identifier.
// Application proto identifier.
proto
string
proto
string
// Address to proxy the incoming connections to
addr
ma
.
Multiaddr
addr
ma
.
Multiaddr
}
}
// NewListener creates new p2p listener
// NewListener creates new p2p listener
func
(
p2p
*
P2P
)
NewListener
(
ctx
context
.
Context
,
proto
string
,
addr
ma
.
Multiaddr
)
(
Listener
,
error
)
{
func
(
p2p
*
P2P
)
NewListener
(
ctx
context
.
Context
,
proto
string
,
addr
ma
.
Multiaddr
)
(
Listener
,
error
)
{
listenerInfo
:=
&
inboundListener
{
listenerInfo
:=
&
inboundListener
{
p2p
:
p2p
,
proto
:
proto
,
proto
:
proto
,
addr
:
addr
,
}
}
p2p
.
peerHost
.
SetStreamHandler
(
protocol
.
ID
(
proto
),
func
(
remote
net
.
Stream
)
{
p2p
.
peerHost
.
SetStreamHandler
(
protocol
.
ID
(
proto
),
func
(
remote
net
.
Stream
)
{
...
...
p2p/listener.go
浏览文件 @
cf6ddcbf
package
p2p
package
p2p
import
(
pstore
"gx/ipfs/QmZb7hAgQEhW9dBbzBudU39gCeD4zbe6xafD52LUuF4cUN/go-libp2p-peerstore"
peer
"gx/ipfs/QmcJukH2sAFjY3HdBKq35WDzWoL3UUu2gt9wdfqZTUyM74/go-libp2p-peer"
p2phost
"gx/ipfs/QmdHyfNVTZ5VtUx4Xz23z8wtnioSrFQ28XSfpVkdhQBkGA/go-libp2p-host"
)
type
Listener
interface
{
type
Listener
interface
{
Protocol
()
string
Protocol
()
string
Address
()
string
Address
()
string
...
@@ -14,15 +8,6 @@ type Listener interface {
...
@@ -14,15 +8,6 @@ type Listener interface {
Close
()
error
Close
()
error
}
}
// NewP2P creates new P2P struct
func
NewP2P
(
identity
peer
.
ID
,
peerHost
p2phost
.
Host
,
peerstore
pstore
.
Peerstore
)
*
P2P
{
return
&
P2P
{
identity
:
identity
,
peerHost
:
peerHost
,
peerstore
:
peerstore
,
}
}
// ListenerRegistry is a collection of local application proto listeners.
// ListenerRegistry is a collection of local application proto listeners.
type
ListenerRegistry
struct
{
type
ListenerRegistry
struct
{
Listeners
map
[
string
]
Listener
Listeners
map
[
string
]
Listener
...
...
p2p/outbound.go
浏览文件 @
cf6ddcbf
...
@@ -12,10 +12,9 @@ import (
...
@@ -12,10 +12,9 @@ import (
peer
"gx/ipfs/QmcJukH2sAFjY3HdBKq35WDzWoL3UUu2gt9wdfqZTUyM74/go-libp2p-peer"
peer
"gx/ipfs/QmcJukH2sAFjY3HdBKq35WDzWoL3UUu2gt9wdfqZTUyM74/go-libp2p-peer"
)
)
//
in
boundListener accepts libp2p streams and proxies them to a manet host
//
out
boundListener accepts libp2p streams and proxies them to a manet host
type
outboundListener
struct
{
type
outboundListener
struct
{
ctx
context
.
Context
ctx
context
.
Context
cancel
context
.
CancelFunc
p2p
*
P2P
p2p
*
P2P
id
peer
.
ID
id
peer
.
ID
...
@@ -34,6 +33,8 @@ func (p2p *P2P) Dial(ctx context.Context, peer peer.ID, proto string, bindAddr m
...
@@ -34,6 +33,8 @@ func (p2p *P2P) Dial(ctx context.Context, peer peer.ID, proto string, bindAddr m
}
}
listener
:=
&
outboundListener
{
listener
:=
&
outboundListener
{
ctx
:
ctx
,
p2p
:
p2p
,
p2p
:
p2p
,
id
:
p2p
.
identity
,
id
:
p2p
.
identity
,
...
...
p2p/p2p.go
浏览文件 @
cf6ddcbf
...
@@ -16,6 +16,22 @@ type P2P struct {
...
@@ -16,6 +16,22 @@ type P2P struct {
peerstore
pstore
.
Peerstore
peerstore
pstore
.
Peerstore
}
}
// NewP2P creates new P2P struct
func
NewP2P
(
identity
peer
.
ID
,
peerHost
p2phost
.
Host
,
peerstore
pstore
.
Peerstore
)
*
P2P
{
return
&
P2P
{
identity
:
identity
,
peerHost
:
peerHost
,
peerstore
:
peerstore
,
Listeners
:
ListenerRegistry
{
Listeners
:
map
[
string
]
Listener
{},
},
Streams
:
StreamRegistry
{
Streams
:
map
[
uint64
]
*
Stream
{},
},
}
}
// CheckProtoExists checks whether a proto handler is registered to
// CheckProtoExists checks whether a proto handler is registered to
// mux handler
// mux handler
func
(
p2p
*
P2P
)
CheckProtoExists
(
proto
string
)
bool
{
func
(
p2p
*
P2P
)
CheckProtoExists
(
proto
string
)
bool
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论