diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2023-02-27 00:14:33 +0100 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2023-02-27 00:14:33 +0100 |
commit | 07e8a1deaa45098e302e5bd85d1528c5c5992233 (patch) | |
tree | a61c78e27c8ee12718edd41dfa3f6506b8e5b983 /src/dht.c | |
parent | flask je prepočasen => src/metainfo.c (diff) | |
download | travnik-07e8a1deaa45098e302e5bd85d1528c5c5992233.tar travnik-07e8a1deaa45098e302e5bd85d1528c5c5992233.tar.gz travnik-07e8a1deaa45098e302e5bd85d1528c5c5992233.tar.bz2 travnik-07e8a1deaa45098e302e5bd85d1528c5c5992233.tar.lz travnik-07e8a1deaa45098e302e5bd85d1528c5c5992233.tar.xz travnik-07e8a1deaa45098e302e5bd85d1528c5c5992233.tar.zst travnik-07e8a1deaa45098e302e5bd85d1528c5c5992233.zip |
Diffstat (limited to 'src/dht.c')
-rw-r--r-- | src/dht.c | 41 |
1 files changed, 1 insertions, 40 deletions
@@ -20,6 +20,7 @@ #include <bencoding.c> #define STRX(x) #x #define STR(x) STRX(x) +#include <lib.c> time_t seconds (void) { struct timespec tp; @@ -34,46 +35,6 @@ int family (const unsigned char * addr) { #define K 8 /** - * writes a hexadecimal representation of a binary string. does not NULL terminate destination. - * - * h and b may not overlap. period. - * - * @param h [out] destination (requires 2l space) - * @param b [in] source - * @param l [in] length of source - */ - -void bin2hex (char * h, const unsigned char * b, size_t l) { - for (size_t i = 0; i < l; i++) { - int ms = b[i] >> 4; - int ls = b[i] & 0xF; - assert(ms < 16); - assert(ls < 16); - *h++ = ms < 10 ? '0'+ms : 'a'+ms-10; - *h++ = ls < 10 ? '0'+ls : 'a'+ls-10; - } -} - -/** - * converts a hexadecimal string to bytes - * - * b and h may not overlap, unless they are the same address - * - * @param b [out] array of bytes to write to with capacity l - * @param h [in] array of hex to read from with 2l hex digits - * @param l [in] length of output array - */ - -void hex2bin (unsigned char * b, const char * h, int l) { - for (int i = 0; i < l; i++) { - char ms = *h++; - char ls = *h++; - b[i] = (ms >= 'a' ? ms - 'a' + 10 : (ms >= 'A' ? ms - 'A' + 10 : ms - '0')) << 4; - b[i] |= (ls >= 'a' ? ls - 'a' + 10 : (ls >= 'A' ? ls - 'A' + 10 : ls - '0')); - } -} - -/** * node representation */ |