mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-22 02:47:48 +08:00
Merge pull request #4428 from ipfs/feat/namesys-logging
Refine gateway and namesys logging
This commit is contained in:
commit
4d41235598
@ -119,7 +119,6 @@ func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
errmsg = errmsg + "bad request for " + r.URL.Path
|
||||
}
|
||||
fmt.Fprint(w, errmsg)
|
||||
log.Error(errmsg) // TODO(cryptix): log errors until we have a better way to expose these (counter metrics maybe)
|
||||
}
|
||||
|
||||
func (i *gatewayHandler) optionsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
@ -287,14 +286,11 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
|
||||
ixnd, err := dirr.Find(ctx, "index.html")
|
||||
switch {
|
||||
case err == nil:
|
||||
log.Debugf("found index.html link for %s", escapedURLPath)
|
||||
|
||||
dirwithoutslash := urlPath[len(urlPath)-1] != '/'
|
||||
goget := r.URL.Query().Get("go-get") == "1"
|
||||
if dirwithoutslash && !goget {
|
||||
// See comment above where originalUrlPath is declared.
|
||||
http.Redirect(w, r, originalUrlPath+"/", 302)
|
||||
log.Debugf("redirect to %s", originalUrlPath+"/")
|
||||
return
|
||||
}
|
||||
|
||||
@ -510,7 +506,6 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
default:
|
||||
log.Warningf("putHandler: unhandled resolve error %T", ev)
|
||||
webError(w, "could not resolve root DAG", ev, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@ -618,8 +613,10 @@ func webError(w http.ResponseWriter, message string, err error, defaultCode int)
|
||||
func webErrorWithCode(w http.ResponseWriter, message string, err error, code int) {
|
||||
w.WriteHeader(code)
|
||||
|
||||
log.Errorf("%s: %s", message, err) // TODO(cryptix): log until we have a better way to expose these (counter metrics maybe)
|
||||
fmt.Fprintf(w, "%s: %s\n", message, err)
|
||||
if code >= 500 {
|
||||
log.Warningf("server error: %s: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// return a 500 error and log
|
||||
|
||||
@ -18,10 +18,9 @@ func resolve(ctx context.Context, r resolver, name string, depth int, prefixes .
|
||||
for {
|
||||
p, err := r.resolveOnce(ctx, name)
|
||||
if err != nil {
|
||||
log.Warningf("Could not resolve %s", name)
|
||||
return "", err
|
||||
}
|
||||
log.Debugf("Resolved %s to %s", name, p.String())
|
||||
log.Debugf("resolved %s to %s", name, p.String())
|
||||
|
||||
if strings.HasPrefix(p.String(), "/ipfs/") {
|
||||
// we've bottomed out with an IPFS path
|
||||
|
||||
@ -55,7 +55,7 @@ func (r *DNSResolver) resolveOnce(ctx context.Context, name string) (path.Path,
|
||||
if !isd.IsDomain(domain) {
|
||||
return "", errors.New("not a valid domain name")
|
||||
}
|
||||
log.Infof("DNSResolver resolving %s", domain)
|
||||
log.Debugf("DNSResolver resolving %s", domain)
|
||||
|
||||
rootChan := make(chan lookupRes, 1)
|
||||
go workDomain(r, domain, rootChan)
|
||||
|
||||
@ -91,7 +91,7 @@ func (ns *mpns) resolveOnce(ctx context.Context, name string) (path.Path, error)
|
||||
}
|
||||
segments := strings.SplitN(name, "/", 4)
|
||||
if len(segments) < 3 || segments[0] != "" {
|
||||
log.Warningf("Invalid name syntax for %s", name)
|
||||
log.Debugf("invalid name syntax for %s", name)
|
||||
return "", ErrResolveFailed
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ func (ns *mpns) resolveOnce(ctx context.Context, name string) (path.Path, error)
|
||||
return "", ErrResolveFailed
|
||||
}
|
||||
|
||||
log.Warningf("No resolver found for %s", name)
|
||||
log.Debugf("no resolver found for %s", name)
|
||||
return "", ErrResolveFailed
|
||||
}
|
||||
|
||||
|
||||
@ -117,7 +117,7 @@ func (r *routingResolver) ResolveN(ctx context.Context, name string, depth int)
|
||||
// resolveOnce implements resolver. Uses the IPFS routing system to
|
||||
// resolve SFS-like names.
|
||||
func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Path, error) {
|
||||
log.Debugf("RoutingResolve: '%s'", name)
|
||||
log.Debugf("RoutingResolver resolving %s", name)
|
||||
cached, ok := r.cacheGet(name)
|
||||
if ok {
|
||||
return cached, nil
|
||||
@ -127,7 +127,7 @@ func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Pa
|
||||
hash, err := mh.FromB58String(name)
|
||||
if err != nil {
|
||||
// name should be a multihash. if it isn't, error out here.
|
||||
log.Warningf("RoutingResolve: bad input hash: [%s]\n", name)
|
||||
log.Debugf("RoutingResolver: bad input hash: [%s]\n", name)
|
||||
return "", err
|
||||
}
|
||||
|
||||
@ -143,7 +143,7 @@ func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Pa
|
||||
ipnsKey := string(h)
|
||||
val, err := r.routing.GetValue(ctx, ipnsKey)
|
||||
if err != nil {
|
||||
log.Warning("RoutingResolve get failed.")
|
||||
log.Debugf("RoutingResolver: dht get failed: %s", err)
|
||||
resp <- err
|
||||
return
|
||||
}
|
||||
@ -179,7 +179,7 @@ func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Pa
|
||||
|
||||
// check sig with pk
|
||||
if ok, err := pubkey.Verify(ipnsEntryDataForSig(entry), entry.GetSignature()); err != nil || !ok {
|
||||
return "", fmt.Errorf("Invalid value. Not signed by PrivateKey corresponding to %v", pubkey)
|
||||
return "", fmt.Errorf("ipns entry for %s has invalid signature", h)
|
||||
}
|
||||
|
||||
// ok sig checks out. this is a valid name.
|
||||
@ -197,7 +197,7 @@ func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Pa
|
||||
return p, nil
|
||||
} else {
|
||||
// Its an old style multihash record
|
||||
log.Warning("Detected old style multihash record")
|
||||
log.Debugf("encountered CIDv0 ipns entry: %s", h)
|
||||
p := path.FromCid(cid.NewCidV0(valh))
|
||||
r.cacheSet(name, p, entry)
|
||||
return p, nil
|
||||
|
||||
Loading…
Reference in New Issue
Block a user