decls.h 2.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Shared for defintions for frisbee client/server code.
 */

#include "log.h"

/*
 * We operate in terms of this blocksize (in bytes). 
 */
#define BLOCKSIZE	1024

/*
 * Each chunk is this many blocks.
 */
#define CHUNKSIZE	1024

/*
 * The number of chunk buffers in the client.
 */
20
#define MAXCHUNKBUFS	64
21 22 23

/*
 * The number of read-ahead chunks that the client will request
24
 * at a time. No point in requesting too far ahead either, since they
25 26 27 28 29
 * are uncompressed/written at a fraction of the network transfer speed.
 * Also, with multiple clients at different stages, each requesting blocks
 * it is likely that there will be plenty more chunks ready or in progress.
 */
#define MAXREADAHEAD	2
30
#define MAXINPROGRESS	8
31 32 33 34 35

/*
 * Timeout (in usecs) for packet receive. The idletimer number is how
 * many PKT timeouts we allow before requesting more data from the server.
 * That is, if we go TIMEOUT usecs without getting a packet, then ask for
36
 * more.
37 38
 */
#define PKTRCV_TIMEOUT		30000
39
#define CLIENT_IDLETIMER_COUNT	3
40 41
#define TIMEOUT_HZ		(1000000 / PKTRCV_TIMEOUT)
#define TIMEOUT_HALFHZ		(TIMEOUT_HZ / 2)
42 43 44

/*
 * Timeout (in seconds!) server will hang around with no active clients.
45
 * Make it zero to never exit. 
46
 */
47
#define SERVER_INACTIVE_SECONDS	(60 * 30)
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

/*
 * The number of disk read blocks in a single read on the server.
 * Must be an even divisor of CHUNKSIZE.
 */
#define MAXREADBLOCKS	32

/*
 * Packet defs.
 */
typedef struct {
	struct {
		int		type;
		int		subtype;
		int		datalen; /* Useful amount of data in packet */
		unsigned int	srcip;   /* Filled in by network level. */
	} hdr;
	union {
		/*
		 * Join/leave the Team. Send a randomized ID, and receive
68 69 70
		 * the number of blocks in the file. This is strictly
		 * informational; the info is reported in the log file.
		 * We must return the number of chunks in the file though.
71 72 73 74 75
		 */
		union {
			unsigned int	clientid;
			int		blockcount;
		} join;
76 77 78 79 80
		
		struct {
			unsigned int	clientid;
			int		elapsed;	/* Stats only */
		} leave;
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

		/*
		 * A data block, indexed by chunk,block.
		 */
		struct {
			int		chunk;
			int		block;
			char		buf[BLOCKSIZE];
		} block;

		/*
		 * A request for a data block, indexed by chunk,block.
		 */
		struct {
			int		chunk;
			int		block;
			int		count;	/* Number of blocks */
		} request;
	} msg;
} Packet_t;
#define PKTTYPE_REQUEST		1
#define PKTTYPE_REPLY		2

#define PKTSUBTYPE_JOIN		1
#define PKTSUBTYPE_LEAVE	2
#define PKTSUBTYPE_BLOCK	3
#define PKTSUBTYPE_REQUEST	4

/*
 * Protos.
 */
int	ClientNetInit(void);
int	ServerNetInit(void);
int	PacketReceive(Packet_t *p);
int	PacketSend(Packet_t *p);
int	PacketReply(Packet_t *p);
char   *CurrentTimeString(void);
int	fsleep(unsigned int usecs);

/*
 * Globals
 */
extern int		debug;
extern int		portnum;
extern struct in_addr	mcastaddr;
extern struct in_addr	mcastif;
extern char	       *filename;