Update last contact even if the remote peer is not authorized yet

This commit is contained in:
wpetit 2019-04-07 09:40:21 +02:00
parent 5986d2bb9b
commit 41f3d5c7ac
1 changed files with 10 additions and 2 deletions

View File

@ -61,9 +61,17 @@ func Authenticate(store peering.Store, key *rsa.PublicKey, funcs ...OptionFunc)
clientClaims, err := assertClientToken(serverClaims.PeerID, store, clientToken)
if err != nil {
logger.Printf("[ERROR] %s", err)
if err == peering.ErrPeerNotFound || err == ErrNotPeered {
switch err {
case peering.ErrPeerNotFound:
sendError(w, http.StatusUnauthorized)
} else {
case ErrNotPeered:
if err := store.UpdateLastContact(serverClaims.PeerID, r.RemoteAddr, time.Now()); err != nil {
logger.Printf("[ERROR] %s", err)
sendError(w, http.StatusInternalServerError)
return
}
sendError(w, http.StatusUnauthorized)
default:
sendError(w, http.StatusInternalServerError)
}
return