Skip to content

Commit

Permalink
daemon: addressed CR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptix committed Jun 8, 2015
1 parent 07b3415 commit 4b337bb
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
}

// construct api endpoint - every time
err, apiErrc := mountHTTPapi(req)
err, apiErrc := serveHTTPApi(req)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
Expand All @@ -206,7 +206,7 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
var gwErrc <-chan error
if len(cfg.Addresses.Gateway) > 0 {
var err error
err, gwErrc = mountHTTPgw(req)
err, gwErrc = serveHTTPGateway(req)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
Expand Down Expand Up @@ -236,29 +236,29 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
}
}

// mountHTTPapi collects options, creates listener, prints status message and starts serving requests
func mountHTTPapi(req cmds.Request) (error, <-chan error) {
// serveHTTPApi collects options, creates listener, prints status message and starts serving requests
func serveHTTPApi(req cmds.Request) (error, <-chan error) {
cfg, err := req.Context().GetConfig()
if err != nil {
return fmt.Errorf("mountHTTPapi: GetConfig() failed: %s", err), nil
return fmt.Errorf("serveHTTPApi: GetConfig() failed: %s", err), nil
}

apiMaddr, err := ma.NewMultiaddr(cfg.Addresses.API)
if err != nil {
return fmt.Errorf("mountHTTPapi: invalid API address: %q (err: %s)", cfg.Addresses.API, err), nil
return fmt.Errorf("serveHTTPApi: invalid API address: %q (err: %s)", cfg.Addresses.API, err), nil
}

apiLis, err := manet.Listen(apiMaddr)
if err != nil {
return fmt.Errorf("mountHTTPapi: manet.Listen(%s) failed: %s", apiMaddr, err), nil
return fmt.Errorf("serveHTTPApi: manet.Listen(%s) failed: %s", apiMaddr, err), nil
}
// we might have listened to /tcp/0 - lets see what we are listing on
apiMaddr = apiLis.Multiaddr()
fmt.Printf("API server listening on %s\n", apiMaddr)

unrestricted, _, err := req.Option(unrestrictedApiAccess).Bool()
if err != nil {
return fmt.Errorf("mountHTTPapi: Option(%s) failed: %s", unrestrictedApiAccess, err), nil
return fmt.Errorf("serveHTTPApi: Option(%s) failed: %s", unrestrictedApiAccess, err), nil
}

apiGw := corehttp.NewGateway(corehttp.GatewayConfig{
Expand Down Expand Up @@ -293,7 +293,7 @@ func mountHTTPapi(req cmds.Request) (error, <-chan error) {

node, err := req.Context().ConstructNode()
if err != nil {
return fmt.Errorf("mountHTTPgw: ConstructNode() failed: %s", err), nil
return fmt.Errorf("serveHTTPGateway: ConstructNode() failed: %s", err), nil
}

errc := make(chan error)
Expand All @@ -303,29 +303,29 @@ func mountHTTPapi(req cmds.Request) (error, <-chan error) {
return nil, errc
}

// mountHTTPgw collects options, creates listener, prints status message and starts serving requests
func mountHTTPgw(req cmds.Request) (error, <-chan error) {
// 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()
if err != nil {
return fmt.Errorf("mountHTTPgw: GetConfig() failed: %s", err), nil
return fmt.Errorf("serveHTTPGateway: GetConfig() failed: %s", err), nil
}

gatewayMaddr, err := ma.NewMultiaddr(cfg.Addresses.Gateway)
if err != nil {
return fmt.Errorf("mountHTTPgw: invalid gateway address: %q (err: %s)", cfg.Addresses.Gateway, err), nil
return fmt.Errorf("serveHTTPGateway: invalid gateway address: %q (err: %s)", cfg.Addresses.Gateway, err), nil
}

writable, writableOptionFound, err := req.Option(writableKwd).Bool()
if err != nil {
return fmt.Errorf("mountHTTPgw: req.Option(%s) failed: %s", writableKwd, err), nil
return fmt.Errorf("serveHTTPGateway: req.Option(%s) failed: %s", writableKwd, err), nil
}
if !writableOptionFound {
writable = cfg.Gateway.Writable
}

gwLis, err := manet.Listen(gatewayMaddr)
if err != nil {
return fmt.Errorf("mountHTTPgw: manet.Listen(%s) failed: %s", gatewayMaddr, err), nil
return fmt.Errorf("serveHTTPGateway: manet.Listen(%s) failed: %s", gatewayMaddr, err), nil
}
// we might have listened to /tcp/0 - lets see what we are listing on
gatewayMaddr = gwLis.Multiaddr()
Expand All @@ -348,7 +348,7 @@ func mountHTTPgw(req cmds.Request) (error, <-chan error) {

node, err := req.Context().ConstructNode()
if err != nil {
return fmt.Errorf("mountHTTPgw: ConstructNode() failed: %s", err), nil
return fmt.Errorf("serveHTTPGateway: ConstructNode() failed: %s", err), nil
}

errc := make(chan error)
Expand Down Expand Up @@ -409,9 +409,9 @@ func merge(cs ...<-chan error) <-chan error {
}
wg.Done()
}
wg.Add(len(cs))
for _, c := range cs {
if c != nil {
wg.Add(1)
go output(c)
}
}
Expand Down

0 comments on commit 4b337bb

Please sign in to comment.