text: # -----------------------------------------------------------------------------
  #             
  # Copyright 2013-2019 lispers.net - Dino Farinacci <farinacci@gmail.com>
  # 
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  # 
  #     http://www.apache.org/licenses/LICENSE-2.0
  # 
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.    
  # 
  # -----------------------------------------------------------------------------
  #
  # lisp-mr.py
  #
  # This file performs LISP Map-Resolver functionality.
  # 
  # -----------------------------------------------------------------------------
  if 64 - 64: i11iIiiIii
  import lisp
  import lispconfig
  import threading
  import select
  if 65 - 65: O0 / iIii1I11I1II1 % OoooooooOO - i1IIi
  if 73 - 73: II111iiii
  if 22 - 22: I1IiiI * Oo0Ooo / OoO0O00 . OoOoOO00 . o0oOOo0O0Ooo / I1ii11iIi11i
  if 48 - 48: oO0o / OOooOOo / I11i / Ii1I
  if 48 - 48: iII111i % IiII + I1Ii111 / ooOoO0o * Ii1I
  if 46 - 46: ooOoO0o * I11i - OoooooooOO
  II1iII1i = [ None , None , None ]
  oO0oIIII = None
  Oo0oO0oo0oO00 = None
  i111I = None
  II1Ii1iI1i = { }
  iiI1iIiI = None
  OOo = lisp . lisp_get_ephemeral_port ( )
  if 1 - 1: II111iiii - I1ii11iIi11i % i11iIiiIii + IiII . I1Ii111
  if 55 - 55: iIii1I11I1II1 - I1IiiI . Ii1I * IiII * i1IIi / iIii1I11I1II1
  if 79 - 79: oO0o + I1Ii111 . ooOoO0o * IiII % I11i . I1IiiI
  if 94 - 94: iII111i * Ii1I / IiII . i1IIi * iII111i
  if 47 - 47: i1IIi % i11iIiiIii
  if 20 - 20: ooOoO0o * II111iiii
  if 65 - 65: o0oOOo0O0Ooo * iIii1I11I1II1 * ooOoO0o
  if 18 - 18: iIii1I11I1II1 / I11i + oO0o / Oo0Ooo - II111iiii - I11i
  if 1 - 1: I11i - OOooOOo % O0 + I1IiiI - iII111i / I11i
  def iIiiI1 ( ) :
   lisp . lisp_referral_cache = lisp . lisp_cache ( )
   return
   if 68 - 68: I1IiiI - i11iIiiIii - OoO0O00 / OOooOOo - OoO0O00 + i1IIi
   if 48 - 48: OoooooooOO % o0oOOo0O0Ooo . I1IiiI - Ii1I % i1IIi % OoooooooOO
   if 3 - 3: iII111i + O0
   if 42 - 42: OOooOOo / i1IIi + i11iIiiIii - Ii1I
   if 78 - 78: OoO0O00
   if 18 - 18: O0 - iII111i / iII111i + ooOoO0o % ooOoO0o - IiII
   if 62 - 62: iII111i - IiII - OoOoOO00 % i1IIi / oO0o
  def OoooooOoo ( kv_pair ) :
   global II1Ii1iI1i
   if 70 - 70: OoO0O00 . OoO0O00 - OoO0O00 / I1ii11iIi11i * OOooOOo
   if 86 - 86: i11iIiiIii + Ii1I + ooOoO0o * I11i + o0oOOo0O0Ooo
   if 61 - 61: OoO0O00 / i11iIiiIii
   if 34 - 34: OoooooooOO + iIii1I11I1II1 + i11iIiiIii - I1ii11iIi11i + i11iIiiIii
   ooOoo0O = lisp . lisp_ddt_root ( )
   if 76 - 76: O0 / o0oOOo0O0Ooo . I1IiiI * Ii1I - OOooOOo
   if 76 - 76: i11iIiiIii / iIii1I11I1II1 . I1ii11iIi11i % OOooOOo / OoooooooOO % oO0o
   if 75 - 75: iII111i
   if 97 - 97: i11iIiiIii
   II1i1Ii11Ii11 = lisp . lisp_referral ( )
   if 35 - 35: o0oOOo0O0Ooo + iII111i + iII111i
   if 11 - 11: iII111i - OoO0O00 % ooOoO0o % iII111i / OoOoOO00 - OoO0O00
   if 74 - 74: iII111i * O0
   if 89 - 89: oO0o + Oo0Ooo
   for Ii1IOo0o0 in kv_pair . keys ( ) :
    if ( Ii1IOo0o0 == "address" ) :
     III1ii1iII = kv_pair [ Ii1IOo0o0 ]
     ooOoo0O . root_address . store_address ( III1ii1iII )
     if 54 - 54: I1IiiI % II111iiii % II111iiii
    if ( Ii1IOo0o0 == "public-key" ) :
     iI1 = kv_pair [ Ii1IOo0o0 ]
     ooOoo0O . public_key = iI1
     if 19 - 19: I11i + ooOoO0o
    if ( Ii1IOo0o0 == "priority" ) :
     iI1 = kv_pair [ Ii1IOo0o0 ]
     ooOoo0O . priority = iI1
     if 53 - 53: OoooooooOO . i1IIi
    if ( Ii1IOo0o0 == "weight" ) :
     iI1 = kv_pair [ Ii1IOo0o0 ]
     ooOoo0O . weight = iI1
     if 18 - 18: o0oOOo0O0Ooo
     if 28 - 28: OOooOOo - IiII . IiII + OoOoOO00 - OoooooooOO + O0
     if 95 - 95: OoO0O00 % oO0o . O0
     if 15 - 15: ooOoO0o / Ii1I . Ii1I - i1IIi
     if 53 - 53: IiII + I1IiiI * oO0o
     if 61 - 61: i1IIi * OOooOOo / OoooooooOO . i11iIiiIii . OoOoOO00
   II1Ii1iI1i [ III1ii1iII ] = ooOoo0O
   if 60 - 60: I11i / I11i
   if 46 - 46: Ii1I * OOooOOo - OoO0O00 * oO0o - I1Ii111
   if 83 - 83: OoooooooOO
   if 31 - 31: II111iiii - OOooOOo . I1Ii111 % OoOoOO00 - O0
   if 4 - 4: II111iiii / ooOoO0o . iII111i
   if 58 - 58: OOooOOo * i11iIiiIii / OoOoOO00 % I1Ii111 - I1ii11iIi11i / oO0o
   for ooOoo0O in II1Ii1iI1i . values ( ) :
    ii11i1 = lisp . lisp_referral_node ( )
    ii11i1 . referral_address = ooOoo0O . root_address
    ii11i1 . priority = ooOoo0O . priority
    ii11i1 . weight = ooOoo0O . weight
    III1ii1iII = ii11i1 . referral_address . print_address ( )
    II1i1Ii11Ii11 . referral_set [ III1ii1iII ] = ii11i1
    if 29 - 29: I1ii11iIi11i % I1IiiI + ooOoO0o / o0oOOo0O0Ooo + OOooOOo * o0oOOo0O0Ooo
   II1i1Ii11Ii11 . eid . afi = lisp . LISP_AFI_ULTIMATE_ROOT
   if 42 - 42: Ii1I + oO0o
   if 76 - 76: I1Ii111 - OoO0O00
   if 70 - 70: ooOoO0o
   if 61 - 61: I1ii11iIi11i . I1ii11iIi11i
   II1i1Ii11Ii11 . add_cache ( )
   return
   if 10 - 10: OoOoOO00 * iII111i . I11i + II111iiii - ooOoO0o * i1IIi
   if 56 - 56: o0oOOo0O0Ooo * IiII * II111iiii
   if 80 - 80: o0oOOo0O0Ooo * II111iiii % II111iiii
   if 59 - 59: iIii1I11I1II1 + I1IiiI - o0oOOo0O0Ooo - I1IiiI + OOooOOo / I1ii11iIi11i
   if 24 - 24: I11i . iII111i % OOooOOo + ooOoO0o % OoOoOO00
   if 4 - 4: IiII - OoO0O00 * OoOoOO00 - I11i
   if 41 - 41: OoOoOO00 . I1IiiI * oO0o % IiII
  def Oo000o ( kv_pair ) :
   if 7 - 7: ooOoO0o * OoO0O00 % oO0o . IiII
   Ii1iIiII1ii1 = [ ]
   if ( lispconfig . lisp_clause_syntax_error ( kv_pair , "eid-prefix" ,
   "prefix" ) ) : return
   for ooOooo000oOO in range ( len ( kv_pair [ "eid-prefix" ] ) ) :
    II1i1Ii11Ii11 = lisp . lisp_referral ( )
    Ii1iIiII1ii1 . append ( II1i1Ii11Ii11 )
    if 59 - 59: II111iiii + OoooooooOO * OoOoOO00 + i1IIi
    if 58 - 58: II111iiii * OOooOOo * I1ii11iIi11i / OOooOOo
   oO0o0OOOO = [ ]
   if ( lispconfig . lisp_clause_syntax_error ( kv_pair , "address" ,
   "referral" ) ) : return
   for ooOooo000oOO in range ( len ( kv_pair [ "address" ] ) ) :
    O0O0OoOO0 = lisp . lisp_referral_node ( )
    oO0o0OOOO . append ( O0O0OoOO0 )
    if 10 - 10: OoooooooOO % iIii1I11I1II1
    if 54 - 54: I1Ii111 - II111iiii % OoOoOO00 % I11i % iIii1I11I1II1 + ooOoO0o
   for Ii1IOo0o0 in kv_pair . keys ( ) :
    iI1 = kv_pair [ Ii1IOo0o0 ]
    if ( Ii1IOo0o0 == "instance-id" ) :
     for ooOooo000oOO in range ( len ( Ii1iIiII1ii1 ) ) :
      II1i1Ii11Ii11 = Ii1iIiII1ii1 [ ooOooo000oOO ]
      I1111I1iII11 = iI1 [ ooOooo000oOO ]
      if ( I1111I1iII11 == "" ) : I1111I1iII11 = "0"
      II1i1Ii11Ii11 . eid . instance_id = int ( I1111I1iII11 )
      II1i1Ii11Ii11 . group . instance_id = int ( I1111I1iII11 )
      if 59 - 59: iIii1I11I1II1 * i11iIiiIii / I1ii11iIi11i * i1IIi * O0
      if 83 - 83: OoO0O00 / I1Ii111 . OoOoOO00 / IiII . OoOoOO00 . OOooOOo
    if ( Ii1IOo0o0 == "eid-prefix" ) :
     for ooOooo000oOO in range ( len ( Ii1iIiII1ii1 ) ) :
      II1i1Ii11Ii11 = Ii1iIiII1ii1 [ ooOooo000oOO ]
      I1111I1iII11 = iI1 [ ooOooo000oOO ]
      if ( I1111I1iII11 != "" ) : II1i1Ii11Ii11 . eid . store_prefix ( I1111I1iII11 )
      if 75 - 75: I11i + OoO0O00 . OoOoOO00 . ooOoO0o + Oo0Ooo . OoO0O00
      if 96 - 96: OOooOOo . ooOoO0o - Oo0Ooo + iIii1I11I1II1 / OoOoOO00 * OOooOOo
    if ( Ii1IOo0o0 == "group-prefix" ) :
     for ooOooo000oOO in range ( len ( Ii1iIiII1ii1 ) ) :
      II1i1Ii11Ii11 = Ii1iIiII1ii1 [ ooOooo000oOO ]
      I1111I1iII11 = iI1 [ ooOooo000oOO ]
      if ( I1111I1iII11 != "" ) : II1i1Ii11Ii11 . group . store_prefix ( I1111I1iII11 )
      if 65 - 65: Ii1I . iIii1I11I1II1 / O0 - Ii1I
      if 21 - 21: I1IiiI * iIii1I11I1II1
      if 91 - 91: IiII
    if ( Ii1IOo0o0 == "priority" ) :
     for ooOooo000oOO in range ( len ( oO0o0OOOO ) ) :
      O0O0OoOO0 = oO0o0OOOO [ ooOooo000oOO ]
      I1111I1iII11 = iI1 [ ooOooo000oOO ]
      if ( I1111I1iII11 == "" ) : I1111I1iII11 = "0"
      O0O0OoOO0 . priority = int ( I1111I1iII11 )
      if 15 - 15: II111iiii
      if 18 - 18: i11iIiiIii . i1IIi % OoooooooOO / O0
    if ( Ii1IOo0o0 == "weight" ) :
     for ooOooo000oOO in range ( len ( oO0o0OOOO ) ) :
      O0O0OoOO0 = oO0o0OOOO [ ooOooo000oOO ]
      I1111I1iII11 = iI1 [ ooOooo000oOO ]
      if ( I1111I1iII11 == "" ) : I1111I1iII11 = "0"
      O0O0OoOO0 . weight = int ( I1111I1iII11 )
      if 75 - 75: OoOoOO00 % o0oOOo0O0Ooo % o0oOOo0O0Ooo . I1Ii111
      if 5 - 5: o0oOOo0O0Ooo * ooOoO0o + OoOoOO00 . OOooOOo + OoOoOO00
    if ( Ii1IOo0o0 == "address" ) :
     for ooOooo000oOO in range ( len ( oO0o0OOOO ) ) :
      O0O0OoOO0 = oO0o0OOOO [ ooOooo000oOO ]
      I1111I1iII11 = iI1 [ ooOooo000oOO ]
      if ( I1111I1iII11 != "" ) : O0O0OoOO0 . referral_address . store_address ( I1111I1iII11 )
      if 91 - 91: O0
      if 61 - 61: II111iiii
      if 64 - 64: ooOoO0o / OoOoOO00 - O0 - I11i
      if 86 - 86: I11i % OoOoOO00 / I1IiiI / OoOoOO00
      if 42 - 42: OoO0O00
      if 67 - 67: I1Ii111 . iII111i . O0
      if 10 - 10: I1ii11iIi11i % I1ii11iIi11i - iIii1I11I1II1 / OOooOOo + Ii1I
   for II1i1Ii11Ii11 in Ii1iIiII1ii1 :
    for O0O0OoOO0 in oO0o0OOOO :
     III1ii1iII = O0O0OoOO0 . referral_address . print_address ( )
     II1i1Ii11Ii11 . referral_set [ III1ii1iII ] = O0O0OoOO0
     if 87 - 87: oO0o * I1ii11iIi11i + OOooOOo / iIii1I11I1II1 / iII111i
    II1i1Ii11Ii11 . add_cache ( )
    if 37 - 37: iII111i - ooOoO0o * oO0o % i11iIiiIii - I1Ii111
   return
   if 83 - 83: I11i / I1IiiI
   if 34 - 34: IiII
   if 57 - 57: oO0o . I11i . i1IIi
   if 42 - 42: I11i + I1ii11iIi11i % O0
   if 6 - 6: oO0o
   if 68 - 68: OoOoOO00 - OoO0O00
   if 28 - 28: OoO0O00 . OOooOOo / OOooOOo + Oo0Ooo . I1ii11iIi11i
  def iiii ( ref , output ) :
   if 1 - 1: Oo0Ooo / o0oOOo0O0Ooo % iII111i * IiII . i11iIiiIii
   III1Iiii1I11 = lisp . lisp_print_elapsed ( ref . uptime )
   IIII = lisp . lisp_print_future ( ref . expires )
   iiIiI = ref . print_eid_tuple ( )
   if 91 - 91: iII111i % i1IIi % iIii1I11I1II1
   IIi1I11I1II = "configured" if ( ref . referral_source . not_set ( ) ) else ref . referral_source . print_address_no_iid ( )
   if 63 - 63: OoooooooOO - OoO0O00 . II111iiii / o0oOOo0O0Ooo . OoOoOO00 / O0
   if 84 - 84: IiII
   OOO00O0O = "--"
   if ( ref . eid . is_ultimate_root ( ) ) :
    iii = "root"
   elif ( IIi1I11I1II == "configured" ) :
    iii = "any"
   else :
    iii = ref . print_referral_type ( )
    if ( ref . is_referral_negative ( ) ) :
     iii = lisp . red ( iii , True )
     if 90 - 90: o0oOOo0O0Ooo % i1IIi / OoO0O00
    OOO00O0O = "{}<br>{}" . format ( IIII , str ( ref . referral_ttl / 60 ) )
    if 44 - 44: Oo0Ooo . OoO0O00 / I1ii11iIi11i + Ii1I
    if 65 - 65: O0
   if ( len ( ref . referral_set ) == 0 ) :
    output += lispconfig . lisp_table_row ( iiIiI , III1Iiii1I11 , OOO00O0O ,
   iii , IIi1I11I1II , "--" , "--" , "--" )
    if 68 - 68: OOooOOo % I1Ii111
    if 88 - 88: iIii1I11I1II1 - ooOoO0o + OOooOOo
   for O0O0OoOO0 in ref . referral_set . values ( ) :
    IiI111111IIII = O0O0OoOO0 . referral_address . print_address_no_iid ( )
    IiI111111IIII += "<br>up" if O0O0OoOO0 . updown else "<br>down"
    if 37 - 37: I1Ii111 / OoOoOO00
    output += lispconfig . lisp_table_row ( iiIiI , III1Iiii1I11 , OOO00O0O ,
   iii , IIi1I11I1II , IiI111111IIII , str ( O0O0OoOO0 . priority ) + "<br>" +
   str ( O0O0OoOO0 . weight ) , str ( O0O0OoOO0 . map_requests_sent ) + "<br>" +
   str ( O0O0OoOO0 . no_responses ) )
    if 23 - 23: O0
    if ( iiIiI != "" ) :
     iiIiI = ""
     III1Iiii1I11 = ""
     OOO00O0O = ""
     IIi1I11I1II = ""
     iii = ""
     if 85 - 85: Ii1I
     if 84 - 84: I1IiiI . iIii1I11I1II1 % OoooooooOO + Ii1I % OoooooooOO % OoO0O00
   return ( [ True , output ] )
   if 42 - 42: OoO0O00 / I11i / o0oOOo0O0Ooo + iII111i / OoOoOO00
   if 84 - 84: ooOoO0o * II111iiii + Oo0Ooo
   if 53 - 53: iII111i % II111iiii . IiII - iIii1I11I1II1 - IiII * II111iiii
   if 77 - 77: iIii1I11I1II1 * OoO0O00
   if 95 - 95: I1IiiI + i11iIiiIii
   if 6 - 6: ooOoO0o / i11iIiiIii + iII111i * oO0o
   if 80 - 80: II111iiii
   if 83 - 83: I11i . i11iIiiIii + II111iiii . o0oOOo0O0Ooo * I11i
  def oooO0 ( ref , output ) :
   if 46 - 46: I1Ii111
   if 60 - 60: o0oOOo0O0Ooo
   if 25 - 25: OoO0O00
   if 62 - 62: OOooOOo + O0
   if ( ref . group . is_null ( ) ) : return ( iiii ( ref , output ) )
   if 98 - 98: o0oOOo0O0Ooo
   if ( ref . source_cache == None ) : return ( [ True , output ] )
   if 51 - 51: Oo0Ooo - oO0o + II111iiii * Ii1I . I11i + oO0o
   if 78 - 78: i11iIiiIii / iII111i - Ii1I / OOooOOo + oO0o
   if 82 - 82: Ii1I
   if 46 - 46: OoooooooOO . i11iIiiIii
   if 94 - 94: o0oOOo0O0Ooo * Ii1I / Oo0Ooo / Ii1I
   output = ref . source_cache . walk_cache ( iiii , output )
   return ( [ True , output ] )
   if 87 - 87: Oo0Ooo . IiII
   if 75 - 75: ooOoO0o + OoOoOO00 + o0oOOo0O0Ooo * I11i % oO0o . iII111i
   if 55 - 55: OOooOOo . I1IiiI
   if 61 - 61: Oo0Ooo % IiII . Oo0Ooo
   if 100 - 100: I1Ii111 * O0
   if 64 - 64: OOooOOo % iIii1I11I1II1 * oO0o
   if 79 - 79: O0
  def oOO00O ( eid_str ) :
   OOOoo0OO , oO0o0 , iI1Ii11iIiI1 , OO0Oooo0oOO0O = lispconfig . lisp_get_lookup_string ( eid_str )
   if 62 - 62: I1IiiI
   if 100 - 100: Ii1I - O0 % oO0o * OOooOOo + I1IiiI
   Oo0O0oooo = "<br>"
   if 33 - 33: I1Ii111 + iII111i * oO0o / iIii1I11I1II1 - I1IiiI
   O0oO = lisp . lisp_referral_cache_lookup ( OOOoo0OO , iI1Ii11iIiI1 , oO0o0 )
   if ( O0oO == None ) :
    Oo0O0oooo += "{} {}" . format ( lisp . lisp_print_sans ( "Lookup not found for" ) ,
   lisp . lisp_print_cour ( eid_str ) )
   else :
    OO0ooOOO0OOO = lisp . lisp_print_elapsed ( O0oO . uptime )
    Oo0O0oooo += "{}{}{}{}{}{}" . format ( lisp . lisp_print_sans ( "{} match lookup for " . format ( "Exact" if oO0o0 else "Longest" ) ) ,
    # ooOoO0o / iII111i + II111iiii % O0
    # OoO0O00
   lisp . lisp_print_cour ( eid_str ) ,
   lisp . lisp_print_sans ( " found " ) ,
   lisp . lisp_print_cour ( O0oO . print_eid_tuple ( ) ) ,
   lisp . lisp_print_sans ( ", referral-type {}" . format ( lisp . lisp_print_cour ( O0oO . print_referral_type ( ) ) ) ) ,
    # oO0o / I11i / I11i
   lisp . lisp_print_sans ( " with uptime {}" . format ( lisp . lisp_print_cour ( OO0ooOOO0OOO ) ) ) )
    if 87 - 87: Oo0Ooo . I1IiiI - II111iiii + O0 / Oo0Ooo / oO0o
    if 25 - 25: I1IiiI . I1IiiI - OoOoOO00 % OoOoOO00 - i11iIiiIii / I1Ii111
   Oo0O0oooo += "<br>"
   return ( Oo0O0oooo )
   if 51 - 51: Oo0Ooo / OoOoOO00 . OOooOOo * o0oOOo0O0Ooo + OoO0O00 * IiII
   if 73 - 73: OoO0O00 + OoooooooOO - O0 - Ii1I - II111iiii
   if 99 - 99: ooOoO0o . Ii1I + I1Ii111 + OoooooooOO % o0oOOo0O0Ooo
   if 51 - 51: iIii1I11I1II1
   if 34 - 34: oO0o + I1IiiI - oO0o
   if 17 - 17: II111iiii % iII111i + I11i - iII111i / OOooOOo + ooOoO0o
   if 59 - 59: OOooOOo % OoOoOO00 . Ii1I * I1ii11iIi11i % I11i
  def oO0o0o0oo ( parameter ) :
   if 32 - 32: OOooOOo
   if 42 - 42: IiII * O0 % i1IIi . OOooOOo / o0oOOo0O0Ooo
   if 32 - 32: I1IiiI * Oo0Ooo
   if 78 - 78: OOooOOo - OoooooooOO - I1ii11iIi11i / ooOoO0o / II111iiii
   if ( parameter != "" ) :
    return ( oOO00O ( parameter ) )
    if 29 - 29: I1IiiI % I1IiiI
    if 94 - 94: iIii1I11I1II1 / Oo0Ooo % iII111i * iII111i * II111iiii
    if 29 - 29: OoO0O00 + OoOoOO00 / o0oOOo0O0Ooo / OOooOOo * iIii1I11I1II1
    if 62 - 62: OOooOOo / oO0o - OoO0O00 . I11i
    if 11 - 11: I1ii11iIi11i . OoO0O00 * IiII * OoooooooOO + ooOoO0o
   IiII111i1i11 = "Enter EID for Referral-Cache lookup:"
   i111iIi1i1II1 = lisp . lisp_eid_help_hover ( '<input type="text" name="eid" />' )
   if 86 - 86: iIii1I11I1II1 / OoOoOO00 . II111iiii
   Oo0O0oooo = '''
          <form action="/lisp/show/referral/lookup" method="post">
          <i><font face="Courier New" size="3">
          {} {}
          <input style="background-color:transparent;border-radius:10px;" type="submit" value="Submit" />
          </font></i></form>
      ''' . format ( lisp . lisp_print_sans ( IiII111i1i11 ) , i111iIi1i1II1 )
   if 19 - 19: I1ii11iIi11i % OoooooooOO % IiII * o0oOOo0O0Ooo % O0
   if 67 - 67: I1IiiI . i1IIi
   if 27 - 27: ooOoO0o % I1IiiI
   if 73 - 73: OOooOOo
   ooO = len ( lisp . lisp_ddt_map_requestQ )
   if ( ooO != 0 ) :
    Ooo0oOooo0 = "{} entries in map-request queue" . format ( ooO )
    oOOOoo00 = lisp . lisp_span ( "LISP-MR Map-Request Queue:" , Ooo0oOooo0 )
    if 9 - 9: O0 % O0 - o0oOOo0O0Ooo
    Oo0O0oooo += lispconfig . lisp_table_header ( oOOOoo00 ,
   "EID-Prefix or (S,G)" , "Nonce" , "Uptime" , "Map-Request Source" ,
   "Retry Count" , "Tried DDT-Root" , "Last Request Sent To" ,
   "Last Map-Referral EID-Prefix" )
    if 51 - 51: I1IiiI . iIii1I11I1II1 - I1ii11iIi11i / O0
    for OOOoO00 in lisp . lisp_ddt_map_requestQ :
     IIiIi11i1i = lisp . lisp_ddt_map_requestQ [ OOOoO00 ]
     I1II1I11I1I = lisp . lisp_print_elapsed ( IIiIi11i1i . uptime )
     OoOO0o = IIiIi11i1i . last_request_sent_to
     OoOO0o = "--" if ( OoOO0o == None ) else OoOO0o . print_address_no_iid ( )
     if 1 - 1: II111iiii
     O0oOo00o = IIiIi11i1i . itr
     O0oOo00o = "--" if ( O0oOo00o == None ) else ( O0oOo00o . print_address_no_iid ( ) + "<br>({}ITR)" . format ( "P" if IIiIi11i1i . from_pitr else "" ) )
     if 81 - 81: IiII % i1IIi . iIii1I11I1II1
     if 4 - 4: i11iIiiIii % OoO0O00 % i1IIi / IiII
     I11iI = IIiIi11i1i . last_cached_prefix [ 0 ]
     ooOoo = IIiIi11i1i . last_cached_prefix [ 1 ]
     I1III1111iIi = "--" if ( I11iI == None ) else lisp . lisp_print_eid_tuple ( I11iI , ooOoo )
     if 38 - 38: iII111i + I11i / I1Ii111 % ooOoO0o - I1ii11iIi11i
     if 14 - 14: oO0o / I1Ii111
     Oo0O0oooo += lispconfig . lisp_table_row ( IIiIi11i1i . print_eid_tuple ( ) ,
   "0x" + lisp . lisp_hex_string ( IIiIi11i1i . nonce ) , I1II1I11I1I , O0oOo00o ,
   IIiIi11i1i . retry_count , "yes" if IIiIi11i1i . tried_root else "no" , OoOO0o ,
   I1III1111iIi )
     if 85 - 85: I11i
     if 20 - 20: oO0o % IiII
    Oo0O0oooo += lispconfig . lisp_table_footer ( )
    if 19 - 19: I1ii11iIi11i % IiII + ooOoO0o / I1Ii111 . ooOoO0o
    if 12 - 12: i1IIi + i1IIi - I1ii11iIi11i * Oo0Ooo % Oo0Ooo - II111iiii
   Ooo0oOooo0 = "{} entries in referral-cache" . format ( lisp . lisp_referral_cache . cache_size ( ) )
   if 52 - 52: ooOoO0o . iII111i + I1Ii111
   oOOOoo00 = lisp . lisp_span ( "LISP-MR Referral-Cache:" , Ooo0oOooo0 )
   if 38 - 38: i1IIi - II111iiii . I1Ii111
   Oo0O0oooo += lispconfig . lisp_table_header ( oOOOoo00 ,
   "EID-Prefix or (S,G)" , "Uptime" , "Expires<br>TTL" ,
   "Referral Type" , "Map-Referral Source" ,
   "Referral Address<br>Node Status" ,
   "Priority<br>Weight" , "Map-Requests Sent<br>No Responses" )
   if 58 - 58: I1IiiI . iII111i + OoOoOO00
   Oo0O0oooo = lisp . lisp_referral_cache . walk_cache ( oooO0 ,
   Oo0O0oooo )
   if 66 - 66: iII111i / oO0o * OoooooooOO + OoooooooOO % I11i
   Oo0O0oooo += lispconfig . lisp_table_footer ( )
   return ( Oo0O0oooo )
   if 49 - 49: oO0o - i11iIiiIii . I1Ii111 * Ii1I % iII111i + i1IIi
   if 71 - 71: o0oOOo0O0Ooo
   if 38 - 38: oO0o % OoOoOO00 + I1ii11iIi11i . i11iIiiIii
   if 53 - 53: i11iIiiIii * iII111i
   if 68 - 68: iIii1I11I1II1 * iIii1I11I1II1 . o0oOOo0O0Ooo / II111iiii % Oo0Ooo
   if 38 - 38: ooOoO0o - OOooOOo / iII111i
   if 66 - 66: O0 % I1ii11iIi11i + i11iIiiIii . OoOoOO00 / Ii1I + I1ii11iIi11i
  def ooo00Ooo ( referral , delete_list ) :
   if 93 - 93: i11iIiiIii - I1IiiI * I1ii11iIi11i * I11i % O0 + OoooooooOO
   if ( referral . expires == 0 ) : return ( [ True , delete_list ] )
   if 25 - 25: IiII + Ii1I / ooOoO0o . o0oOOo0O0Ooo % O0 * OoO0O00
   o0O0oo0OO0O = lisp . lisp_get_timestamp ( )
   if ( referral . uptime + referral . referral_ttl > o0O0oo0OO0O ) :
    return ( [ True , delete_list ] )
    if 68 - 68: oO0o . I11i % OoooooooOO . I11i
    if 64 - 64: iIii1I11I1II1 / I1IiiI . II111iiii + OoooooooOO . OoO0O00
    if 56 - 56: Oo0Ooo . I1ii11iIi11i . I1IiiI
    if 39 - 39: O0 + I1Ii111
    if 91 - 91: OoooooooOO - iIii1I11I1II1 + OoOoOO00 / OoO0O00 . OoOoOO00 + O0
   iIiii1iI1 = lisp . lisp_print_elapsed ( referral . uptime )
   i11ii1ii11i = referral . print_eid_tuple ( )
   lisp . lprint ( "Referral for EID-prefix {} has timed out, had uptime of {}" . format ( lisp . green ( i11ii1ii11i , False ) , iIiii1iI1 ) )
   if 70 - 70: i1IIi - iII111i + Oo0Ooo
   if 12 - 12: o0oOOo0O0Ooo - I1ii11iIi11i % OoOoOO00 * I11i
   if 44 - 44: iII111i % Ii1I
   if 41 - 41: i1IIi - I11i - Ii1I
   if 8 - 8: OoO0O00 + I1Ii111 - o0oOOo0O0Ooo % Oo0Ooo % o0oOOo0O0Ooo * oO0o
   delete_list . append ( referral )
   return ( [ True , delete_list ] )
   if 9 - 9: Oo0Ooo - i11iIiiIii - OOooOOo * Ii1I + ooOoO0o
   if 44 - 44: II111iiii
   if 52 - 52: I1ii11iIi11i - Oo0Ooo + I1ii11iIi11i % o0oOOo0O0Ooo
   if 35 - 35: iIii1I11I1II1
   if 42 - 42: I1Ii111 . I1IiiI . i1IIi + OoOoOO00 + OOooOOo + I1IiiI
   if 31 - 31: iII111i . OOooOOo - ooOoO0o . OoooooooOO / OoooooooOO
   if 56 - 56: OoO0O00 / oO0o / i11iIiiIii + OoooooooOO - Oo0Ooo - I11i
   if 21 - 21: O0 % IiII . I1IiiI / II111iiii + IiII
  def OOOO0O00o ( ref , delete_list ) :
   if 62 - 62: iIii1I11I1II1
   if 12 - 12: OOooOOo / o0oOOo0O0Ooo
   if 42 - 42: Oo0Ooo
   if 19 - 19: oO0o % I1ii11iIi11i * iIii1I11I1II1 + I1IiiI
   if ( ref . group . is_null ( ) ) :
    return ( ooo00Ooo ( ref , delete_list ) )
    if 46 - 46: Oo0Ooo
    if 1 - 1: iII111i
   if ( ref . source_cache == None ) : return ( [ True , delete_list ] )
   if 97 - 97: OOooOOo + iII111i + O0 + i11iIiiIii
   if 77 - 77: o0oOOo0O0Ooo / OoooooooOO
   if 46 - 46: o0oOOo0O0Ooo % iIii1I11I1II1 . iII111i % iII111i + i11iIiiIii
   if 72 - 72: iIii1I11I1II1 * Ii1I % ooOoO0o / OoO0O00
   if 35 - 35: ooOoO0o + i1IIi % I1ii11iIi11i % I11i + oO0o
   delete_list = ref . source_cache . walk_cache ( ooo00Ooo ,
   delete_list )
   return ( [ True , delete_list ] )
   if 17 - 17: i1IIi
   if 21 - 21: Oo0Ooo
   if 29 - 29: I11i / II111iiii / ooOoO0o * OOooOOo
   if 10 - 10: I1Ii111 % IiII * IiII . I11i / Ii1I % OOooOOo
   if 49 - 49: OoO0O00 / oO0o + O0 * o0oOOo0O0Ooo
   if 28 - 28: ooOoO0o + i11iIiiIii / I11i % OoOoOO00 % Oo0Ooo - O0
   if 54 - 54: i1IIi + II111iiii
   if 83 - 83: I1ii11iIi11i - I1IiiI + OOooOOo
  def iIi1Ii1i1iI ( ) :
   lisp . lisp_set_exception ( )
   IIiI1 = [ ]
   if 17 - 17: OOooOOo / OOooOOo / I11i
   ii1 = lisp . lisp_referral_cache
   IIiI1 = ii1 . walk_cache ( OOOO0O00o , IIiI1 )
   if 1 - 1: ooOoO0o % iIii1I11I1II1 + Oo0Ooo . iIii1I11I1II1 % I1IiiI
   if 89 - 89: Ii1I
   if 76 - 76: ooOoO0o
   if 15 - 15: OOooOOo . I11i + OoooooooOO - OoO0O00
   if 69 - 69: iIii1I11I1II1 . I1ii11iIi11i % ooOoO0o + iIii1I11I1II1 / O0 / I1ii11iIi11i
   for II1i1Ii11Ii11 in IIiI1 : II1i1Ii11Ii11 . delete_cache ( )
   if 61 - 61: OOooOOo % OOooOOo * o0oOOo0O0Ooo / o0oOOo0O0Ooo
   if 75 - 75: IiII . ooOoO0o
   if 50 - 50: OoOoOO00
   if 60 - 60: ooOoO0o * iIii1I11I1II1 * I1ii11iIi11i * Oo0Ooo
   iiI1iIiI = threading . Timer (
   lisp . LISP_REFERRAL_TIMEOUT_CHECK_INTERVAL , iIi1Ii1i1iI ,
   [ ] )
   iiI1iIiI . start ( )
   return
   if 69 - 69: Ii1I * O0 . i11iIiiIii / Ii1I . o0oOOo0O0Ooo
   if 63 - 63: I11i + o0oOOo0O0Ooo . II111iiii - I1IiiI
   if 52 - 52: o0oOOo0O0Ooo % Oo0Ooo
   if 64 - 64: O0 % I11i % O0 * OoO0O00 . oO0o + I1IiiI
   if 75 - 75: I11i . OoooooooOO % o0oOOo0O0Ooo * I11i % OoooooooOO
   if 13 - 13: IiII / i11iIiiIii % II111iiii % I11i . I1ii11iIi11i
   if 8 - 8: OoOoOO00 + Oo0Ooo - II111iiii
   if 11 - 11: i1IIi % i11iIiiIii - i1IIi * OoOoOO00
  def i1I11IiI1iiII ( ) :
   global II1iII1i
   global oO0oIIII
   global i111I
   global Oo0oO0oo0oO00
   if 91 - 91: ooOoO0o % ooOoO0o
   lisp . lisp_i_am ( "mr" )
   lisp . lisp_set_exception ( )
   lisp . lisp_print_banner ( "Map-Resolver starting up" )
   if 7 - 7: iII111i / I1ii11iIi11i / i11iIiiIii
   if 21 - 21: oO0o / I1ii11iIi11i + Ii1I + OoooooooOO
   if 91 - 91: i11iIiiIii / i1IIi + iII111i + ooOoO0o * i11iIiiIii
   if 66 - 66: iIii1I11I1II1 % i1IIi - O0 + I11i * I1Ii111 . IiII
   if ( lisp . lisp_get_local_addresses ( ) == False ) : return ( False )
   if 52 - 52: ooOoO0o + O0 . iII111i . I1ii11iIi11i . OoO0O00
   if 97 - 97: I1IiiI / iII111i
   if 71 - 71: II111iiii / i1IIi . I1ii11iIi11i % OoooooooOO . OoOoOO00
   if 41 - 41: i1IIi * II111iiii / OoooooooOO . OOooOOo
   i111I = lisp . lisp_open_send_socket ( "lisp-mrms" , "" )
   oO0oIIII = lisp . lisp_open_listen_socket ( "" , "lisp-mr" )
   O0iII1 = "0.0.0.0" if lisp . lisp_is_raspbian ( ) else "0::0"
   Oo0oO0oo0oO00 = lisp . lisp_open_listen_socket ( O0iII1 ,
   str ( OOo ) )
   II1iII1i [ 0 ] = Oo0oO0oo0oO00
   II1iII1i [ 1 ] = Oo0oO0oo0oO00
   II1iII1i [ 2 ] = oO0oIIII
   if 27 - 27: OoO0O00 . I11i + OoOoOO00 / iIii1I11I1II1 % iII111i . ooOoO0o
   if 14 - 14: oO0o + I1ii11iIi11i - iII111i / O0 . I1Ii111
   if 45 - 45: I1Ii111
   if 83 - 83: OoOoOO00 . OoooooooOO
   iiI1iIiI = threading . Timer (
   lisp . LISP_REFERRAL_TIMEOUT_CHECK_INTERVAL , iIi1Ii1i1iI ,
   [ ] )
   iiI1iIiI . start ( )
   return ( True )
   if 58 - 58: i11iIiiIii + OoooooooOO % OoooooooOO / IiII / i11iIiiIii
   if 62 - 62: OoO0O00 / I1ii11iIi11i
   if 7 - 7: OoooooooOO . IiII
   if 53 - 53: Ii1I % Ii1I * o0oOOo0O0Ooo + OoOoOO00
   if 92 - 92: OoooooooOO + i1IIi / Ii1I * O0
   if 100 - 100: ooOoO0o % iIii1I11I1II1 * II111iiii - iII111i
   if 92 - 92: ooOoO0o
  def II11iI111i1 ( ) :
   if 95 - 95: OoooooooOO - IiII * I1IiiI + OoOoOO00
   if 10 - 10: o0oOOo0O0Ooo / i11iIiiIii
   if 92 - 92: I11i . I1Ii111
   if 85 - 85: I1ii11iIi11i . I1Ii111
   lisp . lisp_close_socket ( Oo0oO0oo0oO00 , "" )
   lisp . lisp_close_socket ( i111I , "lisp-mrms" )
   lisp . lisp_close_socket ( oO0oIIII , "lisp-mr" )
   return
   if 78 - 78: ooOoO0o * I1Ii111 + iIii1I11I1II1 + iIii1I11I1II1 / I1Ii111 . Ii1I
   if 97 - 97: ooOoO0o / I1Ii111 % i1IIi % I1ii11iIi11i
   if 18 - 18: iIii1I11I1II1 % I11i
   if 95 - 95: ooOoO0o + i11iIiiIii * I1Ii111 - i1IIi * I1Ii111 - iIii1I11I1II1
   if 75 - 75: OoooooooOO * IiII
   if 9 - 9: IiII - II111iiii + O0 / iIii1I11I1II1 / i11iIiiIii
   if 39 - 39: IiII * Oo0Ooo + iIii1I11I1II1 - IiII + OOooOOo
  def o0 ( packet , source_str , sport ) :
   if 30 - 30: O0 * OoooooooOO
   I1iIIIi1 = lisp . lisp_control_header ( )
   if ( I1iIIIi1 . decode ( packet ) == None ) :
    lisp . lprint ( "Could not decode control header" )
    return
    if 17 - 17: iIii1I11I1II1 . OoooooooOO / I11i % II111iiii % i1IIi / i11iIiiIii
    if 58 - 58: Oo0Ooo . II111iiii + oO0o - i11iIiiIii / II111iiii / O0
    if 85 - 85: OoOoOO00 + OOooOOo
    if 10 - 10: IiII / OoO0O00 + OoOoOO00 / i1IIi
    if 27 - 27: Ii1I
   oO0OO0 = lisp . lisp_address ( lisp . LISP_AFI_NONE , "" , 0 , 0 )
   oO0OO0 . store_address ( source_str )
   if 82 - 82: IiII - IiII + OoOoOO00
   if 8 - 8: o0oOOo0O0Ooo % iII111i * oO0o % Ii1I . ooOoO0o / ooOoO0o
   if 81 - 81: OoO0O00
   if 99 - 99: oO0o * II111iiii * I1Ii111
   if 92 - 92: Oo0Ooo
   if 40 - 40: OoOoOO00 / IiII
   if ( I1iIIIi1 . type == lisp . LISP_ECM ) :
    OOOoO000 = ( len ( II1Ii1iI1i ) > 0 )
    if ( lisp . lisp_is_running ( "lisp-ms" ) and OOOoO000 == False ) :
     packet = lisp . lisp_packet_ipc ( packet , source_str , sport )
     lisp . lisp_ipc ( packet , i111I , "lisp-ms" )
     return
     if 57 - 57: II111iiii
     if 54 - 54: Oo0Ooo + oO0o + i11iIiiIii
     if 28 - 28: oO0o
     if 70 - 70: IiII
     if 34 - 34: I1Ii111 % IiII
    if ( OOOoO000 ) :
     lisp . lisp_process_ecm ( II1iII1i , packet , oO0OO0 , sport )
     return
     if 3 - 3: II111iiii / OOooOOo + IiII . ooOoO0o . OoO0O00
    lisp . lprint ( "Map-Resolver dropping ECM, DDT or Map-Server not " + "configured" )
    if 83 - 83: oO0o + OoooooooOO
    return
    if 22 - 22: Ii1I % iII111i * OoooooooOO - o0oOOo0O0Ooo / iIii1I11I1II1
    if 86 - 86: OoooooooOO . iII111i % OoOoOO00 / I11i * iII111i / o0oOOo0O0Ooo
    if 64 - 64: i11iIiiIii
    if 38 - 38: IiII / I1IiiI - IiII . I11i
    if 69 - 69: OoooooooOO + I1ii11iIi11i
   if ( I1iIIIi1 . type == lisp . LISP_MAP_REFERRAL ) :
    lisp . lisp_process_map_referral ( II1iII1i , packet , oO0OO0 )
    return
    if 97 - 97: OOooOOo - OoO0O00 / Ii1I . i11iIiiIii % oO0o * oO0o
    if 1 - 1: I1IiiI % ooOoO0o
    if 65 - 65: I1IiiI + OoOoOO00 / OOooOOo
    if 83 - 83: o0oOOo0O0Ooo . iII111i - Oo0Ooo
    if 65 - 65: iIii1I11I1II1 / ooOoO0o . IiII - II111iiii
   lisp . lprint ( "Map-Resolver received an unexpected LISP packet, type: {}" . format ( I1iIIIi1 . type ) )
   if 72 - 72: iIii1I11I1II1 / IiII % iII111i % OOooOOo - I11i % OOooOOo
   return
   if 100 - 100: Oo0Ooo + i11iIiiIii
   if 71 - 71: I11i / o0oOOo0O0Ooo / I1Ii111 % OOooOOo
   if 51 - 51: IiII * O0 / II111iiii . Ii1I % OOooOOo / I1IiiI
   if 9 - 9: I1IiiI % I1IiiI % II111iiii
   if 30 - 30: IiII + I1Ii111 - IiII . IiII - II111iiii + O0
   if 86 - 86: i1IIi
   if 41 - 41: OoOoOO00 * I11i / OoOoOO00 % oO0o
  Ii = {
   "lisp ddt-root" : [ OoooooOoo , {
   "address" : [ False ] ,
   "public-key" : [ False ] ,
   "priority" : [ False , 0 , 255 ] ,
   "weight" : [ False , 0 , 100 ] } ] ,
  
   "lisp referral-cache" : [ Oo000o , {
   "prefix" : [ ] ,
   "instance-id" : [ True , 0 , 0xffffffff ] ,
   "eid-prefix" : [ True ] ,
   "group-prefix" : [ True ] ,
   "referral" : [ ] ,
   "address" : [ True ] ,
   "priority" : [ True , 0 , 255 ] ,
   "weight" : [ True , 0 , 100 ] } ] ,
  
   "show referral-cache" : [ oO0o0o0oo , { } ] ,
   }
  if 77 - 77: OoOoOO00 % Ii1I
  if 9 - 9: OoO0O00 - Oo0Ooo * OoooooooOO . Oo0Ooo
  if 2 - 2: OoooooooOO % OOooOOo
  if 63 - 63: I1IiiI % iIii1I11I1II1
  if 39 - 39: iII111i / II111iiii / I1ii11iIi11i % I1IiiI
  if 89 - 89: I1Ii111 + OoooooooOO + I1Ii111 * i1IIi + iIii1I11I1II1 % I11i
  if ( i1I11IiI1iiII ( ) == False ) :
   lisp . lprint ( "lisp_mr_startup() failed" )
   lisp . lisp_print_banner ( "Map-Resolver abnormal exit" )
   exit ( 1 )
   if 59 - 59: OOooOOo + i11iIiiIii
   if 88 - 88: i11iIiiIii - ooOoO0o
  O0iIi1IiII = [ Oo0oO0oo0oO00 , oO0oIIII ]
  I1i = [ Oo0oO0oo0oO00 ] * 3
  if 72 - 72: iIii1I11I1II1
  while ( True ) :
   try : iiIi , oO , Ii111 = select . select ( O0iIi1IiII , [ ] , [ ] )
   except : break
   if 67 - 67: O0
   if ( Oo0oO0oo0oO00 in iiIi ) :
    Ooo , oO0OO0 , ooooo0o , oo0OoOOO0o0 = lisp . lisp_receive ( I1i [ 0 ] ,
   False )
    if ( oO0OO0 == "" ) : break
    lisp . lisp_parse_packet ( I1i , oo0OoOOO0o0 , oO0OO0 , ooooo0o )
    continue
    if 19 - 19: II111iiii * IiII + Ii1I
    if 65 - 65: OOooOOo . I1Ii111 . OoO0O00 . iII111i - OOooOOo
   Ooo , oO0OO0 , ooooo0o , oo0OoOOO0o0 = lisp . lisp_receive ( oO0oIIII , True )
   if 19 - 19: i11iIiiIii + iII111i % ooOoO0o
   if ( oO0OO0 == "" ) : break
   if 14 - 14: OoO0O00 . II111iiii . I11i / Ii1I % I1ii11iIi11i - ooOoO0o
   if ( Ooo == "command" ) :
    if ( oo0OoOOO0o0 == "clear" ) :
     iIiiI1 ( )
     continue
     if 67 - 67: I11i - OOooOOo . i1IIi
    lispconfig . lisp_process_command ( oO0oIIII , Ooo ,
   oo0OoOOO0o0 , "lisp-mr" , [ Ii ] )
   else :
    o0 ( oo0OoOOO0o0 , oO0OO0 , ooooo0o )
    if 35 - 35: iII111i + ooOoO0o - oO0o . iII111i . IiII
    if 87 - 87: OoOoOO00
    if 25 - 25: i1IIi . OoO0O00 - OoOoOO00 / OoO0O00 % OoO0O00 * iIii1I11I1II1
  II11iI111i1 ( )
  lisp . lisp_print_banner ( "Map-Resolver normal exit" )
  exit ( 0 )
  if 50 - 50: OoO0O00 . i11iIiiIii - oO0o . oO0o
  if 31 - 31: OOooOOo / Oo0Ooo * i1IIi . OoOoOO00
  if 57 - 57: OOooOOo + iIii1I11I1II1 % i1IIi % I1IiiI
  # dd678faae9ac167bc83abf78e5cb2f3f0688d3a3
  