Commit 006ffde8 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Modified to be able to send packets to remote servers. JM-6


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1376 b35dd754-fafc-0310-a699-88a17e54d16e
parent 19ab15c5
...@@ -30,38 +30,47 @@ public class SocketPacketWriteHandler implements ChannelHandler { ...@@ -30,38 +30,47 @@ public class SocketPacketWriteHandler implements ChannelHandler {
private SessionManager sessionManager; private SessionManager sessionManager;
private OfflineMessageStrategy messageStrategy; private OfflineMessageStrategy messageStrategy;
private String serverName = XMPPServer.getInstance().getServerInfo().getName();
private RoutingTable routingTable;
public SocketPacketWriteHandler(SessionManager sessionManager, OfflineMessageStrategy messageStrategy) { public SocketPacketWriteHandler(SessionManager sessionManager, RoutingTable routingTable,
OfflineMessageStrategy messageStrategy) {
this.sessionManager = sessionManager; this.sessionManager = sessionManager;
this.messageStrategy = messageStrategy; this.messageStrategy = messageStrategy;
this.routingTable = routingTable;
} }
public void process(Packet packet) throws UnauthorizedException, PacketException { public void process(Packet packet) throws UnauthorizedException, PacketException {
try { try {
JID recipient = packet.getTo(); JID recipient = packet.getTo();
// Check if the target domain belongs to a remote server
if (recipient != null && !recipient.getDomain().contains(serverName)) {
try {
// Locate the route to the remote server and ask it to process the packet
routingTable.getRoute(recipient).process(packet);
}
catch (NoSuchRouteException e) {
// No root was found so either drop or store the packet
handleUnprocessedPacket(packet);
}
return;
}
// The target domain belongs to the local server
if (recipient == null || (recipient.getNode() == null && recipient.getResource() == null)) { if (recipient == null || (recipient.getNode() == null && recipient.getResource() == null)) {
// no TO was found so send back the packet to the sender
Session senderSession = sessionManager.getSession(packet.getFrom()); Session senderSession = sessionManager.getSession(packet.getFrom());
if (senderSession != null && !senderSession.getConnection().isClosed()) { if (senderSession != null && !senderSession.getConnection().isClosed()) {
senderSession.getConnection().deliver(packet); senderSession.getConnection().deliver(packet);
} }
else { else {
// The sender is no longer available so drop the packet
dropPacket(packet); dropPacket(packet);
} }
} }
else { else {
Session session = sessionManager.getBestRoute(recipient); Session session = sessionManager.getBestRoute(recipient);
if (session == null) { if (session == null) {
if (packet instanceof Message) { handleUnprocessedPacket(packet);
messageStrategy.storeOffline((Message)packet);
}
else if (packet instanceof Presence) {
// presence packets are dropped silently
//dropPacket(packet);
}
else {
// IQ packets are logged but dropped
dropPacket(packet);
}
} }
else { else {
try { try {
...@@ -78,6 +87,20 @@ public class SocketPacketWriteHandler implements ChannelHandler { ...@@ -78,6 +87,20 @@ public class SocketPacketWriteHandler implements ChannelHandler {
} }
} }
private void handleUnprocessedPacket(Packet packet) {
if (packet instanceof Message) {
messageStrategy.storeOffline((Message)packet);
}
else if (packet instanceof Presence) {
// presence packets are dropped silently
//dropPacket(packet);
}
else {
// IQ packets are logged but dropped
dropPacket(packet);
}
}
/** /**
* Drop the packet. * Drop the packet.
* *
......
...@@ -29,7 +29,7 @@ public class PacketDelivererImpl extends BasicModule implements PacketDeliverer ...@@ -29,7 +29,7 @@ public class PacketDelivererImpl extends BasicModule implements PacketDeliverer
/** /**
* The handler that does the actual delivery (could be a channel instead) * The handler that does the actual delivery (could be a channel instead)
*/ */
protected ChannelHandler deliverHandler; protected SocketPacketWriteHandler deliverHandler;
private OfflineMessageStrategy messageStrategy; private OfflineMessageStrategy messageStrategy;
private SessionManager sessionManager; private SessionManager sessionManager;
...@@ -72,7 +72,9 @@ public class PacketDelivererImpl extends BasicModule implements PacketDeliverer ...@@ -72,7 +72,9 @@ public class PacketDelivererImpl extends BasicModule implements PacketDeliverer
public void start() throws IllegalStateException { public void start() throws IllegalStateException {
super.start(); super.start();
deliverHandler = new SocketPacketWriteHandler(sessionManager, messageStrategy); deliverHandler =
new SocketPacketWriteHandler(sessionManager,
XMPPServer.getInstance().getRoutingTable(), messageStrategy);
} }
public void stop() { public void stop() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment