]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/friends.js
Client: add ability to report a video
[github/Chocobozzz/PeerTube.git] / server / lib / friends.js
index f634aedbb4c0b80150b17733cf75d631554a124f..2ea837c9997b5463b5eda6807d0f1ca86b2194bb 100644 (file)
@@ -3,13 +3,13 @@
 const each = require('async/each')
 const eachLimit = require('async/eachLimit')
 const eachSeries = require('async/eachSeries')
-const fs = require('fs')
 const request = require('request')
 const waterfall = require('async/waterfall')
 
 const constants = require('../initializers/constants')
 const db = require('../initializers/database')
 const logger = require('../helpers/logger')
+const peertubeCrypto = require('../helpers/peertube-crypto')
 const requests = require('../helpers/requests')
 
 const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]
@@ -19,7 +19,6 @@ const friends = {
   updateVideoToFriends,
   reportAbuseVideoToFriend,
   hasFriends,
-  getMyCertificate,
   makeFriends,
   quitFriends,
   removeVideoToFriends,
@@ -74,15 +73,11 @@ function hasFriends (callback) {
   })
 }
 
-function getMyCertificate (callback) {
-  fs.readFile(constants.CONFIG.STORAGE.CERT_DIR + 'peertube.pub', 'utf8', callback)
-}
-
 function makeFriends (hosts, callback) {
   const podsScore = {}
 
   logger.info('Make friends!')
-  getMyCertificate(function (err, cert) {
+  peertubeCrypto.getMyPublicCert(function (err, cert) {
     if (err) {
       logger.error('Cannot read public cert.')
       return callback(err)
@@ -203,7 +198,7 @@ function computeForeignPodsList (host, podsScore, callback) {
       else podsScore[foreignPodHost] = 1
     })
 
-    callback()
+    return callback()
   })
 }
 
@@ -212,6 +207,7 @@ function computeWinningPods (hosts, podsScore) {
   // Only add a pod if it exists in more than a half base pods
   const podsList = []
   const baseScore = hosts.length / 2
+
   Object.keys(podsScore).forEach(function (podHost) {
     // If the pod is not me and with a good score we add it
     if (isMe(podHost) === false && podsScore[podHost] > baseScore) {