@cryptotaxi247 / kubo / commits / 9716018ca

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 <juan@benet.ai>

Juan Batiz-Benet committed Jun 19, 2015 at 03:21 UTC 9716018ca5bba11d8096ce77fc22a78701b74e9d
2 files changed +22
cmd/ipfs/daemon.go
+16
@@ -6,6 +6,7 @@ import (
6 "net/http"
7 _ "net/http/pprof"
8 "os"
9 + "sort"
10 "strings"
11 "sync"
12
@@ -179,6 +180,8 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
180 return
181 }
182
183 + printSwarmAddrs(node)
184 +
185 defer func() {
186 // We wait for the node to close first, as the node has children
187 // that it will wait for before closing, such as the API server.
@@ -305,6 +308,19 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
308 return nil, errc
309 }
310
311 +// printSwarmAddrs prints the addresses of the host
312 +func printSwarmAddrs(node *core.IpfsNode) {
313 + var addrs []string
314 + for _, addr := range node.PeerHost.Addrs() {
315 + addrs = append(addrs, addr.String())
316 + }
317 + sort.Sort(sort.StringSlice(addrs))
318 +
319 + for _, addr := range addrs {
320 + fmt.Printf("Swarm listening on %s\n", addr)
321 + }
322 +}
323 +
324 // serveHTTPGateway collects options, creates listener, prints status message and starts serving requests
325 func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
326 cfg, err := req.Context().GetConfig()
test/sharness/t0060-daemon.sh
+6
@@ -36,6 +36,11 @@ test_expect_success "'ipfs config Identity.PeerID' works" '
36 ipfs config Identity.PeerID >config_peerId
37 '
38
39 +test_expect_success "'ipfs swarm addrs local' works" '
40 + ipfs swarm addrs local >local_addrs
41 +'
42 +
43 +
44 # this is lifted straight from t0020-init.sh
45 test_expect_success "ipfs peer id looks good" '
46 PEERID=$(cat config_peerId) &&
@@ -60,6 +65,7 @@ test_expect_success "ipfs daemon output looks good" '
65 echo "peer identity: $PEERID" >>expected_daemon &&
66 echo "to get started, enter:" >>expected_daemon &&
67 printf "\\n\\t$STARTFILE\\n\\n" >>expected_daemon &&
68 + cat local_addrs | sed "s/^/Swarm listening on /" >>expected_daemon &&
69 echo "API server listening on /ip4/127.0.0.1/tcp/5001" >>expected_daemon &&
70 echo "Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080" >>expected_daemon &&
71 test_cmp expected_daemon actual_daemon