Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
fbab2a72
提交
fbab2a72
authored
6月 17, 2015
作者:
Jeromy
提交者:
Juan Batiz-Benet
6月 23, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
broke filters out into a struct
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
上级
e01f8e4f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
33 行增加
和
27 行删除
+33
-27
swarm.go
p2p/net/swarm/swarm.go
+32
-10
swarm_dial.go
p2p/net/swarm/swarm_dial.go
+1
-17
没有找到文件。
p2p/net/swarm/swarm.go
浏览文件 @
fbab2a72
...
...
@@ -16,6 +16,7 @@ import (
ctxgroup
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup"
ma
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
manet
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr-net"
ps
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream"
pst
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream/transport"
psy
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream/transport/yamux"
...
...
@@ -52,7 +53,7 @@ type Swarm struct {
notifs
map
[
inet
.
Notifiee
]
ps
.
Notifiee
// filters for addresses that shouldnt be dialed
filters
[]
*
net
.
IPNet
Filters
*
Filters
cg
ctxgroup
.
ContextGroup
bwc
metrics
.
Reporter
...
...
@@ -68,13 +69,14 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
}
s
:=
&
Swarm
{
swarm
:
ps
.
NewSwarm
(
PSTransport
),
local
:
local
,
peers
:
peers
,
cg
:
ctxgroup
.
WithContext
(
ctx
),
dialT
:
DialTimeout
,
notifs
:
make
(
map
[
inet
.
Notifiee
]
ps
.
Notifiee
),
bwc
:
bwc
,
swarm
:
ps
.
NewSwarm
(
PSTransport
),
local
:
local
,
peers
:
peers
,
cg
:
ctxgroup
.
WithContext
(
ctx
),
dialT
:
DialTimeout
,
notifs
:
make
(
map
[
inet
.
Notifiee
]
ps
.
Notifiee
),
bwc
:
bwc
,
Filters
:
new
(
Filters
),
}
// configure Swarm
...
...
@@ -88,8 +90,28 @@ func (s *Swarm) teardown() error {
return
s
.
swarm
.
Close
()
}
func
(
s
*
Swarm
)
AddDialFilter
(
f
*
net
.
IPNet
)
{
s
.
filters
=
append
(
s
.
filters
,
f
)
type
Filters
struct
{
filters
[]
*
net
.
IPNet
}
func
(
fs
*
Filters
)
AddDialFilter
(
f
*
net
.
IPNet
)
{
fs
.
filters
=
append
(
fs
.
filters
,
f
)
}
func
(
f
*
Filters
)
AddrBlocked
(
a
ma
.
Multiaddr
)
bool
{
_
,
addr
,
err
:=
manet
.
DialArgs
(
a
)
if
err
!=
nil
{
// if we cant parse it, its probably not blocked
return
false
}
ip
:=
net
.
ParseIP
(
addr
)
for
_
,
ft
:=
range
f
.
filters
{
if
ft
.
Contains
(
ip
)
{
return
true
}
}
return
false
}
// CtxGroup returns the Context Group of the swarm
...
...
p2p/net/swarm/swarm_dial.go
浏览文件 @
fbab2a72
...
...
@@ -459,29 +459,13 @@ func (s *Swarm) dialAddr(ctx context.Context, d *conn.Dialer, p peer.ID, addr ma
func
(
s
*
Swarm
)
filterAddrs
(
addrs
[]
ma
.
Multiaddr
)
[]
ma
.
Multiaddr
{
var
out
[]
ma
.
Multiaddr
for
_
,
a
:=
range
addrs
{
if
!
s
.
a
ddrBlocked
(
a
)
{
if
!
s
.
Filters
.
A
ddrBlocked
(
a
)
{
out
=
append
(
out
,
a
)
}
}
return
out
}
func
(
s
*
Swarm
)
addrBlocked
(
a
ma
.
Multiaddr
)
bool
{
_
,
addr
,
err
:=
manet
.
DialArgs
(
a
)
if
err
!=
nil
{
// if we cant parse it, its probably not blocked
return
false
}
ip
:=
net
.
ParseIP
(
addr
)
for
_
,
f
:=
range
s
.
filters
{
if
f
.
Contains
(
ip
)
{
return
true
}
}
return
false
}
// dialConnSetup is the setup logic for a connection from the dial side. it
// needs to add the Conn to the StreamSwarm, then run newConnSetup
func
dialConnSetup
(
ctx
context
.
Context
,
s
*
Swarm
,
connC
conn
.
Conn
)
(
*
Conn
,
error
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论