Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

now using *original chat* plugin (just without ui)

  • Loading branch information...
commit 639b88618988c10f0906a8d45161ff64ca6735c1 1 parent 9b2d182
mic authored
Showing with 844 additions and 857 deletions.
  1. +5 −1 blogracy-vuze/pom.xml
  2. +400 −0 blogracy-vuze/src/main/java/com/aelitis/azureus/plugins/chat/ChatPlugin.java
  3. +2 −3 ...cy-vuze/src/main/java/{net/blogracy → com/aelitis/azureus/plugins}/chat/messaging/MessageListener.java
  4. +31 −18 blogracy-vuze/src/main/java/{net/blogracy → com/aelitis/azureus/plugins}/chat/peer/PeerController.java
  5. +115 −159 ...vuze/src/main/java/{net/blogracy → com/aelitis/azureus/plugins}/chat/peer/impl/PeerControllerImpl.java
  6. +68 −42 ...et/blogracy/chat/messaging/impl → com/aelitis/azureus/plugins/chat/peer/impl/messaging}/CMMessage.java
  7. +13 −8 ...et/blogracy/chat/messaging/impl → com/aelitis/azureus/plugins/chat/peer/impl/messaging}/CMNoRoute.java
  8. +13 −9 ...{net/blogracy/chat/messaging/impl → com/aelitis/azureus/plugins/chat/peer/impl/messaging}/CMRoute.java
  9. +2 −3 .../blogracy/chat/messaging/impl → com/aelitis/azureus/plugins/chat/peer/impl/messaging}/ChatMessage.java
  10. 0  blogracy-vuze/src/main/java/{net/blogracy → com/aelitis/azureus/plugins}/chat/resources/channel.torrent
  11. +10 −10 blogracy-vuze/src/main/java/net/blogracy/Blogracy.java
  12. +0 −326 blogracy-vuze/src/main/java/net/blogracy/chat/ChatManager.java
  13. +0 −78 blogracy-vuze/src/main/java/net/blogracy/chat/web/Bridge.java
  14. +0 −167 blogracy-vuze/src/main/java/net/blogracy/chat/web/TextListener.java
  15. +160 −32 blogracy-vuze/src/main/java/net/blogracy/services/ChatService.java
  16. 0  blogracy-vuze/src/main/plugins/chat/channels/channel
  17. +5 −0 blogracy-vuze/src/main/plugins/chat/plugin.properties
  18. +8 −1 blogracy-web/src/main/java/net/blogracy/WebServer.java
  19. +12 −0 blogracy-web/src/main/java/net/blogracy/controller/ChatController.java
View
6 blogracy-vuze/pom.xml
@@ -13,8 +13,12 @@
<directory>src/main/plugins</directory>
<targetPath>../plugins/</targetPath>
</resource>
- <resource>
+ <!--resource>
<directory>src/main/java/net/blogracy/chat/resources</directory>
+ </resource-->
+ <resource>
+ <directory>src/main/java/com/aelitis/azureus/plugins/chat/resources</directory>
+ <targetPath>com/aelitis/azureus/plugins/chat/resources</targetPath>
</resource>
</resources>
<plugins>
View
400 blogracy-vuze/src/main/java/com/aelitis/azureus/plugins/chat/ChatPlugin.java
@@ -0,0 +1,400 @@
+/*
+ * Created on 28 fevr. 2005
+ * Created by Olivier Chalouhi
+ *
+ * Copyright (C) 2004 Aelitis SARL, All rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details ( see the LICENSE file ).
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * AELITIS, SARL au capital de 30,000 euros,
+ * 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
+ */
+package com.aelitis.azureus.plugins.chat;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.*;
+//import org.eclipse.swt.graphics.Image;
+//import org.eclipse.swt.graphics.ImageData;
+import org.gudy.azureus2.plugins.Plugin;
+import org.gudy.azureus2.plugins.PluginInterface;
+import org.gudy.azureus2.plugins.config.ConfigParameter;
+import org.gudy.azureus2.plugins.config.ConfigParameterListener;
+import org.gudy.azureus2.plugins.download.Download;
+import org.gudy.azureus2.plugins.torrent.Torrent;
+import org.gudy.azureus2.plugins.ui.UIInstance;
+import org.gudy.azureus2.plugins.ui.UIManager;
+import org.gudy.azureus2.plugins.ui.UIManagerListener;
+import org.gudy.azureus2.plugins.ui.config.Parameter;
+import org.gudy.azureus2.plugins.ui.config.PluginConfigUIFactory;
+import org.gudy.azureus2.plugins.ui.tables.TableColumn;
+import org.gudy.azureus2.plugins.ui.tables.TableManager;
+import org.gudy.azureus2.plugins.utils.Formatters;
+import org.gudy.azureus2.plugins.utils.LocaleUtilities;
+import org.gudy.azureus2.ui.swt.plugins.UISWTInstance;
+
+import com.aelitis.azureus.plugins.chat.messaging.MessageListener;
+import com.aelitis.azureus.plugins.chat.peer.PeerController;
+import com.aelitis.azureus.plugins.chat.peer.impl.PeerControllerImpl;
+//import com.aelitis.azureus.plugins.chat.ui.ChatPanelsManager;
+//import com.aelitis.azureus.plugins.chat.ui.MyTorrentsActivityIndicator;
+
+
+public class ChatPlugin implements Plugin, MessageListener, ConfigParameterListener {
+
+ public static final String ID_VIEW_TITLE = "chat.config.title";
+
+ private static final String COLUMN_ID_CHAT_ACTIVITY = "ChatActivityColumn";
+
+ private PluginInterface plugin_interface;
+// private UISWTInstance swtui;
+ private PeerController controller;
+// private LoggerChannel logger;
+
+ //Listeners for the UI
+ private ArrayList listeners;
+ // 1 to 1 relationship with listeners (cheap bidi map)
+ private ArrayList listenersDownload;
+
+ private String nick;
+ private boolean active;
+
+// private String resInactive = "com/aelitis/azureus/plugins/chat/ui/icons/red.png";
+// public Image imgInactive;
+
+// private String resActive = "com/aelitis/azureus/plugins/chat/ui/icons/dgreen.png";
+// public Image imgActive;
+
+// private String resActivity = "com/aelitis/azureus/plugins/chat/ui/icons/lgreen.png";
+// public Image imgActivity;
+
+
+ private String resTorrent = "com/aelitis/azureus/plugins/chat/resources/channel.torrent";
+ public Torrent genericTorrent;
+
+ private static Formatters formatters = null;
+
+ public void
+ initialize(
+ PluginInterface _pi )
+ {
+ plugin_interface = _pi;
+
+ formatters = plugin_interface.getUtilities().getFormatters();
+
+ genericTorrent = loadTorrent(resTorrent);
+
+ PluginConfigUIFactory factory = plugin_interface.getPluginConfigUIFactory();
+ Parameter parameters[] = new Parameter[2];
+ parameters[0] = factory.createBooleanParameter("enable","chat.config.enable",true);
+ parameters[1] = factory.createStringParameter("nick","chat.config.nick","");
+ parameters[1].addConfigParameterListener(this);
+ plugin_interface.addConfigUIParameters(parameters,ID_VIEW_TITLE);
+
+ nick = plugin_interface.getPluginconfig().getPluginStringParameter("nick","Guest" + (int) (Math.random() * 100000));
+ active = plugin_interface.getPluginconfig().getPluginBooleanParameter("enable",true);
+
+ if(active) {
+ listeners = new ArrayList();
+ listenersDownload = new ArrayList();
+
+ controller = new PeerControllerImpl(this);
+ controller.addMessageListener(this);
+ controller.initialize();
+ controller.startPeerProcessing();
+
+/* plugin_interface.getUIManager().addUIListener(
+ new UIManagerListener()
+ {
+ public void
+ UIAttached(
+ UIInstance instance )
+ {
+ if ( instance instanceof UISWTInstance ){
+
+ swtui = (UISWTInstance)instance;
+
+ imgInactive = loadImage(resInactive);
+ imgActive = loadImage(resActive);
+ imgActivity = loadImage(resActivity);
+
+ ChatPanelsManager cpm = new ChatPanelsManager(ChatPlugin.this);
+ swtui.addView(UISWTInstance.VIEW_MYTORRENTS, "Chat", cpm);
+ swtui.addView(UISWTInstance.VIEW_MAIN, "CreateChat", cpm);
+
+ addMyTorrentsColumn();
+ }
+ }
+
+ public void
+ UIDetached(
+ UIInstance instance )
+ {
+
+ }
+ });
+ */
+
+ }
+ }
+
+ public PluginInterface getPluginInterface() {
+ return plugin_interface;
+ }
+
+ public LocaleUtilities getLocaleUtils() {
+ return plugin_interface.getUtilities().getLocaleUtilities();
+ }
+
+ public String getTitle() {
+ LocaleUtilities localeUtils = getLocaleUtils();
+ return localeUtils.getLocalisedMessageText(ChatPlugin.ID_VIEW_TITLE);
+ }
+
+ public void addMessageListener(MessageListener listener, Download download) {
+ synchronized (listeners) {
+ listeners.add(listener);
+ listenersDownload.add(download);
+ }
+
+ listener.downloadAdded(download);
+ if(controller.isDownloadActive(download)) {
+ listener.downloadActive(download);
+ } else {
+ listener.downloadInactive(download);
+ }
+ }
+
+ public void removeMessageListener(MessageListener listener) {
+ synchronized (listeners) {
+ int idx = listeners.indexOf(listener);
+ if (idx >= 0) {
+ listenersDownload.remove(idx);
+ listeners.remove(listener);
+ }
+ }
+
+ }
+
+ public void downloadAdded(Download download) {
+ synchronized (listeners) {
+ for (int i = 0; i < listenersDownload.size(); i++) {
+ Download lDownload = (Download) listenersDownload.get(i);
+ if (download.equals(lDownload)) {
+ MessageListener listener = (MessageListener) listeners.get(i);
+ listener.downloadAdded(download);
+ }
+ }
+ }
+ }
+
+ public void downloadRemoved(Download download) {
+ synchronized (listeners) {
+ for (int i = 0; i < listenersDownload.size(); i++) {
+ Download lDownload = (Download) listenersDownload.get(i);
+ if (download.equals(lDownload)) {
+ MessageListener listener = (MessageListener) listeners.get(i);
+ listener.downloadRemoved(download);
+ }
+ }
+ }
+ }
+
+ public void downloadActive(Download download) {
+ synchronized (listeners) {
+ for (int i = 0; i < listenersDownload.size(); i++) {
+ Download lDownload = (Download) listenersDownload.get(i);
+ if (download.equals(lDownload)) {
+ MessageListener listener = (MessageListener) listeners.get(i);
+ listener.downloadActive(download);
+ }
+ }
+ }
+ }
+
+ public void downloadInactive(Download download) {
+ synchronized (listeners) {
+ for (int i = 0; i < listenersDownload.size(); i++) {
+ Download lDownload = (Download) listenersDownload.get(i);
+ if (download.equals(lDownload)) {
+ MessageListener listener = (MessageListener) listeners.get(i);
+ listener.downloadInactive(download);
+ }
+ }
+ }
+ }
+
+ public void messageReceived(Download download,byte[] sender,String nick,String text) {
+ synchronized (listeners) {
+ for (int i = 0; i < listenersDownload.size(); i++) {
+ Download lDownload = (Download) listenersDownload.get(i);
+ if (download.equals(lDownload)) {
+ MessageListener listener = (MessageListener) listeners.get(i);
+ listener.messageReceived(download, sender, nick, text);
+ }
+ }
+ }
+ }
+
+ public void sendMessage(Download download,String text) {
+ if (download == null)
+ return;
+
+ byte[] peerID = download.getDownloadPeerId();
+ if(peerID != null) {
+ controller.sendMessage(download,peerID,nick,text);
+ } else {
+ messageReceived(download,null,"System","/me : Torrent isn't running, message can't be delivered");
+ }
+ }
+
+ public void configParameterChanged(ConfigParameter param) {
+ nick = plugin_interface.getPluginconfig().getPluginStringParameter("nick","Guest" + (int) (Math.random() * 100000));
+ if(nick.startsWith("System") || nick.startsWith("system")) {
+ nick = "Guest" + (int) (Math.random() * 100000);
+ }
+ }
+
+// private Image loadImage(String res) {
+// InputStream is = this.getClass().getClassLoader().getResourceAsStream(res);
+// if (is != null) {
+// ImageData imageData = new ImageData(is);
+// return new Image(swtui.getDisplay(), imageData);
+// }
+// return null;
+// }
+
+ private Torrent loadTorrent(String res) {
+ InputStream is = this.getClass().getClassLoader().getResourceAsStream(res);
+ if (is != null) {
+ try {
+ return plugin_interface.getTorrentManager().createFromBEncodedInputStream(is);
+ } catch(Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ }
+ return null;
+ }
+
+/* private void addMyTorrentsColumn() {
+
+ MyTorrentsActivityIndicator activityIndicator = new MyTorrentsActivityIndicator(this, controller, swtui);
+
+ addIndicatorToTable(TableManager.TABLE_MYTORRENTS_INCOMPLETE,activityIndicator);
+ addIndicatorToTable(TableManager.TABLE_MYTORRENTS_COMPLETE,activityIndicator);
+ }
+
+ private void addIndicatorToTable(String tableID,MyTorrentsActivityIndicator activityIndicator) {
+ UIManager uiManager = plugin_interface.getUIManager();
+ TableManager tableManager = uiManager.getTableManager();
+ TableColumn activityColumn = tableManager.createColumn(tableID, COLUMN_ID_CHAT_ACTIVITY);
+
+ activityColumn.setAlignment(TableColumn.ALIGN_CENTER);
+ activityColumn.setPosition(2);
+ activityColumn.setRefreshInterval(TableColumn.INTERVAL_GRAPHIC);
+ activityColumn.setType(TableColumn.TYPE_GRAPHIC);
+
+ activityColumn.addCellRefreshListener(activityIndicator);
+
+ tableManager.addColumn(activityColumn);
+ }
+*/
+
+ /**
+ * @return Returns the nick.
+ */
+ public String getNick() {
+ return nick;
+ }
+
+
+ /**
+ * @param nick The nick to set.
+ */
+ public void setNick(String nick) {
+ this.nick = nick;
+ plugin_interface.getPluginconfig().setPluginParameter("nick",nick);
+ }
+
+ public void addIgnore(String nick) {
+ if(controller != null) controller.ignore(nick);
+ }
+
+ public Torrent getChannelTorrent(String channelName) {
+ try {
+ Map genericMap = genericTorrent.writeToMap();
+ Map info = (Map) genericMap.get("info");
+ info.put("name",channelName.getBytes());
+ info.put("name.utf8",channelName.getBytes("UTF-8"));
+ genericMap.put("info",info);
+
+ byte[] channelTorrent = plugin_interface.getUtilities().getFormatters().bEncode(genericMap);
+
+ Torrent result = plugin_interface.getTorrentManager().createFromBEncodedData(channelTorrent);
+ result.setAnnounceURL(new URL("dht://chat.dht/announce"));
+ return result;
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public Download addChannel(String channelName) {
+ Torrent torrent = getChannelTorrent(channelName);
+ String savePath = plugin_interface.getPluginDirectoryName();
+ try {
+ File saveDir = new File(savePath,"channels" + File.separator );
+ saveDir.mkdir();
+ Download dl = plugin_interface.getDownloadManager().addDownload(torrent,null,saveDir);
+ dl.setForceStart(true);
+ return dl;
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+// public UISWTInstance getSWTUI() {
+// return swtui;
+// }
+
+ public static byte[] bEncode(Map map) {
+ if (formatters == null) {
+ return new byte[0];
+ }
+ try {
+ return formatters.bEncode(map);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return new byte[0];
+ }
+ }
+
+ public static Map bDecode(byte[] bytes) {
+ if (formatters == null) {
+ return new HashMap();
+ }
+ try {
+ return formatters.bDecode(bytes);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return new HashMap();
+ }
+ }
+}
View
5 .../net/blogracy/chat/messaging/MessageListener.java → ...ureus/plugins/chat/messaging/MessageListener.java
@@ -1,5 +1,5 @@
/*
- * Created on 28 fevr. 2005
+ * Created on 28 feb. 2005
* Created by Olivier Chalouhi
*
* Copyright (C) 2004 Aelitis SARL, All rights Reserved
@@ -20,8 +20,7 @@
* AELITIS, SARL au capital de 30,000 euros,
* 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
*/
-
-package net.blogracy.chat.messaging;
+package com.aelitis.azureus.plugins.chat.messaging;
import org.gudy.azureus2.plugins.download.Download;
View
49 ...n/java/net/blogracy/chat/peer/PeerController.java → ...tis/azureus/plugins/chat/peer/PeerController.java
@@ -1,5 +1,5 @@
/*
- * Created on Feb 24, 2005
+ * Created on Feb. 24, 2005
* Created by Alon Rohter
* Copyright (C) 2004-2005 Aelitis, All Rights Reserved.
*
@@ -19,38 +19,51 @@
* 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
*
*/
-package net.blogracy.chat.peer;
+
+package com.aelitis.azureus.plugins.chat.peer;
import org.gudy.azureus2.plugins.download.Download;
-import net.blogracy.chat.messaging.MessageListener;
+import com.aelitis.azureus.plugins.chat.messaging.MessageListener;
+/**
+ *
+ */
public interface PeerController {
- //Adds a message listener.
+ /**
+ * Adds a message listener.
+ */
public void addMessageListener(MessageListener listener);
-
- //Initialize.
+
+ /**
+ * Initialize.
+ */
public void initialize();
- //Start Chat cache exchange handling.
+ /**
+ * Start Chat cache exchange handling.
+ */
public void startPeerProcessing();
- //create the Bridge
- public void addBridge(Download download, String channelName);
- //remove the Bridge
- public void removeBridge(String channelName);
-
- //Sends a message to all channels
+ /**
+ * Sends a message to all channels
+ */
public void sendMessage(String nick, String message);
-
- //Sends a message
+
+
+ /**
+ * Sends a message
+ */
public void sendMessage(Download download,byte[] peerID, String nick, String message);
- //Tells if a download is active or not
+ /**
+ * Tells if a download is active or not
+ */
public boolean isDownloadActive(Download download);
- //Ignores a peer by Nick, will also find out the peerID and ignore that ID.
+ /**
+ * Ignores a peer by Nick, will also find out the peerID and ignore that ID.
+ */
public void ignore(String nick);
}
-
View
274 ...t/blogracy/chat/peer/impl/PeerControllerImpl.java → ...us/plugins/chat/peer/impl/PeerControllerImpl.java
@@ -3,8 +3,6 @@
* Created by Alon Rohter
* Copyright (C) 2004-2005 Aelitis, All Rights Reserved.
*
- * Furtherly modified by Andrea Vida, University of Parma (Italy).
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
@@ -16,9 +14,14 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * AELITIS, SARL au capital de 30,000 euros
+ * 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
*
*/
-package net.blogracy.chat.peer.impl;
+
+package com.aelitis.azureus.plugins.chat.peer.impl;
+
import java.util.ArrayList;
import java.util.HashMap;
@@ -26,29 +29,27 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-
import org.gudy.azureus2.plugins.PluginInterface;
import org.gudy.azureus2.plugins.download.*;
import org.gudy.azureus2.plugins.messaging.*;
import org.gudy.azureus2.plugins.network.IncomingMessageQueueListener;
import org.gudy.azureus2.plugins.peers.*;
+import com.aelitis.azureus.plugins.chat.ChatPlugin;
+import com.aelitis.azureus.plugins.chat.messaging.MessageListener;
+import com.aelitis.azureus.plugins.chat.peer.PeerController;
+import com.aelitis.azureus.plugins.chat.peer.impl.messaging.CMMessage;
+import com.aelitis.azureus.plugins.chat.peer.impl.messaging.CMNoRoute;
+import com.aelitis.azureus.plugins.chat.peer.impl.messaging.CMRoute;
+import com.aelitis.azureus.plugins.chat.peer.impl.messaging.ChatMessage;
-import net.blogracy.chat.ChatManager;
-import net.blogracy.chat.messaging.MessageListener;
-import net.blogracy.chat.peer.PeerController;
-import net.blogracy.chat.messaging.impl.CMMessage;
-import net.blogracy.chat.messaging.impl.CMNoRoute;
-import net.blogracy.chat.messaging.impl.CMRoute;
-import net.blogracy.chat.messaging.impl.ChatMessage;
-
-import net.blogracy.chat.web.Bridge;
-
-@SuppressWarnings("rawtypes")
+/**
+ *
+ */
public class PeerControllerImpl implements PeerController {
private final int NB_MAX_HOPS = 10;
- private final ChatManager chat_plugin;
+ private final ChatPlugin chat_plugin;
private Map downloadsToLastMessages;
private static final int NB_LAST_MESSAGES = 512;
@@ -70,27 +71,21 @@
private List nickIgnores;
private List idIgnores;
- //Bridge
- private Bridge[] bridge;
- private static final int MAX_CHANNELS_NUMBER = 70;
- private int bridgeCounter = 0;
-
-
- //private String username;
-
- public PeerControllerImpl(ChatManager plugin, String username) {
+ public PeerControllerImpl( ChatPlugin plugin ) {
this.chat_plugin = plugin;
- //this.username = username;
downloadsToLastMessages = new HashMap();
downloadsToRouters = new HashMap();
downloadsToRoutePeer = new HashMap();
downloadsToPeers = new HashMap();
+
listeners = new ArrayList();
+
nickIgnores = new LinkedList();
idIgnores = new LinkedList();
- bridge = new Bridge[MAX_CHANNELS_NUMBER];
}
-
+
+
+
public void initialize() {
try {
chat_plugin.getPluginInterface().getMessageManager().registerMessageType( new CMMessage( "",new byte[20],-1, "" ) );
@@ -100,96 +95,93 @@ public void initialize() {
catch( MessageException e ) { e.printStackTrace(); }
}
- public void addBridge(Download download, String channelName){
- if (bridgeCounter<MAX_CHANNELS_NUMBER){
- bridge[bridgeCounter] = new Bridge(chat_plugin,download,channelName);
- bridgeCounter++;
- }
- else System.out.println("Max channels number reached");
- }
- public void removeBridge(String channelName){
- int index = findBridgebyChannel(channelName);
- bridge[index].finalize();
- }
+
public void startPeerProcessing() {
PluginInterface pi = chat_plugin.getPluginInterface();
pi.getDownloadManager().addListener(new DownloadManagerListener() {
-
- @SuppressWarnings("unchecked")
- public void downloadAdded( Download dwnld ) {
- downloadsToLastMessages.put(dwnld, new LinkedList());
- downloadsToRoutePeer.put(dwnld, new LinkedList());
- downloadsToRouters.put(dwnld,new ArrayList());
- downloadsToPeers.put(dwnld,new ArrayList());
+
+ public void downloadAdded( Download dwnld ) {
- notifyListenersOfDownloadAdded(dwnld);
- notifyListenersOfDownloadInactive(dwnld);
- }
+ downloadsToLastMessages.put(dwnld, new LinkedList());
+ downloadsToRoutePeer.put(dwnld, new LinkedList());
+ downloadsToRouters.put(dwnld,new ArrayList());
+ downloadsToPeers.put(dwnld,new ArrayList());
+
+ notifyListenersOfDownloadAdded(dwnld);
+ notifyListenersOfDownloadInactive(dwnld);
+ }
- public void downloadRemoved( Download download ) {
- notifyListenersOfDownloadRemoved(download);
+ public void downloadRemoved( Download download ) {
+
+ notifyListenersOfDownloadRemoved(download);
- downloadsToLastMessages.remove(download);
- downloadsToPeers.remove(download);
- downloadsToRoutePeer.remove(download);
- downloadsToRouters.remove(download);
+ downloadsToLastMessages.remove(download);
+ downloadsToPeers.remove(download);
+ downloadsToRoutePeer.remove(download);
+ downloadsToRouters.remove(download);
}
});
- pi.getMessageManager().locateCompatiblePeers(pi,new CMMessage("",new byte[20],0,""),new MessageManagerListener() {
- public void compatiblePeerFound(Download download,Peer peer,Message message) {
- messagingPeerFound(download,peer);
- }
+ pi.getMessageManager().locateCompatiblePeers( pi, new CMMessage("",new byte[20],0,""), new MessageManagerListener() {
+ public void compatiblePeerFound(Download download, Peer peer, Message message) {
+ messagingPeerFound( download, peer );
+ }
- public void peerRemoved(Download download, Peer peer) {
- notifyOfPeerRemoval(download,peer);
- }
+ public void peerRemoved(Download download, Peer peer) {
+ notifyOfPeerRemoval( download, peer );
+ }
});
}
- @SuppressWarnings("unchecked")
- private void messagingPeerFound(final Download download,final Peer peer) {
+
+
+
+
+ private void messagingPeerFound( final Download download, final Peer peer ) {
//Add the peer to the list of peers
List peers = (List) downloadsToPeers.get(download);
if(peers != null) {
- synchronized(peers) {
- if(peers.size() == 0) {notifyListenersOfDownloadActive(download);}
- peers.add(peer);
+ synchronized(peers) {
+ if(peers.size() == 0) {
+ notifyListenersOfDownloadActive(download);
}
+ peers.add(peer);
+ }
}
//register for incoming JPC message handling
- peer.getConnection().getIncomingMessageQueue().registerListener(new IncomingMessageQueueListener() {
- public boolean messageReceived( Message message ) {
+ peer.getConnection().getIncomingMessageQueue().registerListener( new IncomingMessageQueueListener() {
+ public boolean messageReceived( Message message ) {
- if( message.getID().equals( ChatMessage.ID_CHAT_MESSAGE ) ) {
- //System.out.println( "Received [" +message.getDescription()+ "] message from peer [" +peer.getClient()+ " @" +peer.getIp()+ ":" +peer.getPort()+ "]" );
- CMMessage msg = (CMMessage)message;
- processMessage(download,peer,msg);
- return true;
- }
+ if( message.getID().equals( ChatMessage.ID_CHAT_MESSAGE ) ) {
+ //System.out.println( "Received [" +message.getDescription()+ "] message from peer [" +peer.getClient()+ " @" +peer.getIp()+ ":" +peer.getPort()+ "]" );
+ CMMessage msg = (CMMessage)message;
+ processMessage(download,peer,msg);
+ return true;
+ }
- if( message.getID().equals( ChatMessage.ID_CHAT_NO_ROUTE ) ) {
- //System.out.println( "Received [" +message.getDescription()+ "] message from peer [" +peer.getClient()+ " @" +peer.getIp()+ ":" +peer.getPort()+ "]" );
- processNoRoute(download,peer);
- return true;
- }
+ if( message.getID().equals( ChatMessage.ID_CHAT_NO_ROUTE ) ) {
+ //System.out.println( "Received [" +message.getDescription()+ "] message from peer [" +peer.getClient()+ " @" +peer.getIp()+ ":" +peer.getPort()+ "]" );
+ processNoRoute(download,peer);
+ return true;
+ }
- if( message.getID().equals( ChatMessage.ID_CHAT_ROUTE ) ) {
- //System.out.println( "Received [" +message.getDescription()+ "] message from peer [" +peer.getClient()+ " @" +peer.getIp()+ ":" +peer.getPort()+ "]" );
- //CMRoute route = (CMRoute)message;
- processRoute(download,peer);
- return true;
- }
-
- return false;
+ if( message.getID().equals( ChatMessage.ID_CHAT_ROUTE ) ) {
+ //System.out.println( "Received [" +message.getDescription()+ "] message from peer [" +peer.getClient()+ " @" +peer.getIp()+ ":" +peer.getPort()+ "]" );
+ //CMRoute route = (CMRoute)message;
+ processRoute(download,peer);
+ return true;
}
- public void bytesReceived(int byte_count) {/*nothing*/}});
+ return false;
+ }
+
+ public void bytesReceived( int byte_count ) { /*nothing*/ }
+ });
//Peers start as "non routing", ie none of the 2 newly connected peers should
@@ -218,7 +210,6 @@ public boolean messageReceived( Message message ) {
- @SuppressWarnings("unchecked")
private void notifyOfPeerRemoval( final Download download, final Peer peer ) {
List routePeers = (List) downloadsToRoutePeer.get(download);
if(routePeers != null) {
@@ -256,14 +247,12 @@ private void notifyOfPeerRemoval( final Download download, final Peer peer ) {
}
}
- @SuppressWarnings("unchecked")
- private void processMessage(Download download,Peer peer,CMMessage message) {
+ private void processMessage(Download download,Peer peer,CMMessage message) {
// 1. Test if the message has already been processed
- int messageID = message.getMessageID();
- List lastMessages = (List) downloadsToLastMessages.get(download);
+ int messageID = message.getMessageID();
- int bridgeIndex = findBridgebyDownload(download);
+ List lastMessages = (List) downloadsToLastMessages.get(download);
synchronized(lastMessages) {
if(lastMessages.contains(new Integer(messageID))) {
@@ -275,7 +264,7 @@ private void processMessage(Download download,Peer peer,CMMessage message) {
if(lastMessages.size() > NB_LAST_MESSAGES) lastMessages.remove(lastMessages.size() - 1);
- //New message
+ //New message :)
byte[] peerID = message.getSenderID();
String nick = message.getSenderNick();
@@ -299,15 +288,11 @@ private void processMessage(Download download,Peer peer,CMMessage message) {
//Check if Nick doesn't override with our nick
if(!compareIDs(download.getDownloadPeerId(),peerID) && nick.equals(chat_plugin.getNick())) {
- sendMessage(download,download.getDownloadPeerId(),"System","/me : Multiple peers are using the nick " + nick);
- if (bridgeIndex >= 0) bridge[bridgeIndex].sysMsg("Multiple peers are using the nick " + nick);
- else System.out.println("error finding bridge by download");
+ sendMessage(download,download.getDownloadPeerId(),"System","/me : Multiple peers are using the nick " + nick);
}
- String text = message.getText();
+ String text = message.getText();
notifyListenersOfMessageReceived(download,peerID,nick,text);
- if (bridgeIndex >= 0) bridge[bridgeIndex].inMsg(text,nick);
- else System.out.println("error finding bridge by download");
//Dispatch the message
List routePeers = (List) downloadsToRoutePeer.get(download);
@@ -337,7 +322,6 @@ private synchronized void processNoRoute(Download download,Peer peer) {
}
}
- @SuppressWarnings("unchecked")
private synchronized void processRoute(Download download,Peer peer) {
List routePeers = (List) downloadsToRoutePeer.get(download);
synchronized (routePeers) {
@@ -347,7 +331,6 @@ private synchronized void processRoute(Download download,Peer peer) {
}
}
- @SuppressWarnings("unchecked")
public void addMessageListener(MessageListener listener) {
synchronized (listeners) {
listeners.add(listener);
@@ -406,7 +389,7 @@ private void notifyListenersOfDownloadInactive(Download download) {
}
public void sendMessage(String nick,String message) {
- if(downloadsToPeers == null) return;
+ if(downloadsToPeers == null) return;
synchronized (downloadsToPeers) {
Iterator iter = downloadsToPeers.keySet().iterator();
@@ -420,75 +403,48 @@ public void sendMessage(String nick,String message) {
private String oldNick;
public void sendMessage(Download download,byte[] peerID, String nick, String message) {
- sendMessage(download,peerID,nick,message,true);
+ sendMessage(download,peerID,nick,message,true);
}
public void sendMessage(Download download,byte[] peerID, String nick, String message,boolean checkForNick) {
- int bridgeIndex = findBridgebyDownload(download);
-
- if(checkForNick && ! nick.equals("System") && oldNick != null && ! oldNick.equals(nick)) {
- sendMessage(download,peerID,"System","/me : " + oldNick + " is now known as " + nick);
- if(bridgeIndex >= 0) bridge[bridgeIndex].sysMsg(oldNick + " is now known as " + nick);
- else System.out.println("error finding bridge by download");
- }
- if(! nick.equals("System")) oldNick = nick;
+ if(checkForNick && ! nick.equals("System") && oldNick != null && ! oldNick.equals(nick)) {
+ sendMessage(download,peerID,"System","/me : " + oldNick + " is now known as " + nick);
+ }
+ if(! nick.equals("System")) oldNick = nick;
- notifyListenersOfMessageReceived(download,download.getDownloadPeerId(),nick,message);
- List routePeers = (List) downloadsToPeers.get(download);
- if(routePeers != null) {
- synchronized (routePeers) {
- CMMessage msg = new CMMessage(nick,peerID,0,message);
- for(Iterator iter = routePeers.iterator(); iter.hasNext() ;) {
- Peer peerToSendMsg = (Peer) iter.next();
- CMMessage msgToSend = new CMMessage(msg.getMessageID(),nick,peerID,0,message);
- peerToSendMsg.getConnection().getOutgoingMessageQueue().sendMessage(msgToSend);
- }
- }
+ notifyListenersOfMessageReceived(download,download.getDownloadPeerId(),nick,message);
+ List routePeers = (List) downloadsToPeers.get(download);
+ if(routePeers != null) {
+ synchronized (routePeers) {
+ CMMessage msg = new CMMessage(nick,peerID,0,message);
+ for(Iterator iter = routePeers.iterator(); iter.hasNext() ;) {
+ Peer peerToSendMsg = (Peer) iter.next();
+ CMMessage msgToSend = new CMMessage(msg.getMessageID(),nick,peerID,0,message);
+ peerToSendMsg.getConnection().getOutgoingMessageQueue().sendMessage(msgToSend);
+ }
}
+ }
}
private boolean compareIDs(byte[] id1, byte[] id2) {
- if(id1 == null) return id2 == null;
- if(id2 == null) return false;
- if(id1.length != id2.length) return false;
- for(int i = id1.length - 1 ; i >= 0 ; i--) {
- if(id1[i] != id2[i]) return false;
- }
- return true;
+ if(id1 == null) return id2 == null;
+ if(id2 == null) return false;
+ if(id1.length != id2.length) return false;
+ for(int i = id1.length - 1 ; i >= 0 ; i--) {
+ if(id1[i] != id2[i]) return false;
+ }
+ return true;
}
public boolean isDownloadActive(Download download) {
- List peers = (List) downloadsToPeers.get(download);
- if(peers == null) return false;
- return peers.size() > 0;
+ List peers = (List) downloadsToPeers.get(download);
+ if(peers == null) return false;
+ return peers.size() > 0;
}
- @SuppressWarnings("unchecked")
public void ignore(String nick) {
- nickIgnores.add(nick);
- }
-
- private int findBridgebyDownload(Download download){
- int index = -1;
- for (int i=0; i<MAX_CHANNELS_NUMBER;i++){
- if(bridge[i]!= null){
- Download dwn = bridge[i].getDownload();
- if (dwn.equals(download)) index = i;
- }
- }
- return index;
+ nickIgnores.add(nick);
}
- private int findBridgebyChannel(String name){
- int index = -1;
- for (int i=0; i<MAX_CHANNELS_NUMBER;i++){
- if(bridge[i]!= null){
- String ch = bridge[i].getChannelName();
- if (ch.equals(name)) index = i;
- }
- }
- return index;
- }
}
-
View
110 ...a/net/blogracy/chat/messaging/impl/CMMessage.java → ...s/plugins/chat/peer/impl/messaging/CMMessage.java
@@ -1,5 +1,5 @@
/*
- * Created on 28 fevr. 2005
+ * Created on 28 feb. 2005
* Created by Olivier Chalouhi
*
* Copyright (C) 2004 Aelitis SARL, All rights Reserved
@@ -20,14 +20,14 @@
* AELITIS, SARL au capital de 30,000 euros,
* 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
*/
+package com.aelitis.azureus.plugins.chat.peer.impl.messaging;
-package net.blogracy.chat.messaging.impl;
-
+import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
-import net.blogracy.chat.ChatManager;
+import com.aelitis.azureus.plugins.chat.ChatPlugin;
import org.gudy.azureus2.plugins.messaging.Message;
import org.gudy.azureus2.plugins.messaging.MessageException;
@@ -38,6 +38,7 @@
private String description;
private ByteBuffer buffer;
+
//A unique message ID, computed as :
//hash(time,sender,text);
private int messageID;
@@ -53,19 +54,36 @@
//The message itself
private final String text;
- public CMMessage(int id, String senderNick, byte[] senderID, int hops, String text) {
+ public CMMessage(
+ int id,
+ String senderNick,
+ byte[] senderID,
+ int hops,
+ String text) {
this(senderNick,senderID,hops,text,false);
this.messageID = id;
+
generateBuffer();
}
- public CMMessage(String senderNick, byte[] senderID, int hops, String text) {
+ public CMMessage(
+ String senderNick,
+ byte[] senderID,
+ int hops,
+ String text
+ ) {
this(senderNick,senderID,hops,text,true);
}
- private CMMessage(String senderNick, byte[] senderID, int hops, String text, boolean generateBuffer) {
+ private CMMessage(
+ String senderNick,
+ byte[] senderID,
+ int hops,
+ String text,
+ boolean generateBuffer
+ ) {
- this.senderNick = senderNick;
+ this.senderNick = senderNick;
this.senderID = senderID;
this.hops = hops;
this.text = text;
@@ -73,16 +91,15 @@ private CMMessage(String senderNick, byte[] senderID, int hops, String text, boo
String hash = senderID + "," + System.currentTimeMillis() + "," + text;
this.messageID = hash.hashCode();
-
+
+
if(generateBuffer) generateBuffer();
}
- @SuppressWarnings("unchecked")
- private void generateBuffer() {
+ private void generateBuffer() {
this.description = getID()+ " from " + senderNick + " : " + text + " (id: " + messageID + ", hops:" + hops + ")";
- @SuppressWarnings("rawtypes")
- Map mMessage = new HashMap();
+ Map mMessage = new HashMap();
mMessage.put("id",new Long(messageID));
mMessage.put("s",senderID);
mMessage.put("n",senderNick);
@@ -92,65 +109,74 @@ private void generateBuffer() {
byte[] bMessage = new byte[0];
try {
- bMessage = ChatManager.bEncode(mMessage);
+ bMessage = ChatPlugin.bEncode(mMessage);
} catch(Exception exception) {
exception.printStackTrace();
}
- buffer = ByteBuffer.allocate(bMessage.length);
- buffer.put(bMessage);
+ buffer = ByteBuffer.allocate( bMessage.length );
+ buffer.put( bMessage );
buffer.flip();
}
- public int getMessageID() {return messageID;}
- public byte[] getSenderID() {return senderID;}
- public String getSenderNick() {return senderNick;}
- public int getNbHops() {return hops;}
- public String getText() {return text;}
+ public int getMessageID() { return messageID; }
+
+ public byte[] getSenderID() { return senderID; }
+
+ public String getSenderNick() { return senderNick; }
- public String getID() {return ChatMessage.ID_CHAT_MESSAGE;}
- public byte getVersion() {return ChatMessage.CHAT_DEFAULT_VERSION;}
- public int getType() {return Message.TYPE_PROTOCOL_PAYLOAD;}
- public String getDescription() {return description;}
- public ByteBuffer[] getPayload() {return new ByteBuffer[] { buffer };}
- public void destroy() {/*nothing*/}
+ public int getNbHops() { return hops; }
+ public String getText() { return text; }
- public Message create(ByteBuffer data) throws MessageException {
- if(data == null) {
+
+
+ public String getID() { return ChatMessage.ID_CHAT_MESSAGE; }
+
+ public byte getVersion() { return ChatMessage.CHAT_DEFAULT_VERSION; }
+
+ public int getType() { return Message.TYPE_PROTOCOL_PAYLOAD; }
+
+ public String getDescription() { return description; }
+
+ public ByteBuffer[] getPayload() { return new ByteBuffer[] { buffer }; }
+
+ public void destroy() { /*nothing*/ }
+
+
+ public Message create( ByteBuffer data ) throws MessageException {
+ if( data == null ) {
throw new MessageException( "[" +getID() + ":" +getVersion()+ "] decode error: data == null" );
}
- if(data.remaining() < 13) {/*nothing*/}
+ if( data.remaining() < 13 ) {
+
+ }
+
int size = data.remaining();
- byte[] bMessage = new byte[size];
- data.get(bMessage);
-
+ byte[] bMessage = new byte[ size ];
+ data.get( bMessage );
try {
//mMessage.put("id",new Long(messageID));
//mMessage.put("s",senderID);
//mMessage.put("n",senderNick);
//mMessage.put("h",new Long(hops));
//mMessage.put("t",text);
-
- @SuppressWarnings("rawtypes")
- Map mMessage = ChatManager.bDecode(bMessage);
+ Map mMessage = ChatPlugin.bDecode(bMessage);
int messageID = ((Long)mMessage.get("id")).intValue();
byte[] senderID = (byte[])mMessage.get("s");
String senderNick = new String((byte[])mMessage.get("n"));
int hops = ((Long)mMessage.get("h")).intValue();
String text = new String((byte[])mMessage.get("t"));
-
return new CMMessage(messageID,senderNick,senderID,hops,text);
- }
-
- catch(Exception e) {
+ } catch(Exception e) {
throw new MessageException( "[" +getID() + ":" +getVersion()+ "] decode error: " + e );
}
-
+
+
+
}
}
-
View
21 ...a/net/blogracy/chat/messaging/impl/CMNoRoute.java → ...s/plugins/chat/peer/impl/messaging/CMNoRoute.java
@@ -1,5 +1,5 @@
/*
- * Created on 28 fevr. 2005
+ * Created on 28 feb. 2005
* Created by Olivier Chalouhi
*
* Copyright (C) 2004 Aelitis SARL, All rights Reserved
@@ -20,7 +20,7 @@
* AELITIS, SARL au capital de 30,000 euros,
* 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
*/
-package net.blogracy.chat.messaging.impl;
+package com.aelitis.azureus.plugins.chat.peer.impl.messaging;
import java.nio.ByteBuffer;
import org.gudy.azureus2.plugins.messaging.Message;
@@ -31,12 +31,17 @@
private final String description = getID();
private final ByteBuffer buffer = ByteBuffer.allocate(0);
- public String getID() {return ChatMessage.ID_CHAT_NO_ROUTE;}
- public byte getVersion() {return ChatMessage.CHAT_DEFAULT_VERSION;}
- public int getType() {return Message.TYPE_PROTOCOL_PAYLOAD;}
- public String getDescription() {return description;}
- public ByteBuffer[] getPayload() {return new ByteBuffer[] { buffer };}
- public void destroy() {/*nothing*/}
+ public String getID() { return ChatMessage.ID_CHAT_NO_ROUTE; }
+
+ public byte getVersion() { return ChatMessage.CHAT_DEFAULT_VERSION; }
+
+ public int getType() { return Message.TYPE_PROTOCOL_PAYLOAD; }
+
+ public String getDescription() { return description; }
+
+ public ByteBuffer[] getPayload() { return new ByteBuffer[] { buffer }; }
+
+ public void destroy() { /*nothing*/ }
public Message create(ByteBuffer data) throws MessageException {
return new CMNoRoute();
View
22 ...ava/net/blogracy/chat/messaging/impl/CMRoute.java → ...eus/plugins/chat/peer/impl/messaging/CMRoute.java
@@ -1,5 +1,5 @@
/*
- * Created on 28 fevr. 2005
+ * Created on 28 feb. 2005
* Created by Olivier Chalouhi
*
* Copyright (C) 2004 Aelitis SARL, All rights Reserved
@@ -20,8 +20,7 @@
* AELITIS, SARL au capital de 30,000 euros,
* 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
*/
-
-package net.blogracy.chat.messaging.impl;
+package com.aelitis.azureus.plugins.chat.peer.impl.messaging;
import java.nio.ByteBuffer;
import org.gudy.azureus2.plugins.messaging.Message;
@@ -32,12 +31,17 @@
private final String description = getID();
private final ByteBuffer buffer = ByteBuffer.allocate(0);
- public String getID() {return ChatMessage.ID_CHAT_ROUTE;}
- public byte getVersion() {return ChatMessage.CHAT_DEFAULT_VERSION;}
- public int getType() {return Message.TYPE_PROTOCOL_PAYLOAD;}
- public String getDescription() {return description;}
- public ByteBuffer[] getPayload() {return new ByteBuffer[] { buffer };}
- public void destroy() {/*nothing*/}
+ public String getID() { return ChatMessage.ID_CHAT_ROUTE; }
+
+ public byte getVersion() { return ChatMessage.CHAT_DEFAULT_VERSION; }
+
+ public int getType() { return Message.TYPE_PROTOCOL_PAYLOAD; }
+
+ public String getDescription() { return description; }
+
+ public ByteBuffer[] getPayload() { return new ByteBuffer[] { buffer }; }
+
+ public void destroy() { /*nothing*/ }
public Message create(ByteBuffer data) throws MessageException {
return new CMRoute();
View
5 ...net/blogracy/chat/messaging/impl/ChatMessage.java → ...plugins/chat/peer/impl/messaging/ChatMessage.java
@@ -1,5 +1,5 @@
/*
- * Created on 28 fevr. 2005
+ * Created on 28 feb. 2005
* Created by Olivier Chalouhi
*
* Copyright (C) 2004 Aelitis SARL, All rights Reserved
@@ -20,8 +20,7 @@
* AELITIS, SARL au capital de 30,000 euros,
* 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
*/
-
-package net.blogracy.chat.messaging.impl;
+package com.aelitis.azureus.plugins.chat.peer.impl.messaging;
import org.gudy.azureus2.plugins.messaging.Message;
View
0  .../java/net/blogracy/chat/resources/channel.torrent → ...is/azureus/plugins/chat/resources/channel.torrent
File renamed without changes
View
20 blogracy-vuze/src/main/java/net/blogracy/Blogracy.java
@@ -49,26 +49,26 @@
* .PluginInterface)
*/
@Override
- public void initialize(PluginInterface plugin) throws PluginException {
+ public void initialize(PluginInterface vuze) throws PluginException {
// TODO Auto-generated method stub
- createQueues(plugin);
+ createQueues(vuze);
}
- void createQueues(final PluginInterface plugin) {
+ void createQueues(final PluginInterface vuze) {
String brokerUrl = ActiveMQConnection.DEFAULT_BROKER_URL;
try {
connectionFactory = new ActiveMQConnectionFactory(brokerUrl);
connection = connectionFactory.createConnection();
connection.start();
- storeService = new StoreService(connection, plugin);
- lookupService = new LookupService(connection, plugin);
- seedService = new SeedService(connection, plugin);
- downloadService = new DownloadService(connection, plugin);
+ storeService = new StoreService(connection, vuze);
+ lookupService = new LookupService(connection, vuze);
+ seedService = new SeedService(connection, vuze);
+ downloadService = new DownloadService(connection, vuze);
- chatManager = new ChatManager();
- chatManager.initialize(plugin);
- chatService = new ChatService(connection,chatManager, plugin);
+// chatManager = new ChatManager();
+// chatManager.initialize(plugin);
+ chatService = new ChatService(connection, /*chatManager,*/ vuze);
Logger.info("Blogracy Vuze plugin has started correctly");
} catch (Exception e) {
View
326 blogracy-vuze/src/main/java/net/blogracy/chat/ChatManager.java
@@ -1,326 +0,0 @@
-/*
- * Created on 28 fevr. 2005
- * Created by Olivier Chalouhi
- *
- * Copyright (C) 2004 Aelitis SARL, All rights Reserved
- *
- * Furtherly modified by Andrea Vida, University of Parma (Italy).
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details ( see the LICENSE file ).
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * AELITIS, SARL au capital de 30,000 euros,
- * 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
- */
-package net.blogracy.chat;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.nio.channels.FileChannel;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.gudy.azureus2.plugins.Plugin;
-import org.gudy.azureus2.plugins.PluginException;
-import org.gudy.azureus2.plugins.PluginInterface;
-import org.gudy.azureus2.plugins.config.ConfigParameter;
-import org.gudy.azureus2.plugins.config.ConfigParameterListener;
-import org.gudy.azureus2.plugins.download.Download;
-import org.gudy.azureus2.plugins.torrent.Torrent;
-import org.gudy.azureus2.plugins.utils.Formatters;
-import org.gudy.azureus2.plugins.utils.LocaleUtilities;
-
-import net.blogracy.chat.peer.impl.PeerControllerImpl;
-import net.blogracy.chat.peer.PeerController;
-import net.blogracy.chat.messaging.MessageListener;
-import net.blogracy.logging.Logger;
-
-public class ChatManager implements Plugin, MessageListener, ConfigParameterListener{
-
- private PluginInterface plugin_interface;
- private PeerController controller;
-
- private ArrayList listeners;
- private ArrayList listenersDownload;
-
- private String nick;
- private boolean active;
-
- private String resTorrent = "channel.torrent";
- public Torrent genericTorrent;
- private static Formatters formatters = null;
-
- public void initialize(PluginInterface pi) {
- plugin_interface = pi;
- formatters = plugin_interface.getUtilities().getFormatters();
- genericTorrent = loadTorrent(resTorrent);
-
- nick = plugin_interface.getPluginconfig().getPluginStringParameter("nick","Guest" + (int) (Math.random() * 100000));
- active = plugin_interface.getPluginconfig().getPluginBooleanParameter("enable",true);
-
- if(active) {
- listeners = new ArrayList();
- listenersDownload = new ArrayList();
- controller = new PeerControllerImpl(this,nick);
- controller.addMessageListener(this);
- controller.initialize();
- controller.startPeerProcessing();
- }
- }
-
- public PluginInterface getPluginInterface() {
- return plugin_interface;
- }
-
- public LocaleUtilities getLocaleUtils() {
- return plugin_interface.getUtilities().getLocaleUtilities();
- }
-
- @SuppressWarnings("unchecked")
- public void addMessageListener(MessageListener listener, Download download) {
- synchronized (listeners) {
- listeners.add(listener);
- listenersDownload.add(download);
- }
-
- listener.downloadAdded(download);
- if(controller.isDownloadActive(download)) {
- listener.downloadActive(download);
- } else {
- listener.downloadInactive(download);
- }
- }
-
- public void removeMessageListener(MessageListener listener) {
- synchronized (listeners) {
- int idx = listeners.indexOf(listener);
- if (idx >= 0) {
- listenersDownload.remove(idx);
- listeners.remove(listener);
- }
- }
- }
-
- public void downloadAdded(Download download) {
- synchronized (listeners) {
- for (int i = 0; i < listenersDownload.size(); i++) {
- Download lDownload = (Download) listenersDownload.get(i);
- if (download.equals(lDownload)) {
- MessageListener listener = (MessageListener) listeners.get(i);
- listener.downloadAdded(download);
- }
- }
- }
- }
-
- public void downloadRemoved(Download download) {
- synchronized (listeners) {
- for (int i = 0; i < listenersDownload.size(); i++) {
- Download lDownload = (Download) listenersDownload.get(i);
- if (download.equals(lDownload)) {
- MessageListener listener = (MessageListener) listeners.get(i);
- listener.downloadRemoved(download);
- }
- }
- }
- }
-
- public void downloadActive(Download download) {
- synchronized (listeners) {
- for (int i = 0; i < listenersDownload.size(); i++) {
- Download lDownload = (Download) listenersDownload.get(i);
- if (download.equals(lDownload)) {
- MessageListener listener = (MessageListener) listeners.get(i);
- listener.downloadActive(download);
- }
- }
- }
- }
-
- public void downloadInactive(Download download) {
- synchronized (listeners) {
- for (int i = 0; i < listenersDownload.size(); i++) {
- Download lDownload = (Download) listenersDownload.get(i);
- if (download.equals(lDownload)) {
- MessageListener listener = (MessageListener) listeners.get(i);
- listener.downloadInactive(download);
- }
- }
- }
- }
-
- public void messageReceived(Download download,byte[] sender,String nick,String text) {
- synchronized (listeners) {
- for (int i = 0; i < listenersDownload.size(); i++) {
- Download lDownload = (Download) listenersDownload.get(i);
- if (download.equals(lDownload)) {
- MessageListener listener = (MessageListener) listeners.get(i);
- listener.messageReceived(download, sender, nick, text);
- }
- }
- }
- }
-
- public void sendMessage(Download download,String text){
- if (download == null) return;
- byte[] peerID = download.getDownloadPeerId();
- if(peerID != null) {
- controller.sendMessage(download,peerID,nick,text);
- } else {
- System.out.println("System: Torrent isn't running, message can't be delivered");
- }
- }
-
- public void configParameterChanged(ConfigParameter param) {
- nick = plugin_interface.getPluginconfig().getPluginStringParameter("nick","Guest" + (int) (Math.random() * 100000));
- if(nick.startsWith("System") || nick.startsWith("system")) {
- nick = "Guest" + (int) (Math.random() * 100000);
- }
- }
-
- private Torrent loadTorrent(String res) {
- ClassLoader cl = this.getClass().getClassLoader();
- InputStream is = cl.getResourceAsStream(res);
- if (is != null) {
- try {
- return plugin_interface.getTorrentManager().createFromBEncodedInputStream(is);
- } catch(Exception e) {
- Logger.info("System: The channel torrent is impossible to create!");
- return null;
- }
- }
- Logger.info("System: The channel torrent created is null");
- return null;
- }
-
- public String getNick() {
- return nick;
- }
-
- public void setNick(String nick) {
- this.nick = nick;
- plugin_interface.getPluginconfig().setPluginParameter("nick",nick);
- }
-
- /*public void addIgnore(String nick) {
- if(controller != null) controller.ignore(nick);
- }*/
-
- public Torrent getChannelTorrent(String channelName) {
- try {
- Map genericMap = genericTorrent.writeToMap();
- Map info = (Map) genericMap.get("info");
- info.put("name",channelName.getBytes());
- info.put("name.utf8",channelName.getBytes("UTF-8"));
- genericMap.put("info",info);
- byte[] channelTorrent = plugin_interface.getUtilities().getFormatters().bEncode(genericMap);
- Torrent result = plugin_interface.getTorrentManager().createFromBEncodedData(channelTorrent);
- result.setAnnounceURL(new URL("dht://chat.dht/announce"));
- return result;
- } catch(Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public void startNewChannel(String channelName){
- Download newChannelDL = null;
- newChannelDL = addChannel(channelName);
- }
-
- public Download addChannel(String channelName) {
- Torrent torrent = getChannelTorrent(channelName);
- String savePath = plugin_interface.getPluginDirectoryName();
- try {
- File saveDir = new File(savePath,"channels" + File.separator );
- saveDir.mkdir();
- Download dl = plugin_interface.getDownloadManager().addDownload(torrent,null,saveDir);
- dl.setForceStart(true);
-
- File dest = new File(savePath,"channels" + File.separator + channelName);
- File src = new File(savePath,"channels" + File.separator + "channel");
- copyFile(src,dest);
-
- controller.addBridge(dl,channelName);
- return dl;
- } catch(Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public void closeBridge(String channelName){
- controller.removeBridge(channelName);
- }
-
- public static byte[] bEncode(Map map) {
- if (formatters == null) {return new byte[0];}
- try {
- return formatters.bEncode(map);
- } catch (IOException e) {
- e.printStackTrace();
- return new byte[0];
- }
- }
-
- public static Map bDecode(byte[] bytes) {
- if (formatters == null) {return new HashMap();}
- try {
- return formatters.bDecode(bytes);
- } catch (IOException e) {
- e.printStackTrace();
- return new HashMap();
- }
- }
-
- public static void copyFile(File srcFile, File dstFile) {
- if (!dstFile.exists()) {
- try {
- dstFile.createNewFile();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- FileChannel source = null;
- FileChannel destination = null;
- try {
- source = new FileInputStream(srcFile).getChannel();
- destination = new FileOutputStream(dstFile).getChannel();
- destination.transferFrom(source, 0, source.size());
- } catch (IOException e) {
- e.printStackTrace();
- }
- finally {
- if (source != null) {
- try {
- source.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if (destination != null) {
- try {
- destination.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
-}
-
View
78 blogracy-vuze/src/main/java/net/blogracy/chat/web/Bridge.java
@@ -1,78 +0,0 @@
-/*
- * Created by Andrea Vida
- * University of Parma (Italy)
- */
-package net.blogracy.chat.web;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.JMSException;
-import org.apache.activemq.ActiveMQConnection;
-import org.apache.activemq.ActiveMQConnectionFactory;
-import org.apache.log4j.BasicConfigurator;
-import org.apache.log4j.Level;
-import org.gudy.azureus2.plugins.download.Download;
-
-import net.blogracy.chat.ChatManager;
-
-public class Bridge{
-
- @SuppressWarnings("unused")
- private ChatManager plugin;
- private Download download;
- private String channelName;
-
- private ConnectionFactory connectionFactory;
- private Connection connection;
-
- private TextListener textListener;
-
- //create a Bridge item and set up connections with JMS
- public Bridge(ChatManager plugin,Download download,String channelName){
- this.plugin = plugin;
- this.download = download;
- this.channelName = channelName;
-
- BasicConfigurator.configure();
- org.apache.log4j.Logger.getLogger("org.apache").setLevel(Level.INFO);
- String brokerUrl = ActiveMQConnection.DEFAULT_BROKER_URL;
-
- try {
- connectionFactory = new ActiveMQConnectionFactory(brokerUrl);
- connection = connectionFactory.createConnection();
- connection.start();
- textListener = new TextListener(connection,plugin,download,channelName);
- } catch (JMSException e) {
- System.out.println("JMS error: creating JMS connections");
- }
- }
-
- public void inMsg(String message,String nick) {
- if(message.equals("has left the channel")){
- textListener.msgfromVuze(message,nick,"leave");
- }
- else textListener.msgfromVuze(message,nick,"chat");
- }
-
- public void sysMsg(String message) {
- System.out.println("System Message: " + message);
- }
-
- public String getChannelName(){
- return this.channelName;
- }
-
- public Download getDownload(){
- return this.download;
- }
-
- //destroy a Bridge item and close the connection
- public void finalize(){
- try {
- connection.close();
- textListener = null;
- } catch (JMSException e) {
- System.out.println("JMS error: closing JMS connection");}
- }
-
-}
View
167 blogracy-vuze/src/main/java/net/blogracy/chat/web/TextListener.java
@@ -1,167 +0,0 @@
-/*
- * Created by Andrea Vida
- * University of Parma (Italy)
- */
-package net.blogracy.chat.web;
-
-import javax.jms.Connection;
-import javax.jms.DeliveryMode;
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-
-import javax.xml.parsers.*;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-import org.xml.sax.InputSource;
-import org.gudy.azureus2.plugins.download.Download;
-import org.w3c.dom.*;
-import java.io.*;
-
-import net.blogracy.chat.ChatManager;
-
-
-public class TextListener implements MessageListener{
-
- private ChatManager plugin;
- private Download download;
-
- private Session session;
- private Destination topic;
- private MessageProducer producer;
- private MessageConsumer consumer;
-
- private String topicName = "CHAT.DEMO";
- private String channelName = "";
- private String lastMessageSend = "";
- private String lastMessageReceived = "";
-
- public TextListener(Connection connection, ChatManager plugin, Download download, String channelName){
- this.plugin = plugin;
- this.download = download;
- this.channelName = channelName;
- try {
- session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- topic = session.createTopic(topicName);
- producer = session.createProducer(topic);
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- consumer = session.createConsumer(topic);
- consumer.setMessageListener(this);
- } catch (JMSException e) {
- System.out.println("JMS error: creating the text listener");
- }
- }
-
- @Override
- public void onMessage(Message message) {
- if (message instanceof TextMessage) {
- try {
- String text = ((TextMessage) message).getText();
- if (floodControl(text)) {/*System.out.println("Flooding");*/}
- else {
- parseXML(text);
- lastMessageSend = text;
- //System.out.println("Outgoing Message: " + text);
- }
- } catch (JMSException e) {
- System.out.println("JMS error: reading messages");
- }
- }
- else System.out.println("This is not a TextMessage");
- }
-
- public void msgfromVuze(String text,String nick,String type){
- String XMLmessage = createXML(text,nick,type);
- //System.out.println("Incoming Message: " + XMLmessage);
- lastMessageReceived = XMLmessage;
-
- TextMessage message;
- try {
- message = session.createTextMessage();
- message.setText(XMLmessage);
- producer.send(topic, message);
- } catch (JMSException e) {
- System.out.println("JMS error: sending messages");
- }
- }
-
- private void parseXML(String XMLstring){
- try {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- InputSource is = new InputSource();
- is.setCharacterStream(new StringReader(XMLstring));
- Document doc = db.parse(is);
-
- NodeList nodes = doc.getElementsByTagName("message");
- Element element = (Element) nodes.item(0);
- String type = element.getAttribute("type");
- String nick = element.getAttribute("from");
- String channel = element.getAttribute("channel");
- String text = element.getTextContent();
- if (channel.equals(channelName)) msgforVuze(type,nick,text);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- private String createXML(String text,String nick,String type){
- try {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- Document doc = db.newDocument();
-
- Element element = doc.createElement("message");
- element.setAttribute("type",type);
- element.setAttribute("from",nick);
- element.setAttribute("channel",channelName);
- if(type.equals("chat")) element.setTextContent(text);
-
- Source source = new DOMSource(element);
- StringWriter stringWriter = new StringWriter();
- Result result = new StreamResult(stringWriter);
- TransformerFactory factory = TransformerFactory.newInstance();
- Transformer transformer = factory.newTransformer();
- transformer.transform(source, result);
- String XMLstring1 = stringWriter.getBuffer().toString();
- String XMLstring2 = XMLstring1.substring(38);
- return XMLstring2;
- }
- catch (Exception e) {
- e.printStackTrace();
- return "nothing";
- }
- }
-
- private void msgforVuze(String type,String nick,String text){
- if(type.equals("chat")) plugin.sendMessage(download, text);
-
- if(type.equals("join")) {
- plugin.setNick(nick);
- }
-
- if(type.equals("leave")){
- plugin.sendMessage(download, "has left the channel");
- if (nick.equals(plugin.getNick()))plugin.closeBridge(channelName);
- }
-
- }
-
- private boolean floodControl(String text){
- if (text.equals(lastMessageReceived)) return true;
- if (text.equals(lastMessageSend)) return true;
- return false;
- }
-
-}
View
192 blogracy-vuze/src/main/java/net/blogracy/services/ChatService.java
@@ -15,49 +15,177 @@
import javax.jms.Session;
import javax.jms.TextMessage;
-import net.blogracy.chat.ChatManager;
+import javax.xml.parsers.*;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
import net.blogracy.logging.Logger;
+import org.xml.sax.InputSource;
import org.gudy.azureus2.plugins.PluginInterface;
+import org.gudy.azureus2.plugins.download.Download;
+import org.w3c.dom.*;
+
+import com.aelitis.azureus.plugins.chat.ChatPlugin;
+
+import java.io.*;
+import java.util.HashMap;
+
public class ChatService implements MessageListener {
-
- @SuppressWarnings("unused")
- private PluginInterface plugin;
- private ChatManager chatManager;
-
- private Session session;
- private Destination queue;
- private MessageProducer producer;
- private MessageConsumer consumer;
-
- public ChatService(Connection connection, ChatManager cm, PluginInterface plugin) {
- this.plugin = plugin;
- this.chatManager = cm;
- try {
- session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- producer = session.createProducer(null);
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- queue = session.createQueue("chatService");
- consumer = session.createConsumer(queue);
- consumer.setMessageListener(this);
- } catch (JMSException e) {
- Logger.error("JMS error: creating chat service");
- }
- }
+
+ private PluginInterface vuze;
+
+ private Session session;
+ private Destination topic;
+ private MessageProducer producer;
+ private MessageConsumer consumer;
+
+ private String TOPIC_NAME = "CHAT.DEMO";
+ private String lastMessageSend = "";
+ private String lastMessageReceived = "";
+
+ private HashMap<String, Download> channels = new HashMap<String, Download>();
+
+ public ChatService(Connection connection, PluginInterface vuze) {
+ this.vuze = vuze;
+ try {
+ session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ topic = session.createTopic(TOPIC_NAME);
+ producer = session.createProducer(topic);
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ consumer = session.createConsumer(topic);
+ consumer.setMessageListener(this);
+ } catch (JMSException e) {
+ System.out.println("JMS error: creating the text listener");
+ }
+ }
@Override
- public void onMessage(Message request) {
+ public void onMessage(Message message) {
+ if (message instanceof TextMessage) {
+ try {
+ String text = ((TextMessage) message).getText();
+ if (floodControl(text)) {
+ /*System.out.println("Flooding");*/
+ } else {
+ parseXML(text);
+ lastMessageSend = text;
+ //System.out.println("Outgoing Message: " + text);
+ }
+ } catch (JMSException e) {
+ System.out.println("JMS error: reading messages");
+ }
+ }
+ else System.out.println("This is not a TextMessage");
+ }
+
+ public void msgFromVuze(String channel, String type, String nick, String text){
+ String xml = createXML(channel, type, nick, text);
+ //System.out.println("Incoming Message: " + XMLmessage);
+ lastMessageReceived = xml;
+
+ TextMessage message;
try {
- String channelName = ((TextMessage) request).getText();
- chatManager.startNewChannel(channelName);
- Logger.info("chat request by " + channelName + ";");
+ message = session.createTextMessage();
+ message.setText(xml);
+ producer.send(topic, message);
+ } catch (JMSException e) {
+ System.out.println("JMS error: sending messages");
+ }
+ }
+
+ private void parseXML(String xml){
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ InputSource is = new InputSource();
+ is.setCharacterStream(new StringReader(xml));
+ Document doc = db.parse(is);
+ NodeList nodes = doc.getElementsByTagName("message");
+ Element element = (Element) nodes.item(0);
+ String type = element.getAttribute("type");
+ String nick = element.getAttribute("from");
+ String channel = element.getAttribute("channel");
+ String text = element.getTextContent();
+ msgToVuze(channel, type, nick, text);
+ } catch (Exception e) {
+ e.printStackTrace();
}
- catch (JMSException e) {
- Logger.error("JMS error: seed service");
+ }
+
+ private String createXML(String channel, String type, String nick, String text){
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document doc = db.newDocument();
+
+ Element element = doc.createElement("message");
+ element.setAttribute("type", type);
+ element.setAttribute("from", nick);
+ element.setAttribute("channel", channel);
+ if (type.equals("chat")) element.setTextContent(text);
+
+ Source source = new DOMSource(element);
+ StringWriter stringWriter = new StringWriter();
+ Result result = new StreamResult(stringWriter);
+ TransformerFactory factory = TransformerFactory.newInstance();
+ Transformer transformer = factory.newTransformer();
+ transformer.transform(source, result);
+ String str = stringWriter.getBuffer().toString();//.substring(38);
+ return str;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return "nothing";
}
-
}
+ private void msgToVuze(String channel, String type, String nick, String text) {
+ ChatPlugin plugin = (ChatPlugin) vuze.getPluginManager()
+ .getPluginInterfaceByID("chat").getPlugin();
+
+ if (type.equals("chat")) {
+ Download download = channels.get(channel);
+ plugin.sendMessage(download, text);
+ } else if (type.equals("join")) {
+ Logger.info("Joining channel: " + channel);
+
+ plugin.setNick(nick);
+ Download download = plugin.addChannel(channel);
+ channels.put(channel, download);
+ plugin.addMessageListener(new com.aelitis.azureus.plugins.chat.messaging.MessageListener() {
+ public void downloadAdded(Download download) {}
+ public void downloadRemoved(Download download) {}
+ public void downloadActive(Download download) {}
+ public void downloadInactive(Download download) {}
+ public void messageReceived(Download download, byte[] sender, String nick, String text) {
+ String channel = new String(sender);
+ for (String key : channels.keySet()) {
+ if (channels.get(key) == download) channel = key;
+ }
+ String type = "chat";
+ if (text.equals("has left the channel")) type = "leave";
+ msgFromVuze(channel, type, nick, text);
+ }
+ }, download);
+ Logger.info("chat request: " + channel);
+
+ } else if (type.equals("leave")){
+ Download download = channels.get(channel);
+ plugin.sendMessage(download, "has left the channel");
+ if (nick.equals(plugin.getNick())) {
+ // plugin.closeBridge(channelName);
+ }
+ }
+ }
+
+ private boolean floodControl(String text){
+ return (text.equals(lastMessageReceived)
+ ||text.equals(lastMessageSend));
+ }
}
View
0  blogracy-vuze/src/main/plugins/chat/channels/channel
No changes.
View
5 blogracy-vuze/src/main/plugins/chat/plugin.properties
@@ -0,0 +1,5 @@
+plugin.class=com.aelitis.azureus.plugins.chat.ChatPlugin
+plugin.name=Chat
+plugin.langfile=com.aelitis.azureus.plugins.chat.ui.internat.Messages
+plugin.version=1.9
+plugin.id=chat
View
9 blogracy-web/src/main/java/net/blogracy/WebServer.java
@@ -1,6 +1,7 @@
package net.blogracy;
import net.blogracy.model.users.User;
+import net.blogracy.controller.ChatController;
import net.blogracy.controller.DistributedHashTable;
import net.blogracy.controller.FileSharing;
import net.blogracy.config.Configurations;
@@ -25,6 +26,12 @@ public static void main(String[] args) throws Exception
server.start();
// server.join();
+
+ List<User> friends = Configurations.getUserConfig().getFriends();
+ // for (User friend : friends) {
+ // String hash = friend.getHash().toString();
+ // ChatController.createChannel(hash);
+ // }
int TOTAL_WAIT = 5 * 60 * 1000; // 5 minutes
@@ -33,7 +40,7 @@ public static void main(String[] args) throws Exception
String id = Configurations.getUserConfig().getUser().getHash().toString();
sharing.addFeedEntry(id, "" + new java.util.Date(), null);
- List<User> friends = Configurations.getUserConfig().getFriends();
+ // List<User> friends = Configurations.getUserConfig().getFriends();
int wait = TOTAL_WAIT / friends.size();
for (User friend : friends) {
DistributedHashTable.getSingleton().lookup(friend.getHash().toString());
View
12 blogracy-web/src/main/java/net/blogracy/controller/ChatController.java
@@ -62,6 +62,18 @@ public static void setLocalUser(String local) {
}
}
+ public static void createChannel(String channel) {
+ System.out.println("Creating chat channel for: " + channel);
+ TextMessage msg;
+ try {
+ msg = session.createTextMessage();
+ msg.setText(channel);
+ producer.send(hashQueue, msg);
+ } catch (JMSException e) {
+ System.out.println("JMS error: sending messages");
+ }
+ }
+
public static void setRemoteUser(String remote) {
remoteUser = remote;
System.out.println("Remote user hash: " + remoteUser);
Please sign in to comment.
Something went wrong with that request. Please try again.