Skip to content
Snippets Groups Projects
Commit ea28a30e authored by Mosharaf Chowdhury's avatar Mosharaf Chowdhury
Browse files

Makes transfer faster for small swarms (with size < MaxRxPeers)

parent 191af65f
No related branches found
No related tags found
No related merge requests found
...@@ -896,11 +896,11 @@ extends Broadcast with Logging { ...@@ -896,11 +896,11 @@ extends Broadcast with Logging {
class ServeMultipleRequests class ServeMultipleRequests
extends Thread with Logging { extends Thread with Logging {
// Server at most BitTorrentBroadcast.MaxRxPeers peers
var threadPool =
Broadcast.newDaemonFixedThreadPool(BitTorrentBroadcast.MaxRxPeers)
override def run: Unit = { override def run: Unit = {
// Server at most BitTorrentBroadcast.MaxRxPeers peers
var threadPool =
Broadcast.newDaemonFixedThreadPool(BitTorrentBroadcast.MaxRxPeers)
var serverSocket = new ServerSocket (0) var serverSocket = new ServerSocket (0)
listenPort = serverSocket.getLocalPort listenPort = serverSocket.getLocalPort
...@@ -975,8 +975,7 @@ extends Broadcast with Logging { ...@@ -975,8 +975,7 @@ extends Broadcast with Logging {
var keepSending = true var keepSending = true
var numBlocksToSend = BitTorrentBroadcast.MaxChatBlocks var numBlocksToSend = BitTorrentBroadcast.MaxChatBlocks
while (!stopBroadcast && keepSending && numBlocksToSend > 0 && while (!stopBroadcast && keepSending && numBlocksToSend > 0) {
(curTime - startTime) < BitTorrentBroadcast.MaxChatTime) {
// Receive which block to send // Receive which block to send
val blockToSend = ois.readObject.asInstanceOf[Int] val blockToSend = ois.readObject.asInstanceOf[Int]
...@@ -992,6 +991,11 @@ extends Broadcast with Logging { ...@@ -992,6 +991,11 @@ extends Broadcast with Logging {
addToListOfSources (rxSourceInfo) addToListOfSources (rxSourceInfo)
curTime = System.currentTimeMillis curTime = System.currentTimeMillis
// Revoke sending only if there is anyone waiting in the queue
if (curTime - startTime >= BitTorrentBroadcast.MaxChatTime &&
threadPool.getQueue.size > 0) {
keepSending = false
}
} }
} catch { } catch {
// If something went wrong, e.g., the worker at the other end died etc. // If something went wrong, e.g., the worker at the other end died etc.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment