use of org.xmpp.jnodes.RelayChannel in project Openfire by igniterealtime.
the class SmackServiceNode method setup.
private void setup() {
scheduledExecutor.scheduleWithFixedDelay(new Runnable() {
public void run() {
for (final RelayChannel c : channels.values()) {
final long current = System.currentTimeMillis();
final long da = current - c.getLastReceivedTimeA();
final long db = current - c.getLastReceivedTimeB();
if (da > timeout || db > timeout) {
removeChannel(c);
}
}
}
}, timeout, timeout, TimeUnit.MILLISECONDS);
connection.addPacketListener(this, new PacketFilter() {
public boolean accept(Packet packet) {
return packet instanceof JingleChannelIQ || packet instanceof JingleTrackerIQ;
}
});
}
use of org.xmpp.jnodes.RelayChannel in project Openfire by igniterealtime.
the class JingleNodesComponent method handleIQGet.
@Override
protected IQ handleIQGet(IQ iq) throws Exception {
final IQ reply = IQ.createResultIQ(iq);
final Element element = iq.getChildElement();
final String namespace = element.getNamespaceURI();
if (JingleChannelIQ.NAME.equals(element.getName()) && JingleChannelIQ.NAMESPACE.equals(namespace) && UDP.equals(element.attributeValue(PROTOCOL))) {
final Element childElement = iq.getChildElement().createCopy();
final RelayChannel channel = plugin.createRelayChannel();
if (channel != null) {
childElement.addAttribute(HOST, plugin.getPublicIP());
childElement.addAttribute(LOCAL_PORT, Integer.toString(channel.getPortA()));
childElement.addAttribute(REMOTE_PORT, Integer.toString(channel.getPortB()));
reply.setChildElement(childElement);
Log.debug("Created relay channel {}:{}, {}:{}, {}:{}", new Object[] { HOST, plugin.getPublicIP(), LOCAL_PORT, Integer.toString(channel.getPortA()), REMOTE_PORT, Integer.toString(channel.getPortB()) });
} else {
reply.setError(PacketError.Condition.internal_server_error);
}
return reply;
} else if (JingleTrackerIQ.NAME.equals(element.getName()) && JingleTrackerIQ.NAMESPACE.equals(namespace)) {
final List<TrackerEntry> entries = new ArrayList<TrackerEntry>();
entries.add(new TrackerEntry(TrackerEntry.Type.relay, TrackerEntry.Policy._roster, plugin.getServiceName() + "." + getDomain(), UDP));
final String elements = getChildElementXML(entries);
final Element e = DocumentHelper.parseText(elements).getRootElement();
reply.setChildElement(e);
return reply;
}
// feature not implemented.
return null;
}
use of org.xmpp.jnodes.RelayChannel in project Openfire by igniterealtime.
the class JingleNodesPlugin method createRelayChannel.
public RelayChannel createRelayChannel() {
RelayChannel rc = null;
try {
rc = RelayChannel.createLocalRelayChannel(bindAllInterfaces ? "0.0.0.0" : LocalIPResolver.getLocalIP(), getMinPort(), getMaxPort());
final int id = ids.incrementAndGet();
final String sId = String.valueOf(id);
rc.setAttachment(sId);
channels.put(sId, rc);
} catch (IOException e) {
Log.error("Could Not Create Channel.", e);
}
return rc;
}
use of org.xmpp.jnodes.RelayChannel in project Openfire by igniterealtime.
the class SmackServiceNode method createUdpChannel.
protected IQ createUdpChannel(final JingleChannelIQ iq) {
try {
final RelayChannel rc = RelayChannel.createLocalRelayChannel("0.0.0.0", 10000, 40000);
final int id = ids.incrementAndGet();
final String sId = String.valueOf(id);
rc.setAttachment(sId);
channels.put(sId, rc);
final JingleChannelIQ result = new JingleChannelIQ();
result.setType(IQ.Type.RESULT);
result.setTo(iq.getFrom());
result.setFrom(iq.getTo());
result.setPacketID(iq.getPacketID());
result.setHost(rc.getIp());
result.setLocalport(rc.getPortA());
result.setRemoteport(rc.getPortB());
result.setId(sId);
return result;
} catch (IOException e) {
e.printStackTrace();
return JingleChannelIQ.createEmptyError();
}
}
Aggregations