Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
e01f8e4f
提交
e01f8e4f
authored
6月 16, 2015
作者:
Jeromy
提交者:
Juan Batiz-Benet
6月 23, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add in basic address dial filtering
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
上级
3f28663f
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
115 行增加
和
6 行删除
+115
-6
Godeps.json
Godeps/Godeps.json
+4
-0
mask.go
...ace/src/github.com/whyrusleeping/multiaddr-filter/mask.go
+19
-0
mask_test.go
...rc/github.com/whyrusleeping/multiaddr-filter/mask_test.go
+36
-0
core.go
core/core.go
+18
-6
swarm.go
p2p/net/swarm/swarm.go
+8
-0
swarm_dial.go
p2p/net/swarm/swarm_dial.go
+28
-0
config.go
repo/config/config.go
+1
-0
godep.go
util/sadhack/godep.go
+1
-0
没有找到文件。
Godeps/Godeps.json
浏览文件 @
e01f8e4f
...
@@ -240,6 +240,10 @@
...
@@ -240,6 +240,10 @@
"Rev"
:
"3970c95a864f1a40037f796ff596607ce8ae43be"
"Rev"
:
"3970c95a864f1a40037f796ff596607ce8ae43be"
},
},
{
{
"ImportPath"
:
"github.com/whyrusleeping/multiaddr-filter"
,
"Rev"
:
"15837fcc356fddef27c634b0f6379b3b7f259114"
},
{
"ImportPath"
:
"golang.org/x/crypto/blowfish"
,
"ImportPath"
:
"golang.org/x/crypto/blowfish"
,
"Rev"
:
"c84e1f8e3a7e322d497cd16c0e8a13c7e127baf3"
"Rev"
:
"c84e1f8e3a7e322d497cd16c0e8a13c7e127baf3"
},
},
...
...
Godeps/_workspace/src/github.com/whyrusleeping/multiaddr-filter/mask.go
0 → 100644
浏览文件 @
e01f8e4f
package
mask
import
(
"errors"
"net"
"strings"
)
func
NewMask
(
a
string
)
(
*
net
.
IPNet
,
error
)
{
parts
:=
strings
.
Split
(
a
,
"/"
)
if
len
(
parts
)
==
5
&&
parts
[
1
]
==
"ip4"
&&
parts
[
3
]
==
"ipcidr"
{
_
,
ipn
,
err
:=
net
.
ParseCIDR
(
parts
[
2
]
+
"/"
+
parts
[
4
])
if
err
!=
nil
{
return
nil
,
err
}
return
ipn
,
nil
}
return
nil
,
errors
.
New
(
"invalid format"
)
}
Godeps/_workspace/src/github.com/whyrusleeping/multiaddr-filter/mask_test.go
0 → 100644
浏览文件 @
e01f8e4f
package
mask
import
(
"net"
"testing"
)
func
TestFiltered
(
t
*
testing
.
T
)
{
var
tests
=
map
[
string
]
map
[
string
]
bool
{
"/ip4/10.0.0.0/ipcidr/8"
:
map
[
string
]
bool
{
"10.3.3.4"
:
true
,
"10.3.4.4"
:
true
,
"10.4.4.4"
:
true
,
"15.52.34.3"
:
false
,
},
"/ip4/192.168.0.0/ipcidr/16"
:
map
[
string
]
bool
{
"192.168.0.0"
:
true
,
"192.168.1.0"
:
true
,
"192.1.0.0"
:
false
,
"10.4.4.4"
:
false
,
},
}
for
mask
,
set
:=
range
tests
{
m
,
err
:=
NewMask
(
mask
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
for
addr
,
val
:=
range
set
{
ip
:=
net
.
ParseIP
(
addr
)
if
m
.
Contains
(
ip
)
!=
val
{
t
.
Fatalf
(
"expected contains(%s, %s) == %s"
,
mask
,
addr
,
val
)
}
}
}
}
core/core.go
浏览文件 @
e01f8e4f
...
@@ -13,17 +13,17 @@ import (
...
@@ -13,17 +13,17 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"io"
"io"
"net"
"time"
"time"
b58
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"
b58
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"
ctxgroup
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup"
ctxgroup
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup"
ds
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
ds
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
ma
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
ma
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
mamask
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/whyrusleeping/multiaddr-filter"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
metrics
"github.com/ipfs/go-ipfs/metrics"
eventlog
"github.com/ipfs/go-ipfs/thirdparty/eventlog"
diag
"github.com/ipfs/go-ipfs/diagnostics"
diag
"github.com/ipfs/go-ipfs/diagnostics"
metrics
"github.com/ipfs/go-ipfs/metrics"
ic
"github.com/ipfs/go-ipfs/p2p/crypto"
ic
"github.com/ipfs/go-ipfs/p2p/crypto"
discovery
"github.com/ipfs/go-ipfs/p2p/discovery"
discovery
"github.com/ipfs/go-ipfs/p2p/discovery"
p2phost
"github.com/ipfs/go-ipfs/p2p/host"
p2phost
"github.com/ipfs/go-ipfs/p2p/host"
...
@@ -32,6 +32,7 @@ import (
...
@@ -32,6 +32,7 @@ import (
swarm
"github.com/ipfs/go-ipfs/p2p/net/swarm"
swarm
"github.com/ipfs/go-ipfs/p2p/net/swarm"
addrutil
"github.com/ipfs/go-ipfs/p2p/net/swarm/addr"
addrutil
"github.com/ipfs/go-ipfs/p2p/net/swarm/addr"
peer
"github.com/ipfs/go-ipfs/p2p/peer"
peer
"github.com/ipfs/go-ipfs/p2p/peer"
eventlog
"github.com/ipfs/go-ipfs/thirdparty/eventlog"
routing
"github.com/ipfs/go-ipfs/routing"
routing
"github.com/ipfs/go-ipfs/routing"
dht
"github.com/ipfs/go-ipfs/routing/dht"
dht
"github.com/ipfs/go-ipfs/routing/dht"
...
@@ -254,7 +255,18 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
...
@@ -254,7 +255,18 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
// Set reporter
// Set reporter
n
.
Reporter
=
metrics
.
NewBandwidthCounter
()
n
.
Reporter
=
metrics
.
NewBandwidthCounter
()
peerhost
,
err
:=
hostOption
(
ctx
,
n
.
Identity
,
n
.
Peerstore
,
n
.
Reporter
)
// get undialable addrs from config
cfg
:=
n
.
Repo
.
Config
()
var
addrfilter
[]
*
net
.
IPNet
for
_
,
s
:=
range
cfg
.
DialBlocklist
{
f
,
err
:=
mamask
.
NewMask
(
s
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"incorrectly formatter address filter in config: %s"
,
s
)
}
addrfilter
=
append
(
addrfilter
,
f
)
}
peerhost
,
err
:=
hostOption
(
ctx
,
n
.
Identity
,
n
.
Peerstore
,
n
.
Reporter
,
addrfilter
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -508,12 +520,12 @@ func listenAddresses(cfg *config.Config) ([]ma.Multiaddr, error) {
...
@@ -508,12 +520,12 @@ func listenAddresses(cfg *config.Config) ([]ma.Multiaddr, error) {
return
listen
,
nil
return
listen
,
nil
}
}
type
HostOption
func
(
ctx
context
.
Context
,
id
peer
.
ID
,
ps
peer
.
Peerstore
,
bwr
metrics
.
Reporter
)
(
p2phost
.
Host
,
error
)
type
HostOption
func
(
ctx
context
.
Context
,
id
peer
.
ID
,
ps
peer
.
Peerstore
,
bwr
metrics
.
Reporter
,
fs
[]
*
net
.
IPNet
)
(
p2phost
.
Host
,
error
)
var
DefaultHostOption
HostOption
=
constructPeerHost
var
DefaultHostOption
HostOption
=
constructPeerHost
// isolates the complex initialization steps
// isolates the complex initialization steps
func
constructPeerHost
(
ctx
context
.
Context
,
id
peer
.
ID
,
ps
peer
.
Peerstore
,
bwr
metrics
.
Reporter
)
(
p2phost
.
Host
,
error
)
{
func
constructPeerHost
(
ctx
context
.
Context
,
id
peer
.
ID
,
ps
peer
.
Peerstore
,
bwr
metrics
.
Reporter
,
fs
[]
*
net
.
IPNet
)
(
p2phost
.
Host
,
error
)
{
// no addresses to begin with. we'll start later.
// no addresses to begin with. we'll start later.
network
,
err
:=
swarm
.
NewNetwork
(
ctx
,
nil
,
id
,
ps
,
bwr
)
network
,
err
:=
swarm
.
NewNetwork
(
ctx
,
nil
,
id
,
ps
,
bwr
)
...
...
p2p/net/swarm/swarm.go
浏览文件 @
e01f8e4f
...
@@ -4,6 +4,7 @@ package swarm
...
@@ -4,6 +4,7 @@ package swarm
import
(
import
(
"fmt"
"fmt"
"net"
"sync"
"sync"
"time"
"time"
...
@@ -50,6 +51,9 @@ type Swarm struct {
...
@@ -50,6 +51,9 @@ type Swarm struct {
notifmu
sync
.
RWMutex
notifmu
sync
.
RWMutex
notifs
map
[
inet
.
Notifiee
]
ps
.
Notifiee
notifs
map
[
inet
.
Notifiee
]
ps
.
Notifiee
// filters for addresses that shouldnt be dialed
filters
[]
*
net
.
IPNet
cg
ctxgroup
.
ContextGroup
cg
ctxgroup
.
ContextGroup
bwc
metrics
.
Reporter
bwc
metrics
.
Reporter
}
}
...
@@ -84,6 +88,10 @@ func (s *Swarm) teardown() error {
...
@@ -84,6 +88,10 @@ func (s *Swarm) teardown() error {
return
s
.
swarm
.
Close
()
return
s
.
swarm
.
Close
()
}
}
func
(
s
*
Swarm
)
AddDialFilter
(
f
*
net
.
IPNet
)
{
s
.
filters
=
append
(
s
.
filters
,
f
)
}
// CtxGroup returns the Context Group of the swarm
// CtxGroup returns the Context Group of the swarm
func
filterAddrs
(
listenAddrs
[]
ma
.
Multiaddr
)
([]
ma
.
Multiaddr
,
error
)
{
func
filterAddrs
(
listenAddrs
[]
ma
.
Multiaddr
)
([]
ma
.
Multiaddr
,
error
)
{
if
len
(
listenAddrs
)
>
0
{
if
len
(
listenAddrs
)
>
0
{
...
...
p2p/net/swarm/swarm_dial.go
浏览文件 @
e01f8e4f
...
@@ -303,6 +303,8 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) {
...
@@ -303,6 +303,8 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) {
ila
,
_
:=
s
.
InterfaceListenAddresses
()
ila
,
_
:=
s
.
InterfaceListenAddresses
()
remoteAddrs
=
addrutil
.
Subtract
(
remoteAddrs
,
ila
)
remoteAddrs
=
addrutil
.
Subtract
(
remoteAddrs
,
ila
)
remoteAddrs
=
addrutil
.
Subtract
(
remoteAddrs
,
s
.
peers
.
Addrs
(
s
.
local
))
remoteAddrs
=
addrutil
.
Subtract
(
remoteAddrs
,
s
.
peers
.
Addrs
(
s
.
local
))
remoteAddrs
=
s
.
filterAddrs
(
remoteAddrs
)
log
.
Debugf
(
"%s swarm dialing %s -- local:%s remote:%s"
,
s
.
local
,
p
,
s
.
ListenAddresses
(),
remoteAddrs
)
log
.
Debugf
(
"%s swarm dialing %s -- local:%s remote:%s"
,
s
.
local
,
p
,
s
.
ListenAddresses
(),
remoteAddrs
)
if
len
(
remoteAddrs
)
==
0
{
if
len
(
remoteAddrs
)
==
0
{
err
:=
errors
.
New
(
"peer has no addresses"
)
err
:=
errors
.
New
(
"peer has no addresses"
)
...
@@ -454,6 +456,32 @@ func (s *Swarm) dialAddr(ctx context.Context, d *conn.Dialer, p peer.ID, addr ma
...
@@ -454,6 +456,32 @@ func (s *Swarm) dialAddr(ctx context.Context, d *conn.Dialer, p peer.ID, addr ma
return
connC
,
nil
return
connC
,
nil
}
}
func
(
s
*
Swarm
)
filterAddrs
(
addrs
[]
ma
.
Multiaddr
)
[]
ma
.
Multiaddr
{
var
out
[]
ma
.
Multiaddr
for
_
,
a
:=
range
addrs
{
if
!
s
.
addrBlocked
(
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
// dialConnSetup is the setup logic for a connection from the dial side. it
// needs to add the Conn to the StreamSwarm, then run newConnSetup
// needs to add the Conn to the StreamSwarm, then run newConnSetup
func
dialConnSetup
(
ctx
context
.
Context
,
s
*
Swarm
,
connC
conn
.
Conn
)
(
*
Conn
,
error
)
{
func
dialConnSetup
(
ctx
context
.
Context
,
s
*
Swarm
,
connC
conn
.
Conn
)
(
*
Conn
,
error
)
{
...
...
repo/config/config.go
浏览文件 @
e01f8e4f
...
@@ -26,6 +26,7 @@ type Config struct {
...
@@ -26,6 +26,7 @@ type Config struct {
Tour
Tour
// local node's tour position
Tour
Tour
// local node's tour position
Gateway
Gateway
// local node's gateway server options
Gateway
Gateway
// local node's gateway server options
SupernodeRouting
SupernodeClientConfig
// local node's routing servers (if SupernodeRouting enabled)
SupernodeRouting
SupernodeClientConfig
// local node's routing servers (if SupernodeRouting enabled)
DialBlocklist
[]
string
Log
Log
Log
Log
}
}
...
...
util/sadhack/godep.go
浏览文件 @
e01f8e4f
...
@@ -6,4 +6,5 @@ import _ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/dustin/go-hum
...
@@ -6,4 +6,5 @@ import _ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/dustin/go-hum
// similar to the above, only used in the tests makefile
// similar to the above, only used in the tests makefile
import
_
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/whyrusleeping/iptb"
import
_
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/whyrusleeping/iptb"
import
_
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/chriscool/go-sleep"
import
_
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/chriscool/go-sleep"
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论