protected TRTrackerAnnouncerMuxer(
      TOTorrent _torrent, TRTrackerAnnouncerFactory.DataProvider _f_provider, boolean _manual)
      throws TRTrackerAnnouncerException {
    super(_torrent);

    try {
      last_response_informed =
          new TRTrackerAnnouncerResponseImpl(
              null,
              _torrent.getHashWrapper(),
              TRTrackerAnnouncerResponse.ST_OFFLINE,
              TRTrackerAnnouncer.REFRESH_MINIMUM_SECS,
              "Initialising");

    } catch (TOTorrentException e) {

      Logger.log(new LogEvent(_torrent, LOGID, "Torrent hash retrieval fails", e));

      throw (new TRTrackerAnnouncerException("TRTrackerAnnouncer: URL encode fails"));
    }

    is_manual = _manual;
    f_provider = _f_provider;

    split();
  }
예제 #2
0
 /**
  * @param torrent
  * @param string
  * @since 3.0.1.5
  */
 public static void log(TOTorrent torrent, String string) {
   String hash = "";
   try {
     hash = torrent.getHashWrapper().toBase32String();
   } catch (Exception e) {
   }
   log(hash + "] " + string);
 }
예제 #3
0
  private static void updateMetaData_handleReply(
      TOTorrent torrent, String hash, String replyType, Map mapHashes) {
    if (hash == null && torrent != null) {
      try {
        hash = torrent.getHashWrapper().toBase32String();
      } catch (Exception e) {
      }
    }

    GlobalManager gm = AzureusCoreFactory.getSingleton().getGlobalManager();
    DownloadManager dm = gm.getDownloadManager(new HashWrapper(Base32.decode(hash)));

    if (torrent == null && dm != null) {
      torrent = dm.getTorrent();
    }
    Map contentMap = PlatformTorrentUtils.getContentMap(torrent);

    final TOTorrent torrentFinal = torrent;

    if (replyType.equals(PlatformMessenger.REPLY_EXCEPTION)) {
      if (torrent != null) {
        // try again in a bit
        log(torrent, "Exception, retrying later");
        SimpleTimer.addEvent(
            "Update MD Retry",
            SystemTime.getCurrentTime() + RETRY_METADATA,
            new TimerEventPerformer() {
              public void perform(TimerEvent event) {
                log(torrentFinal, "retry time");
                PlatformTorrentUtils.updateMetaData(torrentFinal, 15000);
              }
            });
      }
    } else {
      Map jsonMapMetaData = hash == null ? null : (Map) mapHashes.get(hash);
      if (jsonMapMetaData != null) {
        long oldLastUpdated = getContentLastUpdated(torrent);
        long expireyMins = 0;

        for (Iterator iter = jsonMapMetaData.keySet().iterator(); iter.hasNext(); ) {
          String key = (String) iter.next();
          Object value = jsonMapMetaData.get(key);

          if (value == null || value.equals(null)) {
            contentMap.remove(key);
          } else if ((key.equals("Thumbnail") || key.endsWith(".B64")) && value instanceof String) {
            contentMap.put(key, Base64.decode((String) value));
          } else if (key.equals("expires-in-mins") && value instanceof Long) {
            expireyMins = ((Long) value).longValue();
          } else {
            contentMap.put(key, value);
          }
          writeTorrentIfExists(torrent);
        }

        // crappy way of updating the display name
        if (dm != null) {
          String title = PlatformTorrentUtils.getContentTitle(torrent);
          if (title != null
              && title.length() > 0
              && dm.getDownloadState().getDisplayName() == null) {
            dm.getDownloadState().setDisplayName(title);
          }
        }
        triggerMetaDataUpdateListeners(torrent);

        if (torrent != null) {
          // setup next refresh

          long refreshOn;
          if (expireyMins > 0) {
            refreshOn = SystemTime.getCurrentTime() + (expireyMins * 60 * 1000L);
          } else {
            long newLastUpdated = getContentLastUpdated(torrent);

            long diff = newLastUpdated - oldLastUpdated;
            log(
                torrent,
                "Last Updated: new "
                    + new Date(newLastUpdated)
                    + ";old "
                    + new Date(oldLastUpdated)
                    + ";diff="
                    + diff);
            if (diff > 0 && oldLastUpdated != 0) {
              diff *= 2;
              if (diff < MIN_MD_REFRESH_MS) {
                diff = MIN_MD_REFRESH_MS;
              } else if (diff > MAX_MD_REFRESH_MS) {
                diff = MAX_MD_REFRESH_MS;
              }
              refreshOn = SystemTime.getOffsetTime(diff);
            } else {
              refreshOn = SystemTime.getCurrentTime() + (7 * 24 * 60 * 60 * 1000L);
            }
          }

          log(torrent, "got MD. Next refresh in " + (refreshOn - SystemTime.getCurrentTime()));
          setMetaDataRefreshOn(torrent, refreshOn);
          SimpleTimer.addEvent(
              "Update MD",
              refreshOn,
              new TimerEventPerformer() {
                public void perform(TimerEvent event) {
                  PlatformTorrentUtils.updateMetaData(torrentFinal, 15000);
                }
              });
        }
      } else if (torrent != null) {
        long refreshOn = SystemTime.getCurrentTime() + (30 * 24 * 60 * 60 * 1000L);
        setMetaDataRefreshOn(torrent, refreshOn);
        log(torrent, "no hash in reply. Next refresh on " + new Date(refreshOn));
      }
    }
  }
  private void _openView(int viewID, Object data) {
    switch (viewID) {
      case VIEW_CONSOLE:
        openView(SideBar.SIDEBAR_HEADER_PLUGINS, LoggerView.class, null, data, true);
        break;

      case VIEW_ALLPEERS:
        openView(SideBar.SIDEBAR_HEADER_TRANSFERS, PeersSuperView.class, null, data, true);
        break;

      case VIEW_PEERS_STATS:
        openView(SideBar.SIDEBAR_HEADER_PLUGINS, ClientStatsView.class, null, data, true);
        break;

      case VIEW_CONFIG:
        showConfig((data instanceof String) ? (String) data : null);
        break;

      case VIEW_DM_DETAILS:
        {
          String id = SideBar.SIDEBAR_TORRENT_DETAILS_PREFIX;
          if (data instanceof DownloadManager) {
            DownloadManager dm = (DownloadManager) data;
            TOTorrent torrent = dm.getTorrent();
            if (torrent != null) {
              try {
                id += torrent.getHashWrapper().toBase32String();
              } catch (TOTorrentException e) {
                e.printStackTrace();
              }
            }
          }

          MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
          if (mdi != null) {
            mdi.loadEntryByID(id, true, false, data);
          }
        }
        break;

      case VIEW_DM_MULTI_OPTIONS:
        openView(SideBar.SIDEBAR_HEADER_TRANSFERS, TorrentOptionsView.class, null, data, true);
        break;

      case VIEW_MYSHARES:
        openView(SideBar.SIDEBAR_HEADER_TRANSFERS, MySharesView.class, null, data, true);
        break;

      case VIEW_MYTORRENTS:
        {
          MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
          if (mdi != null) {
            mdi.showEntryByID(SideBar.SIDEBAR_SECTION_LIBRARY);
          }
        }
        break;

      case VIEW_MYTRACKER:
        openView(SideBar.SIDEBAR_HEADER_TRANSFERS, MyTrackerView.class, null, data, true);
        break;

      case VIEW_TAGS_OVERVIEW:
        {
          MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();

          if (mdi != null) {

            mdi.showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TAGS);
          }

          break;
        }
      case VIEW_TAG:
        {
          if (data instanceof Tag) {

            Tag tag = (Tag) data;

            String id = "Tag." + tag.getTagType().getTagType() + "." + tag.getTagID();

            MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();

            if (mdi != null) {

              mdi.loadEntryByID(id, true, false, data);
            }
          }
          break;
        }
      default:
        break;
    }
  }