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 {
private SessionManager sessionManager;
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.messageStrategy = messageStrategy;
this.routingTable = routingTable;
}
public void process(Packet packet) throws UnauthorizedException, PacketException {
try {
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)) {
// no TO was found so send back the packet to the sender
Session senderSession = sessionManager.getSession(packet.getFrom());
if (senderSession != null && !senderSession.getConnection().isClosed()) {
senderSession.getConnection().deliver(packet);
}
else {
// The sender is no longer available so drop the packet
dropPacket(packet);
}
}
else {
Session session = sessionManager.getBestRoute(recipient);
if (session == null) {
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);
}
handleUnprocessedPacket(packet);
}
else {
try {
......@@ -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.
*
......
......@@ -29,7 +29,7 @@ public class PacketDelivererImpl extends BasicModule implements PacketDeliverer
/**
* The handler that does the actual delivery (could be a channel instead)
*/
protected ChannelHandler deliverHandler;
protected SocketPacketWriteHandler deliverHandler;
private OfflineMessageStrategy messageStrategy;
private SessionManager sessionManager;
......@@ -72,7 +72,9 @@ public class PacketDelivererImpl extends BasicModule implements PacketDeliverer
public void start() throws IllegalStateException {
super.start();
deliverHandler = new SocketPacketWriteHandler(sessionManager, messageStrategy);
deliverHandler =
new SocketPacketWriteHandler(sessionManager,
XMPPServer.getInstance().getRoutingTable(), messageStrategy);
}
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