Re: [SR-Users] htable + event_routes + mod-init + htable:expired

2020-10-31 Thread Brandon Armstead
As a workaround, this seems to work and $sht(server=>auth::token) is always
reported back by kamcmd htable.dump server :

route[HTTP_AUTH_REPLY] {

xinfo("[$ci][$rm] HTTP_AUTH_REPLY received");


if($http_ok) {

xinfo("[HTTP_AUTH_REPLY][$http_rs] request was sucessful");

} else {

xinfo("[HTTP_AUTH_REPLY][$http_rs] request was unsucessful");

}


if($http_err) {

xinfo("[HTTP_AUTH_REPLY][ERROR] $http_err");

}


xinfo("[HTTP_AUTH_REPLY][RESPONSE][BODY] $http_rb");


# lock auth token

sht_lock("server=>auth::token");


# set token

$sht(server=>auth::token) = $http_rb;


# unlock auth token

sht_unlock("server=>auth::token");

}


event_route[htable:expired:server] {

xinfo("[HTABLE:expired:server] initializing");


$http_req(all) = $null;

$http_req(timeout) = 100;

$http_req(method) = "POST";

$http_req(suspend) = 1;

$http_req(hdr) = "Content-Type: application/json";

$http_req(body) = '{"email": "bran...@cryy.com", "password":""}';

http_async_query("https://www.cryy.com/api/auth/token;, "HTTP_AUTH
_REPLY");

}


event_route[htable:mod-init] {

# generate auth token into


http_client_query("https://www.cryy.com/api/auth/token;, '{"email": "
bran...@cryy.com", "password":""}', "$var(result)");


# lock auth token

sht_lock("server=>auth::token");


# set auth token

$sht(server=>auth::token) = $var(result);


# unlock auth token

sht_unlock("server=>auth::token");



xinfo("AUTH_TOKEN_RECEIVED, $sht(server=>auth::token)");

}


Is working -- I have to use http_client on htable module initialization, as
http_async_client seems to start its workers after mod-init and results in:

Oct 31 21:04:37 main kamailio[2088]: ERROR: http_async_client
[async_http.c:622]:
async_push_query(): failed to pass the query to async workers

Oct 31 21:04:37 main kamailio[2088]: ERROR: http_async_client
[async_http.c:588]:
async_send_query(): failed to relay query: https://www.cryy.com/api/auth
/token


(workers start after mod-init request) shown here:


Oct 31 21:04:38 main kamailio[2088]: INFO: http_async_client [async_http.c:84]:
async_http_init_worker(): started worker process: 1

Oct 31 21:04:38 main kamailio[2088]: INFO: http_async_client [async_http.c:84]:
async_http_init_worker(): started worker process: 2

Oct 31 21:04:38 main kamailio[2088]: INFO: http_async_client [async_http.c:84]:
async_http_init_worker(): started worker process: 3

Oct 31 21:04:38 main kamailio[2088]: INFO: http_async_client [async_http.c:84]:
async_http_init_worker(): started worker process: 4


So I suspect there are two separate issues going on here, 1) handling htable
in memory between htable-mod-init and htable:expired:server and 2) unable
to use http_async_client inside htable-mod:init.  I've also double checked
that these modules are loaded after htable in kamailio config.

I look forward to hearing any input anyone may have on this, thanks for
your time in advance!

- Brandon

On Fri, Oct 30, 2020 at 10:55 PM Brandon Armstead  wrote:

> Running  5.5.0-dev3
>
> modparam("htable", "htable", "ipban=>size=8;autoexpire=300;dmqreplicate
> =1;")
> modparam("htable", "enable_dmq", 1)
> modparam("htable", "dmq_init_sync", 1)
> modparam("htable", "timer_procs", 4)
> modparam("htable", "timer_interval", 5)
> modparam("htable", "db_expires", 1)
> modparam("htable", "htable", "account=>size=4;dmqreplicate=1;")
> modparam("htable", "htable", "server=>size=4;autoexpire=15;")
>
> I'm attempting to retrieve an auth token in the init process and also
> refresh the token upon expiration in the htable:expired event.
>
> I'm seeing some behavior where every other execution of htable:expired
> the variable $sht(server=>auth::token) is set per kamcmd htable.dump
> server, however xinfo() reports that the token was retrieved in the
> variable $sht(server=>auth::token).
>
> Please see remaining event route config below:
>
> event_route[htable:mod-init] {
>
> # generate auth token into
>
>
> http_client_query("https://www.cryy.com/api/auth/token;, '{"email": "
> bran...@cryy.com", "password":""}', "$var(result)");
>
>
> sht_lock("server=>auth::token");
>
>
> $sht(server=>auth::token) = $var(result);
>
>
> sht_unlock("server=>auth::token");
>
>
>
> xinfo("AUTH_TOKEN_RECEIVED, $sht(server=>auth::token)");
>
> }
>
>
> event_route[htable:expired:server] {
>
> # process expired htable, renew auth token
>
> xinfo("AUTH_TOKEN_EXPIRED, lets retrieve a new one");
>
>
> http_client_query("https://www.cryy.com/api/auth/token;, '{"email": "
> bran...@cryy.com", "password":""}', "$var(result)");
>
>
> sht_lock("server=>auth::token");
>
> $sht(server=>auth::time) = $TS;
>
> $sht(server=>auth::token) = $var(result);
>
> sht_unlock("server=>auth::token");
>
>
> xinfo("AUTH_TOKEN_RECEIVED, $sht(server=>auth::token)");
>
> xinfo("AUTH_TOKEN_TIME, 

Re: [SR-Users] tsilo - failure to add branches (-1)

2020-10-31 Thread Jurijs Ivolga
Hi,

Any ideas regarding "t_append_branches(): failure to add branches (-1)"?

Is there a way somehow to dump what ts_append handover towards tm? I think
if I would be able to see this I will be able to understand what is wrong.
I tried tm:local-request and failure route and branch route, but these
routes are not executed when this error happens.

Maybe the issue is that the TLS connection is established between Kamailio
and UAC what is in front my Register and this Register kamailio just tries
to connect directly towards UAC and it fails? At least this is my idea why
this might fail.

Jurijs


On Thu, Oct 29, 2020 at 8:38 AM Jurijs Ivolga 
wrote:

> Hi Federico,
>
> Indeed I had a messed up config at that point. I cleaned it up, but still
> had the same problem.
>
> Full log in attachment.
>
> Here is some part of it:
>
> 45(51) DEBUG: {1 21 REGISTER 6z~FzexPro} tsilo [ts_append.c:72]:
>> ts_append(): transaction 16864:783220347 found for
>> sip:1443452187102-0af7c6035717-0...@voipstaging.myappapp.net, going to
>> append branches
>> 45(51) DEBUG: {1 21 REGISTER 6z~FzexPro} tm [t_lookup.c:1612]:
>> t_lookup_ident_filter(): transaction found
>> 45(51) DEBUG: {1 21 REGISTER 6z~FzexPro} registrar [lookup.c:306]:
>> lookup_helper(): contact for [1443452187102-0af7c6035717-0001] found by
>> address
>> 45(51) DEBUG: {1 21 REGISTER 6z~FzexPro} tm [t_append_branches.c:77]:
>> t_append_branches(): transaction 16864:783220347 in status 180
>> 45(51) DEBUG: {1 21 REGISTER 6z~FzexPro} tm [t_append_branches.c:99]:
>> t_append_branches(): Call 3ed4a6c3051ea46b50487a0d1b5b25ec@10.10.0.0: 1
>> (0) outgoing branches
>> 45(51) DEBUG: {1 21 REGISTER 6z~FzexPro} tm [t_append_branches.c:163]:
>> t_append_branches(): Call 3ed4a6c3051ea46b50487a0d1b5b25ec@10.10.0.0: 1
>> (0) outgoing branches after clear_branches()
>> 45(51) ERROR: {1 21 REGISTER 6z~FzexPro} tm [t_append_branches.c:172]: 
>> *t_append_branches():
>> failure to add branches (-1)*
>> 45(51) INFO: {1 21 REGISTER 6z~FzexPro}