ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MP/MP/Kernel.pm
(Generate patch)

Comparing AnyEvent-MP/MP/Kernel.pm (file contents):
Revision 1.87 by root, Sun Mar 4 19:45:03 2012 UTC vs.
Revision 1.88 by root, Thu Mar 8 21:37:51 2012 UTC

411 if exists $LMON{$_[1]}; 411 if exists $LMON{$_[1]};
412} 412}
413 413
414sub _secure_check { 414sub _secure_check {
415 $SECURE->($SRCNODE->{id}) 415 $SECURE->($SRCNODE->{id})
416 or $SRCNODE->{id} eq $NODE
416 or die "remote execution attempt by insecure node\n"; 417 or die "remote execution attempt by insecure node\n";
417} 418}
418 419
419our %NODE_REQ = ( 420our %NODE_REQ = (
420 # internal services 421 # internal services
444 # "public" services - not actually public 445 # "public" services - not actually public
445 446
446 # another node wants to kill a local port 447 # another node wants to kill a local port
447 kil => \&_kill, 448 kil => \&_kill,
448 449
450 # is the remote node considered secure?
451# secure => sub {
452# #TODO#
453# },
454
449 # relay message to another node / generic echo 455 # relay message to another node / generic echo
450 snd => \&snd,
451 snd_multiple => sub { 456 snd => sub {
452 snd @$_ for @_ 457 &_secure_check;
458 &snd
453 }, 459 },
454 460
455 # random utilities 461 # random utilities
456 eval => sub { 462 eval => sub {
457 &_secure_check; 463 &_secure_check;
458 my @res = do { package main; eval shift }; 464 my @res = do { package main; eval shift };
459 snd @_, "$@", @res if @_; 465 snd @_, "$@", @res if @_;
460 }, 466 },
461 time => sub { 467 time => sub {
468 &_secure_check;
462 snd @_, AE::now; 469 snd @_, AE::now;
463 }, 470 },
464 devnull => sub { 471 devnull => sub {
465 # 472 #
466 }, 473 },
596# "'g" -> node -> undef 603# "'g" -> node -> undef
597# ... 604# ...
598# 605#
599 606
600# used on all nodes: 607# used on all nodes:
601our $MASTER; # the global node we bind ourselves to, unless we are global ourselves 608our $MASTER; # the global node we bind ourselves to
602our $MASTER_MON; 609our $MASTER_MON;
603our %LOCAL_DB; # this node database 610our %LOCAL_DB; # this node database
604 611
605our %GLOBAL_DB; # all local databases, merged - empty on non-global nodes 612our %GLOBAL_DB; # all local databases, merged - empty on non-global nodes
606 613
629} 636}
630 637
631sub global_req_del { 638sub global_req_del {
632 delete $GLOBAL_REQ{$_[0]}; 639 delete $GLOBAL_REQ{$_[0]};
633} 640}
641
642#################################
643# master rpc
644
645our %GLOBAL_RES;
646our $GLOBAL_RES_ID = "a";
647
648sub global_call {
649 my $id = ++$GLOBAL_RES_ID;
650 $GLOBAL_RES{$id} = pop;
651 global_req_add $id, [@_, $id];
652}
653
654$NODE_REQ{g_reply} = sub {
655 my $id = shift;
656 global_req_del $id;
657 my $cb = delete $GLOBAL_RES{$id}
658 or return;
659 &$cb
660};
661
662#################################
634 663
635sub g_find { 664sub g_find {
636 global_req_add "g_find $_[0]", [g_find => $_[0]]; 665 global_req_add "g_find $_[0]", [g_find => $_[0]];
637} 666}
638 667
690 719
691############################################################################# 720#############################################################################
692# local database operations 721# local database operations
693 722
694# local database management 723# local database management
724
695sub db_set($$;$) { 725sub db_set($$;$) {
696 $LOCAL_DB{$_[0]}{$_[1]} = $_[2]; 726 $LOCAL_DB{$_[0]}{$_[1]} = $_[2];
697 snd $MASTER, g_add => $_[0] => $_[1] => $_[2] 727 snd $MASTER, g_add => $_[0] => $_[1] => $_[2]
698 if defined $MASTER; 728 if defined $MASTER;
699} 729}
708 my ($family, $key) = @_; 738 my ($family, $key) = @_;
709 &db_set; 739 &db_set;
710 Guard::guard { db_del $family => $key } 740 Guard::guard { db_del $family => $key }
711} 741}
712 742
743# database query
744
745sub db_family {
746 my ($family, $cb) = @_;
747 global_call g_db_family => $family, $cb;
748}
749
713sub db_keys($$$) { 750sub db_keys {
714 #d# 751 my ($family, $cb) = @_;
752 global_call g_db_keys => $family, $cb;
715} 753}
716 754
717#d# db_values 755sub db_values {
718#d# db_family 756 my ($family, $cb) = @_;
719#d# db_key 757 global_call g_db_values => $family, $cb;
758}
759
760# database monitoring
720 761
721our %LOCAL_MON; # f, reply 762our %LOCAL_MON; # f, reply
722our %MON_DB; # f, k, value 763our %MON_DB; # f, k, value
723 764
724sub db_mon($@) { 765sub db_mon($@) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines