⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 register.xpl

📁 OpenCDN内容分发系统
💻 XPL
字号:
<?xml version="1.0"?><!DOCTYPE methoddef SYSTEM "rpc-method.dtd"><methoddef><name>Register</name><version>1.0</version><signature>string struct</signature><help>Description:    Accepts authenticated registrations from nodesArguments:      a structure containing                KEY                VALUE                Address            the node IP address                Port               its TCP port                Transport          isma (or other profile supported)                DirectFootprint    ref to a list of domains or IP address prefixes                IndirectFootprint  ref to a list of domains or IP address prefixes                Digest             Fingerprint of the node                AuthToken          token to authenticate de-registration requestsReturns:        a struct containing                KEY                VALUE                ret_code           int (numeric return code)                ret_val            string (message string)                name               the CDN centered on this RRDM                delay              delay in secs between re-registrations                RTSPpassword       password to authenticate pull requests                                   between streaming servers                AuthToken          authentication token to use in all following                                   RPC-XML method calls</help><code language="perl"><![CDATA[#!/usr/bin/perluse CommLib qw(node_log mk_digest);################################################################################ Sub Name:     Register## Description:  Accepts authenticated registrations from nodes## Arguments:    a structure containing#               KEY                VALUE#               Address            the node IP address#               Port               its TCP port#               Transport          isma | wm | real#               DirectFootprint    ref to a list of domains or IP address prefixes#               IndirectFootprint  ref to a list of domains or IP address prefixes#               Digest             Fingerprint of the node#               AuthToken          token to authenticate de-registration requests## Globals affected:#               %nodes             hash with registration data from nodes#               %footp             hash  " addresses of nodes for a given FP#               %surro             hash  " of surrogates for given origin and FP#               %peers             hash  " nodes from which media is received#               %nonce_by_ID       hash  " nonce for given entity (Node/Origin) ID## Returns:      a struct containing#               KEY                VALUE#               ret_code           int (numeric return code)#               ret_val            string (message string)#               name               the CDN centered on this RRDM#               delay              delay in secs between re-registrations#               RTSPpassword       password to authenticate pull requests#                                  between streaming servers#               AuthToken          authentication token to use in all following#                                  RPC-XML method calls###############################################################################sub Register {    require RRDMlib;    my $parm_ref   = pop @_;       # gets hash reference for input parameters    my $t;    my ($numnod, $delay);          # number of nodes and re-registration delay    my ($node_ID, $myDigest);    # gets input parameters    my $node_addr  = $$parm_ref{Address};    my $node_port  = $$parm_ref{Port};    my $node_char  = $$parm_ref{Character};    my $transport  = $$parm_ref{Transport};    my $TR_FP_ref  = $$parm_ref{IndirectFootprint};    my $LH_FP_ref  = $$parm_ref{DirectFootprint};    my $hisDigest  = $$parm_ref{Digest};    my $hisToken   = $$parm_ref{AuthToken};    my ( $retcode, $retval ) = ( '200', '' );    # Determines per-Node delay for re-registrations    $numnod = (keys %RRDMlib::nodes) + 1;          # number of nodes    $delay = &RRDMlib::rereg_delay ($numnod, $RRDMconfig::rreg_pace);    node_log ( "*** Register invoked by $node_addr:$node_port, transport = $transport, transit_FP = @$TR_FP_ref LH_FP @$LH_FP_ref, character $node_char", 3, 'r');    if (@$TR_FP_ref==() && @$LH_FP_ref==()) {    # empty FP is a dereg request      # Authentication dereg request      if ( $hisToken eq $RRDMlib::auth_token ) { # dereg authorized        node_log ("De-registration for node $node_addr:$node_port", 1, 'r');        $retval = &RRDMlib::De_Register ($node_addr);        # Deletes respective nonce        delete $RRDMlib::nonce_by_ID{"$node_addr:$node_port"};      } else {  # request unauthorized        node_log ("De-registration for node $node_addr:$node_port unauthorized", 1, 'r');        $retcode = '401';        $retval = 'Unauthorized';        return { ret_code  => $retcode,  ret_val => $retval,                 name      => 'noname',  delay   => '600',                 RTSPpassword => '',                 AuthToken    => '' };      } # End dereg request authentication    }    else {                                       # Registration or re-reg      # Beginning reg request authentication      # Builds node identification      $node_ID = $node_addr.':'.$node_port;      # Calculates my digest      $myDigest = mk_digest ($RRDMlib::nonce_by_ID{$node_ID});      # Checks method caller's identity      if ( $hisDigest ne $myDigest ) { # identity unknown!        if  ( $RRDMlib::nonce_by_ID{$node_ID} ) { # is not his first 'Register' call          node_log ("    (Register) Authentication of the node $node_ID failed", 1, 'r');          # Deletes respective nonce          delete $RRDMlib::nonce_by_ID{$node_ID};        }        $retcode = '401';        $retval = 'Unauthorized';        # Registration ends here        return { ret_code  => $retcode,  ret_val => $retval,                 name      => 'noname',  delay   => '600',                 RTSPpassword => '',                 AuthToken    => '' };      }      # End authentication node      node_log ("    (Register) Authentication of the node $node_ID succeeded", 3, 'r');      # Authentication went fine: go on with registration!!      if (defined $RRDMlib::nodes{$node_addr}) { # Already seen: is a re-reg        $RRDMlib::nodes{$node_addr}{'rtime'} = time;        $RRDMlib::nodes{$node_addr}{'utime'} = time + $delay;        $retval = "Node $node_addr already present. Timestamps updated";        #node_log ($retval, 3, 'r');      } else {                                   # new node        # add registration data to %nodes        $RRDMlib::nodes{$node_addr} = { 'port'      => $node_port,#                                        'transport' => $transport,                                        'health'    => 100,                                        'character' => $node_char,                                        'rtime'     => time,                                        'utime'     => time + $delay };        unless ($RRDMlib::nodes{$node_addr}{'transport'} =~ $transport) {          $RRDMlib::nodes{$node_addr}{'transport'} .= $transport;        }        # populates nodes and footprint hashes with registration data        if (($retval=&RRDMlib::save_Register($node_addr, $TR_FP_ref, "transit")) eq "" &&            ($retval=&RRDMlib::save_Register($node_addr, $LH_FP_ref,      "LH")) eq "") {              $retval = "Registration of $node_addr successful";              node_log ("Registration for node $node_addr:$node_port ($node_char)", 1, 'r');              node_log ("  - transport $transport", 1, 'r');              node_log ("  - transit_FP = @$TR_FP_ref", 1, 'r');              node_log ("  - LH_FP      = @$LH_FP_ref", 1, 'r');        } # Here $retval could hold an error coming from RRDMlib::save_Register        else {          node_log ("Registration of $node_addr unsuccessfull: $retval", 1, 'r');          $retcode = '510';                        # Footprint malformed        }      }    }    # Debug controls    #&RRDMlib::show_table('nodes');    #&RRDMlib::show_table('footp');    return { ret_code => $retcode,               ret_val => $retval,             name     => $RRDMconfig::oCDN_name, delay   => $delay,             RTSPpassword => $RRDMconfig::RTSPpassword,             AuthToken    => $RRDMlib::auth_token };}__END__]]></code></methoddef>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -