<commit_before>#!/usr/bin/env python
###############################################################################
#
# SageMathCloud: A collaborative web-based interface to Sage, IPython, LaTeX and the Terminal.
#
#    Copyright (C) 2014, <NAME>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################



# Configure tinc on this node

import json, os, socket, sys

sys.path.append(os.environ['SALVUS_ROOT'])
import misc

tinc_path = '/home/salvus/salvus/salvus/data/local/etc/tinc/'
tinc_conf = os.path.join(tinc_path, 'tinc.conf')


def init():
    external_address = sys.argv[2]
    internal_address = misc.local_ip_address()
    tinc_address     = sys.argv[3]
    tincname         = sys.argv[4]

    if not os.path.exists(tinc_path):
        os.makedirs(tinc_path)

    run_path = '/home/salvus/salvus/salvus/data/local/var/run/'
    if not os.path.exists(run_path):
        os.makedirs(run_path)

    tinc_up = os.path.join(tinc_path, 'tinc-up')

    open(tinc_up,'w').write(
          "#!/bin/sh\nifconfig $INTERFACE %s netmask 255.192.0.0 txqueuelen 10000"%tinc_address)

    os.popen("chmod a+rx %s"%tinc_up)

    open(tinc_conf,'w').write("Name = %s\nKeyExpire = 2592000\nProcessPriority = high\n"%tincname)

    rsa_key_priv = os.path.join(tinc_path, 'rsa_key.priv')
    rsa_key_pub  = os.path.join(tinc_path, 'hosts', tincname)

    if os.path.exists(rsa_key_priv): os.unlink(rsa_key_priv)
    if os.path.exists(rsa_key_pub): os.unlink(rsa_key_pub)

    os.popen("tincd --config %s -K"%tinc_path).read()

    host_file  = os.path.join(tinc_path, 'hosts', tincname)
    public_key = open(rsa_key_pub).read().strip()

    # We give the internal address for Address= since only other GCE nodes will connect to these nodes, and<commit_msg>make configure_tinc script slightly more robust<commit_after>#!/usr/bin/env python
###############################################################################
#
# SageMathCloud: A collaborative web-based interface to Sage, IPython, LaTeX and the Terminal.
#
#    Copyright (C) 2014, <NAME>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################



# Configure tinc on this node

import json, os, socket, sys

salvus_root = os.environ['SALVUS_ROOT']
sys.path.append(salvus_root)
import misc

tinc_conf_hosts = os.path.join(salvus_root, 'conf/tinc_hosts')
tinc_path = '/home/salvus/salvus/salvus/data/local/etc/tinc/'
tinc_conf = os.path.join(tinc_path, 'tinc.conf')
hosts_path = os.path.join(tinc_path, 'hosts')
if not os.path.exists(hosts_path):
    # symbolic link from tinc_conf_hosts to hosts_path
    os.symlink(tinc_conf_hosts, hosts_path)
        

def init():
    external_address = sys.argv[2]
    internal_address = misc.local_ip_address()
    tinc_address     = sys.argv[3]
    tincname         = sys.argv[4]

    if not os.path.exists(tinc_path):
        os.makedirs(tinc_path)

    run_path = '/home/salvus/salvus/salvus/data/local/var/run/'
    if not os.path.exists(run_path):
        os.makedirs(run_path)

    tinc_up = os.path.join(tinc_path, 'tinc-up')

    open(tinc_up,'w').write(
          "#!/bin/sh\nifconfig $INTERFACE %s netmask 255.192.0.0 txqueuelen 10000"%tinc_address)

    os.popen("chmod a+rx %s"%tinc_up)

    open(tinc_conf,'w').write("Name = %s\nKeyExpire = 2592000\nProcessPriority = high\n"%tincname)

    rsa_key_priv = os.path.join(tinc_path, 'rsa_key.priv')
    rsa_key_pub  = os.path.join(tinc_path, 'hosts', tincname)

    if os.path.exists(rsa_key_priv): os.unlink(rsa_key_priv)
    if os.path.exists(rsa_key_pub): os.unlink(rsa_key_pub)

    os.popen("tincd --config %s -K"%tinc_path).read()

    host_file  = os.path.join(hosts_path, tincname)
    public_key = open(rsa_key_pub).read().strip()

    # We give the internal address for Address= since only other GCE nodes will connect to these nodes, and
{'fraction_non_alphanumeric': 0.167663515338607, 'fraction_numerical': 0.010804553347482154, 'mean_word_length': 3.8721804511278197, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7227058', 'n_tokens_mistral': 1831, 'n_tokens_neox': 1741, 'n_words': 450}