Skip to content

Commit

Permalink
handle un-tombstoning
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Oct 2, 2023
1 parent 735db31 commit b60c71e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions bgs/bgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,33 @@ func (bgs *BGS) handleFedEvent(ctx context.Context, host *models.PDS, env *event
return fmt.Errorf("rebase was true in event seq:%d,host:%s", evt.Seq, host.Host)
}

if host.ID != u.PDS {
log.Infow("received event for repo from different pds than expected", "repo", evt.Repo, "expPds", u.PDS, "gotPds", host.Host)
subj, err := bgs.createExternalUser(ctx, evt.Repo)
if err != nil {
return err
}

if subj.PDS != host.ID {
return fmt.Errorf("event from non-authoritative pds")
}
}

if u.Tombstoned {
// we've checked the authority of the users PDS, so reinstate the account
if err := bgs.db.Model(&User{}).Where("id = ?", u.ID).UpdateColumn("tombstoned", false).Error; err != nil {
return fmt.Errorf("failed to un-tombstone a user: %w", err)
}

ai, err := bgs.Index.LookupUser(ctx, u.ID)
if err != nil {
return fmt.Errorf("failed to look up user (tombstone recover): %w", err)
}

// Now a simple re-crawl should suffice to bring the user back online
return bgs.Index.Crawler.AddToCatchupQueue(ctx, host, ai, evt)
}

// skip the fast path for rebases or if the user is already in the slow path
if bgs.Index.Crawler.RepoInSlowPath(ctx, host, u.ID) {
rebasesCounter.WithLabelValues(host.Host).Add(1)
Expand Down Expand Up @@ -1050,6 +1077,7 @@ func (s *BGS) createExternalUser(ctx context.Context, did string) (*models.Actor
return nil, fmt.Errorf("failed to update users pds: %w", err)
}

exu.PDS = peering.ID
}

if exu.Handle.String != handle {
Expand Down

0 comments on commit b60c71e

Please sign in to comment.