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.75 by root, Thu Mar 1 18:48:02 2012 UTC vs.
Revision 1.76 by root, Thu Mar 1 19:37:59 2012 UTC

126 } 126 }
127 127
128 $nonce 128 $nonce
129} 129}
130 130
131# binary to alphanumeric
131sub alnumbits($) { 132sub alnumbits($) {
132 my $data = $_[0];
133
134 if (eval "use Math::GMP 2.05; 1") {
135 $data = Math::GMP::get_str_gmp (
136 (Math::GMP::new_from_scalar_with_base (+(unpack "H*", $data), 16)),
137 62
138 );
139 } else {
140 $data = MIME::Base64::encode_base64 $data, ""; 133 (my $data = MIME::Base64::encode_base64 $_[0], "") =~ y%+/=%-_%d;
141 $data =~ s/=//;
142 $data =~ s/x/x0/g;
143 $data =~ s/\//x1/g;
144 $data =~ s/\+/x2/g;
145 }
146
147 $data 134 $data
148} 135}
149 136
150sub gen_uniq { 137sub gen_uniq {
138 # 48 bits happen to fit perfectly into 8 chars
139 # we add one more char to get 54 bits.
151 alnumbits pack "nna*", $$ & 0xffff, time & 0xffff, nonce 2 140 substr +(alnumbits pack "nna*", $$ & 0xffff, time & 0xffff, nonce 3), 0, 9
152} 141}
153 142
154our $CONFIG; # this node's configuration 143our $CONFIG; # this node's configuration
155 144
156our $RUNIQ; # remote uniq value 145our $RUNIQ; # remote uniq value
166 155
167our $GLOBAL; # true if node is a global ("directory") node 156our $GLOBAL; # true if node is a global ("directory") node
168our %LISTENER; 157our %LISTENER;
169our $LISTENER; # our listeners, as arrayref 158our $LISTENER; # our listeners, as arrayref
170 159
171our $SRCNODE; # holds the sending node during _inject 160our $SRCNODE; # holds the sending node _object_ during _inject
172 161
173sub _init_names { 162sub _init_names {
174 $RUNIQ = alnumbits nonce 96/8;
175 $UNIQ = gen_uniq; 163 $UNIQ = gen_uniq;
164 $RUNIQ = substr +(alnumbits nonce 64/8), 0, 10; # for remote port names &c, should be longer than $UNIQ
176 $NODE = "anon/$RUNIQ"; 165 $NODE = "anon/$RUNIQ";
177} 166}
178 167
179_init_names; 168_init_names;
180 169
463 snd => \&snd, 452 snd => \&snd,
464 snd_multiple => sub { 453 snd_multiple => sub {
465 snd @$_ for @_ 454 snd @$_ for @_
466 }, 455 },
467 456
468 # informational
469 info => sub {
470 snd @_, $NODE;
471 },
472 known_nodes => sub {
473 snd @_, known_nodes;
474 },
475 up_nodes => sub {
476 snd @_, up_nodes;
477 },
478
479 # random utilities 457 # random utilities
480 eval => sub { 458 eval => sub {
459 #d#SECURE
481 my @res = do { package main; eval shift }; 460 my @res = do { package main; eval shift };
482 snd @_, "$@", @res if @_; 461 snd @_, "$@", @res if @_;
483 }, 462 },
484 time => sub { 463 time => sub {
485 snd @_, AE::time; 464 snd @_, AE::now;
486 }, 465 },
487 devnull => sub { 466 devnull => sub {
488 # 467 #
489 }, 468 },
490 "" => sub { 469 "" => sub {
493); 472);
494 473
495$NODE{""} = $NODE{$NODE} = new AnyEvent::MP::Node::Self $NODE; 474$NODE{""} = $NODE{$NODE} = new AnyEvent::MP::Node::Self $NODE;
496$PORT{""} = sub { 475$PORT{""} = sub {
497 my $tag = shift; 476 my $tag = shift;
477 #d#SECURE (load_func)
498 eval { &{ $node_req{$tag} ||= load_func $tag } }; 478 eval { &{ $node_req{$tag} ||= load_func $tag } };
499 $WARN->(2, "error processing node message: $@") if $@; 479 $WARN->(2, "error processing node message: $@") if $@;
500}; 480};
501 481
502############################################################################# 482#############################################################################

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines