raw: Merge data.
[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 struct sw_state {
39         unsigned int state:4;
40         unsigned int info:4;
41 };
42
43 struct sw_hash {
44         u_int8_t h_array[SWIFT_HASH_SIZE];
45 };
46
47 struct sockaddr_sw {
48         __SOCKADDR_COMMON(sin_);
49         struct in_addr sin_addr;
50         struct sw_hash sw_hash;
51
52         /* Pad to size of `struct sockaddr'.  */
53         unsigned char sw_zero[sizeof(struct sockaddr) -
54                 __SOCKADDR_COMMON_SIZE -
55                 sizeof(struct sw_hash) -
56                 sizeof(struct in_addr)];
57 };
58
59 /*
60  * swift header (work in progress)
61  */
62
63 struct swhdr {
64         /* file hash (to be seeded or requested) */
65         struct sw_hash base_hash;
66         u_int8_t piece_hash;
67         struct sw_state sock_state;
68 };
69
70 #ifdef __cplusplus
71 }
72 #endif
73
74 #endif /* SWIFT_TYPES_ */