Search in sources :

Example 1 with RelayChannel

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;
        }
    });
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) RelayChannel(org.xmpp.jnodes.RelayChannel)

Example 2 with RelayChannel

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;
}
Also used : TrackerEntry(org.xmpp.jnodes.smack.TrackerEntry) Element(org.dom4j.Element) JingleChannelIQ(org.xmpp.jnodes.smack.JingleChannelIQ) JingleTrackerIQ(org.xmpp.jnodes.smack.JingleTrackerIQ) IQ(org.xmpp.packet.IQ) ArrayList(java.util.ArrayList) List(java.util.List) RelayChannel(org.xmpp.jnodes.RelayChannel)

Example 3 with RelayChannel

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;
}
Also used : IOException(java.io.IOException) RelayChannel(org.xmpp.jnodes.RelayChannel)

Example 4 with RelayChannel

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();
    }
}
Also used : IOException(java.io.IOException) RelayChannel(org.xmpp.jnodes.RelayChannel)

Aggregations

RelayChannel (org.xmpp.jnodes.RelayChannel)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Element (org.dom4j.Element)1 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)1 Packet (org.jivesoftware.smack.packet.Packet)1 JingleChannelIQ (org.xmpp.jnodes.smack.JingleChannelIQ)1 JingleTrackerIQ (org.xmpp.jnodes.smack.JingleTrackerIQ)1 TrackerEntry (org.xmpp.jnodes.smack.TrackerEntry)1 IQ (org.xmpp.packet.IQ)1