… | |
… | |
411 | if exists $LMON{$_[1]}; |
411 | if exists $LMON{$_[1]}; |
412 | } |
412 | } |
413 | |
413 | |
414 | sub _secure_check { |
414 | sub _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 | |
419 | our %NODE_REQ = ( |
420 | our %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: |
601 | our $MASTER; # the global node we bind ourselves to, unless we are global ourselves |
608 | our $MASTER; # the global node we bind ourselves to |
602 | our $MASTER_MON; |
609 | our $MASTER_MON; |
603 | our %LOCAL_DB; # this node database |
610 | our %LOCAL_DB; # this node database |
604 | |
611 | |
605 | our %GLOBAL_DB; # all local databases, merged - empty on non-global nodes |
612 | our %GLOBAL_DB; # all local databases, merged - empty on non-global nodes |
606 | |
613 | |
… | |
… | |
629 | } |
636 | } |
630 | |
637 | |
631 | sub global_req_del { |
638 | sub global_req_del { |
632 | delete $GLOBAL_REQ{$_[0]}; |
639 | delete $GLOBAL_REQ{$_[0]}; |
633 | } |
640 | } |
|
|
641 | |
|
|
642 | ################################# |
|
|
643 | # master rpc |
|
|
644 | |
|
|
645 | our %GLOBAL_RES; |
|
|
646 | our $GLOBAL_RES_ID = "a"; |
|
|
647 | |
|
|
648 | sub 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 | |
635 | sub g_find { |
664 | sub 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 | |
695 | sub db_set($$;$) { |
725 | sub 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 | |
|
|
745 | sub db_family { |
|
|
746 | my ($family, $cb) = @_; |
|
|
747 | global_call g_db_family => $family, $cb; |
|
|
748 | } |
|
|
749 | |
713 | sub db_keys($$$) { |
750 | sub db_keys { |
714 | #d# |
751 | my ($family, $cb) = @_; |
|
|
752 | global_call g_db_keys => $family, $cb; |
715 | } |
753 | } |
716 | |
754 | |
717 | #d# db_values |
755 | sub 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 | |
721 | our %LOCAL_MON; # f, reply |
762 | our %LOCAL_MON; # f, reply |
722 | our %MON_DB; # f, k, value |
763 | our %MON_DB; # f, k, value |
723 | |
764 | |
724 | sub db_mon($@) { |
765 | sub db_mon($@) { |