diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index c50551f27bbf86cf55e9f4b45e76ce0822ded897..9778168540e6126d7b6dda25083e03a07b0864b3 100644 --- a/cmd/ipfs/daemon.go +++ b/cmd/ipfs/daemon.go @@ -6,6 +6,7 @@ import ( "net/http" _ "net/http/pprof" "os" + "sort" "strings" "sync" @@ -179,6 +180,8 @@ func daemonFunc(req cmds.Request, res cmds.Response) { return } + printSwarmAddrs(node) + defer func() { // We wait for the node to close first, as the node has children // that it will wait for before closing, such as the API server. @@ -305,6 +308,19 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) { return nil, errc } +// printSwarmAddrs prints the addresses of the host +func printSwarmAddrs(node *core.IpfsNode) { + 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) + } +} + // serveHTTPGateway collects options, creates listener, prints status message and starts serving requests func serveHTTPGateway(req cmds.Request) (error, <-chan error) { cfg, err := req.Context().GetConfig() diff --git a/test/sharness/t0060-daemon.sh b/test/sharness/t0060-daemon.sh index eaffe6384c15a28a4f5fde0a426d72b534d6df9f..a81d2c9f39d826de8443e4da0228e39adb997c75 100755 --- a/test/sharness/t0060-daemon.sh +++ b/test/sharness/t0060-daemon.sh @@ -36,6 +36,11 @@ test_expect_success "'ipfs config Identity.PeerID' works" ' ipfs config Identity.PeerID >config_peerId ' +test_expect_success "'ipfs swarm addrs local' works" ' + ipfs swarm addrs local >local_addrs +' + + # this is lifted straight from t0020-init.sh test_expect_success "ipfs peer id looks good" ' PEERID=$(cat config_peerId) && @@ -60,6 +65,7 @@ test_expect_success "ipfs daemon output looks good" ' echo "peer identity: $PEERID" >>expected_daemon && echo "to get started, enter:" >>expected_daemon && printf "\\n\\t$STARTFILE\\n\\n" >>expected_daemon && + cat local_addrs | sed "s/^/Swarm listening on /" >>expected_daemon && echo "API server listening on /ip4/127.0.0.1/tcp/5001" >>expected_daemon && echo "Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080" >>expected_daemon && test_cmp expected_daemon actual_daemon