1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-30 01:52:26 +08:00

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>
This commit is contained in:
Juan Batiz-Benet
2015-06-19 03:21:01 -07:00
parent 500f51300d
commit 9716018ca5
2 changed files with 22 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"net/http" "net/http"
_ "net/http/pprof" _ "net/http/pprof"
"os" "os"
"sort"
"strings" "strings"
"sync" "sync"
@ -179,6 +180,8 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
return return
} }
printSwarmAddrs(node)
defer func() { defer func() {
// We wait for the node to close first, as the node has children // 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. // 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 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 // serveHTTPGateway collects options, creates listener, prints status message and starts serving requests
func serveHTTPGateway(req cmds.Request) (error, <-chan error) { func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
cfg, err := req.Context().GetConfig() cfg, err := req.Context().GetConfig()

View File

@ -36,6 +36,11 @@ test_expect_success "'ipfs config Identity.PeerID' works" '
ipfs config Identity.PeerID >config_peerId 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 # this is lifted straight from t0020-init.sh
test_expect_success "ipfs peer id looks good" ' test_expect_success "ipfs peer id looks good" '
PEERID=$(cat config_peerId) && PEERID=$(cat config_peerId) &&
@ -60,6 +65,7 @@ test_expect_success "ipfs daemon output looks good" '
echo "peer identity: $PEERID" >>expected_daemon && echo "peer identity: $PEERID" >>expected_daemon &&
echo "to get started, enter:" >>expected_daemon && echo "to get started, enter:" >>expected_daemon &&
printf "\\n\\t$STARTFILE\\n\\n" >>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 "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 && echo "Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080" >>expected_daemon &&
test_cmp expected_daemon actual_daemon test_cmp expected_daemon actual_daemon