Skip to content

Commit

Permalink
chore: check if default relay is active
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Feb 15, 2024
1 parent 952a6c0 commit c9bfcd0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions internal/nostr/nostr.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ func (svc *NostrService) InfoHandler(c echo.Context) error {

relay, isCustomRelay, err := svc.getRelayConnection(c.Request().Context(), requestData.RelayURL)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("error connecting to custom relay: %s", err))
if isCustomRelay {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("error connecting to custom relay: %s", err))
}
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("error connecting to default relay: %s", err))
}
if isCustomRelay {
defer relay.Close()
Expand Down Expand Up @@ -123,7 +126,14 @@ func (svc *NostrService) getRelayConnection(ctx context.Context, customRelayURL
relay, err := nostr.RelayConnect(ctx, customRelayURL)
return relay, true, err // true means custom and the relay should be closed
}
return svc.defaultRelay, false, nil
// check if the default relay is active
if svc.defaultRelay.IsConnected() {
return svc.defaultRelay, false, nil
} else {
logrus.Info("lost connection to default relay, reconnecting...")
relay, err := nostr.RelayConnect(context.Background(), svc.config.DefaultRelayURL)
return relay, false, err
}
}

func (svc *NostrService) processRequest(ctx context.Context, requestData *NIP47Request) (*nostr.Event, int, error) {
Expand Down

0 comments on commit c9bfcd0

Please sign in to comment.