APの統計とログの修正と強化 (#5585)

* Fix #5580

* Improve AP logging
This commit is contained in:
MeiMei
2019-11-07 00:02:18 +09:00
committed by syuilo
parent 8bdd4fd061
commit 873444c3c6
4 changed files with 45 additions and 41 deletions

View File

@@ -6,15 +6,10 @@ import * as cache from 'lookup-dns-cache';
import config from '../../config';
import { ILocalUser } from '../../models/entities/user';
import { publishApLogStream } from '../../services/stream';
import { apLogger } from './logger';
import { UserKeypairs, Instances } from '../../models';
import { fetchMeta } from '../../misc/fetch-meta';
import { toPuny } from '../../misc/convert-host';
import { UserKeypairs } from '../../models';
import { ensure } from '../../prelude/ensure';
import * as httpsProxyAgent from 'https-proxy-agent';
export const logger = apLogger.createSubLogger('deliver');
const agent = config.proxy
? new httpsProxyAgent(config.proxy)
: new https.Agent({
@@ -24,28 +19,7 @@ const agent = config.proxy
export default async (user: ILocalUser, url: string, object: any) => {
const timeout = 10 * 1000;
const { protocol, host, hostname, port, pathname, search } = new URL(url);
// ブロックしてたら中断
const meta = await fetchMeta();
if (meta.blockedHosts.includes(toPuny(host))) {
logger.info(`skip (blocked) ${url}`);
return;
}
// closedなら中断
const closedHosts = await Instances.find({
where: {
isMarkedAsClosed: true
},
cache: 60 * 1000
});
if (closedHosts.map(x => x.host).includes(toPuny(host))) {
logger.info(`skip (closed) ${url}`);
return;
}
logger.info(`--> ${url}`);
const { protocol, hostname, port, pathname, search } = new URL(url);
const data = JSON.stringify(object);
@@ -73,10 +47,8 @@ export default async (user: ILocalUser, url: string, object: any) => {
}
}, res => {
if (res.statusCode! >= 400) {
logger.warn(`${url} --> ${res.statusCode}`);
reject(res);
} else {
logger.succ(`${url} --> ${res.statusCode}`);
resolve();
}
});