<commit_before>/*
 * Jitsi Videobridge, OpenSource video conferencing.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jitsi.videobridge.groovysh;

import groovy.lang.*;
import org.jitsi.util.*;
import org.osgi.framework.*;

import java.io.*;
import java.net.*;
import java.util.*;
import java.util.concurrent.*;

/**
 * @author <NAME>
 */
public class GroovyShellActivator
        implements BundleActivator
{
    /**
     * The <tt>Logger</tt> used by the <tt>GroovyShellActivator</tt> class and
     * its instances to print debug information.
     */
    private static final Logger logger
            = Logger.getLogger(GroovyShellActivator.class);

    /**
     * Accept no more than 10 simultaneous connections at a time.
     */
    private static final int MAX_CLIENTS = 10;

    /**
     * Some easy to remember prime number.
     */
    private static final int SERVER_SOCKET_PORT = 6869;

    /**
     * Wait no more than 3 minutes for user input.
     */
    private static final int CLIENT_SOCKET_TIMEOUT = 3 * 60 * 1000;

    /**
     * Executor service for client connection handlers.
     */
    private static final ExecutorService executorService
            = Executors.newFixedThreadPool(MAX_CLIENTS);

    /**
     *
     */
    private ServerSocket serverSocket;


    @Override
    public void start(final BundleContext ctx) {
        // Create the server thread.
        Thread serverThread = new Thread() {

            @Override
            public void run()
            {
                try
                {
                    serverSocket = new ServerSocket(SERVER_SOCKET_PORT);

                    while (true)
                    {
                        Socket clientSocket = serverSocket.accept();
                        clientSocket.setSoTimeout(CLIENT_SOCKET_TIMEOUT);

                        // Set the variables to expose to the shell.
                        Binding binding = new Binding();
                        binding.setVariable("state", new GroovyShellState(ctx));

                        // Create and start shell thread.
                        GroovyShellWorker w
                                = new GroovyShellWorker(clientSocket, binding);

                        executorService.execute(w);
                    }
                }
                catch (IOException e)
                {
                    logger.error(e.getMessage(), e);
                }
                finally
                {
                    GroovyShellActivator.this.stop(ctx);
                }

            }
        };

        serverThread.setDaemon(true);<commit_msg>Restrict the groovy shell to localhost.<commit_after>/*
 * Jitsi Videobridge, OpenSource video conferencing.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package org.jitsi.videobridge.groovysh;

import groovy.lang.*;
import org.jitsi.util.*;
import org.osgi.framework.*;

import java.io.*;
import java.net.*;
import java.util.*;
import java.util.concurrent.*;

/**
 * @author <NAME>
 */
public class GroovyShellActivator
        implements BundleActivator
{
    /**
     * The <tt>Logger</tt> used by the <tt>GroovyShellActivator</tt> class and
     * its instances to print debug information.
     */
    private static final Logger logger
            = Logger.getLogger(GroovyShellActivator.class);

    /**
     * Accept no more than 10 simultaneous connections at a time.
     */
    private static final int MAX_CLIENTS = 10;

    /**
     * Where to bind.
     */
    private static final String SERVER_BIND_ADDR = "127.0.0.1";

    /**
     * Some easy to remember prime number.
     */
    private static final int SERVER_SOCKET_PORT = 6869;

    /**
     * Wait no more than 3 minutes for user input.
     */
    private static final int CLIENT_SOCKET_TIMEOUT = 3 * 60 * 1000;

    /**
     * Executor service for client connection handlers.
     */
    private static final ExecutorService executorService
            = Executors.newFixedThreadPool(MAX_CLIENTS);

    /**
     *
     */
    private ServerSocket serverSocket;


    @Override
    public void start(final BundleContext ctx) {
        // Create the server thread.
        Thread serverThread = new Thread() {

            @Override
            public void run()
            {
                try
                {
                    InetAddress bindAddress = InetAddress.getByName(SERVER_BIND_ADDR);
                    serverSocket = new ServerSocket(SERVER_SOCKET_PORT, 50, bindAddress);

                    while (true)
                    {
                        Socket clientSocket = serverSocket.accept();
                        clientSocket.setSoTimeout(CLIENT_SOCKET_TIMEOUT);

                        // Set the variables to expose to the shell.
                        Binding binding = new Binding();
                        binding.setVariable("state", new GroovyShellState(ctx));

                        // Create and start shell thread.
                        GroovyShellWorker w
                                = new GroovyShellWorker(clientSocket, binding);

                        executorService.execute(w);
                    }
                }
                catch (IOException e)
                {
                    logger.error(e.getMessage(), e);
                }
                finally
                {
                    GroovyShellActivator.this.stop(ctx);
                }

            }
        };

        serverThread.setDaemon(true);
{'fraction_non_alphanumeric': 0.08361867003063615, 'fraction_numerical': 0.007208506037123806, 'mean_word_length': 1.5576036866359446, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4442743', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1361, 'n_words': 380}