void peers_connect_to_acceptors(struct peers* p) { int i; for (i = 0; i < evpaxos_acceptor_count(p->config); i++) { struct sockaddr_in addr = evpaxos_acceptor_address(p->config, i); peers_connect(p, i, &addr); } }
struct evproposer* evproposer_init(int id, const char* config_file, struct event_base* b) { int i; struct evproposer* p; struct config* conf = read_config(config_file); //读取配置文件 if (conf == NULL) return NULL; // Check id validity of proposer_id if (id < 0 || id >= MAX_N_OF_PROPOSERS) { //检查proposerid paxos_log_error("Invalid proposer id: %d", id); return NULL; } p = malloc(sizeof(struct evproposer)); p->id = id; p->base = b; p->preexec_window = paxos_config.proposer_preexec_window; //128 // Setup client listener p->receiver = tcp_receiver_new(b, &conf->proposers[id], handle_request, p); //创建新的接收器 // Setup connections to acceptors p->acceptors = peers_new(b, conf->acceptors_count); //连接池 for (i = 0; i < conf->acceptors_count; i++) peers_connect(p->acceptors, &conf->acceptors[i], handle_request, p); //连接各个acceptor // Setup timeout p->tv.tv_sec = paxos_config.proposer_timeout; p->tv.tv_usec = 0; p->timeout_ev = evtimer_new(b, proposer_check_timeouts, p); event_add(p->timeout_ev, &p->tv); //添加超时事件 p->state = proposer_new(p->id, conf->acceptors_count); //创建新的proposer状态机 free_config(conf); return p; }