]> git.ipfire.org Git - thirdparty/opentracker.git/commitdiff
Every cool project needs at least one header file
authorerdgeist <>
Thu, 7 Dec 2006 01:31:30 +0000 (01:31 +0000)
committererdgeist <>
Thu, 7 Dec 2006 01:31:30 +0000 (01:31 +0000)
trackerlogic.h [new file with mode: 0644]

diff --git a/trackerlogic.h b/trackerlogic.h
new file mode 100644 (file)
index 0000000..46efb57
--- /dev/null
@@ -0,0 +1,60 @@
+#ifndef __TRACKERLOGIC_H__
+#define __TRACKERLOGIC_H__
+
+/* Should be called BYTE, WORD, DWORD - but some OSs already have that and there's no #iftypedef */
+/* They mark memory used as data instead of integer or human readable string -
+   they should be cast before used as integer/text */
+typedef unsigned char  ot_byte;
+typedef unsigned short ot_word;
+typedef unsigned long  ot_dword;
+
+typedef unsigned long  ot_time;
+typedef ot_byte        ot_hash[20];
+typedef ot_byte        ot_ip[ 4/*0*/ ];
+// tunables
+const unsigned long OT_TIMEOUT          = 2700;
+const unsigned long OT_HUGE_FILESIZE    = 1024*1024*256; // Thats 256MB per file, enough for 204800 peers of 128 bytes
+
+// We will not service v6, yes
+#define OT_COMPACT_ONLY
+
+#define MEMMOVE              memmove
+#define BZERO                bzero
+#define FORMAT_FIXED_STRING  sprintf
+#define FORMAT_FORMAT_STRING sprintf
+#define BINARY_FIND          binary_search
+#define NOW                  time(NULL)
+
+typedef struct ot_peer {
+#ifndef OT_COMPACT_ONLY
+  ot_hash id;
+  ot_hash key;
+#endif
+  ot_ip   ip;
+  ot_word port;
+  ot_time death;
+  ot_byte flags;
+} *ot_peer;
+ot_byte PEER_FLAG_SEEDING   = 0x80;
+ot_byte PEER_IP_LENGTH_MASK = 0x3f;
+
+typedef struct {
+  ot_hash       hash;
+  ot_peer       peer_list;
+  unsigned long peer_count;
+  unsigned long seed_count;
+} *ot_torrent;
+
+void *map_file( char *file_name );
+void  unmap_file( char *file_name, void *map, unsigned long real_size );
+
+// This behaves quite like bsearch but allows to find
+// the insertion point for inserts after unsuccessful searches
+// in this case exactmatch is 0 on exit
+//
+void *binary_search( const void *key, const void *base,
+                     const unsigned long member_count, const unsigned long member_size,
+                     int (*compar) (const void *, const void *),
+                     int *exactmatch );
+
+#endif