diff options
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 | } | ||