Commits

Anonymous committed 8d38ded

own address config parameter

  • Participants
  • Parent commits d89bb6d

Comments (0)

Files changed (2)

File server/src/jetbrains/buildServer/artifactsMirror/ServerTorrentsDirectorySeeder.java

  */
 package jetbrains.buildServer.artifactsMirror;
 
-import jetbrains.buildServer.RootUrlHolder;
 import jetbrains.buildServer.artifactsMirror.seeder.FileLink;
 import jetbrains.buildServer.artifactsMirror.seeder.TorrentFileFactory;
 import jetbrains.buildServer.artifactsMirror.seeder.TorrentsDirectorySeeder;
-import jetbrains.buildServer.artifactsMirror.torrent.TorrentTracker;
 import jetbrains.buildServer.artifactsMirror.torrent.TorrentUtil;
 import jetbrains.buildServer.log.Loggers;
 import jetbrains.buildServer.serverSide.*;
 import java.io.File;
 import java.io.FileFilter;
 import java.io.IOException;
+import java.net.InetAddress;
 import java.util.Collection;
 import java.util.Collections;
 
 public class ServerTorrentsDirectorySeeder {
   private final TorrentTrackerManager myTorrentTrackerManager;
   private final TorrentsDirectorySeeder myTorrentsDirectorySeeder;
-  private final RootUrlHolder myRootUrlHolder;
   private volatile int myFileSizeThreshold;
 
   public ServerTorrentsDirectorySeeder(@NotNull ServerPaths serverPaths,
-                                       @NotNull RootUrlHolder rootUrlHolder,
                                        @NotNull TorrentTrackerManager torrentTrackerManager,
                                        @NotNull EventDispatcher<BuildServerListener> eventDispatcher) {
     myTorrentTrackerManager = torrentTrackerManager;
-    myRootUrlHolder = rootUrlHolder;
     File torrentsStorage = new File(serverPaths.getPluginDataDirectory(), "torrents");
     torrentsStorage.mkdirs();
     myTorrentsDirectorySeeder = new TorrentsDirectorySeeder(torrentsStorage, new TorrentFileFactory() {
     }
   }
 
-  public void startSeeder() {
+  public void startSeeder(@NotNull String seederAddress) {
     stopSeeder();
 
     try {
-      myTorrentsDirectorySeeder.start(TorrentTracker.getServerAddress(myRootUrlHolder.getRootUrl()));
+      myTorrentsDirectorySeeder.start(InetAddress.getByName(seederAddress));
     } catch (Exception e) {
       Loggers.SERVER.warn("Failed to start torrent seeder, error: " + e.toString());
     }

File server/src/jetbrains/buildServer/artifactsMirror/TorrentConfigurator.java

 
 public class TorrentConfigurator implements TorrentTrackerConfiguration {
   public final static String TRACKER_ENABLED = "torrent.tracker.enabled";
-  public final static String TRACKER_HOST = "torrent.tracker.host";
+  public final static String OWN_ADDRESS = "torrent.ownAddress";
   public final static String SEEDER_ENABLED = "torrent.seeder.enabled";
   public final static String FILE_SIZE_THRESHOLD = "file.size.threshold.mb";
   public final static String MAX_NUMBER_OF_SEEDED_TORRENTS = "max.seeded.torrents.number";
       public void serverStartup() {
         super.serverStartup();
         if (isEnabled(TRACKER_ENABLED)) {
-          myTrackerManager.startTracker(getTrackerAddress());
+          myTrackerManager.startTracker(getOwnAddress());
         }
         executors.getLowPriorityExecutorService().submit(new Runnable() {
           public void run() {
     myConfiguration.setProperty(TRACKER_ENABLED, Boolean.toString(enabled));
     if (changed) {
       if (enabled) {
-        myTrackerManager.startTracker(getTrackerAddress());
+        myTrackerManager.startTracker(getOwnAddress());
       } else {
         myTrackerManager.stopTracker();
       }
   private void startSeeder() {
     mySeederManager.setFileSizeThreshold(getFileSizeThresholdMb());
     mySeederManager.setMaxNumberOfSeededTorrents(getMaxNumberOfSeededTorrents());
-    mySeederManager.startSeeder();
+    mySeederManager.startSeeder(getOwnAddress());
   }
 
   public int getFileSizeThresholdMb() {
   }
 
   @NotNull
-  private String getTrackerAddress() {
-    String hostName = myConfiguration.getProperty(TRACKER_HOST);
+  private String getOwnAddress() {
+    String hostName = myConfiguration.getProperty(OWN_ADDRESS);
     if (hostName != null) return hostName;
 
     try {