cbf930bc7114f6bdb3eb4184c27000b52c3bcc3e
[swifty.git] / src / raw / swift_types.h
1 /*
2  * swift data structures
3  *
4  * swift struct sockaddr is dubbed struct sockaddr_sw.
5  * swhdr is swift packet header (as delivered on the network).
6  *
7  * 2011, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
8  */
9
10 #ifndef SWIFT_TYPES_
11 #define SWIFT_TYPES_    1
12
13 #include <sys/types.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 /*
22  * 143 is a free IP protocol number (as shown in /etc/protocols
23  * and <netinet/in.h>).
24  */
25
26 #define IPPROTO_SWIFT           143
27
28 /*
29  * swift address
30  *   - IP address (Network Layer)
31  *   - file hash (or hash for part of a file)
32  *       - a seeder (sender) publishes that hash
33  *       - a leecher (receiver) requests that hash
34  *       - stands as port number both for sender and receiver
35  */
36
37 #define SWIFT_HASH_SIZE         8
38
39 struct sw_hash {
40         unsigned char h_array[SWIFT_HASH_SIZE];
41 };
42
43 struct sockaddr_sw {
44         __SOCKADDR_COMMON(sin_);
45         struct in_addr sin_addr;
46         struct sw_hash sw_hash;
47
48         /* Pad to size of `struct sockaddr'.  */
49         unsigned char sw_zero[sizeof(struct sockaddr) -
50                 __SOCKADDR_COMMON_SIZE -
51                 sizeof(struct sw_hash) -
52                 sizeof(struct in_addr)];
53 };
54
55 /*
56  * swift header (work in progress)
57  */
58
59 struct swhdr {
60         /* file hash (to be seeded or requested) */
61         u_int8_t base_hash[SWIFT_HASH_SIZE];
62         /* TODO */
63 };
64
65 #ifdef __cplusplus
66 }
67 #endif
68
69 #endif /* SWIFT_TYPES_ */