forked from contiki-os/contiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeluge.h
159 lines (133 loc) · 4.22 KB
/
deluge.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* Copyright (c) 2007, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*/
/**
* \file
* Header for Deluge.
* \author
* Nicolas Tsiftes <[email protected]>
*/
#ifndef DELUGE_H
#define DELUGE_H
#include "net/rime/rime.h"
PROCESS_NAME(deluge_process);
#define LONG_TIMER(et, counter, time) \
do { \
for (counter = 0; counter < time; counter++) { \
etimer_set(&et, CLOCK_SECOND); \
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); \
} \
} while (0)
#define DELUGE_UNICAST_CHANNEL 55
#define DELUGE_BROADCAST_CHANNEL 56
/* All the packets in a page have been received. */
#define PAGE_COMPLETE 1
/* All pages up to, and including, this page are complete. */
#define PAGE_AVAILABLE 1
#define S_PKT 64 /* Deluge packet size. */
#define N_PKT 4 /* Packets per page. */
#define S_PAGE (S_PKT * N_PKT) /* Fixed page size. */
/* Bounds for the round time in seconds. */
#define T_LOW 2
#define T_HIGH 64
/* Random interval for request transmissions in jiffies. */
#define T_R (CLOCK_SECOND * 2)
/* Bound for the number of advertisements. */
#define CONST_K 1
/* The number of pages in this object. */
#define OBJECT_PAGE_COUNT(obj) (((obj).size + (S_PAGE - 1)) / S_PAGE)
#define ALL_PACKETS ((1 << N_PKT) - 1)
#define DELUGE_CMD_SUMMARY 1
#define DELUGE_CMD_REQUEST 2
#define DELUGE_CMD_PACKET 3
#define DELUGE_CMD_PROFILE 4
#define DELUGE_STATE_MAINTAIN 1
#define DELUGE_STATE_RX 2
#define DELUGE_STATE_TX 3
#define CONST_LAMBDA 2
#define CONST_ALPHA 0.5
#define CONST_OMEGA 8
#define ESTIMATED_TX_TIME (CLOCK_SECOND)
typedef uint8_t deluge_object_id_t;
struct deluge_msg_summary {
uint8_t cmd;
uint8_t version;
uint8_t highest_available;
deluge_object_id_t object_id;
};
struct deluge_msg_request {
uint8_t cmd;
uint8_t version;
uint8_t pagenum;
uint8_t request_set;
deluge_object_id_t object_id;
};
struct deluge_msg_packet {
uint8_t cmd;
uint8_t version;
uint8_t pagenum;
uint8_t packetnum;
uint16_t crc;
deluge_object_id_t object_id;
unsigned char payload[S_PKT];
};
struct deluge_msg_profile {
uint8_t cmd;
uint8_t version;
uint8_t npages;
deluge_object_id_t object_id;
uint8_t version_vector[];
};
struct deluge_object {
char *filename;
uint16_t object_id;
uint16_t size;
uint8_t version;
uint8_t update_version;
struct deluge_page *pages;
uint8_t current_rx_page;
int8_t current_tx_page;
uint8_t nrequests;
uint8_t current_page[S_PAGE];
uint8_t tx_set;
int cfs_fd;
linkaddr_t summary_from;
};
struct deluge_page {
uint32_t packet_set;
uint16_t crc;
clock_time_t last_request;
clock_time_t last_data;
uint8_t flags;
uint8_t version;
};
int deluge_disseminate(char *file, unsigned version);
#endif