aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/friends.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/friends.js')
-rw-r--r--server/lib/friends.js20
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')
6const fs = require('fs') 6const fs = require('fs')
7const mongoose = require('mongoose') 7const mongoose = require('mongoose')
8const request = require('request') 8const request = require('request')
9const urlUtil = require('url')
9const waterfall = require('async/waterfall') 10const waterfall = require('async/waterfall')
10 11
11const constants = require('../initializers/constants') 12const 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
270function 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}