diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-10-23 19:31:47 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-10-26 20:28:34 +0200 |
commit | 2c49ca42d14087ce8e1695759435f796a290470b (patch) | |
tree | 657faa7eabed5362ed715fee7c955a8ab44b3b29 /server/lib | |
parent | 43666d616d286ba64ce237facd7e247da7fb9d3c (diff) | |
download | PeerTube-2c49ca42d14087ce8e1695759435f796a290470b.tar.gz PeerTube-2c49ca42d14087ce8e1695759435f796a290470b.tar.zst PeerTube-2c49ca42d14087ce8e1695759435f796a290470b.zip |
Server: do not make friends with myself
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/friends.js | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/server/lib/friends.js b/server/lib/friends.js index 55cecc53e..b2ad0bbb3 100644 --- a/server/lib/friends.js +++ b/server/lib/friends.js | |||
@@ -6,6 +6,7 @@ const eachSeries = require('async/eachSeries') | |||
6 | const fs = require('fs') | 6 | const fs = require('fs') |
7 | const mongoose = require('mongoose') | 7 | const mongoose = require('mongoose') |
8 | const request = require('request') | 8 | const request = require('request') |
9 | const urlUtil = require('url') | ||
9 | const waterfall = require('async/waterfall') | 10 | const waterfall = require('async/waterfall') |
10 | 11 | ||
11 | const constants = require('../initializers/constants') | 12 | const constants = require('../initializers/constants') |
@@ -173,8 +174,11 @@ function computeWinningPods (urls, podsScore) { | |||
173 | // Only add a pod if it exists in more than a half base pods | 174 | // Only add a pod if it exists in more than a half base pods |
174 | const podsList = [] | 175 | const podsList = [] |
175 | const baseScore = urls.length / 2 | 176 | const baseScore = urls.length / 2 |
176 | Object.keys(podsScore).forEach(function (pod) { | 177 | Object.keys(podsScore).forEach(function (podUrl) { |
177 | if (podsScore[pod] > baseScore) podsList.push({ url: pod }) | 178 | // If the pod is not me and with a good score we add it |
179 | if (isMe(podUrl) === false && podsScore[podUrl] > baseScore) { | ||
180 | podsList.push({ url: podUrl }) | ||
181 | } | ||
178 | }) | 182 | }) |
179 | 183 | ||
180 | return podsList | 184 | return podsList |
@@ -262,3 +266,15 @@ function createRequest (type, data, to) { | |||
262 | if (err) logger.error('Cannot save the request.', { error: err }) | 266 | if (err) logger.error('Cannot save the request.', { error: err }) |
263 | }) | 267 | }) |
264 | } | 268 | } |
269 | |||
270 | function isMe (url) { | ||
271 | const parsedUrl = urlUtil.parse(url) | ||
272 | |||
273 | const hostname = parsedUrl.hostname | ||
274 | const port = parseInt(parsedUrl.port) | ||
275 | |||
276 | const myHostname = constants.CONFIG.WEBSERVER.HOST | ||
277 | const myPort = constants.CONFIG.WEBSERVER.PORT | ||
278 | |||
279 | return hostname === myHostname && port === myPort | ||
280 | } | ||