diff options
author | irungentoo <irungentoo@gmail.com> | 2014-05-25 12:27:48 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-05-25 12:27:48 -0400 |
commit | 82e38883a239f265089982bc255de0f9db618ce7 (patch) | |
tree | 1d38b2ff978e86246695cc7e473af309eacdba2a /toxcore/assoc.c | |
parent | 9d53bc5d1dabd3142f58cafd9fffa18f783f96df (diff) | |
parent | 08ca08dcd952d55a0df75e5efa25a5d8afa70e3f (diff) |
Merge branch 'mannol1-Multicalls' into multi-av
Diffstat (limited to 'toxcore/assoc.c')
-rw-r--r-- | toxcore/assoc.c | 78 |
1 files changed, 26 insertions, 52 deletions
diff --git a/toxcore/assoc.c b/toxcore/assoc.c index 1015d83e..44128688 100644 --- a/toxcore/assoc.c +++ b/toxcore/assoc.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include "config.h" | 3 | #include "config.h" |
4 | #endif | 4 | #endif |
5 | 5 | ||
6 | #include "logger.h" | ||
6 | #include "DHT.h" | 7 | #include "DHT.h" |
7 | #include "assoc.h" | 8 | #include "assoc.h" |
8 | #include "ping.h" | 9 | #include "ping.h" |
@@ -523,9 +524,7 @@ static void client_id_self_update(Assoc *assoc) | |||
523 | assoc->self_hash = id_hash(assoc, assoc->self_client_id); | 524 | assoc->self_hash = id_hash(assoc, assoc->self_client_id); |
524 | } | 525 | } |
525 | 526 | ||
526 | #ifdef LOGGING | 527 | LOGGER_DEBUG("id is now set, purging cache of self-references"); |
527 | loglog("assoc: id is now set, purging cache of self-references...\n"); | ||
528 | #endif | ||
529 | 528 | ||
530 | /* if we already added some (or loaded some) entries, | 529 | /* if we already added some (or loaded some) entries, |
531 | * look and remove if we find a match | 530 | * look and remove if we find a match |
@@ -820,10 +819,8 @@ Assoc *new_Assoc(size_t bits, size_t entries, uint8_t *public_id) | |||
820 | entries_test = prime_upto_min9(entries_test - 1); | 819 | entries_test = prime_upto_min9(entries_test - 1); |
821 | 820 | ||
822 | if (entries_test != entries) { | 821 | if (entries_test != entries) { |
823 | #ifdef LOGGING | 822 | |
824 | sprintf(logbuffer, "new_Assoc(): trimmed %i to %i.\n", (int)entries, (int)entries_test); | 823 | LOGGER_DEBUG("trimmed %i to %i.\n", (int)entries, (int)entries_test); |
825 | loglog(logbuffer); | ||
826 | #endif | ||
827 | entries = (size_t)entries_test; | 824 | entries = (size_t)entries_test; |
828 | } | 825 | } |
829 | } | 826 | } |
@@ -872,7 +869,7 @@ void Assoc_self_client_id_changed(Assoc *assoc, uint8_t *id) | |||
872 | 869 | ||
873 | #ifdef LOGGING | 870 | #ifdef LOGGING |
874 | static char *idpart2str(uint8_t *id, size_t len); | 871 | static char *idpart2str(uint8_t *id, size_t len); |
875 | #endif | 872 | #endif /* LOGGING */ |
876 | 873 | ||
877 | /* refresh buckets */ | 874 | /* refresh buckets */ |
878 | void do_Assoc(Assoc *assoc, DHT *dht) | 875 | void do_Assoc(Assoc *assoc, DHT *dht) |
@@ -928,53 +925,31 @@ void do_Assoc(Assoc *assoc, DHT *dht) | |||
928 | break; | 925 | break; |
929 | } | 926 | } |
930 | 927 | ||
931 | #ifdef LOGGING | ||
932 | size_t total = 0, written = sprintf(logbuffer, "assoc: [%u] => ", | ||
933 | (uint32_t)(candidate % assoc->candidates_bucket_count)); | ||
934 | |||
935 | if (written > 0) | ||
936 | total += written; | ||
937 | |||
938 | #endif | ||
939 | |||
940 | if (seen) { | 928 | if (seen) { |
941 | IPPTsPng *ippts = seen->seen_family == AF_INET ? &seen->client.assoc4 : &seen->client.assoc6; | 929 | IPPTsPng *ippts = seen->seen_family == AF_INET ? &seen->client.assoc4 : &seen->client.assoc6; |
942 | #ifdef LOGGING | ||
943 | written = sprintf(logbuffer + total, " S[%s...] %s:%u", idpart2str(seen->client.client_id, 8), | ||
944 | ip_ntoa(&ippts->ip_port.ip), htons(ippts->ip_port.port)); | ||
945 | 930 | ||
946 | if (written > 0) | 931 | LOGGER_DEBUG("[%u] => S[%s...] %s:%u", (uint32_t)(candidate % assoc->candidates_bucket_count), |
947 | total += written; | 932 | idpart2str(seen->client.client_id, 8), ip_ntoa(&ippts->ip_port.ip), htons(ippts->ip_port.port)); |
948 | 933 | ||
949 | #endif | ||
950 | DHT_getnodes(dht, &ippts->ip_port, seen->client.client_id, target_id); | 934 | DHT_getnodes(dht, &ippts->ip_port, seen->client.client_id, target_id); |
951 | seen->getnodes = unix_time(); | 935 | seen->getnodes = unix_time(); |
952 | } | 936 | } |
953 | 937 | ||
954 | if (heard && (heard != seen)) { | 938 | if (heard && (heard != seen)) { |
955 | IP_Port *ipp = heard->heard_family == AF_INET ? &heard->assoc_heard4 : &heard->assoc_heard6; | 939 | IP_Port *ipp = heard->heard_family == AF_INET ? &heard->assoc_heard4 : &heard->assoc_heard6; |
956 | #ifdef LOGGING | ||
957 | written = sprintf(logbuffer + total, " H[%s...] %s:%u", idpart2str(heard->client.client_id, 8), ip_ntoa(&ipp->ip), | ||
958 | htons(ipp->port)); | ||
959 | 940 | ||
960 | if (written > 0) | 941 | LOGGER_DEBUG("[%u] => H[%s...] %s:%u", (uint32_t)(candidate % assoc->candidates_bucket_count), |
961 | total += written; | 942 | idpart2str(heard->client.client_id, 8), ip_ntoa(&ipp->ip), htons(ipp->port)); |
962 | 943 | ||
963 | #endif | ||
964 | DHT_getnodes(dht, ipp, heard->client.client_id, target_id); | 944 | DHT_getnodes(dht, ipp, heard->client.client_id, target_id); |
965 | heard->getnodes = unix_time(); | 945 | heard->getnodes = unix_time(); |
966 | } | 946 | } |
967 | 947 | ||
968 | #ifdef LOGGING | 948 | LOGGER_SCOPE ( |
969 | |||
970 | if (!heard && !seen) | ||
971 | sprintf(logbuffer + total, "no nodes to talk to??\n"); | ||
972 | else | ||
973 | /* for arcane reasons, sprintf(str, "\n") doesn't function */ | ||
974 | sprintf(logbuffer + total, "%s", "\n"); | ||
975 | 949 | ||
976 | loglog(logbuffer); | 950 | if ( !heard && !seen ) |
977 | #endif | 951 | LOGGER_DEBUG("[%u] => no nodes to talk to??", (uint32_t)(candidate % assoc->candidates_bucket_count)); |
952 | ); | ||
978 | } | 953 | } |
979 | } | 954 | } |
980 | 955 | ||
@@ -1008,11 +983,11 @@ static char *idpart2str(uint8_t *id, size_t len) | |||
1008 | void Assoc_status(Assoc *assoc) | 983 | void Assoc_status(Assoc *assoc) |
1009 | { | 984 | { |
1010 | if (!assoc) { | 985 | if (!assoc) { |
1011 | loglog("Assoc status: no assoc\n"); | 986 | LOGGER_INFO("Assoc status: no assoc"); |
1012 | return; | 987 | return; |
1013 | } | 988 | } |
1014 | 989 | ||
1015 | loglog("[b:p] hash => [id...] used, seen, heard\n"); | 990 | LOGGER_INFO("[b:p] hash => [id...] used, seen, heard"); |
1016 | 991 | ||
1017 | size_t bid, cid, total = 0; | 992 | size_t bid, cid, total = 0; |
1018 | 993 | ||
@@ -1023,24 +998,23 @@ void Assoc_status(Assoc *assoc) | |||
1023 | Client_entry *entry = &bucket->list[cid]; | 998 | Client_entry *entry = &bucket->list[cid]; |
1024 | 999 | ||
1025 | if (entry->hash) { | 1000 | if (entry->hash) { |
1026 | sprintf(logbuffer, "[%3i:%3i] %08x => [%s...] %i, %i(%c), %i(%c)\n", | ||
1027 | (int)bid, (int)cid, entry->hash, idpart2str(entry->client.client_id, 8), | ||
1028 | entry->used_at ? (int)(unix_time() - entry->used_at) : 0, | ||
1029 | entry->seen_at ? (int)(unix_time() - entry->seen_at) : 0, | ||
1030 | entry->seen_at ? (entry->seen_family == AF_INET ? '4' : (entry->seen_family == AF_INET6 ? '6' : '?')) : '?', | ||
1031 | entry->heard_at ? (int)(unix_time() - entry->heard_at) : 0, | ||
1032 | entry->heard_at ? (entry->heard_family == AF_INET ? '4' : (entry->heard_family == AF_INET6 ? '6' : '?')) : '?'); | ||
1033 | loglog(logbuffer); | ||
1034 | total++; | 1001 | total++; |
1002 | |||
1003 | LOGGER_INFO("[%3i:%3i] %08x => [%s...] %i, %i(%c), %i(%c)\n", | ||
1004 | (int)bid, (int)cid, entry->hash, idpart2str(entry->client.client_id, 8), | ||
1005 | entry->used_at ? (int)(unix_time() - entry->used_at) : 0, | ||
1006 | entry->seen_at ? (int)(unix_time() - entry->seen_at) : 0, | ||
1007 | entry->seen_at ? (entry->seen_family == AF_INET ? '4' : (entry->seen_family == AF_INET6 ? '6' : '?')) : '?', | ||
1008 | entry->heard_at ? (int)(unix_time() - entry->heard_at) : 0, | ||
1009 | entry->heard_at ? (entry->heard_family == AF_INET ? '4' : (entry->heard_family == AF_INET6 ? '6' : '?')) : '?'); | ||
1035 | } | 1010 | } |
1036 | } | 1011 | } |
1037 | } | 1012 | } |
1038 | 1013 | ||
1039 | if (total) { | 1014 | if (total) { |
1040 | sprintf(logbuffer, "Total: %i entries, table usage %i%%.\n", (int)total, | 1015 | LOGGER_INFO("Total: %i entries, table usage %i%%.\n", (int)total, |
1041 | (int)(total * 100 / (assoc->candidates_bucket_count * assoc->candidates_bucket_size))); | 1016 | (int)(total * 100 / (assoc->candidates_bucket_count * assoc->candidates_bucket_size))); |
1042 | loglog(logbuffer); | ||
1043 | } | 1017 | } |
1044 | } | 1018 | } |
1045 | 1019 | ||
1046 | #endif | 1020 | #endif /* LOGGING */ |