summaryrefslogtreecommitdiffstats
path: root/src/dht.c
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2023-02-27 00:14:33 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2023-02-27 00:14:33 +0100
commit07e8a1deaa45098e302e5bd85d1528c5c5992233 (patch)
treea61c78e27c8ee12718edd41dfa3f6506b8e5b983 /src/dht.c
parentflask je prepočasen => src/metainfo.c (diff)
downloadtravnik-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.c41
1 files changed, 1 insertions, 40 deletions
diff --git a/src/dht.c b/src/dht.c
index d97b80b..ba87fb7 100644
--- a/src/dht.c
+++ b/src/dht.c
@@ -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
*/