diff options
-rw-r--r-- | server/controllers/api/remote/videos.ts | 9 | ||||
-rw-r--r-- | server/controllers/client.ts | 7 | ||||
-rw-r--r-- | server/helpers/peertube-crypto.ts | 13 | ||||
-rw-r--r-- | server/helpers/requests.ts | 36 | ||||
-rw-r--r-- | server/initializers/constants.ts | 7 | ||||
-rw-r--r-- | server/initializers/migrator.ts | 4 | ||||
-rw-r--r-- | server/lib/friends.ts | 6 | ||||
-rw-r--r-- | server/lib/request/abstract-request-scheduler.ts | 1 | ||||
-rw-r--r-- | server/lib/request/request-scheduler.ts | 9 | ||||
-rw-r--r-- | server/middlewares/secure.ts | 2 |
10 files changed, 40 insertions, 54 deletions
diff --git a/server/controllers/api/remote/videos.ts b/server/controllers/api/remote/videos.ts index ebe4eca36..eb033637e 100644 --- a/server/controllers/api/remote/videos.ts +++ b/server/controllers/api/remote/videos.ts | |||
@@ -64,8 +64,7 @@ function remoteVideos (req: express.Request, res: express.Response, next: expres | |||
64 | const fromPod = res.locals.secure.pod | 64 | const fromPod = res.locals.secure.pod |
65 | 65 | ||
66 | // We need to process in the same order to keep consistency | 66 | // We need to process in the same order to keep consistency |
67 | // TODO: optimization | 67 | Promise.each(requests, (request: any) => { |
68 | Promise.mapSeries(requests, (request: any) => { | ||
69 | const data = request.data | 68 | const data = request.data |
70 | 69 | ||
71 | // Get the function we need to call in order to process the request | 70 | // Get the function we need to call in order to process the request |
@@ -79,7 +78,7 @@ function remoteVideos (req: express.Request, res: express.Response, next: expres | |||
79 | }) | 78 | }) |
80 | .catch(err => logger.error('Error managing remote videos.', { error: err })) | 79 | .catch(err => logger.error('Error managing remote videos.', { error: err })) |
81 | 80 | ||
82 | // We don't need to keep the other pod waiting | 81 | // Don't block the other pod |
83 | return res.type('json').status(204).end() | 82 | return res.type('json').status(204).end() |
84 | } | 83 | } |
85 | 84 | ||
@@ -87,7 +86,7 @@ function remoteVideosQadu (req: express.Request, res: express.Response, next: ex | |||
87 | const requests = req.body.data | 86 | const requests = req.body.data |
88 | const fromPod = res.locals.secure.pod | 87 | const fromPod = res.locals.secure.pod |
89 | 88 | ||
90 | Promise.mapSeries(requests, (request: any) => { | 89 | Promise.each(requests, (request: any) => { |
91 | const videoData = request.data | 90 | const videoData = request.data |
92 | 91 | ||
93 | return quickAndDirtyUpdateVideoRetryWrapper(videoData, fromPod) | 92 | return quickAndDirtyUpdateVideoRetryWrapper(videoData, fromPod) |
@@ -101,7 +100,7 @@ function remoteVideosEvents (req: express.Request, res: express.Response, next: | |||
101 | const requests = req.body.data | 100 | const requests = req.body.data |
102 | const fromPod = res.locals.secure.pod | 101 | const fromPod = res.locals.secure.pod |
103 | 102 | ||
104 | Promise.mapSeries(requests, (request: any) => { | 103 | Promise.each(requests, (request: any) => { |
105 | const eventData = request.data | 104 | const eventData = request.data |
106 | 105 | ||
107 | return processVideosEventsRetryWrapper(eventData, fromPod) | 106 | return processVideosEventsRetryWrapper(eventData, fromPod) |
diff --git a/server/controllers/client.ts b/server/controllers/client.ts index e4d69eae7..d42e8396d 100644 --- a/server/controllers/client.ts +++ b/server/controllers/client.ts | |||
@@ -8,15 +8,14 @@ import { | |||
8 | CONFIG, | 8 | CONFIG, |
9 | REMOTE_SCHEME, | 9 | REMOTE_SCHEME, |
10 | STATIC_PATHS, | 10 | STATIC_PATHS, |
11 | STATIC_MAX_AGE | 11 | STATIC_MAX_AGE, |
12 | OPENGRAPH_COMMENT | ||
12 | } from '../initializers' | 13 | } from '../initializers' |
13 | import { root, readFileBufferPromise } from '../helpers' | 14 | import { root, readFileBufferPromise } from '../helpers' |
14 | import { VideoInstance } from '../models' | 15 | import { VideoInstance } from '../models' |
15 | 16 | ||
16 | const clientsRouter = express.Router() | 17 | const clientsRouter = express.Router() |
17 | 18 | ||
18 | // TODO: move to constants | ||
19 | const opengraphComment = '<!-- opengraph tags -->' | ||
20 | const distPath = join(root(), 'client', 'dist') | 19 | const distPath = join(root(), 'client', 'dist') |
21 | const embedPath = join(distPath, 'standalone', 'videos', 'embed.html') | 20 | const embedPath = join(distPath, 'standalone', 'videos', 'embed.html') |
22 | const indexPath = join(distPath, 'index.html') | 21 | const indexPath = join(distPath, 'index.html') |
@@ -85,7 +84,7 @@ function addOpenGraphTags (htmlStringPage: string, video: VideoInstance) { | |||
85 | tagsString += '<meta property="' + tagName + '" content="' + tagValue + '" />' | 84 | tagsString += '<meta property="' + tagName + '" content="' + tagValue + '" />' |
86 | }) | 85 | }) |
87 | 86 | ||
88 | return htmlStringPage.replace(opengraphComment, tagsString) | 87 | return htmlStringPage.replace(OPENGRAPH_COMMENT, tagsString) |
89 | } | 88 | } |
90 | 89 | ||
91 | function generateWatchHtmlPage (req: express.Request, res: express.Response, next: express.NextFunction) { | 90 | function generateWatchHtmlPage (req: express.Request, res: express.Response, next: express.NextFunction) { |
diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index 8e8001cd6..0c73e8539 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import * as crypto from 'crypto' | 1 | import * as crypto from 'crypto' |
2 | import * as fs from 'fs' | 2 | import * as Promise from 'bluebird' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | 4 | ||
5 | import { | 5 | import { |
@@ -52,18 +52,15 @@ function sign (data: string|Object) { | |||
52 | dataString = JSON.stringify(data) | 52 | dataString = JSON.stringify(data) |
53 | } catch (err) { | 53 | } catch (err) { |
54 | logger.error('Cannot sign data.', { error: err }) | 54 | logger.error('Cannot sign data.', { error: err }) |
55 | return '' | 55 | return Promise.resolve('') |
56 | } | 56 | } |
57 | } | 57 | } |
58 | 58 | ||
59 | sign.update(dataString, 'utf8') | 59 | sign.update(dataString, 'utf8') |
60 | 60 | ||
61 | // TODO: make async | 61 | return getMyPrivateCert().then(myKey => { |
62 | const certPath = join(CONFIG.STORAGE.CERT_DIR, PRIVATE_CERT_NAME) | 62 | return sign.sign(myKey, SIGNATURE_ENCODING) |
63 | const myKey = fs.readFileSync(certPath) | 63 | }) |
64 | const signature = sign.sign(myKey.toString(), SIGNATURE_ENCODING) | ||
65 | |||
66 | return signature | ||
67 | } | 64 | } |
68 | 65 | ||
69 | function comparePassword (plainPassword: string, hashPassword: string) { | 66 | function comparePassword (plainPassword: string, hashPassword: string) { |
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index b31074373..183f6df0d 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts | |||
@@ -33,7 +33,6 @@ type MakeSecureRequestParams = { | |||
33 | method: 'GET'|'POST' | 33 | method: 'GET'|'POST' |
34 | toPod: PodInstance | 34 | toPod: PodInstance |
35 | path: string | 35 | path: string |
36 | sign: boolean | ||
37 | data?: Object | 36 | data?: Object |
38 | } | 37 | } |
39 | function makeSecureRequest (params: MakeSecureRequestParams) { | 38 | function makeSecureRequest (params: MakeSecureRequestParams) { |
@@ -47,31 +46,30 @@ function makeSecureRequest (params: MakeSecureRequestParams) { | |||
47 | return rej(new Error('Cannot make a secure request with a non POST method.')) | 46 | return rej(new Error('Cannot make a secure request with a non POST method.')) |
48 | } | 47 | } |
49 | 48 | ||
50 | // Add signature if it is specified in the params | 49 | const host = CONFIG.WEBSERVER.HOST |
51 | if (params.sign === true) { | ||
52 | const host = CONFIG.WEBSERVER.HOST | ||
53 | 50 | ||
54 | let dataToSign | 51 | let dataToSign |
55 | if (params.data) { | 52 | if (params.data) { |
56 | dataToSign = params.data | 53 | dataToSign = params.data |
57 | } else { | 54 | } else { |
58 | // We do not have data to sign so we just take our host | 55 | // We do not have data to sign so we just take our host |
59 | // It is not ideal but the connection should be in HTTPS | 56 | // It is not ideal but the connection should be in HTTPS |
60 | dataToSign = host | 57 | dataToSign = host |
61 | } | 58 | } |
62 | 59 | ||
60 | sign(dataToSign).then(signature => { | ||
63 | requestParams.json['signature'] = { | 61 | requestParams.json['signature'] = { |
64 | host, // Which host we pretend to be | 62 | host, // Which host we pretend to be |
65 | signature: sign(dataToSign) | 63 | signature |
66 | } | 64 | } |
67 | } | ||
68 | 65 | ||
69 | // If there are data informations | 66 | // If there are data informations |
70 | if (params.data) { | 67 | if (params.data) { |
71 | requestParams.json['data'] = params.data | 68 | requestParams.json['data'] = params.data |
72 | } | 69 | } |
73 | 70 | ||
74 | request.post(requestParams, (err, response, body) => err ? rej(err) : res({ response, body })) | 71 | request.post(requestParams, (err, response, body) => err ? rej(err) : res({ response, body })) |
72 | }) | ||
75 | }) | 73 | }) |
76 | } | 74 | } |
77 | 75 | ||
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index bf99f4df6..2792d3228 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -287,6 +287,10 @@ const USER_ROLES: { [ id: string ]: UserRole } = { | |||
287 | 287 | ||
288 | // --------------------------------------------------------------------------- | 288 | // --------------------------------------------------------------------------- |
289 | 289 | ||
290 | const OPENGRAPH_COMMENT = '<!-- opengraph tags -->' | ||
291 | |||
292 | // --------------------------------------------------------------------------- | ||
293 | |||
290 | // Special constants for a test instance | 294 | // Special constants for a test instance |
291 | if (isTestInstance() === true) { | 295 | if (isTestInstance() === true) { |
292 | CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14 | 296 | CONSTRAINTS_FIELDS.VIDEOS.DURATION.max = 14 |
@@ -306,12 +310,13 @@ export { | |||
306 | CONFIG, | 310 | CONFIG, |
307 | CONSTRAINTS_FIELDS, | 311 | CONSTRAINTS_FIELDS, |
308 | FRIEND_SCORE, | 312 | FRIEND_SCORE, |
309 | JOBS_FETCHING_INTERVAL, | ||
310 | JOB_STATES, | 313 | JOB_STATES, |
311 | JOBS_CONCURRENCY, | 314 | JOBS_CONCURRENCY, |
312 | JOBS_FETCH_LIMIT_PER_CYCLE, | 315 | JOBS_FETCH_LIMIT_PER_CYCLE, |
316 | JOBS_FETCHING_INTERVAL, | ||
313 | LAST_MIGRATION_VERSION, | 317 | LAST_MIGRATION_VERSION, |
314 | OAUTH_LIFETIME, | 318 | OAUTH_LIFETIME, |
319 | OPENGRAPH_COMMENT, | ||
315 | PAGINATION_COUNT_DEFAULT, | 320 | PAGINATION_COUNT_DEFAULT, |
316 | PODS_SCORE, | 321 | PODS_SCORE, |
317 | PREVIEWS_SIZE, | 322 | PREVIEWS_SIZE, |
diff --git a/server/initializers/migrator.ts b/server/initializers/migrator.ts index d381551b5..3184ec920 100644 --- a/server/initializers/migrator.ts +++ b/server/initializers/migrator.ts | |||
@@ -35,9 +35,7 @@ function migrate () { | |||
35 | return getMigrationScripts().then(migrationScripts => ({ actualVersion, migrationScripts })) | 35 | return getMigrationScripts().then(migrationScripts => ({ actualVersion, migrationScripts })) |
36 | }) | 36 | }) |
37 | .then(({ actualVersion, migrationScripts }) => { | 37 | .then(({ actualVersion, migrationScripts }) => { |
38 | return Promise.mapSeries(migrationScripts, entity => { | 38 | return Promise.each(migrationScripts, entity => executeMigration(actualVersion, entity)) |
39 | return executeMigration(actualVersion, entity) | ||
40 | }) | ||
41 | }) | 39 | }) |
42 | .then(() => { | 40 | .then(() => { |
43 | logger.info('Migrations finished. New migration version schema: %s', LAST_MIGRATION_VERSION) | 41 | logger.info('Migrations finished. New migration version schema: %s', LAST_MIGRATION_VERSION) |
diff --git a/server/lib/friends.ts b/server/lib/friends.ts index 498144318..c24839cb6 100644 --- a/server/lib/friends.ts +++ b/server/lib/friends.ts | |||
@@ -141,9 +141,7 @@ function makeFriends (hosts: string[]) { | |||
141 | logger.info('Make friends!') | 141 | logger.info('Make friends!') |
142 | return getMyPublicCert() | 142 | return getMyPublicCert() |
143 | .then(cert => { | 143 | .then(cert => { |
144 | return Promise.mapSeries(hosts, host => { | 144 | return Promise.each(hosts, host => computeForeignPodsList(host, podsScore)).then(() => cert) |
145 | return computeForeignPodsList(host, podsScore) | ||
146 | }).then(() => cert) | ||
147 | }) | 145 | }) |
148 | .then(cert => { | 146 | .then(cert => { |
149 | logger.debug('Pods scores computed.', { podsScore: podsScore }) | 147 | logger.debug('Pods scores computed.', { podsScore: podsScore }) |
@@ -169,7 +167,6 @@ function quitFriends () { | |||
169 | const requestParams = { | 167 | const requestParams = { |
170 | method: 'POST' as 'POST', | 168 | method: 'POST' as 'POST', |
171 | path: '/api/' + API_VERSION + '/remote/pods/remove', | 169 | path: '/api/' + API_VERSION + '/remote/pods/remove', |
172 | sign: true, | ||
173 | toPod: null | 170 | toPod: null |
174 | } | 171 | } |
175 | 172 | ||
@@ -178,6 +175,7 @@ function quitFriends () { | |||
178 | // The other pod will exclude us automatically after a while | 175 | // The other pod will exclude us automatically after a while |
179 | return Promise.map(pods, pod => { | 176 | return Promise.map(pods, pod => { |
180 | requestParams.toPod = pod | 177 | requestParams.toPod = pod |
178 | |||
181 | return makeSecureRequest(requestParams) | 179 | return makeSecureRequest(requestParams) |
182 | }, { concurrency: REQUESTS_IN_PARALLEL }) | 180 | }, { concurrency: REQUESTS_IN_PARALLEL }) |
183 | .then(() => pods) | 181 | .then(() => pods) |
diff --git a/server/lib/request/abstract-request-scheduler.ts b/server/lib/request/abstract-request-scheduler.ts index dd77fddb7..128fc5b28 100644 --- a/server/lib/request/abstract-request-scheduler.ts +++ b/server/lib/request/abstract-request-scheduler.ts | |||
@@ -70,7 +70,6 @@ abstract class AbstractRequestScheduler <T> { | |||
70 | protected makeRequest (toPod: PodInstance, requestEndpoint: string, requestsToMake: Object) { | 70 | protected makeRequest (toPod: PodInstance, requestEndpoint: string, requestsToMake: Object) { |
71 | const params = { | 71 | const params = { |
72 | toPod: toPod, | 72 | toPod: toPod, |
73 | sign: true, // Prove our identity | ||
74 | method: 'POST' as 'POST', | 73 | method: 'POST' as 'POST', |
75 | path: '/api/' + API_VERSION + '/remote/' + requestEndpoint, | 74 | path: '/api/' + API_VERSION + '/remote/' + requestEndpoint, |
76 | data: requestsToMake // Requests we need to make | 75 | data: requestsToMake // Requests we need to make |
diff --git a/server/lib/request/request-scheduler.ts b/server/lib/request/request-scheduler.ts index 0dd796fb0..8927d53bb 100644 --- a/server/lib/request/request-scheduler.ts +++ b/server/lib/request/request-scheduler.ts | |||
@@ -61,16 +61,9 @@ class RequestScheduler extends AbstractRequestScheduler<RequestsGrouped> { | |||
61 | } | 61 | } |
62 | 62 | ||
63 | createRequest ({ type, endpoint, data, toIds, transaction }: RequestSchedulerOptions) { | 63 | createRequest ({ type, endpoint, data, toIds, transaction }: RequestSchedulerOptions) { |
64 | // TODO: check the setPods works | ||
65 | const podIds = [] | ||
66 | |||
67 | // If there are no destination pods abort | 64 | // If there are no destination pods abort |
68 | if (toIds.length === 0) return undefined | 65 | if (toIds.length === 0) return undefined |
69 | 66 | ||
70 | toIds.forEach(toPod => { | ||
71 | podIds.push(toPod) | ||
72 | }) | ||
73 | |||
74 | const createQuery = { | 67 | const createQuery = { |
75 | endpoint, | 68 | endpoint, |
76 | request: { | 69 | request: { |
@@ -85,7 +78,7 @@ class RequestScheduler extends AbstractRequestScheduler<RequestsGrouped> { | |||
85 | 78 | ||
86 | return db.Request.create(createQuery, dbRequestOptions) | 79 | return db.Request.create(createQuery, dbRequestOptions) |
87 | .then(request => { | 80 | .then(request => { |
88 | return request.setPods(podIds, dbRequestOptions) | 81 | return request.setPods(toIds, dbRequestOptions) |
89 | }) | 82 | }) |
90 | } | 83 | } |
91 | 84 | ||
diff --git a/server/middlewares/secure.ts b/server/middlewares/secure.ts index 0fa9ee9d2..f58bea734 100644 --- a/server/middlewares/secure.ts +++ b/server/middlewares/secure.ts | |||
@@ -41,7 +41,7 @@ function checkSignature (req: express.Request, res: express.Response, next: expr | |||
41 | return res.sendStatus(403) | 41 | return res.sendStatus(403) |
42 | }) | 42 | }) |
43 | .catch(err => { | 43 | .catch(err => { |
44 | logger.error('Cannot get signed host in body.', { error: err }) | 44 | logger.error('Cannot get signed host in body.', { error: err.stack, signature: req.body.signature.signature }) |
45 | return res.sendStatus(500) | 45 | return res.sendStatus(500) |
46 | }) | 46 | }) |
47 | } | 47 | } |