path: root/trackerlogic.h
diff options
authorerdgeist <>2008-12-06 18:46:00 +0000
committererdgeist <>2008-12-06 18:46:00 +0000
commit08c71627839a9134367db354c8255f7a720e1ff3 (patch)
treeb429abf6b3c26c7f851b522f5d4fb6797ad02d29 /trackerlogic.h
parenta4ed31d517f77a21afe12918a9cb256489daac74 (diff)
Renamed OT_FLAG to OT_PEERFLAG to make code easier to read
Introduced READ16/32 and WRITE16/32 makros to abstract loading/storing from unaligned addresses away on cpu's that can actually load/store everywhere Removed all unnecessary memmoves, especially where it only moved 6 bytes in inner loop. I replaced them with WRITE16/32(READ16/32()) makros
Diffstat (limited to 'trackerlogic.h')
1 files changed, 13 insertions, 4 deletions
diff --git a/trackerlogic.h b/trackerlogic.h
index 81bd97a..1705928 100644
--- a/trackerlogic.h
+++ b/trackerlogic.h
@@ -11,6 +11,15 @@
11#include <time.h> 11#include <time.h>
12#include <stdint.h> 12#include <stdint.h>
13 13
14/* Libowfat */
15#include <uint16.h>
16#include <uint32.h>
18#define READ16(addr,offs) ((int16_t)uint16_read((offs)+(uint8_t*)(addr)))
19#define READ32(addr,offs) ((int32_t)uint32_read((offs)+(uint8_t*)(addr)))
20#define WRITE16(addr,offs,val) uint16_pack((offs)+(uint8_t*)(addr),(val))
21#define WRITE32(addr,offs,val) uint32_pack((offs)+(uint8_t*)(addr),(val))
14typedef uint8_t ot_hash[20]; 23typedef uint8_t ot_hash[20];
15typedef time_t ot_time; 24typedef time_t ot_time;
16 25
@@ -55,10 +64,10 @@ static const uint8_t PEER_FLAG_STOPPED = 0x20;
55static const uint8_t PEER_FLAG_FROM_SYNC = 0x10; 64static const uint8_t PEER_FLAG_FROM_SYNC = 0x10;
56static const uint8_t PEER_FLAG_LEECHING = 0x00; 65static const uint8_t PEER_FLAG_LEECHING = 0x00;
57 66
58#define OT_SETIP( peer, ip ) memmove((peer),(ip),4); 67#define OT_SETIP(peer,ip) WRITE32((peer),0,READ32((ip),0))
59#define OT_SETPORT( peer, port ) memmove(((uint8_t*)peer)+4,(port),2); 68#define OT_SETPORT(peer,port) WRITE16((peer),4,READ16((port),0))
60#define OT_FLAG(peer) (((uint8_t*)(peer))[6]) 69#define OT_PEERFLAG(peer) (((uint8_t*)(peer))[6])
61#define OT_PEERTIME(peer) (((uint8_t*)(peer))[7]) 70#define OT_PEERTIME(peer) (((uint8_t*)(peer))[7])
62 71
63#define OT_PEER_COMPARE_SIZE ((size_t)6) 72#define OT_PEER_COMPARE_SIZE ((size_t)6)
64#define OT_HASH_COMPARE_SIZE (sizeof(ot_hash)) 73#define OT_HASH_COMPARE_SIZE (sizeof(ot_hash))