aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/friends.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/friends.js')
-rw-r--r--lib/friends.js24
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/friends.js b/lib/friends.js
index b0086a38b..badf09c7d 100644
--- a/lib/friends.js
+++ b/lib/friends.js
@@ -30,8 +30,7 @@
30 function addVideoToFriends (video) { 30 function addVideoToFriends (video) {
31 // To avoid duplicates 31 // To avoid duplicates
32 var id = video.name + video.magnetUri 32 var id = video.name + video.magnetUri
33 // namePath is null 33 // ensure namePath is null
34 // TODO
35 video.namePath = null 34 video.namePath = null
36 PoolRequests.addRequest(id, 'add', video) 35 PoolRequests.addRequest(id, 'add', video)
37 } 36 }
@@ -51,13 +50,15 @@
51 logger.info('Make friends!') 50 logger.info('Make friends!')
52 fs.readFile(peertubeCrypto.getCertDir() + 'peertube.pub', 'utf8', function (err, cert) { 51 fs.readFile(peertubeCrypto.getCertDir() + 'peertube.pub', 'utf8', function (err, cert) {
53 if (err) { 52 if (err) {
54 logger.error('Cannot read public cert.', { error: err }) 53 logger.error('Cannot read public cert.')
55 return callback(err) 54 return callback(err)
56 } 55 }
57 56
58 var urls = config.get('network.friends') 57 var urls = config.get('network.friends')
59 58
60 async.each(urls, computeForeignPodsList, function () { 59 async.each(urls, computeForeignPodsList, function (err) {
60 if (err) return callback(err)
61
61 logger.debug('Pods scores computed.', { pods_score: pods_score }) 62 logger.debug('Pods scores computed.', { pods_score: pods_score })
62 var pods_list = computeWinningPods(urls, pods_score) 63 var pods_list = computeWinningPods(urls, pods_score)
63 logger.debug('Pods that we keep computed.', { pods_to_keep: pods_list }) 64 logger.debug('Pods that we keep computed.', { pods_to_keep: pods_list })
@@ -72,7 +73,8 @@
72 // Let's give 1 point to the pod we ask the friends list 73 // Let's give 1 point to the pod we ask the friends list
73 pods_score[url] = 1 74 pods_score[url] = 1
74 75
75 getForeignPodsList(url, function (foreign_pods_list) { 76 getForeignPodsList(url, function (err, foreign_pods_list) {
77 if (err) return callback(err)
76 if (foreign_pods_list.length === 0) return callback() 78 if (foreign_pods_list.length === 0) return callback()
77 79
78 async.each(foreign_pods_list, function (foreign_pod, callback_each) { 80 async.each(foreign_pods_list, function (foreign_pod, callback_each) {
@@ -108,7 +110,10 @@
108 110
109 // Get the list of our videos to send to our new friends 111 // Get the list of our videos to send to our new friends
110 Videos.listOwned(function (err, videos_list) { 112 Videos.listOwned(function (err, videos_list) {
111 if (err) throw err 113 if (err) {
114 logger.error('Cannot get the list of videos we own.')
115 return callback(err)
116 }
112 117
113 var data = { 118 var data = {
114 url: http + '://' + host + ':' + port, 119 url: http + '://' + host + ':' + port,
@@ -145,7 +150,7 @@
145 poolRequests.activate() 150 poolRequests.activate()
146 151
147 if (err) { 152 if (err) {
148 logger.error('There was some errors when we wanted to make friends.', { error: err }) 153 logger.error('There was some errors when we wanted to make friends.')
149 return callback(err) 154 return callback(err)
150 } 155 }
151 156
@@ -212,8 +217,9 @@
212 var path = '/api/' + constants.API_VERSION + '/pods' 217 var path = '/api/' + constants.API_VERSION + '/pods'
213 218
214 request.get(url + path, function (err, response, body) { 219 request.get(url + path, function (err, response, body) {
215 if (err) throw err 220 if (err) return callback(err)
216 callback(JSON.parse(body)) 221
222 callback(null, JSON.parse(body))
217 }) 223 })
218 } 224 }
219})() 225})()