Skip to content

Commit

Permalink
Deliverキューに宛先がSharedInboxかどうかのフラグを追加 ( #10298 関係 ) (#10317)
Browse files Browse the repository at this point in the history
* enhance(backend): 配送先が410 Goneで応答してきた場合配送停止するように

* Update CHANGELOG.md

* Deliverキューのデータに宛先がSharedInboxかどうかのフラグを追加

* Fix lint

* Mapを使用するように

* Fix typo
  • Loading branch information
CyberRex0 authored Mar 14, 2023
1 parent 3cb669a commit c05c504
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 27 deletions.
3 changes: 2 additions & 1 deletion packages/backend/src/core/QueueService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class QueueService {
) {}

@bindThis
public deliver(user: ThinUser, content: IActivity | null, to: string | null) {
public deliver(user: ThinUser, content: IActivity | null, to: string | null, isSharedInbox: boolean) {
if (content == null) return null;
if (to == null) return null;

Expand All @@ -36,6 +36,7 @@ export class QueueService {
},
content,
to,
isSharedInbox,
};

return this.deliverQueue.add(data, {
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/src/core/RelayService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class RelayService {
const relayActor = await this.getRelayActor();
const follow = await this.apRendererService.renderFollowRelay(relay, relayActor);
const activity = this.apRendererService.addContext(follow);
this.queueService.deliver(relayActor, activity, relay.inbox);
this.queueService.deliver(relayActor, activity, relay.inbox, false);

return relay;
}
Expand All @@ -76,7 +76,7 @@ export class RelayService {
const follow = this.apRendererService.renderFollowRelay(relay, relayActor);
const undo = this.apRendererService.renderUndo(follow, relayActor);
const activity = this.apRendererService.addContext(undo);
this.queueService.deliver(relayActor, activity, relay.inbox);
this.queueService.deliver(relayActor, activity, relay.inbox, false);

await this.relaysRepository.delete(relay.id);
}
Expand Down Expand Up @@ -120,7 +120,7 @@ export class RelayService {
const signed = await this.apRendererService.attachLdSignature(copy, user);

for (const relay of relays) {
this.queueService.deliver(user, signed, relay.inbox);
this.queueService.deliver(user, signed, relay.inbox, false);
}
}
}
12 changes: 6 additions & 6 deletions packages/backend/src/core/UserBlockingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class UserBlockingService implements OnApplicationShutdown {

if (this.userEntityService.isLocalUser(blocker) && this.userEntityService.isRemoteUser(blockee)) {
const content = this.apRendererService.addContext(this.apRendererService.renderBlock(blocking));
this.queueService.deliver(blocker, content, blockee.inbox);
this.queueService.deliver(blocker, content, blockee.inbox, false);
}
}

Expand Down Expand Up @@ -163,13 +163,13 @@ export class UserBlockingService implements OnApplicationShutdown {
// リモートにフォローリクエストをしていたらUndoFollow送信
if (this.userEntityService.isLocalUser(follower) && this.userEntityService.isRemoteUser(followee)) {
const content = this.apRendererService.addContext(this.apRendererService.renderUndo(this.apRendererService.renderFollow(follower, followee), follower));
this.queueService.deliver(follower, content, followee.inbox);
this.queueService.deliver(follower, content, followee.inbox, false);
}

// リモートからフォローリクエストを受けていたらReject送信
if (this.userEntityService.isRemoteUser(follower) && this.userEntityService.isLocalUser(followee)) {
const content = this.apRendererService.addContext(this.apRendererService.renderReject(this.apRendererService.renderFollow(follower, followee, request.requestId!), followee));
this.queueService.deliver(followee, content, follower.inbox);
this.queueService.deliver(followee, content, follower.inbox, false);
}
}

Expand Down Expand Up @@ -211,13 +211,13 @@ export class UserBlockingService implements OnApplicationShutdown {
// リモートにフォローをしていたらUndoFollow送信
if (this.userEntityService.isLocalUser(follower) && this.userEntityService.isRemoteUser(followee)) {
const content = this.apRendererService.addContext(this.apRendererService.renderUndo(this.apRendererService.renderFollow(follower, followee), follower));
this.queueService.deliver(follower, content, followee.inbox);
this.queueService.deliver(follower, content, followee.inbox, false);
}

// リモートからフォローをされていたらRejectFollow送信
if (this.userEntityService.isLocalUser(followee) && this.userEntityService.isRemoteUser(follower)) {
const content = this.apRendererService.addContext(this.apRendererService.renderReject(this.apRendererService.renderFollow(follower, followee), followee));
this.queueService.deliver(followee, content, follower.inbox);
this.queueService.deliver(followee, content, follower.inbox, false);
}
}

Expand Down Expand Up @@ -262,7 +262,7 @@ export class UserBlockingService implements OnApplicationShutdown {
// deliver if remote bloking
if (this.userEntityService.isLocalUser(blocker) && this.userEntityService.isRemoteUser(blockee)) {
const content = this.apRendererService.addContext(this.apRendererService.renderUndo(this.apRendererService.renderBlock(blocking), blocker));
this.queueService.deliver(blocker, content, blockee.inbox);
this.queueService.deliver(blocker, content, blockee.inbox, false);
}
}

Expand Down
16 changes: 8 additions & 8 deletions packages/backend/src/core/UserFollowingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class UserFollowingService {
if (this.userEntityService.isRemoteUser(follower) && this.userEntityService.isLocalUser(followee) && blocked) {
// リモートフォローを受けてブロックしていた場合は、エラーにするのではなくRejectを送り返しておしまい。
const content = this.apRendererService.addContext(this.apRendererService.renderReject(this.apRendererService.renderFollow(follower, followee, requestId), followee));
this.queueService.deliver(followee, content, follower.inbox);
this.queueService.deliver(followee, content, follower.inbox, false);
return;
} else if (this.userEntityService.isRemoteUser(follower) && this.userEntityService.isLocalUser(followee) && blocking) {
// リモートフォローを受けてブロックされているはずの場合だったら、ブロック解除しておく。
Expand Down Expand Up @@ -131,7 +131,7 @@ export class UserFollowingService {

if (this.userEntityService.isRemoteUser(follower) && this.userEntityService.isLocalUser(followee)) {
const content = this.apRendererService.addContext(this.apRendererService.renderAccept(this.apRendererService.renderFollow(follower, followee, requestId), followee));
this.queueService.deliver(followee, content, follower.inbox);
this.queueService.deliver(followee, content, follower.inbox, false);
}
}

Expand Down Expand Up @@ -294,13 +294,13 @@ export class UserFollowingService {

if (this.userEntityService.isLocalUser(follower) && this.userEntityService.isRemoteUser(followee)) {
const content = this.apRendererService.addContext(this.apRendererService.renderUndo(this.apRendererService.renderFollow(follower, followee), follower));
this.queueService.deliver(follower, content, followee.inbox);
this.queueService.deliver(follower, content, followee.inbox, false);
}

if (this.userEntityService.isLocalUser(followee) && this.userEntityService.isRemoteUser(follower)) {
// local user has null host
const content = this.apRendererService.addContext(this.apRendererService.renderReject(this.apRendererService.renderFollow(follower, followee), followee));
this.queueService.deliver(followee, content, follower.inbox);
this.queueService.deliver(followee, content, follower.inbox, false);
}
}

Expand Down Expand Up @@ -389,7 +389,7 @@ export class UserFollowingService {

if (this.userEntityService.isLocalUser(follower) && this.userEntityService.isRemoteUser(followee)) {
const content = this.apRendererService.addContext(this.apRendererService.renderFollow(follower, followee));
this.queueService.deliver(follower, content, followee.inbox);
this.queueService.deliver(follower, content, followee.inbox, false);
}
}

Expand All @@ -406,7 +406,7 @@ export class UserFollowingService {
const content = this.apRendererService.addContext(this.apRendererService.renderUndo(this.apRendererService.renderFollow(follower, followee), follower));

if (this.userEntityService.isLocalUser(follower)) { // 本来このチェックは不要だけどTSに怒られるので
this.queueService.deliver(follower, content, followee.inbox);
this.queueService.deliver(follower, content, followee.inbox, false);
}
}

Expand Down Expand Up @@ -449,7 +449,7 @@ export class UserFollowingService {

if (this.userEntityService.isRemoteUser(follower) && this.userEntityService.isLocalUser(followee)) {
const content = this.apRendererService.addContext(this.apRendererService.renderAccept(this.apRendererService.renderFollow(follower, followee, request.requestId!), followee));
this.queueService.deliver(followee, content, follower.inbox);
this.queueService.deliver(followee, content, follower.inbox, false);
}

this.userEntityService.pack(followee.id, followee, {
Expand Down Expand Up @@ -557,7 +557,7 @@ export class UserFollowingService {
});

const content = this.apRendererService.addContext(this.apRendererService.renderReject(this.apRendererService.renderFollow(follower, followee, request?.requestId ?? undefined), followee));
this.queueService.deliver(followee, content, follower.inbox);
this.queueService.deliver(followee, content, follower.inbox, false);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/core/UserSuspendService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class UserSuspendService {
}

for (const inbox of queue) {
this.queueService.deliver(user, content, inbox);
this.queueService.deliver(user, content, inbox, true);
}
}
}
Expand Down Expand Up @@ -84,7 +84,7 @@ export class UserSuspendService {
}

for (const inbox of queue) {
this.queueService.deliver(user as any, content, inbox);
this.queueService.deliver(user as any, content, inbox, true);
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions packages/backend/src/core/activitypub/ApDeliverManagerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ class DeliverManager {
public async execute() {
if (!this.userEntityService.isLocalUser(this.actor)) return;

const inboxes = new Set<string>();
// The value flags whether it is shared or not.
const inboxes = new Map<string, boolean>();

/*
build inbox list
Expand Down Expand Up @@ -185,7 +186,7 @@ class DeliverManager {

for (const following of followers) {
const inbox = following.followerSharedInbox ?? following.followerInbox;
inboxes.add(inbox);
inboxes.set(inbox, following.followerSharedInbox === null);
}
}

Expand All @@ -197,11 +198,12 @@ class DeliverManager {
// check that they actually have an inbox
&& recipe.to.inbox != null,
)
.forEach(recipe => inboxes.add(recipe.to.inbox!));
.forEach(recipe => inboxes.set(recipe.to.inbox!, false));

// deliver
for (const inbox of inboxes) {
this.queueService.deliver(this.actor, this.activity, inbox);
// inbox[0]: inbox, inbox[1]: whether it is sharedInbox
this.queueService.deliver(this.actor, this.activity, inbox[0], inbox[1]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class DeliverProcessorService {
// 4xx
if (res.isClientError) {
// 相手が閉鎖していることを明示しているため、配送停止する
if (res.statusCode === 410) {
if (job.data.isSharedInbox && res.statusCode === 410) {
this.federatedInstanceService.fetch(host).then(i => {
this.instancesRepository.update(i.id, {
isSuspended: true,
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/queue/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export type DeliverJobData = {
content: unknown;
/** inbox URL to deliver */
to: string;
/** whether it is sharedInbox */
isSharedInbox: boolean;
};

export type InboxJobData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
const actor = await this.instanceActorService.getInstanceActor();
const targetUser = await this.usersRepository.findOneByOrFail({ id: report.targetUserId });

this.queueService.deliver(actor, this.apRendererService.addContext(this.apRendererService.renderFlag(actor, targetUser.uri!, report.comment)), targetUser.inbox);
this.queueService.deliver(actor, this.apRendererService.addContext(this.apRendererService.renderFlag(actor, targetUser.uri!, report.comment)), targetUser.inbox, false);
}

await this.abuseUserReportsRepository.update(report.id, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
if (note.userHost != null) {
const pollOwner = await this.usersRepository.findOneByOrFail({ id: note.userId }) as RemoteUser;

this.queueService.deliver(me, this.apRendererService.addContext(await this.apRendererService.renderVote(me, vote, note, poll, pollOwner)), pollOwner.inbox);
this.queueService.deliver(me, this.apRendererService.addContext(await this.apRendererService.renderVote(me, vote, note, poll, pollOwner)), pollOwner.inbox, false);
}

// リモートフォロワーにUpdate配信
Expand Down

0 comments on commit c05c504

Please sign in to comment.