Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
bba2d05c
提交
bba2d05c
authored
9月 05, 2018
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
p2p: cleanup after listener iface split
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
dd48b823
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
9 行增加
和
38 行删除
+9
-38
local_listener.go
p2p/local_listener.go
+1
-31
p2p.go
p2p/p2p.go
+1
-1
p2p_listener.go
p2p/p2p_listener.go
+6
-5
remote.go
p2p/remote.go
+1
-1
没有找到文件。
p2p/local_listener.go
浏览文件 @
bba2d05c
...
...
@@ -4,11 +4,9 @@ import (
"errors"
"sync"
net
"gx/ipfs/QmQSbtGXCyNrj34LWL8EgXyNNYDZ8r3SwQcpW5pPxVhLnM/go-libp2p-net"
peer
"gx/ipfs/QmQsErDt8Qgw1XrsXf2BpEzDgGWtB1YLsTAARBup5b6B9W/go-libp2p-peer"
ma
"gx/ipfs/QmYmsdtJ3HsodkePE3eU3TsCaP2YvPZJ4LoXnNkDE5Tpt7/go-multiaddr"
"gx/ipfs/QmZNkThpqfVXs9GNbexPrfBbXSLNYeKrE7jwFM2oqHbyqN/go-libp2p-protocol"
p2phost
"gx/ipfs/QmfH9FKYv3Jp1xiyL8sPchGBUBg6JA6XviwajAo3qgnT3B/go-libp2p-host"
)
// ListenerLocal listens for connections and proxies them to a target
...
...
@@ -31,40 +29,12 @@ type ListenersLocal struct {
starting
map
[
string
]
struct
{}
}
func
newListenerRegistry
(
id
peer
.
ID
,
host
p2phost
.
Host
)
*
ListenersLocal
{
func
newListenerRegistry
(
id
peer
.
ID
)
*
ListenersLocal
{
reg
:=
&
ListenersLocal
{
Listeners
:
map
[
string
]
ListenerLocal
{},
starting
:
map
[
string
]
struct
{}{},
}
addr
,
err
:=
ma
.
NewMultiaddr
(
maPrefix
+
id
.
Pretty
())
if
err
!=
nil
{
panic
(
err
)
}
host
.
SetStreamHandlerMatch
(
"/x/"
,
func
(
p
string
)
bool
{
reg
.
RLock
()
defer
reg
.
RUnlock
()
for
_
,
l
:=
range
reg
.
Listeners
{
if
l
.
ListenAddress
()
.
Equal
(
addr
)
&&
string
(
l
.
Protocol
())
==
p
{
return
true
}
}
return
false
},
func
(
stream
net
.
Stream
)
{
reg
.
RLock
()
defer
reg
.
RUnlock
()
for
_
,
l
:=
range
reg
.
Listeners
{
if
l
.
ListenAddress
()
.
Equal
(
addr
)
&&
l
.
Protocol
()
==
stream
.
Protocol
()
{
go
l
.
(
*
remoteListener
)
.
handleStream
(
stream
)
return
}
}
})
return
reg
}
...
...
p2p/p2p.go
浏览文件 @
bba2d05c
...
...
@@ -27,7 +27,7 @@ func NewP2P(identity peer.ID, peerHost p2phost.Host, peerstore pstore.Peerstore)
peerHost
:
peerHost
,
peerstore
:
peerstore
,
ListenersLocal
:
newListenerRegistry
(
identity
,
peerHost
),
ListenersLocal
:
newListenerRegistry
(
identity
),
ListenersP2P
:
newListenerP2PRegistry
(
identity
,
peerHost
),
Streams
:
&
StreamRegistry
{
...
...
p2p/p2p_listener.go
浏览文件 @
bba2d05c
...
...
@@ -12,12 +12,13 @@ import (
)
// Listener listens for connections and proxies them to a target
type
P2PListener
interface
{
type
ListenerP2P
interface
{
Protocol
()
protocol
.
ID
ListenAddress
()
ma
.
Multiaddr
TargetAddress
()
ma
.
Multiaddr
start
()
error
handleStream
(
remote
net
.
Stream
)
// Close closes the listener. Does not affect child streams
Close
()
error
...
...
@@ -27,13 +28,13 @@ type P2PListener interface {
type
ListenersP2P
struct
{
sync
.
RWMutex
Listeners
map
[
protocol
.
ID
]
Listener
Local
Listeners
map
[
protocol
.
ID
]
Listener
P2P
starting
map
[
protocol
.
ID
]
struct
{}
}
func
newListenerP2PRegistry
(
id
peer
.
ID
,
host
p2phost
.
Host
)
*
ListenersP2P
{
reg
:=
&
ListenersP2P
{
Listeners
:
map
[
protocol
.
ID
]
Listener
Local
{},
Listeners
:
map
[
protocol
.
ID
]
Listener
P2P
{},
starting
:
map
[
protocol
.
ID
]
struct
{}{},
}
...
...
@@ -59,7 +60,7 @@ func newListenerP2PRegistry(id peer.ID, host p2phost.Host) *ListenersP2P {
for
_
,
l
:=
range
reg
.
Listeners
{
if
l
.
ListenAddress
()
.
Equal
(
addr
)
&&
l
.
Protocol
()
==
stream
.
Protocol
()
{
go
l
.
(
*
remoteListener
)
.
handleStream
(
stream
)
go
l
.
handleStream
(
stream
)
return
}
}
...
...
@@ -69,7 +70,7 @@ func newListenerP2PRegistry(id peer.ID, host p2phost.Host) *ListenersP2P {
}
// Register registers listenerInfo into this registry and starts it
func
(
r
*
ListenersP2P
)
Register
(
l
Listener
Local
)
error
{
func
(
r
*
ListenersP2P
)
Register
(
l
Listener
P2P
)
error
{
r
.
Lock
()
k
:=
l
.
Protocol
()
...
...
p2p/remote.go
浏览文件 @
bba2d05c
...
...
@@ -23,7 +23,7 @@ type remoteListener struct {
}
// ForwardRemote creates new p2p listener
func
(
p2p
*
P2P
)
ForwardRemote
(
ctx
context
.
Context
,
proto
protocol
.
ID
,
addr
ma
.
Multiaddr
)
(
P2PListener
,
error
)
{
func
(
p2p
*
P2P
)
ForwardRemote
(
ctx
context
.
Context
,
proto
protocol
.
ID
,
addr
ma
.
Multiaddr
)
(
ListenerP2P
,
error
)
{
listener
:=
&
remoteListener
{
p2p
:
p2p
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论