Skip to content

Commit

Permalink
rpc auth: handle some auth errors gracefully
Browse files Browse the repository at this point in the history
particuarly we will ignore authorization errors for some broadcasts and somply
not include those responses in the assembled one.
  • Loading branch information
hsanjuan committed May 9, 2019
1 parent 949e6f2 commit a86c7ca
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions api/ipfsproxy/ipfsproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,10 @@ func (proxy *Server) repoStatHandler(w http.ResponseWriter, r *http.Request) {

for i, err := range errs {
if err != nil {
if rpc.IsAuthorizationError(err) {
logger.Debug(err)
continue
}
logger.Errorf("%s repo/stat errored: %s", peers[i], err)
continue
}
Expand Down
26 changes: 22 additions & 4 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1333,12 +1333,21 @@ func (c *Cluster) Peers(ctx context.Context) []*api.ID {
rpcutil.CopyIDsToIfaces(peers),
)

finalPeers := []*api.ID{}

for i, err := range errs {
if err != nil {
peers[i] = &api.ID{}
peers[i].ID = members[i]
peers[i].Error = err.Error()
if err == nil {
finalPeers = append(finalPeers, peers[i])
continue
}

if rpc.IsAuthorizationError(err) {
continue
}

peers[i] = &api.ID{}
peers[i].ID = members[i]
peers[i].Error = err.Error()
}

return peers
Expand Down Expand Up @@ -1382,6 +1391,11 @@ func (c *Cluster) globalPinInfoCid(ctx context.Context, comp, method string, h c
continue
}

if rpc.IsAuthorizationError(e) {
logger.Debug("rpc auth error:", e)
continue
}

// Deal with error cases (err != nil): wrap errors in PinInfo
logger.Errorf("%s: error in broadcast response from %s: %s ", c.id, members[i], e)
pin.PeerMap[peer.IDB58Encode(members[i])] = &api.PinInfo{
Expand Down Expand Up @@ -1447,6 +1461,10 @@ func (c *Cluster) globalPinInfoSlice(ctx context.Context, comp, method string) (
erroredPeers := make(map[peer.ID]string)
for i, r := range replies {
if e := errs[i]; e != nil { // This error must come from not being able to contact that cluster member
if rpc.IsAuthorizationError(e) {
logger.Debug("rpc auth error", e)
continue
}
logger.Errorf("%s: error in broadcast response from %s: %s ", c.id, members[i], e)
erroredPeers[members[i]] = e.Error()
} else {
Expand Down

0 comments on commit a86c7ca

Please sign in to comment.