Example #1
0
//Process to listen incomming packets from other Servers.
func processInbox(server cluster.Server, SM *sm.State_Machine) {
	for {
		env := <-server.Inbox()
		switch env.Msg.(type) {
		case sm.VoteReq:
			SM.CommMedium.NetCh <- env.Msg
		case sm.VoteResp:
			SM.CommMedium.NetCh <- env.Msg
		case sm.AppEntrReq:
			SM.CommMedium.NetCh <- env.Msg
		case sm.AppEntrResp:
			SM.CommMedium.NetCh <- env.Msg
		}
	}
}
Example #2
0
//Process to send packets to other Servers.
func processOutbox(server cluster.Server, SM *sm.State_Machine, msg sm.Send) {
	//broadcast messagess.
	if msg.PeerId == 0 {
		switch msg.Event.(type) {
		case sm.AppEntrReq:
			AppReq := msg.Event.(sm.AppEntrReq)
			server.Outbox() <- &cluster.Envelope{Pid: cluster.BROADCAST, Msg: AppReq}
		case sm.VoteReq:
			VotReq := msg.Event.(sm.VoteReq)
			server.Outbox() <- &cluster.Envelope{Pid: cluster.BROADCAST, Msg: VotReq}
		}
	} else {
		//send to particular node.
		switch msg.Event.(type) {
		case sm.AppEntrReq:
			AppReq := msg.Event.(sm.AppEntrReq)
			server.Outbox() <- &cluster.Envelope{Pid: int(msg.PeerId), Msg: AppReq}
		case sm.AppEntrResp:
			AppResp := msg.Event.(sm.AppEntrResp)
			AppResp.Peer = int32(server.Pid())
			server.Outbox() <- &cluster.Envelope{Pid: int(msg.PeerId), Msg: AppResp}
		case sm.VoteResp:
			VotResp := msg.Event.(sm.VoteResp)
			server.Outbox() <- &cluster.Envelope{Pid: int(msg.PeerId), Msg: VotResp}
		}
	}
}