···5555// Attempts creation of a new account associated with the given host, presumably because the account was discovered on that host's stream.
5656//
5757// If the account's identity doesn't match the host, this will fail. We only create accounts associated with hosts we already know of, not remote hosts (aka, no spidering).
5858-func (r *Relay) CreateHostAccount(ctx context.Context, did syntax.DID, hostID uint64, hostname string) (*models.Account, error) {
5858+func (r *Relay) CreateAccountHost(ctx context.Context, did syntax.DID, hostID uint64, hostname string) (*models.Account, error) {
5959 // NOTE: this method doesn't use locking. the database UNIQUE constraint should prevent duplicate account creation.
6060 logger := r.Logger.With("did", did, "hostname", hostname)
61616262- //newUsersDiscovered.Inc()
6262+ newUsersDiscovered.Inc()
6363 //start := time.Now()
64646565 ident, err := r.Dir.LookupDID(ctx, did)
···8383 }
8484 }
85858686- // TODO: fetch the full host, apply throttling or rate-limits?
8686+ // TODO: could be verifying upstream status here (using r.HostChecker); not particularly urgent because triggering event is already coming from the relevant host
87878888- // TODO: could be verifying upstream status here (using r.HostChecker)
8989- // XXX: limits/throttling; reach in to Slurper?
9088 acc := models.Account{
9189 DID: did.String(),
9290 HostID: hostID,
9391 Status: models.AccountStatusActive,
9492 UpstreamStatus: models.AccountStatusActive,
9393+ }
9494+9595+ host, err := r.GetHostByID(ctx, hostID)
9696+ if err != nil {
9797+ return nil, err
9898+ }
9999+ if host.AccountCount >= host.AccountLimit {
100100+ acc.Status = models.AccountStatusHostThrottled
95101 }
9610297103 // create Account row and increment host count in the same transaction
···147153 }
148154 }
149155150150- // TODO: could check upstream status here (using r.HostChecker)
151151- // TODO: for example, a moved account might go from takendown to active
152152- // XXX: limits/throttling; read in to Slurper?
156156+ // TODO: check new upstream status here (using r.HostChecker). In particular, a moved account might go from takendown to active
153157154158 // create Account row and increment host count in the same transaction
155159 err = r.db.Transaction(func(tx *gorm.DB) error {
+1-1
cmd/relay/relay/domain_ban.go
···1111 "gorm.io/gorm"
1212)
13131414-// XXX: tests for domain ban logic (which hit an actual database)
1414+// TODO: tests for domain ban logic (which hit an actual database)
15151616// DomainIsBanned checks if the given hostname is banned. It checks all domain suffixs.
1717//
+7
cmd/relay/relay/host.go
···69697070func (r *Relay) UpdateHostAccountLimit(ctx context.Context, hostID uint64, accountLimit int64) error {
71717272+ if accountLimit < 0 {
7373+ return fmt.Errorf("negative account limit")
7474+ }
7575+7276 host, err := r.GetHostByID(ctx, hostID)
7377 if err != nil {
7478 return err
7579 }
76808181+ // TODO: manage accounts marked as "host-throttled" when host-level account limits change (all in a transaction)
8282+ // If limit increased: potentially mark some "host-throttled" accounts as "active" (ordered by UID ascending)
8383+ // If limit decreased: potentially mark some "active" accounts as "host-throttled" (ordered by UID descending?)
7784 if err := r.db.Model(models.Host{}).Where("id = ?", hostID).Update("account_limit", accountLimit).Error; err != nil {
7885 return err
7986 }
+4-4
cmd/relay/relay/ingest.go
···7575 return nil, nil, fmt.Errorf("fetching account: %w", err)
7676 }
77777878- acc, err = r.CreateHostAccount(ctx, did, hostID, hostname)
7878+ acc, err = r.CreateAccountHost(ctx, did, hostID, hostname)
7979 if err != nil {
8080 return nil, nil, err
8181 }
···83838484 if acc == nil {
8585 // TODO: this is defensive and could be removed
8686- panic(ErrAccountNotFound)
8686+ return nil, nil, ErrAccountNotFound
8787 }
88888989 // verify that the account is on the subscribed host (or update if it should be)
···118118 }
119119120120 if ident == nil {
121121- // XXX: what to do if identity resolution fails
121121+ // TODO: what to do if identity resolution fails
122122 }
123123124124 prevRepo, err := r.GetAccountRepo(ctx, acc.UID)
···168168 }
169169170170 if ident == nil {
171171- // XXX: what to do if identity resolution fails
171171+ // TODO: what to do if identity resolution fails
172172 }
173173174174 newRepo, err := r.VerifyRepoSync(ctx, evt, ident, hostname)