func main() {
	timestamp.InitTimeStamp()
	for {
		fmt.Println(timestamp.GetTimeStamp())
		time.Sleep(time.Second)
	}
}
func (mul *Multicast) SendUniMessage(kind string, str string, dest string, timeout int) {
	// a:= message.Announcement{
	// 	Content: str,
	// }
	tsm := customtypes.TsMessage{
		Stamp:   timestamp.GetTimeStamp(),
		Group:   dest,
		Src:     mul.Info.Hostname,
		Kind:    kind,
		Content: str,
	}
	addr := mul.Info.AddrMap[dest]
	mul.sendMessage(addr, tsm)
}
// 	}
// }
func (mul *Multicast) LockRequest(group string) {
	fmt.Println(mul.GroupState[group])
	if mul.GroupState[group] == "wait" {
		mul.GroupState[group] = "request"
		mul.RequestStamp[group] = timestamp.GetTimeStamp()
		mul.RequestWait[group] = len(mul.Info.GroupMember[group]) - 1
		fmt.Println("size:", mul.RequestWait[group])
		mul.SendMulticast("lock_request", "request", group, 5000)
		// for {
		// 	if mul.GroupState[group]=="in" {
		// 		return
		// 	}
		// }
	} else {

	}
}
func (mul *Multicast) SendMulticast(kind string, str string, group string, timeout int) {
	// a:= message.Announcement{
	// 	Content: str,
	// }
	members := mul.Info.GroupMember[group]
	//	src:=members[mul.Info.Hostname]
	//	mul.groupVector[group].AddOneVector(src)
	//	ts := mul.groupVector[group]
	tsm := customtypes.TsMessage{
		Stamp:   timestamp.GetTimeStamp(),
		Group:   group,
		Src:     mul.Info.Hostname,
		Kind:    kind,
		Content: str,
	}
	for mem, _ := range members {
		if mem == mul.Info.Hostname {
			continue
		}
		addr := mul.Info.AddrMap[mem]
		mul.sendMessage(addr, tsm)
	}
}