Changeset 33:e6fcdf12b9a0 in freeDiameter for freeDiameter/peers.c
- Timestamp:
- Oct 29, 2009, 6:05:45 PM (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
freeDiameter/peers.c
r29 r33 40 40 pthread_rwlock_t fd_g_peers_rw = PTHREAD_RWLOCK_INITIALIZER; 41 41 42 /* List of active peers */ 43 struct fd_list fd_g_activ_peers = FD_LIST_INITIALIZER(fd_g_activ_peers); /* peers linked by their p_actives oredered by p_diamid */ 44 pthread_rwlock_t fd_g_activ_peers_rw = PTHREAD_RWLOCK_INITIALIZER; 45 46 /* List of validation callbacks (registered with fd_peer_validate_register) */ 47 static struct fd_list validators = FD_LIST_INITIALIZER(validators); /* list items are simple fd_list with "o" pointing to the callback */ 48 static pthread_rwlock_t validators_rw = PTHREAD_RWLOCK_INITIALIZER; 49 42 50 43 51 /* Alloc / reinit a peer structure. if *ptr is not NULL, it must already point to a valid struct fd_peer. */ … … 69 77 p->p_hbh = lrand48(); 70 78 CHECK_FCT( fd_fifo_new(&p->p_events) ); 71 CHECK_FCT( fd_fifo_new(&p->p_recv) );72 79 CHECK_FCT( fd_fifo_new(&p->p_tosend) ); 73 80 fd_list_init(&p->p_sentreq, p); … … 206 213 CHECK_FCT( fd_fifo_del(&p->p_events) ); 207 214 208 CHECK_FCT( fd_thr_term(&p->p_inthr) );209 while ( fd_fifo_tryget(p->p_recv, &t) == 0 ) {210 struct msg * m = t;211 TRACE_DEBUG(FULL, "Found message %p in incoming queue of peer %p being destroyed", m, p);212 /* We simply destroy, the remote peer will re-send to someone else...*/213 CHECK_FCT(fd_msg_free(m));214 }215 CHECK_FCT( fd_fifo_del(&p->p_recv) );216 217 215 CHECK_FCT( fd_thr_term(&p->p_outthr) ); 218 216 while ( fd_fifo_tryget(p->p_tosend, &t) == 0 ) { … … 220 218 TRACE_DEBUG(FULL, "Found message %p in outgoing queue of peer %p being destroyed, requeue", m, p); 221 219 /* We simply requeue in global, the routing thread will re-handle it. */ 222 220 CHECK_FCT(fd_fifo_post(fd_g_outgoing, &m)); 223 221 } 224 222 CHECK_FCT( fd_fifo_del(&p->p_tosend) ); … … 318 316 fd_peer_free(&peer); 319 317 } 318 319 /* Now empty the validators list */ 320 CHECK_FCT_DO( pthread_rwlock_wrlock(&validators_rw), /* continue */ ); 321 while (!FD_IS_LIST_EMPTY( &validators )) { 322 struct fd_list * v = validators.next; 323 fd_list_unlink(v); 324 free(v); 325 } 326 CHECK_FCT_DO( pthread_rwlock_unlock(&validators_rw), /* continue */ ); 320 327 321 328 return 0; … … 460 467 int fd_peer_validate_register ( int (*peer_validate)(struct peer_info * /* info */, int * /* auth */, int (**cb2)(struct peer_info *)) ) 461 468 { 462 463 TODO("..."); 464 return ENOTSUP; 465 } 466 467 /* Validate a peer by calling the callbacks in turn -- return 0 if the peer is validated, ! 0 in case of error or if the peer is rejected */ 469 struct fd_list * v; 470 471 TRACE_ENTRY("%p", peer_validate); 472 CHECK_PARAMS(peer_validate); 473 474 /* Alloc a new entry */ 475 CHECK_MALLOC( v = malloc(sizeof(struct fd_list)) ); 476 fd_list_init( v, peer_validate ); 477 478 /* Add at the beginning of the list */ 479 CHECK_FCT( pthread_rwlock_wrlock(&validators_rw) ); 480 fd_list_insert_after(&validators, v); 481 CHECK_FCT( pthread_rwlock_unlock(&validators_rw)); 482 483 /* Done! */ 484 return 0; 485 } 486 487 /* Validate a peer by calling the callbacks in turn -- return 0 if the peer is validated, ! 0 in case of error (>0) or if the peer is rejected (-1) */ 468 488 int fd_peer_validate( struct fd_peer * peer ) 469 489 { 470 TODO("Default to reject"); 471 TODO("Call all callbacks in turn"); 472 TODO("Save cb2 in the peer if needed"); 473 return ENOTSUP; 474 } 490 int ret = 0; 491 struct fd_list * v; 492 493 CHECK_FCT( pthread_rwlock_rdlock(&validators_rw) ); 494 for (v = validators.next; v != &validators; v = v->next) { 495 int auth = 0; 496 pthread_cleanup_push(fd_cleanup_rwlock, &validators_rw); 497 CHECK_FCT_DO( ret = ((int(*)(struct peer_info *, int *, int (**)(struct peer_info *)))(v->o)) (&peer->p_hdr.info, &auth, &peer->p_cb2), goto out ); 498 pthread_cleanup_pop(0); 499 if (auth) { 500 ret = (auth > 0) ? 0 : -1; 501 goto out; 502 } 503 peer->p_cb2 = NULL; 504 } 505 506 /* No callback has given a firm result, the default is to reject */ 507 ret = -1; 508 out: 509 CHECK_FCT( pthread_rwlock_unlock(&validators_rw)); 510 return ret; 511 }
Note: See TracChangeset
for help on using the changeset viewer.