Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
feat: use different domain when anchor origin is down
Browse files Browse the repository at this point in the history
Signed-off-by: Firas Qutishat <firas.qutishat@securekey.com>
  • Loading branch information
fqutishat committed Aug 9, 2022
1 parent 7c7e258 commit fb0a017
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions component/vdr/orb/vdr.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const (
ipfsPrefix = "ipfs://"
httpsProtocol = "https"
httpProtocol = "http"
retry = 3
)

var logger = log.New("aries-framework-ext/vdr/orb") //nolint: gochecknoglobals
Expand Down Expand Up @@ -648,12 +649,28 @@ func (v *VDR) Update(didDoc *docdid.Doc, opts ...vdrapi.DIDMethodOption) error {
updateOpt = append(updateOpt, updatedAlsoKnownAsOpts...)

updateOpt = append(updateOpt, update.WithSidetreeEndpoint(func() ([]string, error) {
var endpoint *models.Endpoint
endpoint, errGet := v.discoveryService.GetEndpoint(docResolution.DocumentMetadata.Method.AnchorOrigin)
if errGet != nil {
logger.Warnf("failed to get anchor origin %s endpoints will choose random domain: %w",
docResolution.DocumentMetadata.Method.AnchorOrigin, errGet)

for i := 1; i <= retry; i++ {
domain, errChoose := v.selectDomainSvc.Choose(v.domains)
if err != nil {
return nil, errChoose
}

// TODO make sure it's latest anchor origin
endpoint, err = v.discoveryService.GetEndpoint(docResolution.DocumentMetadata.Method.AnchorOrigin)
if err != nil {
return nil, fmt.Errorf("failed to get endpoints: %w", err)
domainEndpoint, errEndpoint := v.discoveryService.GetEndpoint(domain)
if err != nil {
if i == retry {
return nil, fmt.Errorf("failed to get endpoints: %w", errEndpoint)
}

continue
}

return domainEndpoint.OperationEndpoints, nil
}
}

return endpoint.OperationEndpoints, nil
Expand Down

0 comments on commit fb0a017

Please sign in to comment.