#!/usr/bin/perl -s
##
##
##
## Copyright (c) 2001, Vipul Ved Prakash.  All rights reserved.
## This code is free software; you can redistribute it and/or modify
## it under the same terms as Perl itself.
##
## $Id: razor-discover,v 1.6 2001/12/24 10:20:08 vipul Exp $

use lib qw(lib/);
use Razor::Client; 
use Razor::Config;

my %options;
my $config = Razor::Config::findconf ('razor.conf');
if ($d) { $options{debug} = 1 }
if ($v) { 
    print "Razor Client Tools $Razor::Client::VERSION, protocol version $Razor::Version::PROTOCOL\n";
    exit 1;
}
my $client = new Razor::Client ( "$ENV{HOME}/razor.conf", (force_discovery => 1, %options) );

=head1 NAME

razor-discover - Razor Discovery Agent

=head1 SYNOPSIS

    razor-discover -d 

=head1 DESCRIPTION

All razor agents automatically discover closest server after
C<rediscovery_wait> time has elapsed. C<razor-discover> forces immediate
rediscovery.

=head1 CLOSEST SERVER DISCOVERY PROTOCOL

Razor agents and servers belong to a Razor zone. The default open-source
zone is "razor.vipul.net". Servers in a zone are named in order -
a.zone, b.zone, c.zone and so on. To discover the closest server, an agent
sequentially walks the list of servers from a.zone 
till it finds a server with a CNAME of C<list.terminator>. This
indicates the server before C<list.terminator> is the last server
in the zone. 

Agents then send out TCP pings to ECHO port of the available servers. The
list of servers is sorted on the round trip time of ping packages. The
closest server is chosen for all subsequent communications. The list of
addresses is written to a file. At some point, when the closest server is
not responding, the next closest server is used in its stead. 

The next closest server remains the chosen server till rediscovery. This
provides seamless recovery from server/network outages, semantically
broken servers, and transition from old to new protocols.

All servers in a zone participate in a synchronization protocol to keep
their individual copies of the entire Catalogue up-to-date.

=head1 WHEN TO RUN

razor-discover is a diagnostic and development tool. As an end-user, you
should never have to run it.

=head1 AUTHOR

Vipul Ved Prakash, E<lt>mail@vipul.netE<gt>

=cut

=head1 SEE ALSO

razor.conf(5), razor-check(1), razor-report(1)

=head1 LICENSE

This is free software, distributed under the ARTISTIC license.

