1 #ifndef PACHI_DISTRIBUTED_PROTOCOL_H
2 #define PACHI_DISTRIBUTED_PROTOCOL_H
4 #include <sys/socket.h>
10 /* Each slave thread maintains a ring of 256 buffers holding
11 * incremental stats received from the slave. The oldest
12 * buffer is recycled to hold stats sent to the slave and
13 * received the next reply. */
14 #define BUFFERS_PER_SLAVE_BITS 8
15 #define BUFFERS_PER_SLAVE (1 << BUFFERS_PER_SLAVE_BITS)
18 typedef void (*buffer_hook
)(void *buf
, int size
);
19 typedef void (*state_alloc_hook
)(struct slave_state
*sstate
);
20 typedef int (*getargs_hook
)(void *buf
, struct slave_state
*sstate
, int cmd_id
);
24 /* All buffers have the same physical size. size is the
25 * number of valid bytes. It is set only when the buffer
26 * is actually in the receive queueue. */
35 struct in_addr client
; // for debugging only
36 state_alloc_hook alloc_hook
;
37 buffer_hook insert_hook
;
38 getargs_hook args_hook
;
40 /* Index in received_queue of most recent processed
41 * buffer, -1 if none processed yet. */
44 /* --- PRIVATE DATA for protocol.c --- */
46 struct buf_state b
[BUFFERS_PER_SLAVE
];
50 /* --- PRIVATE DATA for merge.c --- */
52 /* Hash table of incremental stats. */
53 struct incr_stats
*stats_htable
;
57 /* Hash indices updated by stats merge. */
61 extern struct slave_state default_sstate
;
63 void protocol_lock(void);
64 void protocol_unlock(void);
66 void logline(struct in_addr
*client
, char *prefix
, char *s
);
68 void clear_receive_queue(void);
69 void update_cmd(struct board
*b
, char *cmd
, char *args
, bool new_id
);
70 void new_cmd(struct board
*b
, char *cmd
, char *args
);
71 void get_replies(double time_limit
, int min_replies
);
72 void protocol_init(char *slave_port
, char *proxy_port
, int max_slaves
);
74 extern int reply_count
;
75 extern char **gtp_replies
;
76 extern int active_slaves
;
78 /* All binary buffers received from all slaves in current move are in
79 * receive_queue[0..queue_length-1] */
80 extern struct buf_state
**receive_queue
;
81 extern int queue_length
;
82 /* Queue age is incremented each time the queue is emptied. */
85 /* Max size of all gtp commands for one game.
86 * 60 chars for the first line of genmoves plus 100 lines
87 * of 30 chars each for the stats at last move. */
88 #define CMDS_SIZE (60*MAX_GAMELEN + 30*100)
90 /* Max size for one line of reply or slave log. */