From 5f00d4980bdc55bce8d23e38392b345d525dbf4a Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Thu, 23 Jun 2022 16:54:54 +0200 Subject: [feature] Implement `/api/v1/instance/peers` endpoint (#660) * add missing license headers * start adding instance peers get * rename domainblock.go * embed domain in domainblock so it can be reused * update swagger docs * add test instances to db * update tests * add/update instancepeersget * update domain model * add getinstancepeers to db * instance-expose-peers, instance-expose-suspended * add auth checks for both current filters * attach endpoint to router * include public comment * obfuscate domain if required * go mod tidy * update swagger docs * remove unnecessary comment * return 'flat' peerlist if no query params provided --- internal/db/bundb/instance.go | 19 +++++++++++++++++++ internal/db/instance.go | 3 +++ 2 files changed, 22 insertions(+) (limited to 'internal/db') diff --git a/internal/db/bundb/instance.go b/internal/db/bundb/instance.go index d16fac90b..c8a9c5776 100644 --- a/internal/db/bundb/instance.go +++ b/internal/db/bundb/instance.go @@ -98,6 +98,25 @@ func (i *instanceDB) CountInstanceDomains(ctx context.Context, domain string) (i return count, nil } +func (i *instanceDB) GetInstancePeers(ctx context.Context, includeSuspended bool) ([]*gtsmodel.Instance, db.Error) { + instances := []*gtsmodel.Instance{} + + q := i.conn. + NewSelect(). + Model(&instances). + Where("domain != ?", config.GetHost()) + + if !includeSuspended { + q = q.Where("? IS NULL", bun.Ident("suspended_at")) + } + + if err := q.Scan(ctx); err != nil { + return nil, i.conn.ProcessError(err) + } + + return instances, nil +} + func (i *instanceDB) GetInstanceAccounts(ctx context.Context, domain string, maxID string, limit int) ([]*gtsmodel.Account, db.Error) { logrus.Debug("GetAccountsForInstance") diff --git a/internal/db/instance.go b/internal/db/instance.go index 45ff7d7b4..9e69d1b9b 100644 --- a/internal/db/instance.go +++ b/internal/db/instance.go @@ -37,4 +37,7 @@ type Instance interface { // GetInstanceAccounts returns a slice of accounts from the given instance, arranged by ID. GetInstanceAccounts(ctx context.Context, domain string, maxID string, limit int) ([]*gtsmodel.Account, Error) + + // GetInstancePeers returns a slice of instances that the host instance knows about. + GetInstancePeers(ctx context.Context, includeSuspended bool) ([]*gtsmodel.Instance, Error) } -- cgit v1.2.3