diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-06-16 19:22:49 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-06-16 19:22:49 +0000 |
commit | ddefc2b2e4b461cf8beae38ebda30ee8711cd5d2 (patch) | |
tree | 0c8790a1a26a69bd13d28cca9b4d90592a044475 /src | |
parent | 428625cb12c77dd4176c9f62923fa723dc4fb0e2 (diff) | |
download | gnunet-ddefc2b2e4b461cf8beae38ebda30ee8711cd5d2.tar.gz gnunet-ddefc2b2e4b461cf8beae38ebda30ee8711cd5d2.zip |
-proper data layout vpn record
Diffstat (limited to 'src')
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 15 | ||||
-rw-r--r-- | src/namestore/namestore_common.c | 43 |
2 files changed, 47 insertions, 11 deletions
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 7ce45e651..0753125d4 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -1593,6 +1593,8 @@ resolve_record_vpn (struct ResolverHandle *rh, | |||
1593 | struct GNUNET_CRYPTO_HashAsciiEncoded s_pid; | 1593 | struct GNUNET_CRYPTO_HashAsciiEncoded s_pid; |
1594 | struct GNUNET_HashCode serv_desc; | 1594 | struct GNUNET_HashCode serv_desc; |
1595 | struct GNUNET_CRYPTO_HashAsciiEncoded s_sd; | 1595 | struct GNUNET_CRYPTO_HashAsciiEncoded s_sd; |
1596 | char* pos; | ||
1597 | size_t len = (sizeof (uint32_t) * 2) + (sizeof (struct GNUNET_HashCode) * 2); | ||
1596 | 1598 | ||
1597 | /* We cancel here as to not include the ns lookup in the timeout */ | 1599 | /* We cancel here as to not include the ns lookup in the timeout */ |
1598 | if (rh->timeout_task != GNUNET_SCHEDULER_NO_TASK) | 1600 | if (rh->timeout_task != GNUNET_SCHEDULER_NO_TASK) |
@@ -1611,8 +1613,7 @@ resolve_record_vpn (struct ResolverHandle *rh, | |||
1611 | } | 1613 | } |
1612 | 1614 | ||
1613 | /* Extracting VPN information FIXME rd parsing with NS API?*/ | 1615 | /* Extracting VPN information FIXME rd parsing with NS API?*/ |
1614 | if (4 != SSCANF ((char*)rd, "%d:%d:%s:%s", &af, &proto, | 1616 | if (len != rd->data_size) |
1615 | (char*)&s_pid, (char*)&s_sd)) | ||
1616 | { | 1617 | { |
1617 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1618 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1618 | "GNS_PHASE_REC_VPN-%llu: Error parsing VPN RR!\n", | 1619 | "GNS_PHASE_REC_VPN-%llu: Error parsing VPN RR!\n", |
@@ -1621,6 +1622,16 @@ resolve_record_vpn (struct ResolverHandle *rh, | |||
1621 | return; | 1622 | return; |
1622 | } | 1623 | } |
1623 | 1624 | ||
1625 | pos = (char*)rd; | ||
1626 | memcpy (&af, pos, sizeof (uint32_t)); | ||
1627 | pos += sizeof (uint32_t); | ||
1628 | memcpy (&proto, pos, sizeof (uint32_t)); | ||
1629 | pos += sizeof (uint32_t); | ||
1630 | memcpy (&s_pid, pos, sizeof (struct GNUNET_HashCode)); | ||
1631 | pos += sizeof (struct GNUNET_HashCode); | ||
1632 | memcpy (&s_sd, pos, sizeof (struct GNUNET_HashCode)); | ||
1633 | |||
1634 | |||
1624 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_pid, &peer_id)) || | 1635 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_pid, &peer_id)) || |
1625 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_sd, &serv_desc))) | 1636 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_sd, &serv_desc))) |
1626 | { | 1637 | { |
diff --git a/src/namestore/namestore_common.c b/src/namestore/namestore_common.c index 15a48cf36..2b34a84e7 100644 --- a/src/namestore/namestore_common.c +++ b/src/namestore/namestore_common.c | |||
@@ -319,6 +319,13 @@ GNUNET_NAMESTORE_value_to_string (uint32_t type, | |||
319 | uint32_t soa_retry; | 319 | uint32_t soa_retry; |
320 | uint32_t soa_expire; | 320 | uint32_t soa_expire; |
321 | uint32_t soa_min; | 321 | uint32_t soa_min; |
322 | uint32_t *af; | ||
323 | uint32_t *proto; | ||
324 | char* vpn_str; | ||
325 | struct GNUNET_HashCode *h_peer; | ||
326 | struct GNUNET_HashCode *h_serv; | ||
327 | struct GNUNET_CRYPTO_HashAsciiEncoded s_peer; | ||
328 | struct GNUNET_CRYPTO_HashAsciiEncoded s_serv; | ||
322 | 329 | ||
323 | switch (type) | 330 | switch (type) |
324 | { | 331 | { |
@@ -377,7 +384,16 @@ GNUNET_NAMESTORE_value_to_string (uint32_t type, | |||
377 | case GNUNET_NAMESTORE_TYPE_LEHO: | 384 | case GNUNET_NAMESTORE_TYPE_LEHO: |
378 | return GNUNET_strndup (data, data_size); | 385 | return GNUNET_strndup (data, data_size); |
379 | case GNUNET_NAMESTORE_TYPE_VPN: | 386 | case GNUNET_NAMESTORE_TYPE_VPN: |
380 | return GNUNET_strndup (data, data_size); | 387 | af = (uint32_t*)data; |
388 | proto = (uint32_t*)((char*)af + sizeof (uint32_t)); | ||
389 | h_peer = (struct GNUNET_HashCode*)((char*)proto + sizeof (struct GNUNET_HashCode)); | ||
390 | h_serv = (struct GNUNET_HashCode*)((char*)h_peer + sizeof (struct GNUNET_HashCode)); | ||
391 | |||
392 | GNUNET_CRYPTO_hash_to_enc (h_peer, &s_peer); | ||
393 | GNUNET_CRYPTO_hash_to_enc (h_serv, &s_serv); | ||
394 | if (GNUNET_OK != GNUNET_asprintf (&vpn_str, "%d:%d:%s:%s", af, proto, (char*)&s_peer, (char*)&s_serv)) | ||
395 | return NULL; | ||
396 | return vpn_str; | ||
381 | default: | 397 | default: |
382 | GNUNET_break (0); | 398 | GNUNET_break (0); |
383 | } | 399 | } |
@@ -416,11 +432,12 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type, | |||
416 | uint32_t soa_retry; | 432 | uint32_t soa_retry; |
417 | uint32_t soa_expire; | 433 | uint32_t soa_expire; |
418 | uint32_t soa_min; | 434 | uint32_t soa_min; |
419 | struct GNUNET_HashCode hash; | 435 | struct GNUNET_HashCode *h_peer; |
436 | struct GNUNET_HashCode *h_serv; | ||
420 | struct GNUNET_CRYPTO_HashAsciiEncoded s_peer; | 437 | struct GNUNET_CRYPTO_HashAsciiEncoded s_peer; |
421 | struct GNUNET_CRYPTO_HashAsciiEncoded s_serv; | 438 | struct GNUNET_CRYPTO_HashAsciiEncoded s_serv; |
422 | int af; | 439 | uint32_t* af; |
423 | int proto; | 440 | uint32_t* proto; |
424 | 441 | ||
425 | switch (type) | 442 | switch (type) |
426 | { | 443 | { |
@@ -503,18 +520,26 @@ GNUNET_NAMESTORE_string_to_value (uint32_t type, | |||
503 | *data_size = strlen (s); | 520 | *data_size = strlen (s); |
504 | return GNUNET_OK; | 521 | return GNUNET_OK; |
505 | case GNUNET_NAMESTORE_TYPE_VPN: | 522 | case GNUNET_NAMESTORE_TYPE_VPN: |
523 | |||
524 | *data_size = sizeof (uint32_t) * 2; | ||
525 | *data_size += sizeof (struct GNUNET_HashCode) * 2; | ||
526 | *data = GNUNET_malloc (*data_size); | ||
527 | af = (uint32_t*)(*data); | ||
528 | proto = (uint32_t*) ((char*)af + sizeof (uint32_t)); | ||
529 | h_peer = (struct GNUNET_HashCode*)((char*)proto + sizeof (uint32_t)); | ||
530 | h_serv = (struct GNUNET_HashCode*)((char*)h_peer + sizeof (struct GNUNET_HashCode)); | ||
531 | |||
506 | if (4 != SSCANF (s,"%d:%d:%s:%s", | 532 | if (4 != SSCANF (s,"%d:%d:%s:%s", |
507 | &af, &proto, (char*)&s_peer, (char*)&s_serv)) | 533 | af, proto, (char*)&s_peer, (char*)&s_serv)) |
508 | { | 534 | { |
509 | return GNUNET_SYSERR; | 535 | return GNUNET_SYSERR; |
510 | } | 536 | } |
511 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_peer, &hash)) || | 537 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_peer, h_peer)) || |
512 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_serv, &hash))) | 538 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_serv, h_serv))) |
513 | { | 539 | { |
540 | GNUNET_free (*data); | ||
514 | return GNUNET_SYSERR; | 541 | return GNUNET_SYSERR; |
515 | } | 542 | } |
516 | *data = GNUNET_strdup (s); | ||
517 | *data_size = strlen (s); | ||
518 | return GNUNET_OK; | 543 | return GNUNET_OK; |
519 | default: | 544 | default: |
520 | GNUNET_break (0); | 545 | GNUNET_break (0); |