From 9716018ca5bba11d8096ce77fc22a78701b74e9d Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Fri, 19 Jun 2015 03:21:01 -0700 Subject: [PATCH] daemon output includes swarm addresses daemon output now includes initial swarm addresses. this is not a full solution, as a change in network will not trigger re-printing. We need a good way to do that. This made me re-think how we're outputting these messages, perhaps we should be throwing them as log.Events, and capturing some with a special keyword to output to the user on stdout. Things like network addresses being rebound, NATs being holepunched, external network addresses being figured out, connections established, etc may be valuable events to show the user. Of course, these should be very few, as a noisy daemon is an annoying daemon. License: MIT Signed-off-by: Juan Batiz-Benet --- cmd/ipfs/daemon.go | 16 ++++++++++++++++ test/sharness/t0060-daemon.sh | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index c50551f27..977816854 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 eaffe6384..a81d2c9f3 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