CDS
view release on metacpan or search on metacpan
# This is part of the Condensation Perl Module 0.31 (cli) built on 2022-12-08.
# See https://condensation.io for information about the Condensation Data System.
use strict;
use warnings;
use 5.010000;
use CDS::C;
=pod
=head1 CDS - Condensation Data System
Condensation is a general-purpose distributed data system with conflict-free synchronization, and inherent end-to-end security.
This is the Perl implementation. It comes with a Perl module:
use CDS;
and a command line tool:
cds
More information is available on L<condensation.io|https://condensation.io>.
=cut
use Cwd;
use Digest::SHA;
use Encode;
use Fcntl;
use HTTP::Date;
use HTTP::Headers;
use HTTP::Request;
use HTTP::Server::Simple;
use LWP::UserAgent;
use Time::Local;
use utf8;
package CDS;
our $VERSION = '0.31';
our $edition = 'cli';
our $releaseDate = '2022-12-08';
sub now { time * 1000 }
sub SECOND { 1000 }
sub MINUTE { 60 * 1000 }
sub HOUR { 60 * 60 * 1000 }
sub DAY { 24 * 60 * 60 * 1000 }
sub WEEK { 7 * 24 * 60 * 60 * 1000 }
sub MONTH { 30 * 24 * 60 * 60 * 1000 }
sub YEAR { 365 * 24 * 60 * 60 * 1000 }
# File system utility functions.
sub readBytesFromFile {
my $class = shift;
my $filename = shift;
open(my $fh, '<:bytes', $filename) || return;
local $/;
my $content = <$fh>;
close $fh;
return $content;
}
sub writeBytesToFile {
my $class = shift;
my $filename = shift;
open(my $fh, '>:bytes', $filename) || return;
print $fh @_;
close $fh;
}
sub collectActorgroup {
my $o = shift;
my $label = shift;
my $value = shift;
for my $member ($value->actorGroup->members) {
my $actorOnStore = $member->actorOnStore;
$o->addKnownPublicKey($actorOnStore->publicKey);
push @{$o->{accountTokens}}, CDS::AccountToken->new($actorOnStore->store, $actorOnStore->publicKey->hash);
}
}
sub collectKeypair {
my $o = shift;
my $label = shift;
my $value = shift;
$o->{keyPairToken} = $value;
$o->{actorHash} = $value->keyPair->publicKey->hash;
}
sub collectStore {
my $o = shift;
my $label = shift;
my $value = shift;
push @{$o->{stores}}, $value;
}
sub new {
my $class = shift;
my $actor = shift;
bless {actor => $actor, ui => $actor->ui} }
# END AUTOGENERATED
# HTML FOLDER NAME show-card
# HTML TITLE Show an actor's public card
sub help {
my $o = shift;
my $cmd = shift;
my $ui = $o->{ui};
$ui->space;
$ui->command('cds show card of ACCOUNT');
$ui->command('cds show card of ACTOR [on STORE]');
$ui->command('cds show card of KEYPAIR [on STORE]');
$ui->p('Shows the card(s) of an actor.');
$ui->space;
$ui->command('cds show card of ACTORGROUP');
$ui->p('Shows all cards of an actor group.');
$ui->space;
$ui->command('cds show card');
$ui->p('Shows the card of the selected actor on the selected store.');
$ui->space;
$ui->command('cds show my card');
$ui->p('Shows your own card.');
$ui->space;
$ui->p('An actor usually has one card. If no cards are shown, the corresponding actor does not exist, is not using that store, or has not properly announced itself. Two cards may exist while the actor is updating its card. Such a state is temporary,...
$ui->space;
$ui->p('A peer consists of one or more actors, which all publish their own card. The cards are usually different, but should contain consistent information.');
$ui->space;
$ui->p('You can publish your own card (i.e. the card of your main key pair) using');
$ui->p(' cds announce');
$ui->space;
}
sub showCard {
my $o = shift;
my $cmd = shift;
$o->{keyPairToken} = $o->{actor}->preferredKeyPairToken;
$o->{stores} = [];
$o->{accountTokens} = [];
$o->{knownPublicKeys} = {};
$cmd->collect($o);
# Use actorHash/store
if (! scalar @{$o->{accountTokens}}) {
$o->{actorHash} = $o->{actor}->preferredActorHash if ! $o->{actorHash};
push @{$o->{stores}}, $o->{actor}->preferredStores if ! scalar @{$o->{stores}};
for my $store (@{$o->{stores}}) {
push @{$o->{accountTokens}}, CDS::AccountToken->new($store, $o->{actorHash});
}
}
# Show the cards
$o->addKnownPublicKey($o->{keyPairToken}->keyPair->publicKey);
$o->addKnownPublicKey($o->{actor}->keyPair->publicKey);
for my $accountToken (@{$o->{accountTokens}}) {
$o->processAccount($accountToken);
}
$o->{ui}->space;
}
sub showMyCard {
my $o = shift;
my $cmd = shift;
$o->{keyPairToken} = $o->{actor}->preferredKeyPairToken;
$o->processAccount(CDS::AccountToken->new($o->{actor}->messagingStore, $o->{actor}->keyPair->publicKey->hash));
$o->processAccount(CDS::AccountToken->new($o->{actor}->storageStore, $o->{actor}->keyPair->publicKey->hash)) if $o->{actor}->storageStore->url ne $o->{actor}->messagingStore->url;
$o->{ui}->space;
}
sub processAccount {
my $o = shift;
my $accountToken = shift;
$o->{ui}->space;
# Query the store
my $store = $accountToken->cliStore;
my ($hashes, $storeError) = $store->list($accountToken->actorHash, 'public', 0);
if (defined $storeError) {
$o->{ui}->title('public box of ', $o->{actor}->blueAccountReference($accountToken));
return;
}
( run in 2.422 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )