Changeset 9105
- Timestamp:
- 12/14/13 19:11:11 (10 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/module-cacheex.c
r9093 r9105 26 26 extern CS_MUTEX_LOCK ecm_pushed_deleted_lock; 27 27 extern struct ecm_request_t *ecm_pushed_deleted; 28 extern CS_MUTEX_LOCK ecmcache_lock; 29 extern struct ecm_request_t *ecmcwcache; 30 31 32 static void *chkcache_process(void) 33 { 34 set_thread_name(__func__); 35 36 time_t timeout; 37 struct ecm_request_t *er, *ecm; 38 #ifdef CS_CACHEEX 39 uint8_t add_hitcache_er; 40 struct s_reader *cl_rdr; 41 struct s_reader *rdr; 42 struct s_ecm_answer *ea; 43 struct s_client *cex_src=NULL; 44 #endif 45 struct s_write_from_cache *wfc=NULL; 46 47 while(1) 48 { 49 cs_readlock(&ecmcache_lock); 50 for(er = ecmcwcache; er; er = er->next) 51 { 52 timeout = time(NULL)-((cfg.ctimeout+500)/1000+1); 53 if(er->tps.time < timeout) 54 { break; } 55 56 if(er->rc<E_UNHANDLED || er->readers_timeout_check) //already answered 57 { continue; } 58 59 //******** CHECK IF FOUND ECM IN CACHE 60 ecm = check_cache(er, er->client); 61 if(ecm) //found in cache 62 { 63 64 #ifdef CS_CACHEEX 65 //check for add_hitcache 66 if(ecm->cacheex_src) //cw from cacheex 67 { 68 if((er->cacheex_wait_time && !er->cacheex_wait_time_expired) || !er->cacheex_wait_time) //only when no wait_time expires (or not wait_time) 69 { 70 71 //add_hitcache already called, but we check if we have to call it for these (er) caid|prid|srvid 72 if(ecm->prid!=er->prid || ecm->srvid!=er->srvid) 73 { 74 cex_src = ecm->cacheex_src && is_valid_client(ecm->cacheex_src) && !ecm->cacheex_src->kill ? ecm->cacheex_src : NULL; //here we should be sure cex client has not been freed! 75 if(cex_src){ //add_hitcache only if client is really active 76 add_hitcache_er=1; 77 cl_rdr = cex_src->reader; 78 if(cl_rdr && cl_rdr->cacheex.mode == 2) 79 { 80 for(ea = er->matching_rdr; ea; ea = ea->next) 81 { 82 rdr = ea->reader; 83 if(cl_rdr == rdr && ((ea->status & REQUEST_ANSWERED) == REQUEST_ANSWERED)) 84 { 85 cs_debug_mask(D_CACHEEX|D_CSP|D_LB,"{client %s, caid %04X, prid %06X, srvid %04X} [CACHEEX] skip ADD self request!", (check_client(er->client)?er->client->account->usr:"-"),er->caid, er->prid, er->srvid); 86 add_hitcache_er=0; //don't add hit cache, reader requested self 87 } 88 } 89 } 90 91 if(add_hitcache_er) 92 { add_hitcache(cex_src, er); } //USE cacheex client (to get correct group) and ecm from requesting client (to get correct caid|prid|srvid)!!! 93 } 94 } 95 96 } 97 else 98 { 99 //add_hitcache already called, but we have to remove it because cacheex not coming before wait_time 100 if(ecm->prid==er->prid && ecm->srvid==er->srvid) 101 { del_hitcache(ecm); } 102 } 103 } 104 //END check for add_hitcache 105 #endif 106 107 if(check_client(er->client)) 108 { 109 110 wfc=NULL; 111 if(!cs_malloc(&wfc, sizeof(struct s_write_from_cache))) 112 { 113 free(ecm); 114 continue; 115 } 116 117 wfc->er_new=er; 118 wfc->er_cache=ecm; 119 120 if(!add_job(er->client, ACTION_ECM_ANSWER_CACHE, wfc, sizeof(struct s_write_from_cache))) //write_ecm_answer_fromcache 121 { 122 free(ecm); 123 continue; 124 } 125 } 126 else 127 { free(ecm); } 128 } 129 } 130 cs_readunlock(&ecmcache_lock); 131 132 cs_sleepms(10); 133 } 134 135 return NULL; 136 } 137 138 void checkcache_process_thread_start(void) 139 { 140 start_thread((void *) &chkcache_process, "chkcache_process"); 141 } 28 142 29 143 void cacheex_init(void) -
trunk/module-cacheex.h
r9093 r9105 59 59 int32_t chk_csp_ctab(ECM_REQUEST *er, CECSPVALUETAB *tab); 60 60 uint8_t check_cacheex_filter(struct s_client *cl, ECM_REQUEST *er); 61 void checkcache_process_thread_start(void); 62 61 63 #else 62 64 static inline void cacheex_init(void) { }; -
trunk/oscam-config-account.c
r9093 r9105 380 380 DEF_OPT_FUNC("cacheex_ecm_filter" , OFS(cacheex.filter_caidtab), cacheex_hitvaluetab_fn), 381 381 DEF_OPT_UINT8("cacheex_drop_csp" , OFS(cacheex.drop_csp), 0), 382 DEF_OPT_UINT8("cacheex_allow_request" , OFS(cacheex.allow_request), 1),382 DEF_OPT_UINT8("cacheex_allow_request" , OFS(cacheex.allow_request), 0), 383 383 DEF_OPT_INT8("no_wait_time" , OFS(no_wait_time), 0), 384 384 #endif -
trunk/oscam-config-reader.c
r9093 r9105 983 983 DEF_OPT_INT8("cacheex_maxhop" , OFS(cacheex.maxhop), 0), 984 984 DEF_OPT_FUNC("cacheex_ecm_filter" , OFS(cacheex.filter_caidtab), cacheex_hitvaluetab_fn), 985 DEF_OPT_UINT8("cacheex_allow_request" , OFS(cacheex.allow_request), 1),985 DEF_OPT_UINT8("cacheex_allow_request" , OFS(cacheex.allow_request), 0), 986 986 DEF_OPT_UINT8("cacheex_drop_csp" , OFS(cacheex.drop_csp), 0), 987 987 #endif -
trunk/oscam-ecm.c
r9093 r9105 428 428 } 429 429 430 431 static void *chkcache_process(void)432 {433 set_thread_name(__func__);434 435 time_t timeout;436 struct ecm_request_t *er, *ecm;437 #ifdef CS_CACHEEX438 uint8_t add_hitcache_er;439 struct s_reader *cl_rdr;440 struct s_reader *rdr;441 struct s_ecm_answer *ea;442 struct s_client *cex_src=NULL;443 #endif444 struct s_write_from_cache *wfc=NULL;445 446 while(1)447 {448 cs_readlock(&ecmcache_lock);449 for(er = ecmcwcache; er; er = er->next)450 {451 timeout = time(NULL)-((cfg.ctimeout+500)/1000+1);452 if(er->tps.time < timeout)453 { break; }454 455 if(er->rc<E_UNHANDLED || er->readers_timeout_check) //already answered456 { continue; }457 458 //******** CHECK IF FOUND ECM IN CACHE459 ecm = check_cache(er, er->client);460 if(ecm) //found in cache461 {462 463 #ifdef CS_CACHEEX464 //check for add_hitcache465 if(ecm->cacheex_src) //cw from cacheex466 {467 if((er->cacheex_wait_time && !er->cacheex_wait_time_expired) || !er->cacheex_wait_time) //only when no wait_time expires (or not wait_time)468 {469 470 //add_hitcache already called, but we check if we have to call it for these (er) caid|prid|srvid471 if(ecm->prid!=er->prid || ecm->srvid!=er->srvid)472 {473 cex_src = ecm->cacheex_src && is_valid_client(ecm->cacheex_src) && !ecm->cacheex_src->kill ? ecm->cacheex_src : NULL; //here we should be sure cex client has not been freed!474 if(cex_src){ //add_hitcache only if client is really active475 add_hitcache_er=1;476 cl_rdr = cex_src->reader;477 if(cl_rdr && cl_rdr->cacheex.mode == 2)478 {479 for(ea = er->matching_rdr; ea; ea = ea->next)480 {481 rdr = ea->reader;482 if(cl_rdr == rdr && ((ea->status & REQUEST_ANSWERED) == REQUEST_ANSWERED))483 {484 cs_debug_mask(D_CACHEEX|D_CSP|D_LB,"{client %s, caid %04X, prid %06X, srvid %04X} [CACHEEX] skip ADD self request!", (check_client(er->client)?er->client->account->usr:"-"),er->caid, er->prid, er->srvid);485 add_hitcache_er=0; //don't add hit cache, reader requested self486 }487 }488 }489 490 if(add_hitcache_er)491 { add_hitcache(cex_src, er); } //USE cacheex client (to get correct group) and ecm from requesting client (to get correct caid|prid|srvid)!!!492 }493 }494 495 }496 else497 {498 //add_hitcache already called, but we have to remove it because cacheex not coming before wait_time499 if(ecm->prid==er->prid && ecm->srvid==er->srvid)500 { del_hitcache(ecm); }501 }502 }503 //END check for add_hitcache504 #endif505 506 if(check_client(er->client))507 {508 509 wfc=NULL;510 if(!cs_malloc(&wfc, sizeof(struct s_write_from_cache)))511 {512 free(ecm);513 continue;514 }515 516 wfc->er_new=er;517 wfc->er_cache=ecm;518 519 if(!add_job(er->client, ACTION_ECM_ANSWER_CACHE, wfc, sizeof(struct s_write_from_cache))) //write_ecm_answer_fromcache520 {521 free(ecm);522 continue;523 }524 }525 else526 { free(ecm); }527 }528 }529 cs_readunlock(&ecmcache_lock);530 531 cs_sleepms(10);532 }533 534 return NULL;535 }536 537 538 void checkcache_process_thread_start(void)539 {540 start_thread((void *) &chkcache_process, "chkcache_process");541 }542 543 430 void cw_process_thread_start(void) 544 431 { … … 1349 1236 1350 1237 1351 void add_cache_from_reader(struct s_reader *rdr, int32_t csp_hash, uchar * cw, int16_t caid, int32_t prid, int16_t srvid ){1238 void add_cache_from_reader(struct s_reader *rdr, int32_t csp_hash, uchar *ecmd5, uchar *cw, int16_t caid, int32_t prid, int16_t srvid ){ 1352 1239 ECM_REQUEST *ecm; 1353 1240 if (cs_malloc(&ecm, sizeof(ECM_REQUEST))){ … … 1357 1244 ecm->prid = prid; 1358 1245 ecm->srvid = srvid; 1359 ecm->csp_hash= csp_hash; 1246 memcpy(ecm->ecmd5, ecmd5, CS_ECMSTORESIZE); 1247 ecm->csp_hash = csp_hash; 1360 1248 ecm->rc = E_FOUND; 1361 1249 memcpy(ecm->cw, cw, sizeof(ecm->cw)); … … 1418 1306 if(ea && ea->rc < E_NOTFOUND) 1419 1307 { 1420 add_cache_from_reader(eardr, ert->csp_hash, e a->cw, ert->caid, ert->prid, ert->srvid );1308 add_cache_from_reader(eardr, ert->csp_hash, ert->ecmd5, ea->cw, ert->caid, ert->prid, ert->srvid ); 1421 1309 } 1422 1310 … … 1529 1417 if(ert->rc==E_FOUND) 1530 1418 { 1531 add_cache_from_reader(eardr, ert->csp_hash, e a->cw, ert->caid, ert->prid, ert->srvid );1419 add_cache_from_reader(eardr, ert->csp_hash, ert->ecmd5, ea->cw, ert->caid, ert->prid, ert->srvid ); 1532 1420 #ifdef CS_CACHEEX 1533 1421 if(ert->cacheex_src && cfg.check_cw_count>1) //if answer form cacheex reader, and we have to check cw count, not send answer to client -
trunk/oscam-ecm.h
r9093 r9105 2 2 #define OSCAM_ECM_H_ 3 3 4 void checkcache_process_thread_start(void);5 4 void cw_process_thread_start(void); 6 5 void cw_process_thread_wakeup(void); -
trunk/oscam.c
r9093 r9105 1390 1390 start_thread((void *) &reader_check, "reader check"); 1391 1391 cw_process_thread_start(); 1392 #ifdef CS_CACHEEX 1392 1393 checkcache_process_thread_start(); 1394 #endif 1393 1395 1394 1396 lcd_thread_start(); -
trunk/tommyDS_hashlin/tommytypes.h
r9093 r9105 300 300 tommy_inline unsigned tommy_ilog2_u32(tommy_uint32_t value) 301 301 { 302 #if defined(_MSC_VER)303 unsigned long count;304 _BitScanReverse(&count, value);305 return count;306 #elif defined(__GNUC__)307 /*308 * GCC implements __builtin_clz(x) as "__builtin_clz(x) = bsr(x) ^ 31"309 *310 * Where "x ^ 31 = 31 - x", but gcc does not optimize "31 - __builtin_clz(x)" to bsr(x),311 * but generates 31 - (bsr(x) xor 31).312 *313 * So we write "__builtin_clz(x) ^ 31" instead of "31 - __builtin_clz(x)".314 */315 return __builtin_clz(value) ^ 31;316 #else317 302 /* Find the log base 2 of an N-bit integer in O(lg(N)) operations with multiply and lookup */ 318 303 /* from http://graphics.stanford.edu/~seander/bithacks.html */ … … 329 314 330 315 return TOMMY_DE_BRUIJN_INDEX_ILOG2[(tommy_uint32_t)(value * 0x07C4ACDDU) >> 27]; 331 #endif332 316 } 333 317 … … 342 326 tommy_inline unsigned tommy_ctz_u32(tommy_uint32_t value) 343 327 { 344 #if defined(_MSC_VER)345 unsigned long count;346 _BitScanForward(&count, value);347 return count;348 #elif defined(__GNUC__)349 return __builtin_ctz(value);350 #else351 328 /* Count the consecutive zero bits (trailing) on the right with multiply and lookup */ 352 329 /* from http://graphics.stanford.edu/~seander/bithacks.html */ … … 357 334 358 335 return TOMMY_DE_BRUIJN_INDEX_CTZ[(tommy_uint32_t)(((value & -value) * 0x077CB531U)) >> 27]; 359 #endif360 336 } 361 337
Note:
See TracChangeset
for help on using the changeset viewer.