Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
830ed487
提交
830ed487
authored
6月 02, 2018
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
p2p: refactor first review
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
3e0184bd
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
36 行增加
和
30 行删除
+36
-30
p2p.go
core/commands/p2p.go
+10
-8
experimental-features.md
docs/experimental-features.md
+11
-8
listener.go
p2p/listener.go
+1
-1
local.go
p2p/local.go
+4
-4
p2p.go
p2p/p2p.go
+2
-2
remote.go
p2p/remote.go
+5
-5
stream.go
p2p/stream.go
+3
-2
没有找到文件。
core/commands/p2p.go
浏览文件 @
830ed487
...
...
@@ -68,10 +68,12 @@ var p2pForwardCmd = &cmds.Command{
Helptext
:
cmdkit
.
HelpText
{
Tagline
:
"Forward connections to or from libp2p services"
,
ShortDescription
:
`
Forward connections to <listen-address> to <target-address>. Protocol specifies
the libp2p protocol to use.
Forward connections made to <listen-address> to <target-address>.
To create libp2p service listener, specify '/ipfs' as <listen-address>
<protocol> specifies the libp2p protocol name to use for libp2p
connections and/or handlers.
To create a libp2p service listener, specify '/ipfs' as <listen-address>
Examples:
ipfs p2p forward myproto /ipfs /ip4/127.0.0.1/tcp/1234
...
...
@@ -83,8 +85,8 @@ Examples:
`
,
},
Arguments
:
[]
cmdkit
.
Argument
{
cmdkit
.
StringArg
(
"protocol"
,
true
,
false
,
"Protocol
identifier
."
),
cmdkit
.
StringArg
(
"listen-address"
,
true
,
false
,
"Listening endpoint"
),
cmdkit
.
StringArg
(
"protocol"
,
true
,
false
,
"Protocol
name
."
),
cmdkit
.
StringArg
(
"listen-address"
,
true
,
false
,
"Listening endpoint
.
"
),
cmdkit
.
StringArg
(
"target-address"
,
true
,
false
,
"Target endpoint."
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
...
...
@@ -311,7 +313,7 @@ var p2pStreamLsCmd = &cmds.Command{
Tagline
:
"List active p2p streams."
,
},
Options
:
[]
cmdkit
.
Option
{
cmdkit
.
BoolOption
(
"headers"
,
"v"
,
"Print table headers (
Hagndler
ID, Protocol, Local, Remote)."
),
cmdkit
.
BoolOption
(
"headers"
,
"v"
,
"Print table headers (ID, Protocol, Local, Remote)."
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
n
,
err
:=
p2pGetNode
(
req
)
...
...
@@ -326,7 +328,7 @@ var p2pStreamLsCmd = &cmds.Command{
output
.
Streams
=
append
(
output
.
Streams
,
P2PStreamInfoOutput
{
HandlerID
:
strconv
.
FormatUint
(
id
,
10
),
Protocol
:
s
.
Protocol
,
Protocol
:
s
tring
(
s
.
Protocol
)
,
OriginAddress
:
s
.
OriginAddr
.
String
(),
TargetAddress
:
s
.
TargetAddr
.
String
(),
...
...
@@ -349,7 +351,7 @@ var p2pStreamLsCmd = &cmds.Command{
w
:=
tabwriter
.
NewWriter
(
buf
,
1
,
2
,
1
,
' '
,
0
)
for
_
,
stream
:=
range
list
.
Streams
{
if
headers
{
fmt
.
Fprintln
(
w
,
"I
d
\t
Protocol
\t
Origin
\t
Target"
)
fmt
.
Fprintln
(
w
,
"I
D
\t
Protocol
\t
Origin
\t
Target"
)
}
fmt
.
Fprintf
(
w
,
"%s
\t
%s
\t
%s
\t
%s
\n
"
,
stream
.
HandlerID
,
stream
.
Protocol
,
stream
.
OriginAddress
,
stream
.
TargetAddress
)
...
...
docs/experimental-features.md
浏览文件 @
830ed487
...
...
@@ -282,9 +282,12 @@ going to use `/kickass/1.0`.
1.
A "server" node with peer ID
`$SERVER_ID`
2.
A "client" node.
**
On the "server" nod
e:**
**
Netcat exampl
e:**
First, start your application and have it listen on
`$APP_PORT`
.
***On the "server" node:**
*
First, start your application and have it listen for TCP connections on
port
`$APP_PORT`
.
Then, configure the p2p listener by running:
...
...
@@ -296,11 +299,11 @@ This will configure IPFS to forward all incoming `/p2p/kickass/1.0` streams to
`127.0.0.1:$APP_PORT`
(opening a new connection to
`127.0.0.1:$APP_PORT`
per
incoming stream.
**
On the "client" node:
**
**
*On the "client" node:*
*
*
First, configure the
p2p dialer to forward all inbound connections on
`127.0.0.1:SOME_PORT`
to the listener behind
`/p2p/kickass/1.0`
on the server
node
.
First, configure the
client p2p dialer, so that it forwards all inbound
connections on
`127.0.0.1:SOME_PORT`
to the server node listening
on
`/p2p/kickass/1.0`
.
```
sh
>
ipfs p2p forward /kickass/1.0 /ip4/127.0.0.1/tcp/
$SOME_PORT
/ipfs/
$SERVER_ID
...
...
@@ -310,12 +313,12 @@ Next, have your application open a connection to `127.0.0.1:$SOME_PORT`. This
connection will be forwarded to the service running on
`127.0.0.1:$APP_PORT`
on
the remote machine. You can test it with netcat:
**
On "server" node:
**
**
*On "server" node:*
*
*
```
sh
>
nc
-v
-l
-p
$APP_PORT
```
**
On "client" node:
**
**
*On "client" node:*
*
*
```
sh
>
nc
-v
127.0.0.1
$SOME_PORT
```
...
...
p2p/listener.go
浏览文件 @
830ed487
...
...
@@ -24,7 +24,7 @@ type listenerKey struct {
// ListenerRegistry is a collection of local application proto listeners.
type
ListenerRegistry
struct
{
Listeners
map
[
listenerKey
]
Listener
lk
*
sync
.
Mutex
lk
sync
.
Mutex
}
func
(
r
*
ListenerRegistry
)
lock
(
l
Listener
)
error
{
...
...
p2p/local.go
浏览文件 @
830ed487
...
...
@@ -19,7 +19,7 @@ type localListener struct {
p2p
*
P2P
id
peer
.
ID
proto
string
proto
protocol
.
ID
laddr
ma
.
Multiaddr
peer
peer
.
ID
...
...
@@ -34,7 +34,7 @@ func (p2p *P2P) ForwardLocal(ctx context.Context, peer peer.ID, proto string, bi
p2p
:
p2p
,
id
:
p2p
.
identity
,
proto
:
proto
,
proto
:
proto
col
.
ID
(
proto
)
,
laddr
:
bindAddr
,
peer
:
peer
,
}
...
...
@@ -66,7 +66,7 @@ func (l *localListener) dial() (net.Stream, error) {
return
nil
,
err
}
return
l
.
p2p
.
peerHost
.
NewStream
(
l
.
ctx
,
l
.
peer
,
protocol
.
ID
(
l
.
proto
)
)
return
l
.
p2p
.
peerHost
.
NewStream
(
l
.
ctx
,
l
.
peer
,
l
.
proto
)
}
func
(
l
*
localListener
)
acceptConns
()
{
...
...
@@ -112,7 +112,7 @@ func (l *localListener) Close() error {
}
func
(
l
*
localListener
)
Protocol
()
string
{
return
l
.
proto
return
string
(
l
.
proto
)
}
func
(
l
*
localListener
)
ListenAddress
()
string
{
...
...
p2p/p2p.go
浏览文件 @
830ed487
...
...
@@ -27,11 +27,11 @@ func NewP2P(identity peer.ID, peerHost p2phost.Host, peerstore pstore.Peerstore)
Listeners
:
&
ListenerRegistry
{
Listeners
:
map
[
listenerKey
]
Listener
{},
lk
:
&
sync
.
Mutex
{},
lk
:
sync
.
Mutex
{},
},
Streams
:
&
StreamRegistry
{
Streams
:
map
[
uint64
]
*
Stream
{},
lk
:
&
sync
.
Mutex
{},
lk
:
sync
.
Mutex
{},
},
}
}
...
...
p2p/remote.go
浏览文件 @
830ed487
...
...
@@ -14,7 +14,7 @@ type remoteListener struct {
p2p
*
P2P
// Application proto identifier.
proto
string
proto
protocol
.
ID
// Address to proxy the incoming connections to
addr
ma
.
Multiaddr
...
...
@@ -25,7 +25,7 @@ func (p2p *P2P) ForwardRemote(ctx context.Context, proto string, addr ma.Multiad
listener
:=
&
remoteListener
{
p2p
:
p2p
,
proto
:
proto
,
proto
:
proto
col
.
ID
(
proto
)
,
addr
:
addr
,
}
...
...
@@ -33,7 +33,7 @@ func (p2p *P2P) ForwardRemote(ctx context.Context, proto string, addr ma.Multiad
return
nil
,
err
}
p2p
.
peerHost
.
SetStreamHandler
(
protocol
.
ID
(
proto
)
,
func
(
remote
net
.
Stream
)
{
p2p
.
peerHost
.
SetStreamHandler
(
listener
.
proto
,
func
(
remote
net
.
Stream
)
{
local
,
err
:=
manet
.
Dial
(
addr
)
if
err
!=
nil
{
remote
.
Reset
()
...
...
@@ -48,7 +48,7 @@ func (p2p *P2P) ForwardRemote(ctx context.Context, proto string, addr ma.Multiad
}
stream
:=
&
Stream
{
Protocol
:
proto
,
Protocol
:
listener
.
proto
,
OriginAddr
:
peerMa
,
TargetAddr
:
addr
,
...
...
@@ -69,7 +69,7 @@ func (p2p *P2P) ForwardRemote(ctx context.Context, proto string, addr ma.Multiad
}
func
(
l
*
remoteListener
)
Protocol
()
string
{
return
l
.
proto
return
string
(
l
.
proto
)
}
func
(
l
*
remoteListener
)
ListenAddress
()
string
{
...
...
p2p/stream.go
浏览文件 @
830ed487
...
...
@@ -6,6 +6,7 @@ import (
ma
"gx/ipfs/QmWWQ2Txc2c6tqjsBpzg5Ar652cHPGNsQQp2SejkNmkUMb/go-multiaddr"
net
"gx/ipfs/QmYj8wdn5sZEHX2XMDWGBvcXJNdzVbaVpHmXvhHBVZepen/go-libp2p-net"
"gx/ipfs/QmZNkThpqfVXs9GNbexPrfBbXSLNYeKrE7jwFM2oqHbyqN/go-libp2p-protocol"
manet
"gx/ipfs/QmcGXGdw9BWDysPJQHxJinjGHha3eEg4vzFETre4woNwcX/go-multiaddr-net"
)
...
...
@@ -13,7 +14,7 @@ import (
type
Stream
struct
{
id
uint64
Protocol
string
Protocol
protocol
.
ID
OriginAddr
ma
.
Multiaddr
TargetAddr
ma
.
Multiaddr
...
...
@@ -59,7 +60,7 @@ func (s *Stream) startStreaming() {
// StreamRegistry is a collection of active incoming and outgoing proto app streams.
type
StreamRegistry
struct
{
Streams
map
[
uint64
]
*
Stream
lk
*
sync
.
Mutex
lk
sync
.
Mutex
nextID
uint64
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论