I have spent the
last day reviewing the karma code and have found that it needs some cleaning
up. I would like to propose the following changes and get some input from
the more experienced jabberd developers.
The code in mio.c
regarding karma does not pay attention to most of what you place in the
<io><karma> section of the jabber.xml. Two reasons 1) a
typical cut and paste coding mistake. 2) Then the information is not even used
latter just the karma defaults found in lib.h.
Here is a diff of
the changes I have made to mio.c so far.
532c532
< mio_karma(new, KARMA_INIT, KARMA_MAX, KARMA_INC, KARMA_DEC, KARMA_PENALTY, KARMA_RESTORE);
---
> mio_karma(new, KARMA_INIT, KARMA_DEF_MAX, KARMA_DEF_INC, KARMA_DEF_DEC, KARMA_DEF_PENALTY, KARMA_DEF_RESTORE);
770,777c770,777
< KARMA_DEF_INIT = j_atoi(xmlnode_get_tag_data(io, "karma/init"), KARMA_INIT);
< KARMA_DEF_INIT = j_atoi(xmlnode_get_tag_data(io, "karma/max"), KARMA_MAX);
< KARMA_DEF_INIT = j_atoi(xmlnode_get_tag_data(io, "karma/inc"), KARMA_INC);
< KARMA_DEF_INIT = j_atoi(xmlnode_get_tag_data(io, "karma/dec"), KARMA_DEC);
< KARMA_DEF_INIT = j_atoi(xmlnode_get_tag_data(io, "karma/penalty"), KARMA_PENALTY);
< KARMA_DEF_INIT = j_atoi(xmlnode_get_tag_data(io, "karma/restore"), KARMA_RESTORE);
< KARMA_DEF_RATE_T = j_atoi(xmlnode_get_attrib(xmlnode_get_tag(io, "rate"), "time"), 5);
< KARMA_DEF_RATE_P = j_atoi(xmlnode_get_attrib(xmlnode_get_tag(io, "rate"), "points"), 25);
---
> KARMA_DEF_INIT = j_atoi(xmlnode_get_tag_data(io, "karma/init"), KARMA_INIT);
> KARMA_DEF_MAX = j_atoi(xmlnode_get_tag_data(io, "karma/max"), KARMA_MAX);
> KARMA_DEF_INC = j_atoi(xmlnode_get_tag_data(io, "karma/inc"), KARMA_INC);
> KARMA_DEF_DEC = j_atoi(xmlnode_get_tag_data(io, "karma/dec"), KARMA_DEC);
> KARMA_DEF_PENALTY = j_atoi(xmlnode_get_tag_data(io, "karma/penalty"), KARMA_PENALTY);
> KARMA_DEF_RESTORE = j_atoi(xmlnode_get_tag_data(io, "karma/restore"), KARMA_RESTORE);
> KARMA_DEF_RATE_T = j_atoi(xmlnode_get_attrib(xmlnode_get_tag(io, "rate"), "time"), 5);
> KARMA_DEF_RATE_P = j_atoi(xmlnode_get_attrib(xmlnode_get_tag(io, "rate"), "points"), 25);
782c782
< register_beat(j_atoi(xmlnode_get_tag_data(io, "heartbeat"), KARMA_HEARTBEAT), _karma_heartbeat, NULL);
---
> register_beat(j_atoi(xmlnode_get_tag_data(io, "karma/heartbeat"), KARMA_HEARTBEAT), _karma_heartbeat, NULL);
855c855
< mio_karma(new, KARMA_INIT, KARMA_MAX, KARMA_INC, KARMA_DEC, KARMA_PENALTY, KARMA_RESTORE);
---
> mio_karma(new, KARMA_INIT, KARMA_DEF_MAX, KARMA_DEF_INC, KARMA_DEF_DEC, KARMA_DEF_PENALTY, KARMA_DEF_RESTORE);
< mio_karma(new, KARMA_INIT, KARMA_MAX, KARMA_INC, KARMA_DEC, KARMA_PENALTY, KARMA_RESTORE);
---
> mio_karma(new, KARMA_INIT, KARMA_DEF_MAX, KARMA_DEF_INC, KARMA_DEF_DEC, KARMA_DEF_PENALTY, KARMA_DEF_RESTORE);
770,777c770,777
< KARMA_DEF_INIT = j_atoi(xmlnode_get_tag_data(io, "karma/init"), KARMA_INIT);
< KARMA_DEF_INIT = j_atoi(xmlnode_get_tag_data(io, "karma/max"), KARMA_MAX);
< KARMA_DEF_INIT = j_atoi(xmlnode_get_tag_data(io, "karma/inc"), KARMA_INC);
< KARMA_DEF_INIT = j_atoi(xmlnode_get_tag_data(io, "karma/dec"), KARMA_DEC);
< KARMA_DEF_INIT = j_atoi(xmlnode_get_tag_data(io, "karma/penalty"), KARMA_PENALTY);
< KARMA_DEF_INIT = j_atoi(xmlnode_get_tag_data(io, "karma/restore"), KARMA_RESTORE);
< KARMA_DEF_RATE_T = j_atoi(xmlnode_get_attrib(xmlnode_get_tag(io, "rate"), "time"), 5);
< KARMA_DEF_RATE_P = j_atoi(xmlnode_get_attrib(xmlnode_get_tag(io, "rate"), "points"), 25);
---
> KARMA_DEF_INIT = j_atoi(xmlnode_get_tag_data(io, "karma/init"), KARMA_INIT);
> KARMA_DEF_MAX = j_atoi(xmlnode_get_tag_data(io, "karma/max"), KARMA_MAX);
> KARMA_DEF_INC = j_atoi(xmlnode_get_tag_data(io, "karma/inc"), KARMA_INC);
> KARMA_DEF_DEC = j_atoi(xmlnode_get_tag_data(io, "karma/dec"), KARMA_DEC);
> KARMA_DEF_PENALTY = j_atoi(xmlnode_get_tag_data(io, "karma/penalty"), KARMA_PENALTY);
> KARMA_DEF_RESTORE = j_atoi(xmlnode_get_tag_data(io, "karma/restore"), KARMA_RESTORE);
> KARMA_DEF_RATE_T = j_atoi(xmlnode_get_attrib(xmlnode_get_tag(io, "rate"), "time"), 5);
> KARMA_DEF_RATE_P = j_atoi(xmlnode_get_attrib(xmlnode_get_tag(io, "rate"), "points"), 25);
782c782
< register_beat(j_atoi(xmlnode_get_tag_data(io, "heartbeat"), KARMA_HEARTBEAT), _karma_heartbeat, NULL);
---
> register_beat(j_atoi(xmlnode_get_tag_data(io, "karma/heartbeat"), KARMA_HEARTBEAT), _karma_heartbeat, NULL);
855c855
< mio_karma(new, KARMA_INIT, KARMA_MAX, KARMA_INC, KARMA_DEC, KARMA_PENALTY, KARMA_RESTORE);
---
> mio_karma(new, KARMA_INIT, KARMA_DEF_MAX, KARMA_DEF_INC, KARMA_DEF_DEC, KARMA_DEF_PENALTY, KARMA_DEF_RESTORE);
I have continued to
leave KARMA_INIT as is fore the time being because this used in some strange way
to indicate it is a new connection. I will spend some more time on
completing that transition.
----------------------------------------------
The karma_heartbeat
has been adjust for registration, but the default value of KARMA_HEARTBEAT is
used in karma.c and may or may not reflect the true heartbeat setting set in
<io><karma>.
karma.c
66-68
/* only increment every KARMA_HEARTBEAT seconds */
if( ( k->last_update + KARMA_HEARTBEAT > cur_time ) && k->last_update != 0)
return;
if( ( k->last_update + KARMA_HEARTBEAT > cur_time ) && k->last_update != 0)
return;
I propose adding a
KARMA_DEF_HEARTBEAT that is set in mio.c and then used as an extern in
karma.c.
-----------------------------------------------
Also client.c and
some others use their own karma settings than those found in <io> and as
state by a comment in the code that they would first like to uses the
<io><karma> setting instead of the defaults found
lib.h.
What I propose is
adding the externs that point to KARMA_DEF... in client .c
et.al.
client.c
504-509
/* XXX note, this isn't quite what i had in mind for
karma
* since it's not taking the default from <io/> over the
* internal defaults... it should take the c2s config first
* any values not there should come from <io/> and any other
* non-matched values should use the internal defaults */
mio_karma2(m, &k);
* since it's not taking the default from <io/> over the
* internal defaults... it should take the c2s config first
* any values not there should come from <io/> and any other
* non-matched values should use the internal defaults */
mio_karma2(m, &k);
----------------------------------------
I would apprciate
feedback on the cleanup presented. Who would I send the updates for
inclusion into CVS.
heg
"If at first the idea is not absurd, then there is
no hope for it." - Albert
Einstein
