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.js62
1 files changed, 31 insertions, 31 deletions
diff --git a/server/lib/friends.js b/server/lib/friends.js
index 006a64404..c3c231604 100644
--- a/server/lib/friends.js
+++ b/server/lib/friends.js
@@ -1,23 +1,23 @@
1'use strict' 1'use strict'
2 2
3var async = require('async') 3const async = require('async')
4var config = require('config') 4const config = require('config')
5var fs = require('fs') 5const fs = require('fs')
6var request = require('request') 6const request = require('request')
7 7
8var constants = require('../initializers/constants') 8const constants = require('../initializers/constants')
9var logger = require('../helpers/logger') 9const logger = require('../helpers/logger')
10var peertubeCrypto = require('../helpers/peertubeCrypto') 10const peertubeCrypto = require('../helpers/peertubeCrypto')
11var Pods = require('../models/pods') 11const Pods = require('../models/pods')
12var poolRequests = require('../lib/poolRequests') 12const poolRequests = require('../lib/poolRequests')
13var requests = require('../helpers/requests') 13const requests = require('../helpers/requests')
14var Videos = require('../models/videos') 14const Videos = require('../models/videos')
15 15
16var http = config.get('webserver.https') ? 'https' : 'http' 16const http = config.get('webserver.https') ? 'https' : 'http'
17var host = config.get('webserver.host') 17const host = config.get('webserver.host')
18var port = config.get('webserver.port') 18const port = config.get('webserver.port')
19 19
20var pods = { 20const pods = {
21 addVideoToFriends: addVideoToFriends, 21 addVideoToFriends: addVideoToFriends,
22 hasFriends: hasFriends, 22 hasFriends: hasFriends,
23 makeFriends: makeFriends, 23 makeFriends: makeFriends,
@@ -27,7 +27,7 @@ var pods = {
27 27
28function addVideoToFriends (video) { 28function addVideoToFriends (video) {
29 // To avoid duplicates 29 // To avoid duplicates
30 var id = video.name + video.magnetUri 30 const id = video.name + video.magnetUri
31 // ensure namePath is null 31 // ensure namePath is null
32 video.namePath = null 32 video.namePath = null
33 poolRequests.addRequest(id, 'add', video) 33 poolRequests.addRequest(id, 'add', video)
@@ -37,13 +37,13 @@ function hasFriends (callback) {
37 Pods.count(function (err, count) { 37 Pods.count(function (err, count) {
38 if (err) return callback(err) 38 if (err) return callback(err)
39 39
40 var has_friends = (count !== 0) 40 const has_friends = (count !== 0)
41 callback(null, has_friends) 41 callback(null, has_friends)
42 }) 42 })
43} 43}
44 44
45function makeFriends (callback) { 45function makeFriends (callback) {
46 var pods_score = {} 46 const pods_score = {}
47 47
48 logger.info('Make friends!') 48 logger.info('Make friends!')
49 fs.readFile(peertubeCrypto.getCertDir() + 'peertube.pub', 'utf8', function (err, cert) { 49 fs.readFile(peertubeCrypto.getCertDir() + 'peertube.pub', 'utf8', function (err, cert) {
@@ -52,7 +52,7 @@ function makeFriends (callback) {
52 return callback(err) 52 return callback(err)
53 } 53 }
54 54
55 var urls = config.get('network.friends') 55 const urls = config.get('network.friends')
56 56
57 async.each(urls, function (url, callback) { 57 async.each(urls, function (url, callback) {
58 computeForeignPodsList(url, pods_score, callback) 58 computeForeignPodsList(url, pods_score, callback)
@@ -60,8 +60,8 @@ function makeFriends (callback) {
60 if (err) return callback(err) 60 if (err) return callback(err)
61 61
62 logger.debug('Pods scores computed.', { pods_score: pods_score }) 62 logger.debug('Pods scores computed.', { pods_score: pods_score })
63 var pods_list = computeWinningPods(urls, pods_score) 63 const pods_list = computeWinningPods(urls, pods_score)
64 logger.debug('Pods that we keep computed.', { pods_to_keep: pods_list }) 64 logger.debug('Pods that we keep.', { pods_to_keep: pods_list })
65 65
66 makeRequestsToWinningPods(cert, pods_list, callback) 66 makeRequestsToWinningPods(cert, pods_list, callback)
67 }) 67 })
@@ -77,7 +77,7 @@ function quitFriends (callback) {
77 Pods.list(function (err, pods) { 77 Pods.list(function (err, pods) {
78 if (err) return callback(err) 78 if (err) return callback(err)
79 79
80 var request = { 80 const request = {
81 method: 'POST', 81 method: 'POST',
82 path: '/api/' + constants.API_VERSION + '/pods/remove', 82 path: '/api/' + constants.API_VERSION + '/pods/remove',
83 sign: true, 83 sign: true,
@@ -109,7 +109,7 @@ function quitFriends (callback) {
109 109
110function removeVideoToFriends (video) { 110function removeVideoToFriends (video) {
111 // To avoid duplicates 111 // To avoid duplicates
112 var id = video.name + video.magnetUri 112 const id = video.name + video.magnetUri
113 poolRequests.addRequest(id, 'remove', video) 113 poolRequests.addRequest(id, 'remove', video)
114} 114}
115 115
@@ -128,7 +128,7 @@ function computeForeignPodsList (url, pods_score, callback) {
128 if (foreign_pods_list.length === 0) return callback() 128 if (foreign_pods_list.length === 0) return callback()
129 129
130 async.each(foreign_pods_list, function (foreign_pod, callback_each) { 130 async.each(foreign_pods_list, function (foreign_pod, callback_each) {
131 var foreign_url = foreign_pod.url 131 const foreign_url = foreign_pod.url
132 132
133 if (pods_score[foreign_url]) pods_score[foreign_url]++ 133 if (pods_score[foreign_url]) pods_score[foreign_url]++
134 else pods_score[foreign_url] = 1 134 else pods_score[foreign_url] = 1
@@ -143,8 +143,8 @@ function computeForeignPodsList (url, pods_score, callback) {
143function computeWinningPods (urls, pods_score) { 143function computeWinningPods (urls, pods_score) {
144 // Build the list of pods to add 144 // Build the list of pods to add
145 // Only add a pod if it exists in more than a half base pods 145 // Only add a pod if it exists in more than a half base pods
146 var pods_list = [] 146 const pods_list = []
147 var base_score = urls.length / 2 147 const base_score = urls.length / 2
148 Object.keys(pods_score).forEach(function (pod) { 148 Object.keys(pods_score).forEach(function (pod) {
149 if (pods_score[pod] > base_score) pods_list.push({ url: pod }) 149 if (pods_score[pod] > base_score) pods_list.push({ url: pod })
150 }) 150 })
@@ -153,7 +153,7 @@ function computeWinningPods (urls, pods_score) {
153} 153}
154 154
155function getForeignPodsList (url, callback) { 155function getForeignPodsList (url, callback) {
156 var path = '/api/' + constants.API_VERSION + '/pods' 156 const path = '/api/' + constants.API_VERSION + '/pods'
157 157
158 request.get(url + path, function (err, response, body) { 158 request.get(url + path, function (err, response, body) {
159 if (err) return callback(err) 159 if (err) return callback(err)
@@ -175,7 +175,7 @@ function makeRequestsToWinningPods (cert, pods_list, callback) {
175 return callback(err) 175 return callback(err)
176 } 176 }
177 177
178 var data = { 178 const data = {
179 url: http + '://' + host + ':' + port, 179 url: http + '://' + host + ':' + port,
180 publicKey: cert, 180 publicKey: cert,
181 videos: videos_list 181 videos: videos_list