提交 a7d1fd42 作者: Juan Batiz-Benet

updating daemon addr output

上级 458afe3d
...@@ -21,6 +21,8 @@ const ( ...@@ -21,6 +21,8 @@ const (
mountKwd = "mount" mountKwd = "mount"
ipfsMountKwd = "mount-ipfs" ipfsMountKwd = "mount-ipfs"
ipnsMountKwd = "mount-ipns" ipnsMountKwd = "mount-ipns"
// apiAddrKwd = "address-api"
// swarmAddrKwd = "address-swarm"
) )
var daemonCmd = &cmds.Command{ var daemonCmd = &cmds.Command{
...@@ -40,6 +42,10 @@ the daemon. ...@@ -40,6 +42,10 @@ the daemon.
cmds.BoolOption(mountKwd, "Mounts IPFS to the filesystem"), cmds.BoolOption(mountKwd, "Mounts IPFS to the filesystem"),
cmds.StringOption(ipfsMountKwd, "Path to the mountpoint for IPFS (if using --mount)"), cmds.StringOption(ipfsMountKwd, "Path to the mountpoint for IPFS (if using --mount)"),
cmds.StringOption(ipnsMountKwd, "Path to the mountpoint for IPNS (if using --mount)"), cmds.StringOption(ipnsMountKwd, "Path to the mountpoint for IPNS (if using --mount)"),
// TODO: add way to override addresses. tricky part: updating the config if also --init.
// cmds.StringOption(apiAddrKwd, "Address for the daemon rpc API (overrides config)"),
// cmds.StringOption(swarmAddrKwd, "Address for the swarm socket (overrides config)"),
}, },
Subcommands: map[string]*cmds.Command{}, Subcommands: map[string]*cmds.Command{},
Run: daemonFunc, Run: daemonFunc,
...@@ -86,19 +92,16 @@ func daemonFunc(req cmds.Request) (interface{}, error) { ...@@ -86,19 +92,16 @@ func daemonFunc(req cmds.Request) (interface{}, error) {
} }
defer lock.Close() defer lock.Close()
// make sure we construct online node. // OK!!! Now we're ready to construct the node.
// make sure we construct an online node.
ctx.Online = true ctx.Online = true
node, err := ctx.GetNode() node, err := ctx.GetNode()
if err != nil { if err != nil {
return nil, err return nil, err
} }
addr, err := ma.NewMultiaddr(cfg.Addresses.API) // verify api address is valid multiaddr
if err != nil { apiMaddr, err := ma.NewMultiaddr(cfg.Addresses.API)
return nil, err
}
_, host, err := manet.DialArgs(addr)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -131,6 +134,17 @@ func daemonFunc(req cmds.Request) (interface{}, error) { ...@@ -131,6 +134,17 @@ func daemonFunc(req cmds.Request) (interface{}, error) {
} }
} }
return nil, listenAndServeAPI(node, req, apiMaddr)
}
func listenAndServeAPI(node *core.IpfsNode, req cmds.Request, addr ma.Multiaddr) error {
_, host, err := manet.DialArgs(addr)
if err != nil {
return err
}
server := manners.NewServer()
mux := http.NewServeMux() mux := http.NewServeMux()
cmdHandler := cmdsHttp.NewHandler(*req.Context(), commands.Root) cmdHandler := cmdsHttp.NewHandler(*req.Context(), commands.Root)
mux.Handle(cmdsHttp.ApiPath+"/", cmdHandler) mux.Handle(cmdsHttp.ApiPath+"/", cmdHandler)
...@@ -138,15 +152,6 @@ func daemonFunc(req cmds.Request) (interface{}, error) { ...@@ -138,15 +152,6 @@ func daemonFunc(req cmds.Request) (interface{}, error) {
ifpsHandler := &ipfsHandler{node} ifpsHandler := &ipfsHandler{node}
mux.Handle("/ipfs/", ifpsHandler) mux.Handle("/ipfs/", ifpsHandler)
err = listenAndServe(node, mux, host)
return nil, err
}
func listenAndServe(node *core.IpfsNode, mux *http.ServeMux, host string) error {
fmt.Printf("API server listening on '%s'\n", host)
s := manners.NewServer()
done := make(chan struct{}, 1) done := make(chan struct{}, 1)
defer func() { defer func() {
done <- struct{}{} done <- struct{}{}
...@@ -160,11 +165,12 @@ func listenAndServe(node *core.IpfsNode, mux *http.ServeMux, host string) error ...@@ -160,11 +165,12 @@ func listenAndServe(node *core.IpfsNode, mux *http.ServeMux, host string) error
return return
} }
log.Info("terminating daemon at %s...", host) log.Info("terminating daemon at %s...", addr)
s.Shutdown <- true server.Shutdown <- true
}() }()
if err := s.ListenAndServe(host, mux); err != nil { fmt.Printf("daemon listening on %s\n", addr)
if err := server.ListenAndServe(host, mux); err != nil {
return err return err
} }
......
...@@ -58,7 +58,7 @@ test_launch_ipfs_mount() { ...@@ -58,7 +58,7 @@ test_launch_ipfs_mount() {
test_expect_success FUSE "'ipfs daemon' output looks good" ' test_expect_success FUSE "'ipfs daemon' output looks good" '
IPFS_PID=$! && IPFS_PID=$! &&
echo "API server listening on '\''127.0.0.1:5001'\''" >expected && echo "daemon listening on /ip4/127.0.0.1/tcp/5001" >expected &&
test_cmp_repeat_10_sec expected actual test_cmp_repeat_10_sec expected actual
' '
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论