use of com.biglybt.core.tracker.client.TRTrackerAnnouncerRequest in project BiglyBT by BiglySoftware.
the class AllTrackersManagerImpl method processUpdates.
private void processUpdates(boolean for_close) {
synchronized (process_lock) {
if (pending_torrents != null && CoreFactory.isCoreRunning()) {
for (TOTorrent torrent : pending_torrents) {
torrent.addListener(AllTrackersManagerImpl.this);
}
got_running = true;
pending_torrents = null;
}
Set<AllTrackersTracker> updates = new HashSet<>();
while (!update_queue.isEmpty()) {
Object[] entry = update_queue.remove();
try {
Object e0 = entry[0];
if (e0 instanceof TOTorrent) {
TOTorrent torrent = (TOTorrent) e0;
if (pending_torrents == null) {
torrent.addListener(AllTrackersManagerImpl.this);
} else {
pending_torrents.add(torrent);
}
continue;
} else if (e0 instanceof String) {
String cmd = (String) e0;
if (cmd.equals("logging_changed")) {
updateLogging();
} else {
Debug.out("eh?");
}
continue;
}
AllTrackersTrackerImpl tracker = (AllTrackersTrackerImpl) e0;
if (host_map.containsKey(tracker.getTrackerName())) {
Object obj = entry[1];
boolean updated = false;
if (obj instanceof String) {
String cmd = (String) obj;
if (cmd.equals("reset_stats")) {
tracker.resetReportedStatsSupport();
updated = true;
} else {
Debug.out("eh?");
}
} else if (obj instanceof TRTrackerAnnouncerResponse) {
TRTrackerAnnouncerResponse a_resp = (TRTrackerAnnouncerResponse) obj;
if (tracker.setOK(a_resp.getStatus() == TRTrackerAnnouncerResponse.ST_ONLINE)) {
updated = true;
}
if (tracker.setStatusString(a_resp.getStatusString())) {
updated = true;
}
if (updated) {
tracker.log(a_resp);
}
} else if (obj instanceof TRTrackerScraperResponse) {
if (tracker.hasStatus()) {
continue;
}
TRTrackerScraperResponse s_resp = (TRTrackerScraperResponse) obj;
if (tracker.setOK(s_resp.getStatus() == TRTrackerScraperResponse.ST_ONLINE)) {
updated = true;
}
if (tracker.setStatusString(s_resp.getStatusString())) {
updated = true;
}
} else if (obj instanceof TRTrackerAnnouncerRequest) {
TRTrackerAnnouncerRequest req = (TRTrackerAnnouncerRequest) obj;
tracker.updateSession(req);
tracker.log(req, false);
updated = true;
}
if (updated) {
updates.add(tracker);
}
}
} catch (Throwable e) {
Debug.out(e);
}
}
if (for_close) {
Set<String> active_privates = new HashSet<>();
for (TRTrackerAnnouncerRequest req : active_requests.keySet()) {
String key = ingestURL(req.getURL());
if (key != null) {
AllTrackersTrackerImpl existing_tracker = host_map.get(key);
if (existing_tracker != null) {
existing_tracker.log(req, true);
if (existing_tracker.getPrivatePercentage() > 80) {
active_privates.add(existing_tracker.getShortKey());
}
}
}
}
if (!active_privates.isEmpty()) {
COConfigurationManager.setParameter(CONFIG_PRIVATE_ACTIVE_AT_CLOSE, new ArrayList<String>(active_privates));
}
} else {
if (!updates.isEmpty()) {
List<AllTrackersTracker> trackers = new ArrayList<>(updates);
for (AllTrackersListener listener : listeners) {
try {
listener.trackerEventOccurred(new AllTrackersEventImpl(AllTrackersEvent.ET_TRACKER_UPDATED, trackers));
} catch (Throwable e) {
Debug.out(e);
}
}
}
}
}
}
Aggregations