Files
@ f6e991030a70
Branch filter:
Location: DistRen/src/common/protocol.h - annotation
f6e991030a70
8.7 KiB
text/plain
tabletennis_del_client() actually deletes the client if it's not at the front of one of the PING or PONG queues (fixing a segfault).
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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | 2a6cba487424 abcf8952747b 2a6cba487424 2a6cba487424 2a6cba487424 2a6cba487424 2a6cba487424 2a6cba487424 2a6cba487424 2a6cba487424 2a6cba487424 2a6cba487424 2a6cba487424 2a6cba487424 2a6cba487424 2a6cba487424 2a6cba487424 2a6cba487424 2a6cba487424 4ca5ce00932e 4ca5ce00932e 4ca5ce00932e 7d1fd1fe48fc 4ca5ce00932e 4ca5ce00932e 2a6cba487424 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 bbfee659a30a bbfee659a30a bbfee659a30a bbfee659a30a da79b5082151 bbfee659a30a bbfee659a30a da79b5082151 da79b5082151 2a6cba487424 2a6cba487424 da79b5082151 4757644414d3 da79b5082151 4757644414d3 4757644414d3 4757644414d3 c6a12058c9da da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 c6a12058c9da c6a12058c9da da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 144cab775ebd da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 4757644414d3 22ee38bf8490 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 22ee38bf8490 4757644414d3 144cab775ebd 4757644414d3 da79b5082151 da79b5082151 da79b5082151 da79b5082151 4757644414d3 4757644414d3 4757644414d3 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 4757644414d3 da79b5082151 4757644414d3 4757644414d3 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 4757644414d3 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 4757644414d3 4757644414d3 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 c6a12058c9da da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 144cab775ebd da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 4757644414d3 4ca5ce00932e 4ca5ce00932e 4ca5ce00932e 4ca5ce00932e eb391af42d62 4ca5ce00932e 7d1fd1fe48fc 7d1fd1fe48fc 4ca5ce00932e 4ca5ce00932e 7c0e60f07a51 4ca5ce00932e da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 7c0e60f07a51 7c0e60f07a51 7c0e60f07a51 da79b5082151 da79b5082151 da79b5082151 ef03a563218c 4ca5ce00932e 4ca5ce00932e 4ca5ce00932e c6a12058c9da c6a12058c9da c6a12058c9da c6a12058c9da c6a12058c9da c6a12058c9da c6a12058c9da c6a12058c9da c6a12058c9da c6a12058c9da c6a12058c9da c6a12058c9da c6a12058c9da 4ca5ce00932e ef03a563218c ef03a563218c eb391af42d62 eb391af42d62 7d1fd1fe48fc 7d1fd1fe48fc 7d1fd1fe48fc 7d1fd1fe48fc da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 da79b5082151 ef03a563218c 4ca5ce00932e 4ca5ce00932e 4ca5ce00932e ef03a563218c ef03a563218c ef03a563218c ef03a563218c ef03a563218c ef03a563218c ef03a563218c ef03a563218c 4ca5ce00932e | /*
Copyright 2010 Nathan Phillip Brink
This file is a part of DistRen.
DistRen is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DistRen is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with DistRen. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DISTREN_PROTOCOL_H
#define DISTREN_PROTOCOL_H
#include <stddef.h>
#include <stdint.h>
/**
* Server types:
*
* It is assumed that any client has at least the functionality of a
* normal client (i.e., accepts all of the REQUIRED requests). These
* bitmask values add to the types of requests one may make to a
* server. After first connecting to a server or receiving a
* connection, a client shall send a DISTREN_REQUEST_VERSION packet
* describing its version.
*/
#define DISTREN_SERVERTYPE_SUBMIT (0x1)
#define DISTREN_SERVERTYPE_DISTRIBUTE (0x2)
#define DISTREN_SERVERTYPE_RENDER (0x4)
#define DISTREN_SERVERTYPE_CLIENT (0x8)
/**
* This file defines the constants and structs that distren clients
* and server use to converse.
*/
/**
* List of request types and metadata.
*/
enum distren_request_type
{
/**
* identifies the version of software being used by the sender and
* tells if it is a client or server. Sends PACKAGE_STRING as well
* as informing the other server what type of server this is.
*
* DATA: struct distren_request followed by PACKAGE_STRING. The length of PACKAGE_STRING must be no longer than 32 bytes.
*
* REQUIRED: ALL
*/
DISTREN_REQUEST_VERSION = 1,
/**
* DATA: up to 32 bytes of a PING cookie
*
* REQUIRED: ALL
*/
DISTREN_REQUEST_PING = 2,
/**
* DATA: up to 32 bytes copied from a received PING cookie
*
* REQUIRED: ALL
*/
DISTREN_REQUEST_PONG = 3,
/**
* The data is the a reason describing why the one end is
* disconnecting. The other end should respectfully close()
* the socket or the sender will timeout shortly.
*
* DATA: A string describing the reason for the connection's
* termination.
*
* REQUIRED: ALL
*/
DISTREN_REQUEST_DISCONNECT = 4,
/**
* DATA: struct distren_request_submit
*
* REQUIRED: DISTREN_SERVERTYPE_SUBMIT
*/
DISTREN_REQUEST_SUBMIT = 5,
/**
* Inform the other party about a job.
*
* DATA: struct distren_request_jobinfo
*
* REQUIRED: ALL
*/
DISTREN_REQUEST_JOBINFO = 6,
/**
* Request a DISTREN_REQUEST_JOBINFO
*
* DATA: struct distren_request_jobinfo_get
*
* REQUIRED: DISTREN_SERVERTYPE_SUBMIT, DISTREN_SERVERTYPE_DISTRIBUTE
*/
DISTREN_REQUEST_JOBINFO_GET = 7,
/**
* Command the other party to render a frame
*
* DATA: struct distren_request_frame_render
*
* REQUIRED: DISTREN_SERVERTYPE_RENDER
*/
DISTREN_REQUEST_FRAME_RENDER = 8,
/**
* Inform the receiver of the sender's state, such as frames being
* rendered or jobs that need to be completed.
*
* DATA: struct distren_request_status
*
* REQUIRED: DISTREN_SERVERTYPE_RENDER, DISTREN_SERVERTYPE_DISTRIBUTE, DISTREN_SERVERTYPE_CLIENT
*/
DISTREN_REQUEST_STATUS = 9,
/**
* Request that the receiver send a DISTREN_REQUEST_FRAME_STATUS
* packet. No data because the sending party might not beforehand
* know what frames/jobs the receiving server is managing.
*
* DATA: (none)
*
* REQUIRED: DISTREN_SERVERTYPE_RENDER
*/
DISTREN_REQUEST_STATUS_GET = 10,
/**
* Allow a client to upload a job tarball over a remoteio line. A
* client that wants to do this must take care not to overbuffer
* his sendqueue so as to be able to respond to PING packets in
* time. A server receiving such a message will want to write the
* file as directly to disk as possible to avoid bagging a server
* down in swap.
*
* It is potential that if a server is DISTREN_SERVERTYPE_SUBMIT
* but not also DISTREN_SERVERTYPE_DISTRIBUTE, that this request
* would be relayed by the DISTREN_SERVERTYPE_SUBMIT server to a
* DISTREN_SERVERTYPE_DISTRIBUTE server so that other clients can
* obtain the file from the distribution server. In this case, the
* file's URL is already known.
*
* Of course, having this sort of functionality at all is where
* the nasty security issues start coming into play :-D.
*
* DATA: struct distren_request_file_post followed by a maximum of 131072 bytes (128kB).
*
* REQUIRED: DISTREN_SERVERTYPE_SUBMIT, DISTREN_SERVERTYPE_DISTRIBUTE
*/
DISTREN_REQUEST_FILE_POST = 11,
/**
* Request information about obtaining a file (such as a
* cURL-compatible URL) based on a distren file URL.
*
* DATA: struct distren_request_file_find
*
* REQUIRED: DISTREN_SERVERTYPE_DISTRIBUTE
*/
DISTREN_REQUEST_FILE_FIND = 12,
/**
* Provide information about obtaining a file (such as a URL).
*
* DATA: struct distren_request_file
*
* REQUIRED: DISTREN_SERVERTYPE_DISTRIBUTE
*/
DISTREN_REQUEST_FILE = 13,
};
struct distren_request
{
uint32_t magic;
/* the length of the data associated with the packet excluding the header */
uint32_t len;
/** treat type as an enum distren_request_type using casting */
uint32_t /* enum distren_request_type */ type;
};
#define DISTREN_REQUEST_VERSION_PACKAGE_STRING_LEN (32)
/**
* A DISTREN_REQUEST_VERSION is started with a bitmask specification
* of the DISTREN_SERVERTYPE_* values.
*/
struct distren_request_version
{
uint32_t servertype;
/* + 1 is for terminating NULL */
char package_string[DISTREN_REQUEST_VERSION_PACKAGE_STRING_LEN + 1];
};
/**
* initializes and allocates request
*/
int distren_request_new(struct distren_request **req, uint32_t len, enum distren_request_type type);
struct remoteio;
/**
Takes a struct distren_request and its associated data, allocates
a new block of data to hold the whole packet, and packets the req
header and data together.
@param rem A remoteio handle to ship this packet off to
@param req Something you initialized with distren_request_new(). You are responsible for distren_request_free()ing this yourself.
@param data A chunk of data the size of req->len. You are responsible for free()ing this yourself.
@return 0 on success and 1 on failure.
*/
int distren_request_send(struct remoteio *rem, struct distren_request *req, void *data);
/**
* initializes and allocates request based on raw input data
* which includes the headers of the request.
*
* @return 0 on success, 1 on failure
*/
int distren_request_new_fromdata(struct distren_request **req, void *data, size_t len);
/**
* Parses requests in a way suitable to be called from a
* remoteio_read_handle_func_t.
*
* If this function returns non-zero, you should handle the request
* and then call this function again (after shortening len and
* incrementing buf, of course).
*
* @param expectlen A pointer to a state variable that, if not NULL, can speed up this function. If you want to use this, you must set the variable to 0 before the first call and preserve the variable.
* @param buf the input buffer.
* @param len the length of buf.
* @param req a pointer to where we should set NULL if we don't have a full request or where we store the address of a newly allocated request. You should call distren_request_free() on this.
* @param req_data a pointer to where the request data pointer should be stored. This will just be set to a pointer in buf, so don't free() this.
* @param err this will be set to 0 if there is no error and to 1 if there is an error and the connection should be closed. You must check this.
* @return number of bytes that we have used from buf and that should be marked used.
*/
size_t distren_request_handle(size_t *expectlen,
void *buf,
size_t len,
struct distren_request **req,
void **req_data,
short *err);
/**
* frees request
*/
int distren_request_free(struct distren_request *req);
/**
* An implementation of remoteio_read_handle_func_t for use with remoteio.
*
* To use this handler, first initialize a struct distren_request_remoteio_data.
* (to be continued... or not...? ;-) )
*/
/* size_t distren_request_remoteio_handle(struct remoteio *rem, void *generic_data, void *buf, size_t len, void *data); */
#endif
|