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