/** * @param dl * @since 3.0.2.3 */ public static String getMediaServerContentURL(Download dl) { // TorrentListViewsUtils.debugDCAD("enter - getMediaServerContentURL"); PluginManager pm = AzureusCoreFactory.getSingleton().getPluginManager(); PluginInterface pi = pm.getPluginInterfaceByID("azupnpav", false); if (pi == null) { Logger.log(new LogEvent(LogIDs.UI3, "Media server plugin not found")); return null; } if (!pi.getPluginState().isOperational()) { Logger.log(new LogEvent(LogIDs.UI3, "Media server plugin not operational")); return null; } try { Program program = Program.findProgram(".qtl"); boolean hasQuickTime = program == null ? false : (program.getName().toLowerCase().indexOf("quicktime") != -1); pi.getIPC().invoke("setQuickTimeAvailable", new Object[] {new Boolean(hasQuickTime)}); Object url = pi.getIPC().invoke("getContentURL", new Object[] {dl}); if (url instanceof String) { return (String) url; } } catch (Throwable e) { Logger.log( new LogEvent(LogIDs.UI3, LogEvent.LT_WARNING, "IPC to media server plugin failed", e)); } return null; }
protected void writeStats() { synchronized (this) { if (!config_enabled) { return; } int period = config_period; long now = SystemTime.getMonotonousTime() / 1000; // if we have a 1 second period then now-last-write_time will often be 0 (due to the // rounding of SystemTime) and the stats won't be written - hence the check against // (period-1). Its only if (now - last_write_time < (period - 1)) { return; } last_write_time = now; try { String dir = config_dir; dir = dir.trim(); if (dir.length() == 0) { dir = File.separator; } String file_name = dir; if (!file_name.endsWith(File.separator)) { file_name = file_name + File.separator; } String file = config_file; if (file.trim().length() == 0) { file = DEFAULT_STATS_FILE_NAME; } file_name += file; if (Logger.isEnabled()) Logger.log(new LogEvent(LOGID, "Stats Logged to '" + file_name + "'")); new StatsWriterImpl(core).write(file_name); } catch (Throwable e) { Logger.log(new LogEvent(LOGID, "Stats Logging fails", e)); } } }
public TRTrackerServerUDP(String _name, int _port, boolean _start_up_ready) { super(_name, _start_up_ready); port = _port; thread_pool = new ThreadPool("TrackerServer:UDP:" + port, THREAD_POOL_SIZE); try { InetAddress bind_ip = NetworkAdmin.getSingleton().getSingleHomedServiceBindAddress(); InetSocketAddress address; DatagramSocket socket; if (bind_ip == null) { address = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), port); socket = new DatagramSocket(port); } else { current_bind_ip = bind_ip; address = new InetSocketAddress(bind_ip, port); socket = new DatagramSocket(address); } socket.setReuseAddress(true); dg_socket = socket; final InetSocketAddress f_address = address; Thread recv_thread = new AEThread("TRTrackerServerUDP:recv.loop") { public void runSupport() { recvLoop(dg_socket, f_address); } }; recv_thread.setDaemon(true); recv_thread.start(); Logger.log(new LogEvent(LOGID, "TRTrackerServerUDP: recv established on port " + port)); } catch (Throwable e) { Logger.log( new LogEvent( LOGID, "TRTrackerServerUDP: " + "DatagramSocket bind failed on port " + port, e)); } }
@Override public DirectByteBuffer[] getData() { try { if (buffer == null) { if (msg_type == REQUEST_MESSAGE_TYPE_ID) { Map<Object, Object> map = new HashMap<Object, Object>(); map.put("msg_type", msg_type); map.put("piece", piece); buffer = MessagingUtil.convertPayloadToBencodedByteStream( map, DirectByteBuffer.AL_MSG_UT_METADATA); } else if (msg_type == DATA_MESSAGE_TYPE_ID) { Map<Object, Object> map = new HashMap<Object, Object>(); map.put("msg_type", msg_type); map.put("piece", piece); map.put("total_size", total_size); byte[] mapPayload = BEncoder.encode(map); buffer = DirectByteBufferPool.getBuffer( DirectByteBuffer.AL_MSG_UT_METADATA, mapPayload.length + metadata.length); buffer.put(DirectByteBuffer.SS_MSG, mapPayload); buffer.put(DirectByteBuffer.SS_MSG, metadata); buffer.flip(DirectByteBuffer.SS_MSG); } else if (msg_type == REJECT_MESSAGE_TYPE_ID) { Map<Object, Object> map = new HashMap<Object, Object>(); map.put("msg_type", msg_type); map.put("piece", piece); buffer = MessagingUtil.convertPayloadToBencodedByteStream( map, DirectByteBuffer.AL_MSG_UT_METADATA); } else { if (Logger.isEnabled()) { Logger.log( new LogEvent( LOGID, LogEvent.LT_ERROR, "METADATA (UT): No valid msg_type=" + msg_type)); } return null; } } return new DirectByteBuffer[] {buffer}; } catch (Throwable e) { // what is the best way to handle this error? if (Logger.isEnabled()) { Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR, "METADATA (UT)", e)); } return new DirectByteBuffer[0]; } }
protected void forceStop( final TRTrackerBTAnnouncerImpl announcer, final String[] networks, final URL url) { if (Logger.isEnabled()) { Logger.log( new LogEvent(getTorrent(), LOGID, "Force stopping " + url + " as private torrent")); } new AEThread2("TRMux:fs", true) { public void run() { try { TRTrackerBTAnnouncerImpl an = new TRTrackerBTAnnouncerImpl( getTorrent(), new TOTorrentAnnounceURLSet[0], networks, true, getHelper()); an.cloneFrom(announcer); an.setTrackerURL(url); an.stop(false); an.destroy(); } catch (Throwable e) { } } }.start(); }
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(); }
/** Allocate and return a new direct ByteBuffer. */ private ByteBuffer allocateNewBuffer(final int _size) { try { return ByteBuffer.allocateDirect(_size); } catch (OutOfMemoryError e) { // Debug.out("Running garbage collector..."); clearBufferPools(); runGarbageCollection(); try { return ByteBuffer.allocateDirect(_size); } catch (OutOfMemoryError ex) { String msg = "Memory allocation failed: Out of direct memory space.\n" + "To fix: Use the -XX:MaxDirectMemorySize=512m command line option,\n" + "or upgrade your Java JRE to version 1.4.2_05 or 1.5 series or newer."; Debug.out(msg); Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_ERROR, msg)); printInUse(true); throw (ex); } } }
public Object setProperty(String str, String val) { // if its us then we probably know what we're doing :P if (!(plugin.getClass().getName().startsWith("org.gudy") || plugin.getClass().getName().startsWith("com.aelitis."))) { if (str.equalsIgnoreCase("plugin.id") || str.equalsIgnoreCase("plugin.version")) { if (org.gudy.azureus2.core3.logging.Logger.isEnabled()) org.gudy.azureus2.core3.logging.Logger.log( new LogEvent( LOGID, LogEvent.LT_WARNING, "Plugin '" + getPluginName() + "' tried to set property '" + str + "' - action ignored")); return (null); } } return (super.setProperty(str, val)); }
public void failed(String licence_key, PluginException error) { if (alreadyFailing) { return; } alreadyFailing = true; UIFunctionsManager.getUIFunctions() .promptUser( MessageText.getString("dlg.auth.install.failed.title"), MessageText.getString( "dlg.auth.install.failed.text", new String[] {licence_key, Debug.getNestedExceptionMessage(error)}), new String[] {MessageText.getString("Button.ok")}, 0, null, null, false, 0, new UserPrompterResultListener() { public void prompterClosed(int result) { alreadyFailing = false; } }); Logger.log(new LogAlert(true, "Error while installing " + licence_key, error)); box.close(0); licence.removeInstallationListener(this); }
public Object put(Object key, Object value) { // if its us then we probably know what we're doing :P if (!(plugin.getClass().getName().startsWith("org.gudy") || plugin.getClass().getName().startsWith("com.aelitis."))) { if ((!initialising) && key instanceof String) { String k_str = (String) key; if (k_str.equalsIgnoreCase("plugin.id") || k_str.equalsIgnoreCase("plugin.version")) { if (org.gudy.azureus2.core3.logging.Logger.isEnabled()) org.gudy.azureus2.core3.logging.Logger.log( new LogEvent( LOGID, LogEvent.LT_WARNING, "Plugin '" + getPluginName() + "' tried to set property '" + k_str + "' - action ignored")); return (null); } } } return (super.put(key, value)); }
/** * Perform the actual version check by connecting to the version server. * * @param data_to_send version message * @return version reply * @throws Exception if the server check connection fails */ private Map performVersionCheck( Map data_to_send, boolean use_az_message, boolean use_http, boolean v6) throws Exception { Exception error = null; Map reply = null; if (use_http) { try { reply = executeHTTP(data_to_send, v6); reply.put("protocol_used", "HTTP"); error = null; } catch (IOException e) { error = e; } catch (Exception e) { Debug.printStackTrace(e); error = e; } } if (reply == null && use_az_message) { try { reply = executeAZMessage(data_to_send, v6); reply.put("protocol_used", "AZMSG"); } catch (IOException e) { error = e; } catch (Exception e) { Debug.printStackTrace(e); error = e; } } if (error != null) { throw (error); } if (Logger.isEnabled()) Logger.log( new LogEvent( LOGID, "VersionCheckClient server " + "version check successful. Received " + reply.size() + " reply keys.")); if (v6) { last_check_time_v6 = SystemTime.getCurrentTime(); } else { last_check_time_v4 = SystemTime.getCurrentTime(); } return reply; }
// @see com.aelitis.azureus.ui.UIFunctions#refreshLanguage() public void refreshLanguage() { try { mainWindow.setSelectedLanguageItem(); } catch (Exception e) { Logger.log(new LogEvent(LOGID, "refreshLanguage", e)); } }
// @see com.aelitis.azureus.ui.UIFunctions#dispose(boolean, boolean) public boolean dispose(boolean for_restart, boolean close_already_in_progress) { try { return mainWindow.dispose(for_restart, close_already_in_progress); } catch (Exception e) { Logger.log(new LogEvent(LOGID, "Disposing MainWindow", e)); } return false; }
// @see com.aelitis.azureus.ui.swt.UIFunctionsSWT#removePluginView(java.lang.String) public void removePluginView(String viewID) { try { PluginsMenuHelper.getInstance().removePluginViews(viewID); } catch (Exception e) { Logger.log(new LogEvent(LOGID, "removePluginView", e)); } }
public static void createTrial() { try { Licence[] trial = featman.createLicences(new String[] {"dvdburn_trial"}); } catch (Throwable e) { String s = "Creating Trial: " + Debug.getNestedExceptionMessage(e); new MessageBoxShell("Trial Error", s).open(null); Logger.log(new LogAlert(true, s, e)); } }
// @see com.aelitis.azureus.ui.swt.UIFunctionsSWT#getPluginViews() public UISWTView[] getPluginViews() { try { return new UISWTView[0]; } catch (Exception e) { Logger.log(new LogEvent(LOGID, "getPluginViews", e)); } return new UISWTView[0]; }
// @see com.aelitis.azureus.ui.swt.UIFunctionsSWT#getSWTPluginInstanceImpl() public UISWTInstanceImpl getSWTPluginInstanceImpl() { try { return mainWindow.getUISWTInstanceImpl(); } catch (Exception e) { Logger.log(new LogEvent(LOGID, "getSWTPluginInstanceImpl", e)); } return null; }
/** Start the server and begin accepting incoming connections. */ public void start() { try { this_mon.enter(); if (!isRunning()) { try { server_channel = ServerSocketChannel.open(); server_channel.socket().setReuseAddress(true); if (receive_buffer_size > 0) server_channel.socket().setReceiveBufferSize(receive_buffer_size); server_channel.socket().bind(bind_address, 1024); if (Logger.isEnabled()) Logger.log(new LogEvent(LOGID, "TCP incoming server socket " + bind_address)); AEThread accept_thread = new AEThread("VServerSelector:port" + bind_address.getPort()) { public void runSupport() { accept_loop(); } }; accept_thread.setDaemon(true); accept_thread.start(); } catch (Throwable t) { Debug.out(t); Logger.log( new LogAlert( LogAlert.UNREPEATABLE, "ERROR, unable to bind TCP incoming server socket to " + bind_address.getPort(), t)); } last_accept_time = SystemTime.getCurrentTime(); // init to now } } finally { this_mon.exit(); } }
// @see com.aelitis.azureus.ui.swt.UIFunctionsSWT#closePluginViews(java.lang.String) public void closePluginViews(String sViewID) { try { MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI(); if (mdi == null) { return; } mdi.closeEntry(sViewID); } catch (Exception e) { Logger.log(new LogEvent(LOGID, "closePluginViews", e)); } }
public void succeeded(InetSocketAddress rendezvous, InetSocketAddress target, Map reply) { removeRequest(this, OUTCOME_SUCCESS); if (Logger.isEnabled()) { Logger.log( new LogEvent( LOGID, "NAT traversal for " + initiator.getDisplayName() + "/" + target + " succeeded")); } adapter.success(target); }
protected NetworkSearch(AzureusCore core, String searchText, Browser browser) { PluginInterface pi = core.getPluginManager().getPluginInterfaceByID("azsearch", false); if (pi == null) { Logger.log(new LogEvent(LOGID, "Search plugin not found")); return; } if (!pi.getPluginState().isOperational()) { Logger.log(new LogEvent(LOGID, "Search plugin not operational")); return; } Logger.log(new LogEvent(LOGID, "Search plugin functionality disabled")); /* Map params = new HashMap(); params.put("expression", searchText); params.put("swtbrowser", browser); try { IPCInterface my_ipc = new IPCInterfaceImpl(this); pi.getIPC().invoke("search", new Object[] { my_ipc, params }); } catch (Throwable e) { Logger.log(new LogEvent(LOGID, "IPC to search plugin failed", e)); } */ }
@Override public Message deserialize(DirectByteBuffer data, byte version) throws MessageException { try { int pos = data.position(DirectByteBuffer.SS_MSG); byte[] raw = new byte[data.remaining(DirectByteBuffer.SS_MSG)]; data.get(DirectByteBuffer.SS_MSG, raw); data.position(DirectByteBuffer.SS_MSG, pos); Map<?, ?> map = MessagingUtil.convertBencodedByteStreamToPayload(data, 2, getID()); int msg_type = ((Long) map.get("msg_type")).intValue(); int piece = ((Long) map.get("piece")).intValue(); if (msg_type == REQUEST_MESSAGE_TYPE_ID) { return new UTMetadata(msg_type, piece, 0, null, (byte) 1); } else if (msg_type == DATA_MESSAGE_TYPE_ID) { int total_size = ((Long) map.get("total_size")).intValue(); int offset = BEncoder.encode(map).length; byte[] metadata = new byte[raw.length - offset]; System.arraycopy(raw, offset, metadata, 0, metadata.length); return new UTMetadata(msg_type, piece, total_size, metadata, (byte) 1); } else if (msg_type == REJECT_MESSAGE_TYPE_ID) { return new UTMetadata(msg_type, piece, 0, null, (byte) 1); } // what is the best way to handle this error? if (Logger.isEnabled()) { Logger.log( new LogEvent(LOGID, LogEvent.LT_ERROR, "METADATA (UT): No valid msg_type=" + msg_type)); } return null; } catch (Throwable e) { // what is the best way to handle this error? if (Logger.isEnabled()) { Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR, "METADATA (UT)", e)); } return null; } }
// @see com.aelitis.azureus.ui.swt.UIFunctionsSWT#addPluginView(java.lang.String, // org.gudy.azureus2.ui.swt.plugins.UISWTViewEventListener) public void addPluginView(final String viewID, final UISWTViewEventListener l) { try { Utils.execSWTThread( new AERunnable() { public void runSupport() { PluginsMenuHelper.getInstance().addPluginView(viewID, l); } }); } catch (Exception e) { Logger.log(new LogEvent(LOGID, "addPluginView", e)); } }
// @see com.aelitis.azureus.ui.swt.UIFunctionsSWT#closeDownloadBars() public void closeDownloadBars() { try { Utils.execSWTThreadLater( 0, new AERunnable() { public void runSupport() { MiniBarManager.getManager().closeAll(); } }); } catch (Exception e) { Logger.log(new LogEvent(LOGID, "closeDownloadBars", e)); } }
private Map executeHTTP(Map data_to_send, boolean v6) throws Exception { if (v6 && !enable_v6) { throw (new Exception("IPv6 is disabled")); } String host = getHost(v6, HTTP_SERVER_ADDRESS_V6, HTTP_SERVER_ADDRESS_V4); if (Logger.isEnabled()) Logger.log( new LogEvent( LOGID, "VersionCheckClient retrieving " + "version information from " + host + ":" + HTTP_SERVER_PORT + " via HTTP")); String url_str = "http://" + (v6 ? UrlUtils.convertIPV6Host(host) : host) + (HTTP_SERVER_PORT == 80 ? "" : (":" + HTTP_SERVER_PORT)) + "/version?"; url_str += URLEncoder.encode(new String(BEncoder.encode(data_to_send), "ISO-8859-1"), "ISO-8859-1"); URL url = new URL(url_str); HttpURLConnection url_connection = (HttpURLConnection) url.openConnection(); url_connection.connect(); try { InputStream is = url_connection.getInputStream(); Map reply = BDecoder.decode(new BufferedInputStream(is)); preProcessReply(reply, v6); return (reply); } finally { url_connection.disconnect(); } }
/* (non-Javadoc) * @see com.aelitis.azureus.ui.swt.UIFunctionsSWT#openPluginView(org.gudy.azureus2.ui.swt.pluginsimpl.UISWTViewCore, java.lang.String) */ public void openPluginView(UISWTViewCore view, String name) { try { MultipleDocumentInterfaceSWT mdi = getMDISWT(); if (mdi == null) { return; } if (mdi.createEntryFromView( MultipleDocumentInterface.SIDEBAR_HEADER_PLUGINS, view, name, null, true, true, true) != null) { return; } } catch (Exception e) { Logger.log(new LogEvent(LOGID, "openPluginView", e)); } }
// @see com.aelitis.azureus.ui.UIFunctions#showConfig(java.lang.String) public boolean showConfig(String section) { try { boolean uiClassic = COConfigurationManager.getStringParameter("ui").equals("az2"); if (uiClassic || COConfigurationManager.getBooleanParameter("Show Options In Side Bar")) { openView(SideBar.SIDEBAR_HEADER_PLUGINS, ConfigView.class, null, section, true); } else { ConfigShell.getInstance().open(section); } return true; } catch (Exception e) { Logger.log(new LogEvent(LOGID, "showConfig", e)); } return false; }
protected void recvLoop(DatagramSocket socket, InetSocketAddress address) { long successful_accepts = 0; long failed_accepts = 0; while (!closed) { try { byte[] buf = new byte[PRUDPPacket.MAX_PACKET_SIZE]; DatagramPacket packet = new DatagramPacket(buf, buf.length, address); socket.receive(packet); successful_accepts++; failed_accepts = 0; String ip = packet.getAddress().getHostAddress(); if (!ip_filter.isInRange(ip, "Tracker", null)) { thread_pool.run(new TRTrackerServerProcessorUDP(this, socket, packet)); } } catch (Throwable e) { if (!closed) { failed_accepts++; Logger.log(new LogEvent(LOGID, "TRTrackerServer: receive failed on port " + port, e)); if ((failed_accepts > 100 && successful_accepts == 0) || failed_accepts > 1000) { // looks like its not going to work... // some kind of socket problem Logger.logTextResource( new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_ERROR, "Network.alert.acceptfail"), new String[] {"" + port, "UDP"}); break; } } } } }
public void create( PeerNATInitiator initiator, InetSocketAddress target, PeerNATTraversalAdapter adapter) { boolean bad = false; synchronized (initiators) { if (negative_result_bloom.contains(target.toString().getBytes())) { bad = true; failed_negative_bloom++; } else { LinkedList requests = (LinkedList) initiators.get(initiator); if (requests == null) { // we get here when download stopped at same time // Debug.out( "initiator not found" ); bad = true; } else { PeerNATTraversal traversal = new PeerNATTraversal(initiator, target, adapter); requests.addLast(traversal); pending_requests.addLast(traversal); if (Logger.isEnabled()) { Logger.log( new LogEvent( LOGID, "created NAT traversal for " + initiator.getDisplayName() + "/" + target)); } } } } if (bad) { adapter.failed(); } }
public void requestEnds(boolean ok) { if (DEBUG) { try { Logger.log( new LogEvent( LOGID, "DMRequest end: " + name + ",ok=" + ok + ", time=" + (SystemTime.getCurrentTime() - start_time))); } catch (Throwable e) { } } }