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

📄 dorelay.xpl

📁 OpenCDN内容分发系统
💻 XPL
字号:
<?xml version="1.0"?><!DOCTYPE methoddef SYSTEM "rpc-method.dtd"><methoddef><name>DoRelay</name><version>1.0</version><signature>struct struct</signature><help> Accepts a struct containing:   KEY               VALUE   Client            string    ip address of the client requesting the media   Transport         string    protocol/format requested by the client   Origin            string    URI of the content origin   OriginAddr        string    for FirshHop behavior   Program           string    URI of the absolute content origin   LH_cn             array     ip:port of the LH candidates   LH_cFP            array     direct footprints of the LH candidates   TR_cn             array     ip:port of the TR candidates   TR_cFP            array     direct footprints of the TR candidates   AuthToken         int       token to authenticate method caller Returns a struct containing:   KEY               VALUE   ret_code          int       numeric return code   ret_val           string    message string   SurrogateUri      string    URI of the surrogate, empty in case of failure   TransitRelayList  array ref list of transit URIs   Prereq_Res        string    result of prerequisite invocation</help><code language="perl"><![CDATA[#!/usr/bin/perl################################################################################   Sub Name:         DoRelay## Accepts a struct containing:#   KEY               VALUE#   Client            string    ip address of the client requesting the media#   Transport         string    protocol/format requested by the client#   Origin            string    URI of the origin from which keep media#   Program           string    URI of the absolute content origin#   OriginAddr        string    Address of Program URI, for FirshHop behavior#   LH_cn             array     ip:port of the LH candidates#   LH_cFP            array     direct footprints of the LH candidates#   TR_cn             array     ip:port of the TR candidates#   TR_cFP            array     direct footprints of the TR candidates#   AuthToken         int       token to authenticate method caller## Returns a struct containing:#   KEY               VALUE#   ret_code          int       numeric return code#   ret_val           string    message string#   SurrogateUri      string    URI of the surrogate, empty in case of failure#   TransitRelayList  array ref list of transit URIs#   Prereq_Res        string    result of prerequisite invocation###############################################################################sub DoRelay {  use CommLib qw(node_log DBF_access);  require "$Node::opt_c";  NodeConfig->import(qw($node_address $node_char $maxband));  my $arg_r    = pop @_;  my $transp   = $$arg_r{Transport};  my $ip_cli   = $$arg_r{Client};  my $or       = $$arg_r{Origin};  my $ip_orig  = $$arg_r{OriginAddr};  my $prog     = $$arg_r{Program};  my $LH_cn_r  = $$arg_r{LH_cn};  my $hisToken = $$arg_r{AuthToken};  my ($ret_val, $ret_code, $SurrogateUri, $TransitRelayList, $prereq_res) =     ('', '', '', '');  my ($tra_chk, $charact, $auth_token) = (undef, undef, undef);  # Retrieves my current AuthToken from DB file  my $auth_t_r = DBF_access ("$Node::us_URI_db", ['AuthToken'], 'r', 'n');  $auth_token = $$auth_t_r{'AuthToken'};  if ($auth_token) {                  # auth_token retrieved    if ( $hisToken ne $auth_token ) { # caller unauthorized      $ret_code = '401';      $ret_val  = 'Unauthorized';      node_log (": [$node_address]:DoRelay: $ret_code $ret_val", 1, 'n');    }  } else {                            # auth_token NOT retrieved    $ret_code = '408';    $ret_val  = 'Unable to retrieve AuthToken from DB_File';    node_log (": [$node_address]:DoRelay: $ret_code $ret_val", 1, 'n');  }  unless ($ret_code) {                # Node is authorized    node_log (": [$node_address]>>> DoRelay request: prog $prog, or $or", 1, 'n');    node_log ("Checking program $prog format...", 3, 'n');    if ( $prog !~ m/rtsp:\/\/.*\// ) {      $ret_val = 'Bad origin or program format';      $ret_code ='420';      node_log ( "$ret_val\n", 1, 'n');    }  }  unless ($ret_code) {    node_log ( 'Checking transport and footprint...', 3, 'n');    $tra_chk = &NodeLib::check_transport ($transp, $ip_cli, $ip_orig, $LH_cn_r);    if ( $tra_chk eq 'bad' ) {      $ret_val = 'Transport and/or footprint do not match.';      $ret_code ='420';      node_log ( "$ret_val", 1, 'n');    }    if ( $tra_chk eq 'FH' ) {           # found a FirstHop node      $tra_chk = 'TR';      $$arg_r{OriginAddr} = '';         # null after FH      node_log ( "...turning FH to TR for origin $ip_orig", 1, 'n');    }  }  unless ($ret_code) {    if ( $tra_chk eq 'LH' ) {       # tries to become a LAST HOP      node_log ( "...client $ip_cli is in direct footprint: node acts as a LH", 1, 'n');    }    else {                          # tries to become a TRANSIT      node_log ( "...client $ip_cli is in indirect footprint: node acts as a TR", 1, 'n');      if ( $node_char eq 'fair' ) { # check health status        my $thrp = &Adaptation::query_band($transp);        my $cpu = &NodeLib::query_cpu;        # decide if lazy or labor        if ( ( (( $maxband - $thrp ) / $maxband) *               (( 100 - $cpu ) / 100 ) * 100 ) < $min_health ) {          $charact = 'lazy';          node_log ( "...health is low", 1, 'n');        }        else {          $charact = 'labor';          node_log ( "...health is fine", 1, 'n');        }        node_log ( "Node character turned from <fair> to <$charact>", 1, 'n');      }      $charact = $charact || $node_char;    }    ($ret_code, $ret_val, $SurrogateUri, $TransitRelayList, $prereq_res ) =          &NodeLib::Transit ( $charact, $tra_chk, $arg_r );  }  return { ret_code         => $ret_code,           ret_val          => $ret_val,           SurrogateUri     => $SurrogateUri,           TransitRelayList => $TransitRelayList,           Prereq_Res       => $prereq_res };}__END__]]></code></methoddef>

⌨️ 快捷键说明

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