<commit_before># Copyright (c) 2003
#	The funknet.org Group.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#	This product includes software developed by The funknet.org
#	Group and its contributors.
# 4. Neither the name of the Group nor the names of its contributors
#    may be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE GROUP AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE GROUP OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.

package Funknet::Tools::ObjectGenerator;
use strict;
use Funknet::Whois qw/ get_object get_object_inverse /;
use Funknet::Whois::ObjectGenerator;

use Data::Dumper;

# error buffer.
our @errors;

=head1 DESCRIPTION

Reasonable interface to the Funknet::Whois::ObjectGenerator stuff.

=cut

sub person {
    my (%args) = @_;

    unless (defined $args{name}) {
	error( "didn't get a name" );
    }
    unless (defined $args{address}) {
	error( "didn't get an address" );
    }
    unless (defined $args{e_mail}) {
	error( "didn't get an email address" );
    }
    unless (defined $args{phone}) {
	error( "didn't get a phone number" );
    }

    if (error()) {
	return undef;
    }
    
    my $gen = Funknet::Whois::ObjectGenerator->new( source => 'FUNKNET' );
    my $me = $gen->person( 'name'    => $args{name},
			   'address' => $args{address},
			   'e_mail'  => $args{e_mail},
			   'phone'   => $args{phone},
			 );
    unless (defined $me) {
	error("creating person object: \n".$gen->error);
	return undef;
    } else {
	return $me;
    }
}

sub key_cert {
    my (%args) = @_;

    unless (defined $args{name}) {
	error( "didn't get a name" );
    }
    unless (defined $args{changed}) {
	error( "didn't get an email address for 'changed:'" );
    }
    unless (defined $args{certif}) {
	error( "didn't get the key material" );
    }

    if (error()) {
	return undef;
    }
    
    my $gen = Funknet::Whois::ObjectGenerator->new( source => 'FUNKNET' );
    my $key = $gen->key_cert( 'name'    => $args{name},
			      'e_mail'  => $args{changed},
			      'certif'  => $args{certif},
			    );
    unless (defined $key) {
	error("creating key-cert: \n".$gen->error);
	return undef;
    } else {
	return $key;
    }
}

sub mntner {
    my (%args) = @_;

    unless (defined $args{person}) {
	error( "didn't a person object name" );
    }
    unless (defined $args{name}) {
	error( "didn't get a mntner name" );
    }
    unless (defined $args{auth}) {
	error( "didn't get an auth param (PGPKEY-?)" );
    }
    unless (defined $args{descr}) {
	error( "didn't get a description" );
    }
    unless (defined $args{e_mail}) {
	error( "didn't get an email address" );
    }

    if (error()) {
	return undef;
    }

    my $gen = Funknet::Whois::ObjectGenerator->new('source' => 'FUNKNET', 
						   'person' => $args{person} );
    
    my $me = $gen->mntner( 'name'   => $args{name}, 
			   'auth'   => $args{auth},
			   'descr'  => $args{descr}, 
			   'e_mail' => $args{e_mail} );
    unless (defined $me) {
	error("generating mntner: \n".$gen->error);
	return undef;
    } else {
	return $me;
    }
}

sub node_set {
    my (%args) = @_;

    # check args - we need: list of peers, the local network, mntner, and the name of the node
    
    unless (defined $args{peers}) {
	error( "didn't get a list of peers" );
    }
    unless (defined $args{network}) {
	error( "didn't get a network" );
    }
    unless (defined $args{mntner}) {
	error( "didn't get a mntner" );
    }
    unless (defined $args{nodename}) {
	error( "didn't get a nodename" );
    }
    unless (defined $args{endpoint}) {
	error( "didn't get an endpoint" );
    }

    if (error()) {
	return undef;
    }
    
    my $ns;
    
    # check the requested local network is available
    
    my $inetnum = get_object('inetnum', "-x $args{network}");
    if (defined $inetnum) {
	error( "network is already taken" );
	return undef;
    }
    
    # check the specified peers exist
    my $peers;
    for my $peer (@{$args{peers}}) {
	$peers->{$peer} = get_object('aut-num', $peer);
	unless (defined $peers->{$peer}) {
	    error( "peer $peer doesn't exist" );
	}
    }
    
    # do objects for a node: tunnels/inetnums, aut-num, inetnum, route
    
    my $mntner = get_object('mntner', $args{mntner});
    unless (defined $mntner) {
	error( "mntner $args{mntner} doesn't exist" );
	return undef;
    }
    my $gen = Funknet::Whois::ObjectGenerator->new( 'source' => 'FUNKNET',
						    'mntner' => $args{mntner},
						    'person' => $mntner->admin_c,
						    'e_mail' => $mntner->upd_to,
						  );
    # get an AS number
    $ns->{as} = $gen->aut_num_assign( 'name'  => $args{nodename},
				      'descr' => $args{nodename},
				      'tuns'  => [ ],
				      'import' => [ ],
				      'export' => [ ],
				    );
    unless (defined $ns->{as}) {
	error("generating as: \n".$gen->error);
	return undef;
    }
<commit_msg>make missing peer fatal<commit_after># Copyright (c) 2003
#	The funknet.org Group.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#	This product includes software developed by The funknet.org
#	Group and its contributors.
# 4. Neither the name of the Group nor the names of its contributors
#    may be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE GROUP AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE GROUP OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.

package Funknet::Tools::ObjectGenerator;
use strict;
use Funknet::Whois qw/ get_object get_object_inverse /;
use Funknet::Whois::ObjectGenerator;

use Data::Dumper;

# error buffer.
our @errors;

=head1 DESCRIPTION

Reasonable interface to the Funknet::Whois::ObjectGenerator stuff.

=cut

sub person {
    my (%args) = @_;

    unless (defined $args{name}) {
	error( "didn't get a name" );
    }
    unless (defined $args{address}) {
	error( "didn't get an address" );
    }
    unless (defined $args{e_mail}) {
	error( "didn't get an email address" );
    }
    unless (defined $args{phone}) {
	error( "didn't get a phone number" );
    }

    if (error()) {
	return undef;
    }
    
    my $gen = Funknet::Whois::ObjectGenerator->new( source => 'FUNKNET' );
    my $me = $gen->person( 'name'    => $args{name},
			   'address' => $args{address},
			   'e_mail'  => $args{e_mail},
			   'phone'   => $args{phone},
			 );
    unless (defined $me) {
	error("creating person object: \n".$gen->error);
	return undef;
    } else {
	return $me;
    }
}

sub key_cert {
    my (%args) = @_;

    unless (defined $args{name}) {
	error( "didn't get a name" );
    }
    unless (defined $args{changed}) {
	error( "didn't get an email address for 'changed:'" );
    }
    unless (defined $args{certif}) {
	error( "didn't get the key material" );
    }

    if (error()) {
	return undef;
    }
    
    my $gen = Funknet::Whois::ObjectGenerator->new( source => 'FUNKNET' );
    my $key = $gen->key_cert( 'name'    => $args{name},
			      'e_mail'  => $args{changed},
			      'certif'  => $args{certif},
			    );
    unless (defined $key) {
	error("creating key-cert: \n".$gen->error);
	return undef;
    } else {
	return $key;
    }
}

sub mntner {
    my (%args) = @_;

    unless (defined $args{person}) {
	error( "didn't a person object name" );
    }
    unless (defined $args{name}) {
	error( "didn't get a mntner name" );
    }
    unless (defined $args{auth}) {
	error( "didn't get an auth param (PGPKEY-?)" );
    }
    unless (defined $args{descr}) {
	error( "didn't get a description" );
    }
    unless (defined $args{e_mail}) {
	error( "didn't get an email address" );
    }

    if (error()) {
	return undef;
    }

    my $gen = Funknet::Whois::ObjectGenerator->new('source' => 'FUNKNET', 
						   'person' => $args{person} );
    
    my $me = $gen->mntner( 'name'   => $args{name}, 
			   'auth'   => $args{auth},
			   'descr'  => $args{descr}, 
			   'e_mail' => $args{e_mail} );
    unless (defined $me) {
	error("generating mntner: \n".$gen->error);
	return undef;
    } else {
	return $me;
    }
}

sub node_set {
    my (%args) = @_;

    # check args - we need: list of peers, the local network, mntner, and the name of the node
    
    unless (defined $args{peers}) {
	error( "didn't get a list of peers" );
    }
    unless (defined $args{network}) {
	error( "didn't get a network" );
    }
    unless (defined $args{mntner}) {
	error( "didn't get a mntner" );
    }
    unless (defined $args{nodename}) {
	error( "didn't get a nodename" );
    }
    unless (defined $args{endpoint}) {
	error( "didn't get an endpoint" );
    }

    if (error()) {
	return undef;
    }
    
    my $ns;
    
    # check the requested local network is available
    
    my $inetnum = get_object('inetnum', "-x $args{network}");
    if (defined $inetnum) {
	error( "network is already taken" );
	return undef;
    }
    
    # check the specified peers exist
    my $peers;
    for my $peer (@{$args{peers}}) {
	$peers->{$peer} = get_object('aut-num', $peer);
	unless (defined $peers->{$peer}) {
	    error( "peer $peer doesn't exist in whois" );
	    return undef;
	}
    }
    
    # do objects for a node: tunnels/inetnums, aut-num, inetnum, route
    
    my $mntner = get_object('mntner', $args{mntner});
    unless (defined $mntner) {
	error( "mntner $args{mntner} doesn't exist" );
	return undef;
    }
    my $gen = Funknet::Whois::ObjectGenerator->new( 'source' => 'FUNKNET',
						    'mntner' => $args{mntner},
						    'person' => $mntner->admin_c,
						    'e_mail' => $mntner->upd_to,
						  );
    # get an AS number
    $ns->{as} = $gen->aut_num_assign( 'name'  => $args{nodename},
				      'descr' => $args{nodename},
				      'tuns'  => [ ],
				      'import' => [ ],
				      'export' => [ ],
				    );
    unless (defined $ns->{as}) {
	error("generating as: \n".$gen->error);
	return undef;
    }

{'fraction_non_alphanumeric': 0.138582549464807, 'fraction_numerical': 0.0014596172559195588, 'mean_word_length': 3.0317097090552467, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '653849', 'n_tokens_mistral': 4374, 'n_tokens_neox': 3949, 'n_words': 1315}