Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
f686b4c8
Commit
f686b4c8
authored
Jul 31, 2017
by
Jeromy Johnson
Committed by
GitHub
Jul 31, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3948 from ipfs/feat/addresses-announce
core: make announced swarm addresses configurable
parents
8ad3b11b
952f658a
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
140 additions
and
8 deletions
+140
-8
cmd/ipfs/daemon.go
cmd/ipfs/daemon.go
+16
-2
core/core.go
core/core.go
+61
-1
package.json
package.json
+5
-0
repo/config/addresses.go
repo/config/addresses.go
+5
-3
repo/config/init.go
repo/config/init.go
+4
-2
test/sharness/t0060-daemon.sh
test/sharness/t0060-daemon.sh
+1
-0
test/sharness/t0140-swarm.sh
test/sharness/t0140-swarm.sh
+48
-0
No files found.
cmd/ipfs/daemon.go
View file @
f686b4c8
...
...
@@ -497,15 +497,29 @@ func printSwarmAddrs(node *core.IpfsNode) {
fmt
.
Println
(
"Swarm not listening, running in offline mode."
)
return
}
var
lisAddrs
[]
string
ifaceAddrs
,
err
:=
node
.
PeerHost
.
Network
()
.
InterfaceListenAddresses
()
if
err
!=
nil
{
log
.
Errorf
(
"failed to read listening addresses: %s"
,
err
)
}
for
_
,
addr
:=
range
ifaceAddrs
{
lisAddrs
=
append
(
lisAddrs
,
addr
.
String
())
}
sort
.
Sort
(
sort
.
StringSlice
(
lisAddrs
))
for
_
,
addr
:=
range
lisAddrs
{
fmt
.
Printf
(
"Swarm listening on %s
\n
"
,
addr
)
}
var
addrs
[]
string
for
_
,
addr
:=
range
node
.
PeerHost
.
Addrs
()
{
addrs
=
append
(
addrs
,
addr
.
String
())
}
sort
.
Sort
(
sort
.
StringSlice
(
addrs
))
for
_
,
addr
:=
range
addrs
{
fmt
.
Printf
(
"Swarm
listening on
%s
\n
"
,
addr
)
fmt
.
Printf
(
"Swarm
announcing
%s
\n
"
,
addr
)
}
}
// serveHTTPGateway collects options, creates listener, prints status message and starts serving requests
...
...
core/core.go
View file @
f686b4c8
...
...
@@ -45,6 +45,7 @@ import (
pnet
"gx/ipfs/QmNMCAuxnQFHLGWcvay3DmVFrKuY6Y2nsc9vzsf4gVouJV/go-libp2p-pnet"
pstore
"gx/ipfs/QmPgDWmTmuzvP7QE5zwo1TmjbJme9pmZHNujB2453jkCTr/go-libp2p-peerstore"
routing
"gx/ipfs/QmPjTrrSfE6TzLv6ya6VWhGcCgPrUAdcgrDcQyRDX2VyW1/go-libp2p-routing"
mafilter
"gx/ipfs/QmQBB2dQLmQHJgs2gqZ3iqL2XiuCtUCvXzWt5kMXDf5Zcr/go-maddr-filter"
ipnet
"gx/ipfs/QmQq9YzmdFdWNTDdArueGyD7L5yyiRQigrRHJnTGkxcEjT/go-libp2p-interface-pnet"
dht
"gx/ipfs/QmRKEzkaiwud2LnwJ9CgBrKw122ddKPTMtLizV3DNimVRD/go-libp2p-kad-dht"
p2phost
"gx/ipfs/QmRNyPNJGNCaZyYonJj7owciWTsMd9gRfEKmZY3o6xwN3h/go-libp2p-host"
...
...
@@ -212,8 +213,17 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
}()
}
addrsFactory
,
err
:=
makeAddrsFactory
(
cfg
.
Addresses
)
if
err
!=
nil
{
return
err
}
hostopts
:=
&
ConstructPeerHostOpts
{
AddrsFactory
:
addrsFactory
,
DisableNatPortMap
:
cfg
.
Swarm
.
DisableNatPortMap
,
}
peerhost
,
err
:=
hostOption
(
ctx
,
n
.
Identity
,
n
.
Peerstore
,
n
.
Reporter
,
addrfilter
,
tpt
,
protec
,
&
ConstructPeerHostOpts
{
DisableNatPortMap
:
cfg
.
Swarm
.
DisableNatPortMap
}
)
addrfilter
,
tpt
,
protec
,
hostopts
)
if
err
!=
nil
{
return
err
}
...
...
@@ -263,6 +273,52 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, routingOption Routin
return
n
.
Bootstrap
(
DefaultBootstrapConfig
)
}
func
makeAddrsFactory
(
cfg
config
.
Addresses
)
(
p2pbhost
.
AddrsFactory
,
error
)
{
var
annAddrs
[]
ma
.
Multiaddr
for
_
,
addr
:=
range
cfg
.
Announce
{
maddr
,
err
:=
ma
.
NewMultiaddr
(
addr
)
if
err
!=
nil
{
return
nil
,
err
}
annAddrs
=
append
(
annAddrs
,
maddr
)
}
filters
:=
mafilter
.
NewFilters
()
noAnnAddrs
:=
map
[
string
]
bool
{}
for
_
,
addr
:=
range
cfg
.
NoAnnounce
{
f
,
err
:=
mamask
.
NewMask
(
addr
)
if
err
==
nil
{
filters
.
AddDialFilter
(
f
)
continue
}
maddr
,
err
:=
ma
.
NewMultiaddr
(
addr
)
if
err
!=
nil
{
return
nil
,
err
}
noAnnAddrs
[
maddr
.
String
()]
=
true
}
return
func
(
allAddrs
[]
ma
.
Multiaddr
)
[]
ma
.
Multiaddr
{
var
addrs
[]
ma
.
Multiaddr
if
len
(
annAddrs
)
>
0
{
addrs
=
annAddrs
}
else
{
addrs
=
allAddrs
}
var
out
[]
ma
.
Multiaddr
for
_
,
maddr
:=
range
addrs
{
// check for exact matches
ok
,
_
:=
noAnnAddrs
[
maddr
.
String
()]
// check for /ipcidr matches
if
!
ok
&&
!
filters
.
AddrBlocked
(
maddr
)
{
out
=
append
(
out
,
maddr
)
}
}
return
out
},
nil
}
func
makeSmuxTransport
(
mplexExp
bool
)
smux
.
Transport
{
mstpt
:=
mssmux
.
NewBlankTransport
()
...
...
@@ -705,6 +761,7 @@ func listenAddresses(cfg *config.Config) ([]ma.Multiaddr, error) {
type
ConstructPeerHostOpts
struct
{
DisableNatPortMap
bool
AddrsFactory
p2pbhost
.
AddrsFactory
}
type
HostOption
func
(
ctx
context
.
Context
,
id
peer
.
ID
,
ps
pstore
.
Peerstore
,
bwr
metrics
.
Reporter
,
fs
[]
*
net
.
IPNet
,
tpt
smux
.
Transport
,
protc
ipnet
.
Protector
,
opts
*
ConstructPeerHostOpts
)
(
p2phost
.
Host
,
error
)
...
...
@@ -730,6 +787,9 @@ func constructPeerHost(ctx context.Context, id peer.ID, ps pstore.Peerstore, bwr
if
!
opts
.
DisableNatPortMap
{
hostOpts
=
append
(
hostOpts
,
p2pbhost
.
NATPortMap
)
}
if
opts
.
AddrsFactory
!=
nil
{
hostOpts
=
append
(
hostOpts
,
opts
.
AddrsFactory
)
}
host
:=
p2pbhost
.
New
(
network
,
hostOpts
...
)
...
...
package.json
View file @
f686b4c8
...
...
@@ -446,6 +446,11 @@
"hash"
:
"Qma7Kuwun7w8SZphjEPDVxvGfetBkqdNGmigDA13sJdLex"
,
"name"
:
"go-ipld-git"
,
"version"
:
"0.1.3"
},
{
"hash"
:
"QmQBB2dQLmQHJgs2gqZ3iqL2XiuCtUCvXzWt5kMXDf5Zcr"
,
"name"
:
"go-maddr-filter"
,
"version"
:
"1.1.4"
}
],
"gxVersion"
:
"0.10.0"
,
...
...
repo/config/addresses.go
View file @
f686b4c8
...
...
@@ -2,7 +2,9 @@ package config
// Addresses stores the (string) multiaddr addresses for the node.
type
Addresses
struct
{
Swarm
[]
string
// addresses for the swarm network
API
string
// address for the local API (RPC)
Gateway
string
// address to listen on for IPFS HTTP object gateway
Swarm
[]
string
// addresses for the swarm to listen on
Announce
[]
string
// swarm addresses to announce to the network
NoAnnounce
[]
string
// swarm addresses not to announce to the network
API
string
// address for the local API (RPC)
Gateway
string
// address to listen on for IPFS HTTP object gateway
}
repo/config/init.go
View file @
f686b4c8
...
...
@@ -36,8 +36,10 @@ func Init(out io.Writer, nBitsForKeypair int) (*Config, error) {
// "/ip4/0.0.0.0/udp/4002/utp", // disabled for now.
"/ip6/::/tcp/4001"
,
},
API
:
"/ip4/127.0.0.1/tcp/5001"
,
Gateway
:
"/ip4/127.0.0.1/tcp/8080"
,
Announce
:
[]
string
{},
NoAnnounce
:
[]
string
{},
API
:
"/ip4/127.0.0.1/tcp/5001"
,
Gateway
:
"/ip4/127.0.0.1/tcp/8080"
,
},
Datastore
:
datastore
,
...
...
test/sharness/t0060-daemon.sh
View file @
f686b4c8
...
...
@@ -39,6 +39,7 @@ test_expect_success "ipfs daemon output looks good" '
STARTFILE="ipfs cat /ipfs/$HASH_WELCOME_DOCS/readme" &&
echo "Initializing daemon..." >expected_daemon &&
sed "s/^/Swarm listening on /" local_addrs >>expected_daemon &&
sed "s/^/Swarm announcing /" local_addrs >>expected_daemon &&
echo "API server listening on '
$API_MADDR
'" >>expected_daemon &&
echo "Gateway (readonly) server listening on '
$GWAY_MADDR
'" >>expected_daemon &&
echo "Daemon is ready" >>expected_daemon &&
...
...
test/sharness/t0140-swarm.sh
View file @
f686b4c8
...
...
@@ -49,4 +49,52 @@ test_expect_success "cant trigger a dial backoff with swarm connect" '
test_kill_ipfs_daemon
announceCfg
=
'["/ip4/127.0.0.1/tcp/4001", "/ip4/1.2.3.4/tcp/1234"]'
test_expect_success
"test_config_set succeeds"
"
ipfs config --json Addresses.Announce '
$announceCfg
'
"
test_launch_ipfs_daemon
test_expect_success
'Addresses.Announce affects addresses'
'
ipfs swarm addrs local >actual &&
grep "/ip4/1.2.3.4/tcp/1234" actual &&
ipfs id -f"<addrs>" | xargs -n1 echo >actual &&
grep "/ip4/1.2.3.4/tcp/1234" actual
'
test_kill_ipfs_daemon
noAnnounceCfg
=
'["/ip4/1.2.3.4/tcp/1234"]'
test_expect_success
"test_config_set succeeds"
"
ipfs config --json Addresses.NoAnnounce '
$noAnnounceCfg
'
"
test_launch_ipfs_daemon
test_expect_success
"Addresses.NoAnnounce affects addresses"
'
ipfs swarm addrs local >actual &&
grep -v "/ip4/1.2.3.4/tcp/1234" actual &&
ipfs id -f"<addrs>" | xargs -n1 echo >actual &&
grep -v "/ip4/1.2.3.4/tcp/1234" actual
'
test_kill_ipfs_daemon
noAnnounceCfg
=
'["/ip4/1.2.3.4/ipcidr/16"]'
test_expect_success
"test_config_set succeeds"
"
ipfs config --json Addresses.NoAnnounce '
$noAnnounceCfg
'
"
test_launch_ipfs_daemon
test_expect_success
"Addresses.NoAnnounce with /ipcidr affects addresses"
'
ipfs swarm addrs local >actual &&
grep -v "/ip4/1.2.3.4/tcp/1234" actual &&
ipfs id -f"<addrs>" | xargs -n1 echo >actual &&
grep -v "/ip4/1.2.3.4/tcp/1234" actual
'
test_kill_ipfs_daemon
test_done
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment