/*
 * Copyright @ 2015-2017 Atlassian Pty Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jitsi.videobridge.octo;

import net.java.sip.communicator.util.*;
import org.jitsi.service.configuration.*;
import org.osgi.framework.*;

import java.net.*;

/**
 * A {@link BundleActivator} for a bridge-to-bridge (Octo) relay.
 *
 * @author Boris Grozev
 */
public class OctoRelayService
    implements BundleActivator
{
    /**
     * The {@link Logger} used by the {@link OctoRelay} class and its
     * instances to print debug information.
     */
    private static final Logger logger
        = Logger.getLogger(OctoRelay.class);

    /**
     * The name of the configuration property which controls the address on
     * which the Octo relay should bind.
     */
    public static final String ADDRESS_PNAME
        = "org.jitsi.videobridge.octo.BIND_ADDRESS";

    /**
     * The name of the property which controls the port number which the Octo
     * relay should use.
     */
    public static final String PORT_PNAME
        = "org.jitsi.videobridge.octo.BIND_PORT";

    /**
     * The Octo relay instance used by this {@link OctoRelayService}.
     */
    private OctoRelay relay;

    /**
     * The {@code ConfigurationService} which looks up values of configuration
     * properties.
     */
    private ConfigurationService cfg;

    /**
     * @return the {@link OctoRelay} managed by this
     * {@link OctoRelayService}.
     */
    public OctoRelay getRelay()
    {
        return relay;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void start(BundleContext bundleContext)
    {
        cfg
            = ServiceUtils.getService(
                    bundleContext, ConfigurationService.class);

        String address = cfg.getString(ADDRESS_PNAME, null);
        int port = cfg.getInt(PORT_PNAME, -1);

        if (address != null && NetworkUtils.isValidPortNumber(port))
        {
            try
            {
                relay = new OctoRelay(address, port);

                bundleContext
                    .registerService(OctoRelayService.class.getName(), this,
                                     null);
                logger.info("Initialized an Octo relay with address "
                                + address + ":" + port);
            }
            catch (UnknownHostException | SocketException e)
            {
                logger.error("Failed to initialize Octo relay with address "
                                 + address + ":" + port + ". ", e);
            }
        }
        else
        {
            logger.info("Octo relay not configured.");
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void stop(BundleContext bundleContext) throws Exception
    {
        if (relay != null)
        {
            relay.stop();
        }
    }

    /**
     * @return the ID of the Octo relay managed by this {@link OctoRelayService}.
     */
    public String getRelayId()
    {
        return relay.getId();
    }
}

@@ -1381,16 +1381,275 @@
 DDRESS%22;
+%0A        %0A    /**%0A     * The name of the configuration property which controls the public address which %0A     * will be used as part of relayId.%0A     */%0A    public static final String PUBLIC_ADDRESS_PNAME%0A        = %22org.jitsi.videobridge.octo.PUBLIC_ADDRESS%22;
 %0A%0A    /*
@@ -2569,32 +2569,109 @@
 S_PNAME, null);%0A
+        String publicAddress = cfg.getString(PUBLIC_ADDRESS_PNAME, address);%0A
         int port
@@ -2865,16 +2865,70 @@
  port);%0A
+                relay.setPublicAddress(publicAddress);
 %0A       

Update OctoRelayService.java