anchor.diff:  -behaviour(gen_server).
   -export([start/0, stop/0, reload/0, register/0,print_info/0]).
   -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
  --export([update_db/1,lookup/1,is_country/1,country_langs/1]).
  --compile(export_all).
  +-export([lookup/1, update_db/1]).
   -include_lib("kernel/include/file.hrl").
   -include_lib("../include/bkdcore.hrl").
   -compile({parse_transform,lager_transform}).
  -
  --record(ci,{country, languages = [], continent}).
  -
  -% ISO 3166-1
  +-compile(export_all).
  +
   -define(COUNTRIES, {<<"AF">>,<<"AL">>,<<"DZ">>,<<"AS">>,<<"AD">>,<<"AO">>,<<"AI">>,<<"AQ">>,<<"AG">>,<<"AR">>,
  -					<<"AM">>,<<"AW">>,<<"AU">>,<<"AT">>,<<"AZ">>,<<"BS">>,<<"BH">>,<<"BD">>,<<"BB">>,<<"BY">>,
  -					<<"BE">>,<<"BZ">>,<<"BJ">>,<<"BM">>,<<"BT">>,<<"BO">>,<<"BA">>,<<"BW">>,<<"BV">>,<<"BR">>,
  -					<<"IO">>,<<"VG">>,<<"BN">>,<<"BG">>,<<"BF">>,<<"03">>,<<"BI">>,<<"KH">>,<<"CM">>,<<"CA">>,
  -					<<"CV">>,<<"01">>,<<"KY">>,<<"CF">>,<<"TD">>,<<"CL">>,<<"CN">>,<<"CX">>,<<"CC">>,<<"CO">>,
  -					<<"KM">>,<<"CG">>,<<"CD">>,<<"CK">>,<<"CR">>,<<"CI">>,<<"HR">>,<<"CU">>,<<"CY">>,<<"CZ">>,
  -					<<"DK">>,<<"DJ">>,<<"DM">>,<<"DO">>,<<"TP">>,<<"EC">>,<<"EG">>,<<"SV">>,<<"GQ">>,<<"ER">>,
  -					<<"EE">>,<<"ET">>,<<"FK">>,<<"FO">>,<<"FJ">>,<<"FI">>,<<"FR">>,<<"FX">>,<<"GF">>,<<"PF">>,
  -					<<"TF">>,<<"GA">>,<<"GM">>,<<"GE">>,<<"DE">>,<<"GH">>,<<"GI">>,<<"GR">>,<<"GL">>,<<"GD">>,
  -					<<"GP">>,<<"GU">>,<<"GT">>,<<"GN">>,<<"GW">>,<<"GY">>,<<"HT">>,<<"HM">>,<<"HN">>,<<"00">>,
  -					<<"HK">>,<<"HU">>,<<"IS">>,<<"IN">>,<<"ID">>,<<"IR">>,<<"IQ">>,<<"IE">>,<<"IL">>,<<"IT">>,
  -					<<"JM">>,<<"JP">>,<<"JO">>,<<"KZ">>,<<"KE">>,<<"KI">>,<<"KR">>,<<"KP">>,<<"KW">>,<<"KG">>,
  -					<<"LA">>,<<"LV">>,<<"LB">>,<<"LS">>,<<"LR">>,<<"LY">>,<<"LI">>,<<"LT">>,<<"LU">>,<<"MO">>,
  -					<<"MK">>,<<"MG">>,<<"MW">>,<<"MY">>,<<"MV">>,<<"ML">>,<<"MT">>,<<"MH">>,<<"MQ">>,<<"MR">>,
  -					<<"MU">>,<<"YT">>,<<"MX">>,<<"FM">>,<<"MD">>,<<"MC">>,<<"MN">>,<<"MS">>,<<"MA">>,<<"MZ">>,
  -					<<"MM">>,<<"NA">>,<<"NR">>,<<"NP">>,<<"NL">>,<<"AN">>,<<"NC">>,<<"NZ">>,<<"NI">>,<<"NE">>,
  -					<<"NG">>,<<"NU">>,<<"NF">>,<<"MP">>,<<"NO">>,<<"OM">>,<<"PK">>,<<"PW">>,<<"PA">>,<<"PG">>,
  -					<<"PY">>,<<"PE">>,<<"PH">>,<<"PN">>,<<"PL">>,<<"PT">>,<<"PR">>,<<"QA">>,<<"RE">>,<<"RO">>,
  -					<<"RU">>,<<"RW">>,<<"KN">>,<<"LC">>,<<"VC">>,<<"WS">>,<<"SM">>,<<"ST">>,<<"SA">>,<<"SN">>,
  -					<<"SC">>,<<"SL">>,<<"SG">>,<<"SK">>,<<"SI">>,<<"SB">>,<<"SO">>,<<"ZA">>,<<"GS">>,<<"ES">>,
  -					<<"LK">>,<<"SH">>,<<"PM">>,<<"SD">>,<<"SR">>,<<"SJ">>,<<"SZ">>,<<"SE">>,<<"CH">>,<<"SY">>,
  -					<<"TW">>,<<"TJ">>,<<"TZ">>,<<"TH">>,<<"TG">>,<<"TK">>,<<"TO">>,<<"TT">>,<<"TN">>,<<"TR">>,
  -					<<"TM">>,<<"TC">>,<<"TV">>,<<"UG">>,<<"UA">>,<<"AE">>,<<"GB">>,<<"US">>,<<"UM">>,<<"UY">>,
  -					<<"UZ">>,<<"VU">>,<<"VA">>,<<"VE">>,<<"VN">>,<<"WF">>,<<"EH">>,<<"YE">>,<<"YU">>,<<"02">>,
  -					<<"ZM">>,<<"ZW">>,<<"VI">>,<<"CS">>,<<"ME">>,<<"PS">>,<<"RS">>,<<"TL">>,<<"JE">>}).
  -
  -% ISO 639
  --define(LANGUAGES,	[{<<"SL">>,[<<"sl">>]},{<<"GR">>,[<<"el">>]},{<<"KR">>,[<<"ko">>]},{<<"LT">>,[<<"lt">>]},{<<"TR">>,[<<"tr">>]},
  -					 {<<"CH">>,[<<"de">>,<<"fr">>,<<"it">>]},{<<"SK">>,[<<"sk">>]},{<<"EO">>,[<<"eo">>]},{<<"GB">>,[<<"en">>]},{<<"HE">>,[<<"he">>]},
  -					 {<<"HR">>,[<<"hr">>]},{<<"DE">>,[<<"de">>]},{<<"ET">>,[<<"am">>]},{<<"EL">>,[<<"el">>]},{<<"HK">>,[<<"zh">>]},
  -					 {<<"IE">>,[<<"en">>]},{<<"CS">>,[<<"cs">>]},{<<"BG">>,[<<"bg">>]},{<<"IS">>,[<<"is">>]},{<<"BY">>,[<<"be">>]},{<<"KZ">>,[<<"kk">>]},
  -					 {<<"JP">>,[<<"ja">>]},{<<"EU">>,[<<"eu">>]},{<<"NL">>,[<<"nl">>]},{<<"US">>,[<<"en">>]},{<<"IN">>,[<<"hi">>]},{<<"LN">>,[<<"la">>]},
  -					 {<<"SV">>,[<<"sv">>]},{<<"KO">>,[<<"ko">>]},{<<"PL">>,[<<"pl">>]},{<<"SI">>,[<<"sl">>]},{<<"CN">>,[<<"zh">>]},{<<"TW">>,[<<"zh">>]},
  -					 {<<"IT">>,[<<"it">>]},{<<"FR">>,[<<"fr">>]},{<<"HU">>,[<<"hu">>]},{<<"BE">>,[<<"fr">>,<<"nl">>]},{<<"BR">>,[<<"pt">>]},
  -					 {<<"SE">>,[<<"sv">>]},{<<"ES">>,[<<"ca">>,<<"es">>,<<"eu">>]},{<<"YU">>,[<<"sr">>]},{<<"ZA">>,[<<"af">>]},{<<"FI">>,[<<"fi">>]},
  -					 {<<"DK">>,[<<"da">>]},{<<"RU">>,[<<"ru">>]},{<<"NZ">>,[<<"en">>]},{<<"RO">>,[<<"ro">>]},{<<"EE">>,[<<"et">>]},{<<"JA">>,[<<"ja">>]},
  -					 {<<"AT">>,[<<"de">>]},{<<"DA">>,[<<"da">>]},{<<"NB">>,[<<"nb">>]},{<<"PT">>,[<<"pt">>]},{<<"AM">>,[<<"hy">>]},{<<"UA">>,[<<"uk">>]},
  -					 {<<"ZH">>,[<<"zh">>]},{<<"CZ">>,[<<"cs">>]},{<<"IL">>,[<<"he">>]},{<<"NO">>,[<<"no">>]},{<<"CA">>,[<<"ca">>,<<"en">>,<<"fr">>]},
  -					 {<<"AU">>,[<<"en">>]},{<<"AL">>, [<<"sq">>]}]).
  -					
  -
  -is_country(C) ->
  -	gen_server:call(?MODULE,{is_country,ctry_format(C)}).
  -	
  -ctry_format([A,B]) ->
  -	ctry_format(<<A,B>>);
  -ctry_format(<<A,B>>) when A >= $a ->
  -	ctry_format(<<(A-32),(B-32)>>);
  -ctry_format(C) ->
  -	C.
  +<<"AM">>,<<"AW">>,<<"AU">>,<<"AT">>,<<"AZ">>,<<"BS">>,<<"BH">>,<<"BD">>,<<"BB">>,<<"BY">>,
  +<<"BE">>,<<"BZ">>,<<"BJ">>,<<"BM">>,<<"BT">>,<<"BO">>,<<"BA">>,<<"BW">>,<<"BV">>,<<"BR">>,
  +<<"IO">>,<<"VG">>,<<"BN">>,<<"BG">>,<<"BF">>,<<"03">>,<<"BI">>,<<"KH">>,<<"CM">>,<<"CA">>,
  +<<"CV">>,<<"01">>,<<"KY">>,<<"CF">>,<<"TD">>,<<"CL">>,<<"CN">>,<<"CX">>,<<"CC">>,<<"CO">>,
  +<<"KM">>,<<"CG">>,<<"CD">>,<<"CK">>,<<"CR">>,<<"CI">>,<<"HR">>,<<"CU">>,<<"CY">>,<<"CZ">>,
  +<<"DK">>,<<"DJ">>,<<"DM">>,<<"DO">>,<<"TP">>,<<"EC">>,<<"EG">>,<<"SV">>,<<"GQ">>,<<"ER">>,
  +<<"EE">>,<<"ET">>,<<"FK">>,<<"FO">>,<<"FJ">>,<<"FI">>,<<"FR">>,<<"FX">>,<<"GF">>,<<"PF">>,
  +<<"TF">>,<<"GA">>,<<"GM">>,<<"GE">>,<<"DE">>,<<"GH">>,<<"GI">>,<<"GR">>,<<"GL">>,<<"GD">>,
  +<<"GP">>,<<"GU">>,<<"GT">>,<<"GN">>,<<"GW">>,<<"GY">>,<<"HT">>,<<"HM">>,<<"HN">>,<<"00">>,
  +<<"HK">>,<<"HU">>,<<"IS">>,<<"IN">>,<<"ID">>,<<"IR">>,<<"IQ">>,<<"IE">>,<<"IL">>,<<"IT">>,
  +<<"JM">>,<<"JP">>,<<"JO">>,<<"KZ">>,<<"KE">>,<<"KI">>,<<"KR">>,<<"KP">>,<<"KW">>,<<"KG">>,
  +<<"LA">>,<<"LV">>,<<"LB">>,<<"LS">>,<<"LR">>,<<"LY">>,<<"LI">>,<<"LT">>,<<"LU">>,<<"MO">>,
  +<<"MK">>,<<"MG">>,<<"MW">>,<<"MY">>,<<"MV">>,<<"ML">>,<<"MT">>,<<"MH">>,<<"MQ">>,<<"MR">>,
  +<<"MU">>,<<"YT">>,<<"MX">>,<<"FM">>,<<"MD">>,<<"MC">>,<<"MN">>,<<"MS">>,<<"MA">>,<<"MZ">>,
  +<<"MM">>,<<"NA">>,<<"NR">>,<<"NP">>,<<"NL">>,<<"AN">>,<<"NC">>,<<"NZ">>,<<"NI">>,<<"NE">>,
  +<<"NG">>,<<"NU">>,<<"NF">>,<<"MP">>,<<"NO">>,<<"OM">>,<<"PK">>,<<"PW">>,<<"PA">>,<<"PG">>,
  +<<"PY">>,<<"PE">>,<<"PH">>,<<"PN">>,<<"PL">>,<<"PT">>,<<"PR">>,<<"QA">>,<<"RE">>,<<"RO">>,
  +<<"RU">>,<<"RW">>,<<"KN">>,<<"LC">>,<<"VC">>,<<"WS">>,<<"SM">>,<<"ST">>,<<"SA">>,<<"SN">>,
  +<<"SC">>,<<"SL">>,<<"SG">>,<<"SK">>,<<"SI">>,<<"SB">>,<<"SO">>,<<"ZA">>,<<"GS">>,<<"ES">>,
  +<<"LK">>,<<"SH">>,<<"PM">>,<<"SD">>,<<"SR">>,<<"SJ">>,<<"SZ">>,<<"SE">>,<<"CH">>,<<"SY">>,
  +<<"TW">>,<<"TJ">>,<<"TZ">>,<<"TH">>,<<"TG">>,<<"TK">>,<<"TO">>,<<"TT">>,<<"TN">>,<<"TR">>,
  +<<"TM">>,<<"TC">>,<<"TV">>,<<"UG">>,<<"UA">>,<<"AE">>,<<"GB">>,<<"US">>,<<"UM">>,<<"UY">>,
  +<<"UZ">>,<<"VU">>,<<"VA">>,<<"VE">>,<<"VN">>,<<"WF">>,<<"EH">>,<<"YE">>,<<"YU">>,<<"02">>,
  +<<"ZM">>,<<"ZW">>,<<"VI">>,<<"CS">>,<<"ME">>,<<"PS">>,<<"RS">>,<<"TL">>,<<"JE">>}).
   
   update_db(Path) ->
   	gen_server:cast(?MODULE,{update, Path}).
  
positive.code: code_change(_, State, _) ->
  	{ok, State}.
  init(_) ->
  	% filelib:ensure_dir(butil:project_rootpath()++"/priv/geoip/"),
  	C = ets:new(countries,[set,private,{keypos,#ci.country}]),
  	% [ets:insert(C,{Ctry}) || Ctry <- tuple_to_list(?COUNTRIES)],
  	% [ets:insert(C,{{langs, Ctry},L}) || {Ctry,L} <- ?LANGUAGES],
  	ets:insert(C,consci(europe(), [])),
  	ets:insert(C,consci(asia(), [])),
  	ets:insert(C,consci(america(), [])),
  	Loclangs = dict:from_list(loclangs()),
  	case filelib:is_dir(butil:project_rootpath()++"/priv/geoip/") of
  		true ->
  			self() ! {check_file,0};
  		_ ->
  			ok
  	end,
  	{ok, #gip{countries = C,loclangs = Loclangs}}.
  
  check_update_csv() ->
  	case application:get_env(bkdcore,geoipv4) of
  
negative.code: 			element(Index, ?COUNTRIES)
  	end.
  
  -record(gip, {tree, countries, ipv4time = 0,ipv6time = 0}).
  
  
  handle_call({lookup,IP},_,P) ->
  	{reply, find_ip(P#gip.tree,IP), P};
  handle_call(stop, _, P) ->
  	{stop, shutdown, stopped, P};
  handle_call(_, _, P) ->
  