/* * do_traversal() * * Find final TGT needed to get CLIENT a ticket for SERVER. Point * OUT_TGT at the desired TGT, which may be an existing cached TGT * (copied into OUT_CC_TGT) or one of the newly obtained TGTs * (collected in OUT_KDC_TGTS). * * Get comfortable; this is somewhat complicated. * * Nomenclature: Cross-realm TGS principal names have the form: * * krbtgt/REMOTE@LOCAL * * krb5_walk_realm_tree() returns a list like: * * krbtgt/R1@R1, krbtgt/R2@R1, krbtgt/R3@R2, ... * * These are prinicpal names, not realm names. We only really use the * remote parts of the TGT principal names. * * The do_traversal loop calls next_closest_tgt() to find the next * closest TGT to the destination realm. next_closest_tgt() updates * NXT_KDC for the following iteration of the do_traversal() loop. * * At the beginning of any given iteration of the do_traversal() loop, * CUR_KDC's remote realm is the remote realm of CUR_TGT->SERVER. The * local realms of CUR_KDC and CUR_TGT->SERVER may not match due to * short-circuit paths provided by intermediate KDCs, e.g., CUR_KDC * might be krbtgt/D@C, while CUR_TGT->SERVER is krbtgt/D@B. * * For example, given KDC_LIST of * * krbtgt/R1@R1, krbtgt/R2@R1, krbtgt/R3@R2, krbtgt/R4@R3, * krbtgt/R5@R4 * * The next_closest_tgt() loop moves NXT_KDC to the left starting from * R5, stopping before it reaches CUR_KDC. When next_closest_tgt() * returns, the do_traversal() loop updates CUR_KDC to be NXT_KDC, and * calls next_closest_tgt() again. * * next_closest_tgt() at start of its loop: * * CUR NXT * | | * V V * +----+----+----+----+----+ * | R1 | R2 | R3 | R4 | R5 | * +----+----+----+----+----+ * * next_closest_tgt() returns after finding a ticket for krbtgt/R3@R1: * * CUR NXT * | | * V V * +----+----+----+----+----+ * | R1 | R2 | R3 | R4 | R5 | * +----+----+----+----+----+ * * do_traversal() updates CUR_KDC: * * NXT * CUR * | * V * +----+----+----+----+----+ * | R1 | R2 | R3 | R4 | R5 | * +----+----+----+----+----+ * * next_closest_tgt() at start of its loop: * * CUR NXT * | | * V V * +----+----+----+----+----+ * | R1 | R2 | R3 | R4 | R5 | * +----+----+----+----+----+ * * etc. * * The algorithm executes in n*(n-1)/2 (the sum of integers from 1 to * n-1) attempts in the worst case, i.e., each KDC only has a * cross-realm ticket for the immediately following KDC in the transit * path. Typically, short-circuit paths will cause execution occur * faster than this worst-case scenario. * * When next_closest_tgt() updates NXT_KDC, it may not perform a * simple increment from CUR_KDC, in part because some KDC may * short-circuit pieces of the transit path. */ static krb5_error_code do_traversal(krb5_context ctx, krb5_ccache ccache, krb5_principal client, krb5_principal server, krb5_creds *out_cc_tgt, krb5_creds **out_tgt, krb5_creds ***out_kdc_tgts) { krb5_error_code retval; struct tr_state state, *ts; *out_tgt = NULL; *out_kdc_tgts = NULL; ts = &state; memset(ts, 0, sizeof(*ts)); ts->ctx = ctx; ts->ccache = ccache; init_cc_tgts(ts); retval = init_rtree(ts, client, server); if (retval) goto cleanup; retval = retr_local_tgt(ts, client); if (retval) goto cleanup; for (ts->cur_kdc = ts->kdc_list, ts->nxt_kdc = NULL; ts->cur_kdc != NULL && ts->cur_kdc < ts->lst_kdc; ts->cur_kdc = ts->nxt_kdc, ts->cur_tgt = ts->nxt_tgt) { retval = next_closest_tgt(ts, client); if (retval) goto cleanup; assert(ts->cur_kdc != ts->nxt_kdc); } if (NXT_TGT_IS_CACHED(ts)) { *out_cc_tgt = *ts->cur_cc_tgt; *out_tgt = out_cc_tgt; MARK_CUR_CC_TGT_CLEAN(ts); } else { /* CUR_TGT is somewhere in KDC_TGTS; no need to copy. */ *out_tgt = ts->nxt_tgt; } cleanup: clean_cc_tgts(ts); if (ts->kdc_list != NULL) krb5_free_realm_tree(ctx, ts->kdc_list); if (ts->ntgts == 0) { *out_kdc_tgts = NULL; if (ts->kdc_tgts != NULL) free(ts->kdc_tgts); } else *out_kdc_tgts = ts->kdc_tgts; return retval; }
int main (int arc, char **argv) { int i,j; init_rtree(); insertar(obtener_raiz(),make_rect(1.0,3.0,2.0,2.5)); insertar(obtener_raiz(),make_rect(1.0,2.0,3.0,5.0)); insertar(obtener_raiz(),make_rect(2.0,3.0,1.0,2.0)); insertar(obtener_raiz(),make_rect(4.0,5.0,4.0,6.0)); insertar(obtener_raiz(),make_rect(4.0,6.0,3.0,6.0)); insertar(obtener_raiz(),make_rect(6.0,7.0,9.0,10.0)); insertar(obtener_raiz(),make_rect(7.0,8.0,10.0,11.0)); insertar(obtener_raiz(),make_rect(6.0,7.0,4.0,10.0)); insertar(obtener_raiz(),make_rect(9.0,9.5,5.0,10.0)); insertar(obtener_raiz(),make_rect(9.1,9.5,5.0,10.0)); insertar(obtener_raiz(),make_rect(9.2,9.6,5.0,10.0)); insertar(obtener_raiz(),make_rect(9.3,9.7,5.0,10.0)); insertar(obtener_raiz(),make_rect(9.4,9.8,5.0,10.0)); insertar(obtener_raiz(),make_rect(9.0,9.5,5.0,10.0)); insertar(obtener_raiz(),make_rect(9.0,9.5,5.0,10.0)); insertar(obtener_raiz(),make_rect(9.0,9.5,5.0,10.0)); insertar(obtener_raiz(),make_rect(9.0,9.5,5.0,10.0)); insertar(obtener_raiz(),make_rect(9.0,9.5,5.0,10.0)); insertar(obtener_raiz(),make_rect(9.0,9.5,5.0,10.0)); insertar(obtener_raiz(),make_rect(9.0,9.5,5.0,10.0)); imprimir_arbol(obtener_raiz(), -1, 0); Dynamic_array resultado = buscar(obtener_raiz(), make_rect(9.0,9.5,5.0,10.0)); printf("Buscar -> [%f,%f]x[%f,%f]\n", 9.0,9.5,5.0,10.0); for(j=0;j<resultado.used;j++) { printf(" Encontrado ->[%f,%f]X[%f,%f]\n", resultado.array[j].x1, resultado.array[j].x2, resultado.array[j].y1, resultado.array[j].y2); } //for(i=0;i<=rtree_ultimo;i++) // imprimir_nodo(leer_nodo(i)); //printf("--------------------------\n"); //printf("--------------------------\n"); //for (i=0;i <= rtree_ultimo; i++) //imprimir_nodo(leer_nodo(i)); return 0; // todo ok //imprimir_nodo(obtener_raiz()); //imprimir_nodo(leer_nodo(0)); //imprimir_nodo(leer_nodo(1)); //imprimir_nodo(leer_nodo(2)); return 0; // todo ok }
int main (int arc, char **argv) { int i, j; double dif; struct timeval before , after; Rectangulo rect; Nodo raiz; usar_linear_split = atoi(argv[1]); int num_rects = atoi(argv[2]); int num_repeticiones = atoi(argv[3]); srand((unsigned int)time(NULL)); // int n_rects[] = { 512, 4096, 32768, 262144, 2097152, 16777216}; // int n_exps[] = { 64, 32, 16, 8, 4, 2}; // int n_exps[] = { 1, 1, 1, 1, 1, 1}; gettimeofday(&before , NULL); for (j=0; j<num_repeticiones;j++){ // insertar en arbol init_rtree(); for (i=0; i<num_rects; i++){ rect = rectangulo_aleatorio(); raiz = obtener_raiz(); insertar(raiz, rect); } /* raiz = obtener_raiz(); // buscar en arbol for (i=0; i<num_rects/10; i++){ rect = rectangulo_aleatorio(); buscar(raiz, rect); } */ } gettimeofday(&after , NULL); dif = time_diff(before , after); printf("Estuve %f segundos duermiendo\n", dif); return 0; }