Skip to content

Commit

Permalink
corrected the failed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Jul 19, 2023
1 parent 538cac8 commit 8522e48
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions exchange/fx_exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ func (e *FxExchange) GetAuthorizedPeers(ctx context.Context) ([]peer.ID, error)
for peerId := range e.authorizedPeers {
peerList = append(peerList, peerId)
}
if e.options == nil {
return nil, fmt.Errorf("options is nil")
}
e.options.authorizedPeers = peerList
return peerList, nil
}
Expand Down Expand Up @@ -256,6 +259,7 @@ func (e *FxExchange) handlePush(from peer.ID, w http.ResponseWriter, r *http.Req
}

func (e *FxExchange) handleAuthorization(from peer.ID, w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
log := log.With("action", actionAuth, "from", from)
defer r.Body.Close()
b, err := io.ReadAll(r.Body)
Expand All @@ -277,20 +281,27 @@ func (e *FxExchange) handleAuthorization(from peer.ID, w http.ResponseWriter, r
delete(e.authorizedPeers, a.Subject)
}
e.authorizedPeersLock.Unlock()
if err := e.updateAuthorizePeers(); err != nil {
if err := e.updateAuthorizePeers(ctx); err != nil {
log.Errorw("failed to update authorized peers", "err", err)
http.Error(w, "", http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
}

func (e *FxExchange) updateAuthorizePeers() error {
func (e *FxExchange) updateAuthorizePeers(ctx context.Context) error {
var peerList []peer.ID
ctx := context.TODO()
peerList, _ = e.GetAuthorizedPeers(ctx)
e.options.authorizedPeers = peerList
if e.options == nil {
return fmt.Errorf("options is nil")
}
log.Infow("update authorized peers", "peers", e.options.authorizedPeers)
if e.updateConfig == nil {
return nil
}
err := e.updateConfig(e.options.authorizedPeers)
log.Infow("update authorized peers", "err", err)
if err != nil {
return err
}
Expand All @@ -309,7 +320,7 @@ func (e *FxExchange) SetAuth(ctx context.Context, on peer.ID, subject peer.ID, a
e.authorizedPeersLock.Unlock()

// Save the updated authorized peers to config file
err := e.updateAuthorizePeers()
err := e.updateAuthorizePeers(ctx)
if err != nil {
return err
}
Expand Down

0 comments on commit 8522e48

Please sign in to comment.