Esempio n. 1
0
    def getNewPeerList(self):
        
        #Dont create too many connections to other peers ( because of performance problems )        
        if(len(self._peersConn) >= self._maxPeerListSize):
            return
        t = SSimulator().tick
        if( (t - self._lastPeerListUpdate) < self._timeBetweenPeerListUpdates):
            return
        else:
            self._lastPeerListUpdate = t
        
        Log.pLD(self, "Ask Tracker for new peers ...".format())
        newPeers = self._torrent.tracker.getPeerList()

        #Filter unwanted peers , for example itself
        def f(x): return ( x.pid != self.pid )
        newPeers = filter( f, newPeers )

        for i in newPeers :
            if (i.pid in self._peersConn) == False:
                newConnection = Connection(self, i)
                self._peersConn[i.pid] = ( 0, i.pid, newConnection, -1 , self.NO_SLOT )
                newConnection.setUploadLimit( self._calculateUploadRate(newConnection) )
                #newConnection.setDownloadLimit( self._calculateDownloadRate(newConnection) )
                newConnection.connect()
                Log.pLD(self, "adding Peer [{0}]".format(i.pid))
Esempio n. 2
0
 def connectToPeer(self, peer):
     #logging.log(Simulator.DEBUG, "[{0}] External peer is connecting! [{1}]".format(self.pid, peer.pid))
     Log.pLD(self, "External peer is connecting! [{0}]".format(peer.pid) )
     newConnection = None
         
     #If we already now this peer, return current connection
     if peer.pid in self._peersConn :
         newConnection = self._peersConn[peer.pid][2]
     else:
         Log.pLD(self, "adding Peer [{0}]".format(peer.pid)) 
         newConnection = Connection(self, peer)
         self._peersConn[peer.pid] = ( 0, peer.pid, newConnection, -1 , self.NO_SLOT)
         newConnection.setUploadLimit( self._calculateUploadRate(newConnection) )
         #newConnection.setDownloadLimit( self._calculateDownloadRate(newConnection) )
         self._peersConn[peer.pid][2].connect()
     
     #Return the connection reference
     return newConnection